diff options
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui')
3 files changed, 42 insertions, 6 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java index 687f43630..a8000d8d5 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java @@ -12,6 +12,7 @@ import net.minecraft.client.gui.GuiEventListener; import net.minecraft.client.render.GuiLighting; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.util.Window; +import net.minecraft.item.ItemStack; import net.minecraft.util.math.MathHelper; import java.awt.*; @@ -22,12 +23,12 @@ public class ContainerGuiOverlay extends Gui { public static String searchTerm = ""; private static int page = 0; + private static ItemListOverlay itemListOverlay; private final List<IWidget> widgets; private final List<QueuedTooltip> queuedTooltips; private Rectangle rectangle; private IMixinContainerGui containerGui; private Window window; - private static ItemListOverlay itemListOverlay; private ButtonWidget buttonLeft, buttonRight; public ContainerGuiOverlay(ContainerGui containerGui) { @@ -147,6 +148,8 @@ public class ContainerGuiOverlay extends Gui { @Override public void draw(int int_1, int int_2, float float_1) { + if (!GuiHelper.isOverlayVisible()) + return; widgets.forEach(widget -> { GuiLighting.disable(); widget.draw(int_1, int_2, float_1); @@ -193,6 +196,34 @@ public class ContainerGuiOverlay extends Gui { for(GuiEventListener listener : listeners) if (listener.keyPressed(int_1, int_2, int_3)) return true; + Point point = ClientHelper.getMouseLocation(); + ItemStack itemStack = null; + for(IWidget widget : itemListOverlay.getListeners()) + if (widget instanceof ItemSlotWidget && ((ItemSlotWidget) widget).isHighlighted(point.x, point.y)) { + itemStack = ((ItemSlotWidget) widget).getCurrentStack(); + break; + } + if (itemStack == null && MinecraftClient.getInstance().currentGui instanceof RecipeViewingWidget) { + RecipeViewingWidget recipeViewingWidget = (RecipeViewingWidget) MinecraftClient.getInstance().currentGui; + for(GuiEventListener entry : recipeViewingWidget.getEntries()) + if (entry instanceof ItemSlotWidget && ((ItemSlotWidget) entry).isHighlighted(point.x, point.y)) { + itemStack = ((ItemSlotWidget) entry).getCurrentStack(); + break; + } + } + if (itemStack == null && MinecraftClient.getInstance().currentGui instanceof ContainerGui) + if (containerGui.getHoveredSlot() != null) + itemStack = containerGui.getHoveredSlot().getStack(); + if (itemStack != null && !itemStack.isEmpty()) { + if (ClientHelper.RECIPE.matchesKey(int_1, int_2)) + return ClientHelper.executeRecipeKeyBind(this, itemStack, containerGui); + else if (ClientHelper.USAGE.matchesKey(int_1, int_2)) + return ClientHelper.executeUsageKeyBind(this, itemStack, containerGui); + } + if (ClientHelper.HIDE.matchesKey(int_1, int_2)) { + GuiHelper.toggleOverlayVisible(); + return true; + } return false; } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java index f87c5a291..bf3897c47 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java @@ -100,7 +100,7 @@ public class ItemSlotWidget extends Drawable implements HighlightableWidget { return ""; } - protected ItemStack getCurrentStack() { + public ItemStack getCurrentStack() { if (itemList.size() == 0) return new ItemStack(Items.AIR); return itemList.get(MathHelper.floor((System.currentTimeMillis() / 500 % (double) itemList.size()) / 1f)); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java index 90bde332d..365ed3cdd 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java @@ -6,6 +6,7 @@ import me.shedaniel.rei.api.IRecipeCategory; import me.shedaniel.rei.api.IRecipeDisplay; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; +import me.shedaniel.rei.client.RecipeHelper; import me.shedaniel.rei.listeners.IMixinContainerGui; import net.minecraft.client.MinecraftClient; import net.minecraft.client.audio.PositionedSoundInstance; @@ -18,8 +19,9 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import java.awt.*; -import java.util.*; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class RecipeViewingWidget extends Gui { @@ -46,8 +48,11 @@ public class RecipeViewingWidget extends Gui { this.widgets = Lists.newArrayList(); this.bounds = new Rectangle(window.getScaledWidth() / 2 - guiWidth / 2, window.getScaledHeight() / 2 - guiHeight / 2, guiWidth, guiHeight); this.categoriesMap = categoriesMap; - this.categories = new LinkedList<>(categoriesMap.keySet()); - Collections.reverse(categories); + this.categories = Lists.newArrayList(); + RecipeHelper.getCategories().forEach(category -> { + if (categoriesMap.containsKey(category)) + categories.add(category); + }); this.selectedCategory = categories.get(0); this.tabs = new ArrayList<>(); } @@ -172,7 +177,7 @@ public class RecipeViewingWidget extends Gui { widgets.addAll(selectedCategory.setupDisplay(getParent(), middleDisplay, new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 108, 150, 66))); } } - + GuiHelper.getOverlay(parent.getContainerGui()).onInitialized(); listeners.addAll(tabs); listeners.add(GuiHelper.getOverlay(parent.getContainerGui())); |
