aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-01-30 00:12:47 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-01-30 00:12:47 +0800
commite7ba883beed7d3d5697c1095249c7dd05518ba76 (patch)
tree4eb02c5643701791294dbe85fd704c5505bae272 /src/main/java
parente8353e0d95d00266e9b188a816b73ce7a4dc090b (diff)
downloadRoughlyEnoughItems-e7ba883beed7d3d5697c1095249c7dd05518ba76.tar.gz
RoughlyEnoughItems-e7ba883beed7d3d5697c1095249c7dd05518ba76.tar.bz2
RoughlyEnoughItems-e7ba883beed7d3d5697c1095249c7dd05518ba76.zip
Fixes Bugs
Close #13 Close #15 Close #18
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java4
-rw-r--r--src/main/java/me/shedaniel/rei/api/IRecipeCategory.java7
-rw-r--r--src/main/java/me/shedaniel/rei/api/SpeedCraftAreaSupplier.java4
-rw-r--r--src/main/java/me/shedaniel/rei/client/ClientHelper.java13
-rw-r--r--src/main/java/me/shedaniel/rei/client/GuiHelper.java34
-rw-r--r--src/main/java/me/shedaniel/rei/client/RecipeHelper.java63
-rw-r--r--src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java49
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java8
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/HighlightableWidget.java10
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java40
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java29
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/QueuedTooltip.java4
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java107
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/SpeedCraftingButtonWidget.java45
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java2
-rw-r--r--src/main/java/me/shedaniel/rei/listeners/IMixinContainerGui.java3
-rw-r--r--src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java16
-rw-r--r--src/main/java/me/shedaniel/rei/mixin/MixinContainerGui.java27
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultBlastingCategory.java9
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultBrewingCategory.java20
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultCampfireCategory.java7
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultCraftingCategory.java7
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java47
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultSmeltingCategory.java9
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultSmokingCategory.java9
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultStoneCuttingCategory.java8
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultStoneCuttingDisplay.java1
27 files changed, 291 insertions, 291 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
index 6c54394c7..308f3d571 100644
--- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
+++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
@@ -4,11 +4,13 @@ import com.google.common.collect.Maps;
import me.shedaniel.rei.api.IRecipePlugin;
import me.shedaniel.rei.client.ClientHelper;
import me.shedaniel.rei.client.ConfigHelper;
+import me.shedaniel.rei.client.GuiHelper;
import me.shedaniel.rei.client.RecipeHelper;
import me.shedaniel.rei.plugin.DefaultPlugin;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.api.loader.Loader;
+import net.fabricmc.fabric.events.client.ClientTickEvent;
import net.fabricmc.fabric.networking.CustomPayloadPacketRegistry;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.ItemStack;
@@ -71,6 +73,8 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
registerPlugin(new Identifier("roughlyenoughitems", "default_plugin"), new DefaultPlugin());
}
configHelper = new ConfigHelper();
+
+ ClientTickEvent.CLIENT.register(GuiHelper::onTick);
}
@Override
diff --git a/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java b/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java
index 5277321a1..cc2bb0e4a 100644
--- a/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java
+++ b/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java
@@ -4,7 +4,6 @@ import com.mojang.blaze3d.platform.GlStateManager;
import me.shedaniel.rei.gui.widget.IWidget;
import me.shedaniel.rei.gui.widget.RecipeBaseWidget;
import me.shedaniel.rei.gui.widget.RecipeViewingWidget;
-import me.shedaniel.rei.listeners.IMixinContainerGui;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.render.GuiLighting;
@@ -28,7 +27,7 @@ public interface IRecipeCategory<T extends IRecipeDisplay> {
return false;
}
- default public List<IWidget> setupDisplay(IMixinContainerGui containerGui, T recipeDisplay, Rectangle bounds) {
+ default public List<IWidget> setupDisplay(T recipeDisplay, Rectangle bounds) {
return Arrays.asList(new RecipeBaseWidget(bounds));
}
@@ -41,4 +40,8 @@ public interface IRecipeCategory<T extends IRecipeDisplay> {
}.drawTexturedRect((int) bounds.getX(), (int) bounds.getY(), 0, 0, (int) bounds.getWidth(), (int) bounds.getHeight());
}
+ default public boolean checkTags() {
+ return false;
+ }
+
}
diff --git a/src/main/java/me/shedaniel/rei/api/SpeedCraftAreaSupplier.java b/src/main/java/me/shedaniel/rei/api/SpeedCraftAreaSupplier.java
index 47e0a66cc..d4db1f072 100644
--- a/src/main/java/me/shedaniel/rei/api/SpeedCraftAreaSupplier.java
+++ b/src/main/java/me/shedaniel/rei/api/SpeedCraftAreaSupplier.java
@@ -6,4 +6,8 @@ public interface SpeedCraftAreaSupplier {
public Rectangle get(Rectangle bounds);
+ default String getButtonText() {
+ return "+";
+ }
+
}
diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelper.java b/src/main/java/me/shedaniel/rei/client/ClientHelper.java
index 86b099bc3..55061aa90 100644
--- a/src/main/java/me/shedaniel/rei/client/ClientHelper.java
+++ b/src/main/java/me/shedaniel/rei/client/ClientHelper.java
@@ -9,7 +9,6 @@ import me.shedaniel.rei.api.IRecipeDisplay;
import me.shedaniel.rei.gui.ContainerGuiOverlay;
import me.shedaniel.rei.gui.widget.ConfigWidget;
import me.shedaniel.rei.gui.widget.RecipeViewingWidget;
-import me.shedaniel.rei.listeners.IMixinContainerGui;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl;
@@ -116,17 +115,17 @@ public class ClientHelper implements ClientModInitializer {
}
}
- public static boolean executeRecipeKeyBind(ContainerGuiOverlay overlay, ItemStack stack, IMixinContainerGui parent) {
- Map<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getRecipesFor(stack);
+ public static boolean executeRecipeKeyBind(ContainerGuiOverlay overlay, ItemStack stack) {
+ Map<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getInstance().getRecipesFor(stack);
if (map.keySet().size() > 0)
- MinecraftClient.getInstance().openGui(new RecipeViewingWidget(MinecraftClient.getInstance().window, parent, map));
+ MinecraftClient.getInstance().openGui(new RecipeViewingWidget(MinecraftClient.getInstance().window, map));
return map.keySet().size() > 0;
}
- public static boolean executeUsageKeyBind(ContainerGuiOverlay overlay, ItemStack stack, IMixinContainerGui parent) {
- Map<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getUsagesFor(stack);
+ public static boolean executeUsageKeyBind(ContainerGuiOverlay overlay, ItemStack stack) {
+ Map<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getInstance().getUsagesFor(stack);
if (map.keySet().size() > 0)
- MinecraftClient.getInstance().openGui(new RecipeViewingWidget(MinecraftClient.getInstance().window, parent, map));
+ MinecraftClient.getInstance().openGui(new RecipeViewingWidget(MinecraftClient.getInstance().window, map));
return map.keySet().size() > 0;
}
diff --git a/src/main/java/me/shedaniel/rei/client/GuiHelper.java b/src/main/java/me/shedaniel/rei/client/GuiHelper.java
index 6fbb6a2a8..b962866f2 100644
--- a/src/main/java/me/shedaniel/rei/client/GuiHelper.java
+++ b/src/main/java/me/shedaniel/rei/client/GuiHelper.java
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import me.shedaniel.rei.gui.ContainerGuiOverlay;
import me.shedaniel.rei.gui.widget.TextFieldWidget;
import me.shedaniel.rei.listeners.IMixinContainerGui;
+import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.ContainerGui;
import net.minecraft.item.ItemStack;
@@ -15,6 +16,8 @@ public class GuiHelper {
private static boolean overlayVisible = true;
private static ContainerGuiOverlay overlay;
public static List<ItemStack> inventoryStacks = Lists.newArrayList();
+ private static ContainerGui lastContainerGui;
+ private static IMixinContainerGui lastMixinContainerGui;
public static boolean isOverlayVisible() {
return overlayVisible;
@@ -24,14 +27,6 @@ public class GuiHelper {
overlayVisible = !overlayVisible;
}
- public static ContainerGuiOverlay getOverlay(IMixinContainerGui lastGui) {
- if (overlay == null) {
- overlay = new ContainerGuiOverlay(lastGui);
- overlay.onInitialized();
- }
- return overlay;
- }
-
public static ContainerGuiOverlay getLastOverlay() {
return overlay;
}
@@ -41,8 +36,27 @@ public class GuiHelper {
overlay.onInitialized();
}
- public static void resetOverlay() {
- overlay = null;
+ public static void onTick(MinecraftClient client) {
+ if (client.currentGui instanceof ContainerGui && lastContainerGui != client.currentGui) {
+ GuiHelper.lastContainerGui = (ContainerGui) client.currentGui;
+ GuiHelper.lastMixinContainerGui = (IMixinContainerGui) lastContainerGui;
+ }
+ }
+
+ public static ContainerGui getLastContainerGui() {
+ return lastContainerGui;
+ }
+
+ public static IMixinContainerGui getLastMixinContainerGui() {
+ return lastMixinContainerGui;
+ }
+
+ public static void setLastContainerGui(ContainerGui lastContainerGui) {
+ GuiHelper.lastContainerGui = lastContainerGui;
+ }
+
+ public static void setLastMixinContainerGui(IMixinContainerGui lastMixinContainerGui) {
+ GuiHelper.lastMixinContainerGui = lastMixinContainerGui;
}
}
diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java
index 378eb2f59..0224933fa 100644
--- a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java
+++ b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java
@@ -15,20 +15,17 @@ import java.util.stream.Collectors;
public class RecipeHelper {
- private static Map<Identifier, List<IRecipeDisplay>> recipeCategoryListMap;
- private static List<IRecipeCategory> categories;
- private static RecipeManager recipeManager;
- private static Map<Identifier, SpeedCraftAreaSupplier> speedCraftAreaSupplierMap;
- private static Map<Identifier, List<SpeedCraftFunctional>> speedCraftFunctionalMap;
-
- public RecipeHelper() {
- this.recipeCategoryListMap = Maps.newHashMap();
- this.categories = Lists.newArrayList();
- this.speedCraftAreaSupplierMap = Maps.newHashMap();
- this.speedCraftFunctionalMap = Maps.newHashMap();
+ private final Map<Identifier, List<IRecipeDisplay>> recipeCategoryListMap = Maps.newHashMap();
+ private final List<IRecipeCategory> categories = Lists.newArrayList();
+ private final Map<Identifier, SpeedCraftAreaSupplier> speedCraftAreaSupplierMap = Maps.newHashMap();
+ private final Map<Identifier, List<SpeedCraftFunctional>> speedCraftFunctionalMap = Maps.newHashMap();
+ private RecipeManager recipeManager;
+
+ public static RecipeHelper getInstance() {
+ return RoughlyEnoughItemsCore.getRecipeHelper();
}
- public static List<ItemStack> findCraftableByItems(List<ItemStack> inventoryItems) {
+ public List<ItemStack> findCraftableByItems(List<ItemStack> inventoryItems) {
List<ItemStack> craftables = new ArrayList<>();
for(List<IRecipeDisplay> value : recipeCategoryListMap.values())
for(IRecipeDisplay recipeDisplay : value) {
@@ -57,25 +54,27 @@ public class RecipeHelper {
return craftables.stream().distinct().collect(Collectors.toList());
}
- public static void registerCategory(IRecipeCategory category) {
+ public void registerCategory(IRecipeCategory category) {
categories.add(category);
recipeCategoryListMap.put(category.getIdentifier(), Lists.newArrayList());
}
- public static void registerRecipe(Identifier categoryIdentifier, IRecipeDisplay display) {
+ public void registerRecipe(Identifier categoryIdentifier, IRecipeDisplay display) {
if (!recipeCategoryListMap.containsKey(categoryIdentifier))
return;
recipeCategoryListMap.get(categoryIdentifier).add(display);
}
- public static Map<IRecipeCategory, List<IRecipeDisplay>> getRecipesFor(ItemStack stack) {
+ public Map<IRecipeCategory, List<IRecipeDisplay>> getRecipesFor(ItemStack stack) {
Map<Identifier, List<IRecipeDisplay>> categoriesMap = new HashMap<>();
categories.forEach(f -> categoriesMap.put(f.getIdentifier(), new LinkedList<>()));
- for(List<IRecipeDisplay> value : recipeCategoryListMap.values())
- for(IRecipeDisplay recipeDisplay : value)
+ for(Map.Entry<Identifier, List<IRecipeDisplay>> entry : recipeCategoryListMap.entrySet()) {
+ IRecipeCategory category = getCategory(entry.getKey());
+ for(IRecipeDisplay recipeDisplay : entry.getValue())
for(ItemStack outputStack : (List<ItemStack>) recipeDisplay.getOutput())
- if (ItemStack.areEqualIgnoreTags(stack, outputStack))
+ if (category.checkTags() ? ItemStack.areEqual(stack, outputStack) : ItemStack.areEqualIgnoreTags(stack, outputStack))
categoriesMap.get(recipeDisplay.getRecipeCategory()).add(recipeDisplay);
+ }
categoriesMap.keySet().removeIf(f -> categoriesMap.get(f).isEmpty());
Map<IRecipeCategory, List<IRecipeDisplay>> recipeCategoryListMap = Maps.newHashMap();
categories.forEach(category -> {
@@ -85,19 +84,24 @@ public class RecipeHelper {
return recipeCategoryListMap;
}
- public static RecipeManager getRecipeManager() {
+ private IRecipeCategory getCategory(Identifier identifier) {
+ return categories.stream().filter(category -> category.getIdentifier().equals(identifier)).findFirst().orElse(null);
+ }
+
+ public RecipeManager getRecipeManager() {
return recipeManager;
}
- public static Map<IRecipeCategory, List<IRecipeDisplay>> getUsagesFor(ItemStack stack) {
+ public Map<IRecipeCategory, List<IRecipeDisplay>> getUsagesFor(ItemStack stack) {
Map<Identifier, List<IRecipeDisplay>> categoriesMap = new HashMap<>();
categories.forEach(f -> categoriesMap.put(f.getIdentifier(), new LinkedList<>()));
- for(List<IRecipeDisplay> value : recipeCategoryListMap.values())
- for(IRecipeDisplay recipeDisplay : value) {
+ for(Map.Entry<Identifier, List<IRecipeDisplay>> entry : recipeCategoryListMap.entrySet()) {
+ IRecipeCategory category = getCategory(entry.getKey());
+ for(IRecipeDisplay recipeDisplay : entry.getValue()) {
boolean found = false;
for(List<ItemStack> input : (List<List<ItemStack>>) recipeDisplay.getInput()) {
for(ItemStack itemStack : input) {
- if (ItemStack.areEqualIgnoreTags(itemStack, stack)) {
+ if (category.checkTags() ? ItemStack.areEqual(itemStack, stack) : ItemStack.areEqualIgnoreTags(itemStack, stack)) {
categoriesMap.get(recipeDisplay.getRecipeCategory()).add(recipeDisplay);
found = true;
break;
@@ -107,6 +111,7 @@ public class RecipeHelper {
break;
}
}
+ }
categoriesMap.keySet().removeIf(f -> categoriesMap.get(f).isEmpty());
Map<IRecipeCategory, List<IRecipeDisplay>> recipeCategoryListMap = Maps.newHashMap();
categories.forEach(category -> {
@@ -116,11 +121,11 @@ public class RecipeHelper {
return recipeCategoryListMap;
}
- public static List<IRecipeCategory> getCategories() {
- return categories;
+ public List<IRecipeCategory> getCategories() {
+ return new LinkedList<>(categories);
}
- public static SpeedCraftAreaSupplier getSpeedCraftButtonArea(IRecipeCategory category) {
+ public SpeedCraftAreaSupplier getSpeedCraftButtonArea(IRecipeCategory category) {
if (!speedCraftAreaSupplierMap.containsKey(category.getIdentifier()))
return bounds -> {
return new Rectangle((int) bounds.getMaxX() - 16, (int) bounds.getMaxY() - 16, 10, 10);
@@ -128,17 +133,17 @@ public class RecipeHelper {
return speedCraftAreaSupplierMap.get(category.getIdentifier());
}
- public static void registerSpeedCraftButtonArea(Identifier category, SpeedCraftAreaSupplier rectangle) {
+ public void registerSpeedCraftButtonArea(Identifier category, SpeedCraftAreaSupplier rectangle) {
speedCraftAreaSupplierMap.put(category, rectangle);
}
- public static List<SpeedCraftFunctional> getSpeedCraftFunctional(IRecipeCategory category) {
+ public List<SpeedCraftFunctional> getSpeedCraftFunctional(IRecipeCategory category) {
if (speedCraftFunctionalMap.get(category.getIdentifier()) == null)
return Lists.newArrayList();
return speedCraftFunctionalMap.get(category.getIdentifier());
}
- public static void registerSpeedCraftFunctional(Identifier category, SpeedCraftFunctional functional) {
+ public void registerSpeedCraftFunctional(Identifier category, SpeedCraftFunctional functional) {
List<SpeedCraftFunctional> list = speedCraftFunctionalMap.containsKey(category) ? new LinkedList<>(speedCraftFunctionalMap.get(category)) : Lists.newLinkedList();
list.add(functional);
speedCraftFunctionalMap.put(category, list);
diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
index 206080582..21c18153c 100644
--- a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
+++ b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
@@ -1,11 +1,11 @@
package me.shedaniel.rei.gui;
+import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.GlStateManager;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.client.ClientHelper;
import me.shedaniel.rei.client.GuiHelper;
import me.shedaniel.rei.gui.widget.*;
-import me.shedaniel.rei.listeners.IMixinContainerGui;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.ContainerGui;
import net.minecraft.client.gui.Gui;
@@ -17,7 +17,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.MathHelper;
import java.awt.*;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -25,34 +24,25 @@ import java.util.stream.Collectors;
public class ContainerGuiOverlay extends Gui {
+ private static final List<QueuedTooltip> QUEUED_TOOLTIPS = Lists.newArrayList();
public static String searchTerm = "";
private static int page = 0;
private static ItemListOverlay itemListOverlay;
- private final List<IWidget> widgets;
- private final List<QueuedTooltip> queuedTooltips;
+ private final List<IWidget> widgets = Lists.newArrayList();
private Rectangle rectangle;
- private IMixinContainerGui containerGui;
private Window window;
private ButtonWidget buttonLeft, buttonRight;
private int lastLeft;
- public ContainerGuiOverlay(IMixinContainerGui containerGui) {
- this.queuedTooltips = new ArrayList<>();
- this.containerGui = containerGui;
- this.widgets = new ArrayList<>();
- }
-
public void onInitialized() {
//Update Variables
this.widgets.clear();
this.window = MinecraftClient.getInstance().window;
- if (MinecraftClient.getInstance().currentGui instanceof ContainerGui)
- this.containerGui = (IMixinContainerGui) MinecraftClient.getInstance().currentGui;
this.rectangle = calculateBoundary();
- widgets.add(this.itemListOverlay = new ItemListOverlay(containerGui, page));
this.lastLeft = getLeft();
-
+ widgets.add(this.itemListOverlay = new ItemListOverlay(page));
this.itemListOverlay.updateList(getItemListArea(), page, searchTerm);
+
widgets.add(buttonLeft = new ButtonWidget(rectangle.x, rectangle.y + 5, 16, 16, "<") {
@Override
public void onPressed(int button, double mouseX, double mouseY) {
@@ -87,7 +77,7 @@ public class ContainerGuiOverlay extends Gui {
widgets.add(new ButtonWidget(10, 35, 40, 20, I18n.translate("text.rei.config")) {
@Override
public void onPressed(int button, double mouseX, double mouseY) {
- ClientHelper.openConfigWindow(containerGui.getContainerGui());
+ ClientHelper.openConfigWindow(GuiHelper.getLastContainerGui());
}
});
this.widgets.add(new LabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + 10, "") {
@@ -117,7 +107,7 @@ public class ContainerGuiOverlay extends Gui {
this.widgets.add(GuiHelper.searchField);
GuiHelper.searchField.setText(searchTerm);
if (RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton())
- this.widgets.add(new CraftableToggleButtonWidget(containerGui, getCraftableToggleArea()) {
+ this.widgets.add(new CraftableToggleButtonWidget(getCraftableToggleArea()) {
@Override
public void onPressed(int button, double mouseX, double mouseY) {
RoughlyEnoughItemsCore.getConfigHelper().toggleCraftableOnly();
@@ -125,6 +115,7 @@ public class ContainerGuiOverlay extends Gui {
}
});
+ this.itemListOverlay.updateList(getItemListArea(), page, searchTerm);
this.listeners.addAll(widgets);
}
@@ -136,7 +127,7 @@ public class ContainerGuiOverlay extends Gui {
RecipeViewingWidget widget = (RecipeViewingWidget) MinecraftClient.getInstance().currentGui;
return new Rectangle(widget.getBounds().x, window.getScaledHeight() - 22, widget.getBounds().width - widthRemoved, 18);
}
- return new Rectangle(containerGui.getContainerLeft(), window.getScaledHeight() - 22, containerGui.getContainerWidth() - widthRemoved, 18);
+ return new Rectangle(GuiHelper.getLastMixinContainerGui().getContainerLeft(), window.getScaledHeight() - 22, GuiHelper.getLastMixinContainerGui().getContainerWidth() - widthRemoved, 18);
}
private Rectangle getCraftableToggleArea() {
@@ -170,8 +161,8 @@ public class ContainerGuiOverlay extends Gui {
GuiLighting.disable();
this.draw(mouseX, mouseY, partialTicks);
GuiLighting.disable();
- queuedTooltips.forEach(queuedTooltip -> containerGui.getContainerGui().drawTooltip(queuedTooltip.text, queuedTooltip.mouse.x, queuedTooltip.mouse.y));
- queuedTooltips.clear();
+ QUEUED_TOOLTIPS.stream().filter(queuedTooltip -> queuedTooltip != null).forEach(queuedTooltip -> MinecraftClient.getInstance().currentGui.drawTooltip(queuedTooltip.text, queuedTooltip.mouse.x, queuedTooltip.mouse.y));
+ QUEUED_TOOLTIPS.clear();
GuiLighting.disable();
}
@@ -190,12 +181,8 @@ public class ContainerGuiOverlay extends Gui {
return lastString.equals(currentString);
}
- public void setContainerGui(IMixinContainerGui containerGui) {
- this.containerGui = containerGui;
- }
-
public void addTooltip(QueuedTooltip queuedTooltip) {
- queuedTooltips.add(queuedTooltip);
+ QUEUED_TOOLTIPS.add(queuedTooltip);
}
@Override
@@ -213,7 +200,7 @@ public class ContainerGuiOverlay extends Gui {
}
private Rectangle calculateBoundary() {
- int startX = containerGui.getContainerLeft() + containerGui.getContainerWidth() + 10;
+ int startX = GuiHelper.getLastMixinContainerGui().getContainerLeft() + GuiHelper.getLastMixinContainerGui().getContainerWidth() + 10;
int width = window.getScaledWidth() - startX;
if (MinecraftClient.getInstance().currentGui instanceof RecipeViewingWidget) {
RecipeViewingWidget widget = (RecipeViewingWidget) MinecraftClient.getInstance().currentGui;
@@ -228,7 +215,7 @@ public class ContainerGuiOverlay extends Gui {
RecipeViewingWidget widget = (RecipeViewingWidget) MinecraftClient.getInstance().currentGui;
return widget.getBounds().x;
}
- return containerGui.getContainerLeft();
+ return GuiHelper.getLastMixinContainerGui().getContainerLeft();
}
private int getTotalPage() {
@@ -273,13 +260,13 @@ public class ContainerGuiOverlay extends Gui {
}
}
if (itemStack == null && MinecraftClient.getInstance().currentGui instanceof ContainerGui)
- if (containerGui.getHoveredSlot() != null)
- itemStack = containerGui.getHoveredSlot().getStack();
+ if (GuiHelper.getLastMixinContainerGui().getHoveredSlot() != null)
+ itemStack = GuiHelper.getLastMixinContainerGui().getHoveredSlot().getStack();
if (itemStack != null && !itemStack.isEmpty()) {
if (ClientHelper.RECIPE.matchesKey(int_1, int_2))
- return ClientHelper.executeRecipeKeyBind(this, itemStack, containerGui);
+ return ClientHelper.executeRecipeKeyBind(this, itemStack);
else if (ClientHelper.USAGE.matchesKey(int_1, int_2))
- return ClientHelper.executeUsageKeyBind(this, itemStack, containerGui);
+ return ClientHelper.executeUsageKeyBind(this, itemStack);
}
if (ClientHelper.HIDE.matchesKey(int_1, int_2)) {
GuiHelper.toggleOverlayVisible();
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java
index ec6c732b5..ceafcec56 100644
--- a/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java
+++ b/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java
@@ -4,7 +4,6 @@ import com.mojang.blaze3d.platform.GlStateManager;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.client.ClientHelper;
import me.shedaniel.rei.client.GuiHelper;
-import me.shedaniel.rei.listeners.IMixinContainerGui;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.GuiLighting;
@@ -20,14 +19,13 @@ public abstract class CraftableToggleButtonWidget extends ButtonWidget {
protected static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
private ItemRenderer itemRenderer;
- private IMixinContainerGui containerGui;
- public CraftableToggleButtonWidget(IMixinContainerGui containerGui, Rectangle rectangle) {
- this(containerGui, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
+ public CraftableToggleButtonWidget(Rectangle rectangle) {
+ this(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
this.itemRenderer = MinecraftClient.getInstance().getItemRenderer();
}
- public CraftableToggleButtonWidget(IMixinContainerGui containerGui, int x, int y, int width, int height) {
+ public CraftableToggleButtonWidget(int x, int y, int width, int height) {
super(x, y, width, height, "");
this.itemRenderer = MinecraftClient.getInstance().getItemRenderer();
}
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/HighlightableWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/HighlightableWidget.java
index 97d097d94..da18cfc97 100644
--- a/src/main/java/me/shedaniel/rei/gui/widget/HighlightableWidget.java
+++ b/src/main/java/me/shedaniel/rei/gui/widget/HighlightableWidget.java
@@ -7,7 +7,15 @@ public interface HighlightableWidget extends IWidget {
public Rectangle getBounds();
default boolean isHighlighted(int mouseX, int mouseY) {
- return getBounds().contains(new Point(mouseX, mouseY));
+ return getBounds().contains(mouseX, mouseY);
+ }
+
+ default boolean isHighlighted(Point point) {
+ return this.isHighlighted(point.x, point.y);
+ }
+
+ default boolean isHighlighted(double mouseX, double mouseY) {
+ return this.isHighlighted((int) mouseX, (int) mouseY);
}
}
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java
index ab4f7f2c8..c20c9b89b 100644
--- a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java
+++ b/