From 2f95b698dee3368666cefe8890a015eb098dd77b Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 31 Jan 2019 15:32:33 +0800 Subject: Update to v2.2.0.15 & Fix Optifine Fix #16 --- src/main/java/me/shedaniel/rei/REIMixinInit.java | 2 + .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 37 +-- .../me/shedaniel/rei/RoughlyEnoughItemsPlugin.java | 53 ++-- .../java/me/shedaniel/rei/api/IRecipeCategory.java | 12 +- .../rei/api/IRecipeCategoryCraftable.java | 18 -- .../shedaniel/rei/api/SpeedCraftAreaSupplier.java | 4 + .../me/shedaniel/rei/api/SpeedCraftFunctional.java | 1 - .../java/me/shedaniel/rei/client/ClientHelper.java | 41 +-- .../java/me/shedaniel/rei/client/GuiHelper.java | 39 ++- .../me/shedaniel/rei/client/KeyBindHelper.java | 13 +- .../java/me/shedaniel/rei/client/REIConfig.java | 6 +- .../shedaniel/rei/client/REIItemListOrdering.java | 4 +- .../java/me/shedaniel/rei/client/RecipeHelper.java | 89 +++--- .../me/shedaniel/rei/gui/ContainerGuiOverlay.java | 64 ++-- .../me/shedaniel/rei/gui/widget/ConfigWidget.java | 3 +- .../gui/widget/CraftableToggleButtonWidget.java | 12 +- .../rei/gui/widget/HighlightableWidget.java | 10 +- .../shedaniel/rei/gui/widget/ItemListOverlay.java | 43 ++- .../shedaniel/rei/gui/widget/ItemSlotWidget.java | 35 +-- .../rei/gui/widget/RecipeViewingWidget.java | 333 --------------------- .../rei/gui/widget/RecipeViewingWidgetGui.java | 296 ++++++++++++++++++ .../rei/gui/widget/SpeedCraftingButtonWidget.java | 42 +++ .../me/shedaniel/rei/gui/widget/TabWidget.java | 6 +- .../me/shedaniel/rei/listeners/ClientLoaded.java | 7 - .../java/me/shedaniel/rei/listeners/IListener.java | 4 - .../rei/listeners/IMixinGuiContainer.java | 2 - .../me/shedaniel/rei/listeners/RecipeSync.java | 9 - .../me/shedaniel/rei/mixin/MixinGuiContainer.java | 27 +- .../me/shedaniel/rei/mixin/MixinGuiCrafting.java | 4 +- .../me/shedaniel/rei/mixin/MixinGuiInventory.java | 4 +- .../me/shedaniel/rei/mixin/MixinGuiRecipeBook.java | 4 +- .../me/shedaniel/rei/mixin/MixinKeyBinding.java | 4 +- .../rei/mixin/MixinNetHandlerPlayClient.java | 9 +- .../me/shedaniel/rei/mixin/MixinPotionBrewing.java | 21 +- .../shedaniel/rei/network/CreateItemsPacket.java | 6 +- .../rei/plugin/DefaultBrewingCategory.java | 15 +- .../rei/plugin/DefaultCraftingCategory.java | 14 +- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 28 +- .../rei/plugin/DefaultSmeltingCategory.java | 12 +- 39 files changed, 634 insertions(+), 699 deletions(-) delete mode 100644 src/main/java/me/shedaniel/rei/api/IRecipeCategoryCraftable.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java create mode 100644 src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidgetGui.java create mode 100644 src/main/java/me/shedaniel/rei/gui/widget/SpeedCraftingButtonWidget.java delete mode 100644 src/main/java/me/shedaniel/rei/listeners/ClientLoaded.java delete mode 100644 src/main/java/me/shedaniel/rei/listeners/IListener.java delete mode 100644 src/main/java/me/shedaniel/rei/listeners/RecipeSync.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/REIMixinInit.java b/src/main/java/me/shedaniel/rei/REIMixinInit.java index 39f3639e2..7b8eb00b6 100644 --- a/src/main/java/me/shedaniel/rei/REIMixinInit.java +++ b/src/main/java/me/shedaniel/rei/REIMixinInit.java @@ -1,5 +1,7 @@ package me.shedaniel.rei; +import net.minecraft.client.Minecraft; +import org.dimdev.rift.listener.client.ClientTickable; import org.dimdev.riftloader.listener.InitializationListener; import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.mixin.Mixins; diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index ad445e1d2..bf0268a90 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -1,47 +1,28 @@ package me.shedaniel.rei; -import com.google.common.collect.Lists; -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.RecipeHelper; -import me.shedaniel.rei.listeners.IListener; -import me.shedaniel.rei.plugin.DefaultPlugin; -import net.minecraft.util.ResourceLocation; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.dimdev.riftloader.listener.InitializationListener; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; public class RoughlyEnoughItemsCore { public static final Logger LOGGER = LogManager.getFormatterLogger("REI"); - private static final List listeners = Arrays.asList(new ClientHelper(), new RecipeHelper()); - private static final ConfigHelper configHelper = new ConfigHelper(); + private static final RecipeHelper RECIPE_HELPER = new RecipeHelper(); + private static final ClientHelper CLIENT_HELPER = new ClientHelper(); + private static final ConfigHelper CONFIG_HELPER = new ConfigHelper(); - public static List getListeners(Class listenerClass) { - return listeners.stream().filter(listener -> { - return listenerClass.isAssignableFrom(listener.getClass()); - }).map(listener -> { - return listenerClass.cast(listener); - }).collect(Collectors.toList()); + public static ConfigHelper getConfigHelper() { + return CONFIG_HELPER; } - public static ConfigHelper getConfigHelper() { - return configHelper; + public static RecipeHelper getRecipeHelper() { + return RECIPE_HELPER; } - private boolean removeListener(IListener listener) { - if (!listeners.contains(listener)) - return false; - listeners.remove(listener); - return true; + public static ClientHelper getClientHelper() { + return CLIENT_HELPER; } } diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsPlugin.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsPlugin.java index 8f91e7e0e..ad3c15ba6 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsPlugin.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsPlugin.java @@ -3,6 +3,7 @@ package me.shedaniel.rei; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import com.google.gson.JsonParser; import me.shedaniel.rei.api.IRecipePlugin; import net.minecraft.util.ResourceLocation; @@ -10,7 +11,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.dimdev.riftloader.ModInfo; import org.dimdev.riftloader.RiftLoader; -import org.dimdev.riftloader.listener.InitializationListener; import java.io.File; import java.io.FileReader; @@ -24,14 +24,15 @@ import java.util.jar.JarFile; import java.util.stream.Collectors; import java.util.zip.ZipEntry; -public class RoughlyEnoughItemsPlugin implements InitializationListener { +public class RoughlyEnoughItemsPlugin { public static final Logger LOGGER = LogManager.getFormatterLogger("REI"); - private static final Map plugins = Maps.newHashMap(); + private static final Map plugins = Maps.newHashMap(); private static JsonParser parser = new JsonParser(); - private static List disablingPlugins; + private static List disablingPlugins; + private static boolean loaded = false; - public static IRecipePlugin registerPlugin(ResourceLocation resourceLocation, IRecipePlugin plugin) { + public static IRecipePlugin registerPlugin(String resourceLocation, IRecipePlugin plugin) { plugins.put(resourceLocation, plugin); RoughlyEnoughItemsPlugin.LOGGER.info("REI: Registered Plugin from %s by %s.", resourceLocation.toString(), plugin.getClass().getSimpleName()); return plugin; @@ -41,24 +42,22 @@ public class RoughlyEnoughItemsPlugin implements InitializationListener { return new LinkedList<>(plugins.values()); } - public static ResourceLocation getPluginResourceLocation(IRecipePlugin plugin) { - for(ResourceLocation ResourceLocation : plugins.keySet()) - if (plugins.get(ResourceLocation).equals(plugin)) - return ResourceLocation; + public static String getPluginResourceLocation(IRecipePlugin plugin) { + for(String resourceLocation : plugins.keySet()) + if (plugins.get(resourceLocation).equals(plugin)) + return resourceLocation; return null; } public static void disablePlugin(ResourceLocation location) { - if (disablingPlugins.stream().noneMatch(location1 -> {return location.equals(location1);})) - disablingPlugins.add(location); + if (disablingPlugins.stream().noneMatch(location1 -> {return location.toString().equals(location1);})) + disablingPlugins.add(location.toString()); } - @Override - public void onInitialization() { - discoverPlugins(); - } - - private void discoverPlugins() { + public static void discoverPlugins() { + if (loaded) + return; + loaded = true; LOGGER.info("REI: Discovering Plugins."); disablingPlugins = Lists.newArrayList(); Collection modInfoCollection = RiftLoader.instance.getMods(); @@ -78,29 +77,27 @@ public class RoughlyEnoughItemsPlugin implements InitializationListener { RoughlyEnoughItemsPlugin.LOGGER.error("REI: Failed to load plugin file from %s. (%s)", (Object) modInfo.id, (Object) e.getLocalizedMessage()); } }); - plugins.forEach((location, plugin) -> plugin.onFirstLoad()); - plugins.keySet().stream().filter(location -> { - return disablingPlugins.contains(location); - }).collect(Collectors.toList()).forEach(location -> { + plugins.values().forEach(IRecipePlugin::onFirstLoad); + new LinkedList<>(plugins.keySet()).stream().filter(location -> disablingPlugins.contains(location)).forEach(location -> { plugins.remove(location); LOGGER.info("REI: Disabled REI plugin %s.", location.toString()); }); - LOGGER.info("REI: Discovered %d REI Plugins%s", plugins.size(), (plugins.size() > 0 ? ": " + String.join(", ", plugins.keySet().stream().map(ResourceLocation::toString).collect(Collectors.toList())) : ".")); + LOGGER.info("REI: Discovered %d REI Plugins%s", plugins.size(), (plugins.size() > 0 ? ": " + String.join(", ", plugins.keySet().stream().collect(Collectors.toList())) : ".")); } - private void loadPluginInfo(ModInfo modInfo, Reader reader) throws Exception { + private static void loadPluginInfo(ModInfo modInfo, Reader reader) throws Exception { JsonElement infoElement = parser.parse(reader); if (infoElement.isJsonArray()) for(JsonElement jsonElement : infoElement.getAsJsonArray()) - parseAndRegisterPlugin(modInfo.id, jsonElement); + parseAndRegisterPlugin(modInfo.id, jsonElement.getAsJsonObject()); else - parseAndRegisterPlugin(modInfo.id, infoElement); + parseAndRegisterPlugin(modInfo.id, infoElement.getAsJsonObject()); reader.close(); } - private void parseAndRegisterPlugin(String modId, JsonElement jsonElement) throws Exception { - ResourceLocation location = new ResourceLocation(modId, jsonElement.getAsJsonObject().getAsJsonPrimitive("id").getAsString()); - Class aClass = Class.forName(jsonElement.getAsJsonObject().getAsJsonPrimitive("initializer").getAsString()); + private static void parseAndRegisterPlugin(String modId, JsonObject jsonObject) throws Exception { + String location = modId + ":" + jsonObject.getAsJsonPrimitive("id").getAsString(); + Class aClass = Class.forName(jsonObject.getAsJsonPrimitive("initializer").getAsString()); IRecipePlugin plugin = IRecipePlugin.class.cast(aClass.newInstance()); registerPlugin(location, plugin); } diff --git a/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java b/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java index dbc4a7204..ca531ca21 100644 --- a/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java @@ -2,8 +2,7 @@ package me.shedaniel.rei.api; 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.IMixinGuiContainer; +import me.shedaniel.rei.gui.widget.RecipeViewingWidgetGui; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; @@ -14,6 +13,7 @@ import net.minecraft.util.ResourceLocation; import java.awt.*; import java.util.Arrays; import java.util.List; +import java.util.function.Supplier; public interface IRecipeCategory { @@ -28,17 +28,21 @@ public interface IRecipeCategory { return false; } - default public List setupDisplay(IMixinGuiContainer containerGui, T recipeDisplay, Rectangle bounds) { + default public List setupDisplay(Supplier recipeDisplaySupplier, Rectangle bounds) { return Arrays.asList(new RecipeBaseWidget(bounds)); } default public void drawCategoryBackground(Rectangle bounds) { GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderHelper.disableStandardItemLighting(); - Minecraft.getInstance().getTextureManager().bindTexture(RecipeViewingWidget.CHEST_GUI_TEXTURE); + Minecraft.getInstance().getTextureManager().bindTexture(RecipeViewingWidgetGui.CHEST_GUI_TEXTURE); new Gui() { }.drawTexturedModalRect((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/IRecipeCategoryCraftable.java b/src/main/java/me/shedaniel/rei/api/IRecipeCategoryCraftable.java deleted file mode 100644 index d16f66654..000000000 --- a/src/main/java/me/shedaniel/rei/api/IRecipeCategoryCraftable.java +++ /dev/null @@ -1,18 +0,0 @@ -package me.shedaniel.rei.api; - -import me.shedaniel.rei.gui.widget.IWidget; -import me.shedaniel.rei.listeners.IMixinGuiContainer; -import net.minecraft.client.gui.Gui; - -import java.awt.*; -import java.util.List; - -public interface IRecipeCategoryCraftable { - - public boolean canAutoCraftHere(Class guiClass, T recipe); - - public boolean performAutoCraft(Gui gui, T recipe); - - public void registerAutoCraftButton(List widgets, Rectangle rectangle, IMixinGuiContainer parentGui, T recipe); - -} 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/api/SpeedCraftFunctional.java b/src/main/java/me/shedaniel/rei/api/SpeedCraftFunctional.java index 6dd998d47..e2ed4b83d 100644 --- a/src/main/java/me/shedaniel/rei/api/SpeedCraftFunctional.java +++ b/src/main/java/me/shedaniel/rei/api/SpeedCraftFunctional.java @@ -1,6 +1,5 @@ package me.shedaniel.rei.api; -import me.shedaniel.rei.plugin.DefaultCraftingDisplay; import net.minecraft.client.gui.Gui; public interface SpeedCraftFunctional { diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelper.java b/src/main/java/me/shedaniel/rei/client/ClientHelper.java index 84ecdd0ba..e4347b85b 100644 --- a/src/main/java/me/shedaniel/rei/client/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/client/ClientHelper.java @@ -2,15 +2,12 @@ package me.shedaniel.rei.client; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import io.netty.buffer.Unpooled; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.IRecipeCategory; 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.ClientLoaded; -import me.shedaniel.rei.listeners.IMixinGuiContainer; +import me.shedaniel.rei.gui.widget.RecipeViewingWidgetGui; import me.shedaniel.rei.network.CreateItemsPacket; import me.shedaniel.rei.network.DeleteItemsPacket; import net.minecraft.client.Minecraft; @@ -32,7 +29,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class ClientHelper implements ClientLoaded { +public class ClientHelper { private static List itemList; private static boolean cheating = false; @@ -48,13 +45,11 @@ public class ClientHelper implements ClientLoaded { String modid = location.getNamespace(); if (modid.equalsIgnoreCase("minecraft")) return "Minecraft"; - return RiftLoader.instance.getMods().stream() - .filter(modInfo -> modInfo.id.equals(modid) || (modInfo.name != null && modInfo.name.equals(modid))) - .findFirst().map(modInfo -> { - if (modInfo.name != null) - return modInfo.name; - return modid; - }).orElse(modid); + return RiftLoader.instance.getMods().stream().filter(modInfo -> modInfo.id.equals(modid) || (modInfo.name != null && modInfo.name.equals(modid))).findFirst().map(modInfo -> { + if (modInfo.name != null) + return modInfo.name; + return modid; + }).orElse(modid); } return ""; } @@ -100,27 +95,25 @@ public class ClientHelper implements ClientLoaded { } else { ResourceLocation location = IRegistry.ITEM.getKey(cheatedStack.getItem()); String tagMessage = cheatedStack.copy().getTag() != null && !cheatedStack.copy().getTag().isEmpty() ? cheatedStack.copy().getTag().toString() : ""; - String madeUpCommand = RoughlyEnoughItemsCore.getConfigHelper().getGiveCommandPrefix() + " " + Minecraft.getInstance().player.getScoreboardName() + " " + - location.toString() + tagMessage + (cheatedStack.getCount() != 1 ? " " + cheatedStack.getCount() : ""); + String madeUpCommand = RoughlyEnoughItemsCore.getConfigHelper().getGiveCommandPrefix() + " " + Minecraft.getInstance().player.getScoreboardName() + " " + location.toString() + tagMessage + (cheatedStack.getCount() != 1 ? " " + cheatedStack.getCount() : ""); if (madeUpCommand.length() > 256) - madeUpCommand = RoughlyEnoughItemsCore.getConfigHelper().getGiveCommandPrefix() + " " + Minecraft.getInstance().player.getScoreboardName() + " " + - location.toString() + (cheatedStack.getCount() != 1 ? " " + cheatedStack.getCount() : ""); + madeUpCommand = RoughlyEnoughItemsCore.getConfigHelper().getGiveCommandPrefix() + " " + Minecraft.getInstance().player.getScoreboardName() + " " + location.toString() + (cheatedStack.getCount() != 1 ? " " + cheatedStack.getCount() : ""); Minecraft.getInstance().player.sendChatMessage(madeUpCommand); return true; } } - public static boolean executeRecipeKeyBind(ContainerGuiOverlay overlay, ItemStack stack, IMixinGuiContainer parent) { - Map> map = RecipeHelper.getRecipesFor(stack); + public static boolean executeRecipeKeyBind(ContainerGuiOverlay overlay, ItemStack stack) { + Map> map = RecipeHelper.getInstance().getRecipesFor(stack); if (map.keySet().size() > 0) - Minecraft.getInstance().displayGuiScreen(new RecipeViewingWidget(Minecraft.getInstance().mainWindow, parent, map)); + Minecraft.getInstance().displayGuiScreen(new RecipeViewingWidgetGui(Minecraft.getInstance().mainWindow, map)); return map.keySet().size() > 0; } - public static boolean executeUsageKeyBind(ContainerGuiOverlay overlay, ItemStack stack, IMixinGuiContainer parent) { - Map> map = RecipeHelper.getUsagesFor(stack); + public static boolean executeUsageKeyBind(ContainerGuiOverlay overlay, ItemStack stack) { + Map> map = RecipeHelper.getInstance().getUsagesFor(stack); if (map.keySet().size() > 0) - Minecraft.getInstance().displayGuiScreen(new RecipeViewingWidget(Minecraft.getInstance().mainWindow, parent, map)); + Minecraft.getInstance().displayGuiScreen(new RecipeViewingWidgetGui(Minecraft.getInstance().mainWindow, map)); return map.keySet().size() > 0; } @@ -129,8 +122,7 @@ public class ClientHelper implements ClientLoaded { } public static List getInventoryItemsTypes() { - List> field_7543 = ImmutableList.of(Minecraft.getInstance().player.inventory.mainInventory, Minecraft.getInstance().player.inventory.armorInventory - , Minecraft.getInstance().player.inventory.offHandInventory); + List> field_7543 = ImmutableList.of(Minecraft.getInstance().player.inventory.mainInventory, Minecraft.getInstance().player.inventory.armorInventory, Minecraft.getInstance().player.inventory.offHandInventory); List inventoryStacks = new ArrayList<>(); field_7543.forEach(itemStacks -> itemStacks.forEach(itemStack -> { if (!itemStack.getItem().equals(Items.AIR)) @@ -139,7 +131,6 @@ public class ClientHelper implements ClientLoaded { return inventoryStacks; } - @Override public void clientLoaded() { IRegistry.ITEM.forEach(item -> { if (!item.equals(Items.ENCHANTED_BOOK)) diff --git a/src/main/java/me/shedaniel/rei/client/GuiHelper.java b/src/main/java/me/shedaniel/rei/client/GuiHelper.java index 4b228b3a6..253a51480 100644 --- a/src/main/java/me/shedaniel/rei/client/GuiHelper.java +++ b/src/main/java/me/shedaniel/rei/client/GuiHelper.java @@ -3,17 +3,22 @@ package me.shedaniel.rei.client; import com.google.common.collect.Lists; import me.shedaniel.rei.gui.ContainerGuiOverlay; import me.shedaniel.rei.gui.widget.TextFieldWidget; +import me.shedaniel.rei.listeners.IMixinGuiContainer; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; +import org.dimdev.rift.listener.client.ClientTickable; import java.util.List; -public class GuiHelper { +public class GuiHelper implements ClientTickable { public static TextFieldWidget searchField; public static List inventoryStacks = Lists.newArrayList(); private static boolean overlayVisible = true; private static ContainerGuiOverlay overlay; + private static GuiContainer lastGuiContainer; + private static IMixinGuiContainer lastMixinGuiContainer; public static boolean isOverlayVisible() { return overlayVisible; @@ -23,14 +28,6 @@ public class GuiHelper { overlayVisible = !overlayVisible; } - public static ContainerGuiOverlay getOverlay(GuiContainer lastGui) { - if (overlay == null) { - overlay = new ContainerGuiOverlay(lastGui); - overlay.onInitialized(); - } - return overlay; - } - public static ContainerGuiOverlay getLastOverlay() { return overlay; } @@ -40,8 +37,28 @@ public class GuiHelper { overlay.onInitialized(); } - public static void resetOverlay() { - overlay = null; + public static GuiContainer getLastGuiContainer() { + return lastGuiContainer; + } + + public static void setLastGuiContainer(GuiContainer lastGuiContainer) { + GuiHelper.lastGuiContainer = lastGuiContainer; + } + + public static IMixinGuiContainer getLastMixinGuiContainer() { + return lastMixinGuiContainer; + } + + public static void setLastMixinGuiContainer(IMixinGuiContainer lastMixinGuiContainer) { + GuiHelper.lastMixinGuiContainer = lastMixinGuiContainer; + } + + @Override + public void clientTick(Minecraft client) { + if (client.currentScreen instanceof GuiContainer && lastGuiContainer != client.currentScreen) { + GuiHelper.lastGuiContainer = (GuiContainer) client.currentScreen; + GuiHelper.lastMixinGuiContainer = (IMixinGuiContainer) lastGuiContainer; + } } } diff --git a/src/main/java/me/shedaniel/rei/client/KeyBindHelper.java b/src/main/java/me/shedaniel/rei/client/KeyBindHelper.java index 65ce788a1..6c253360d 100644 --- a/src/main/java/me/shedaniel/rei/client/KeyBindHelper.java +++ b/src/main/java/me/shedaniel/rei/client/KeyBindHelper.java @@ -5,7 +5,6 @@ import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.listeners.IMixinKeyBinding; import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.util.InputMappings; -import net.minecraft.util.ResourceLocation; import org.dimdev.rift.listener.client.KeyBindingAdder; import java.util.Collection; @@ -13,9 +12,9 @@ import java.util.List; public class KeyBindHelper implements KeyBindingAdder { - private static final ResourceLocation RECIPE_KEYBIND = new ResourceLocation("roughlyenoughitems", "recipe_keybind"); - private static final ResourceLocation USAGE_KEYBIND = new ResourceLocation("roughlyenoughitems", "usage_keybind"); - private static final ResourceLocation HIDE_KEYBIND = new ResourceLocation("roughlyenoughitems", "hide_keybind"); + private static final String RECIPE_KEYBIND = "roughlyenoughitems:recipe_keybind"; + private static final String USAGE_KEYBIND = "roughlyenoughitems:usage_keybind"; + private static final String HIDE_KEYBIND = "roughlyenoughitems:hide_keybind"; public static KeyBinding RECIPE, USAGE, HIDE; @Override @@ -34,9 +33,9 @@ public class KeyBindHelper implements KeyBindingAdder { ((IMixinKeyBinding) keyBinding).addCategory(category); } - private KeyBinding createKeyBinding(ResourceLocation location, InputMappings.Type inputType, int keyCode, String category) { - RoughlyEnoughItemsCore.LOGGER.info("Registering: key." + location.toString().replaceAll(":", ".") + " in " + category); - return new KeyBinding("key." + location.toString().replaceAll(":", "."), inputType, keyCode, category); + private KeyBinding createKeyBinding(String resourceLocation, InputMappings.Type inputType, int keyCode, String category) { + RoughlyEnoughItemsCore.LOGGER.info("Registering: key." + resourceLocation.replaceAll(":", ".") + " in " + category); + return new KeyBinding("key." + resourceLocation.replaceAll(":", "."), inputType, keyCode, category); } } diff --git a/src/main/java/me/shedaniel/rei/client/REIConfig.java b/src/main/java/me/shedaniel/rei/client/REIConfig.java index db14b282f..49ccb1dec 100644 --- a/src/main/java/me/shedaniel/rei/client/REIConfig.java +++ b/src/main/java/me/shedaniel/rei/client/REIConfig.java @@ -3,13 +3,9 @@ package me.shedaniel.rei.client; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import java.awt.event.KeyEvent; - public class REIConfig { - public static Gson GSON = new GsonBuilder() - .setPrettyPrinting() - .create(); + public static Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public REIItemListOrdering itemListOrdering = REIItemListOrdering.REGISTRY; public boolean isAscending = true; diff --git a/src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java b/src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java index b0167d352..8f9e317eb 100644 --- a/src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java +++ b/src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java @@ -4,9 +4,7 @@ import com.google.gson.annotations.SerializedName; public enum REIItemListOrdering { - @SerializedName("registry") REGISTRY("ordering.rei.registry"), - @SerializedName("name") NAME("ordering.rei.name"), - @SerializedName("item_groups") ITEM_GROUPS("ordering.rei.item_groups"); + @SerializedName("registry") REGISTRY("ordering.rei.registry"), @SerializedName("name") NAME("ordering.rei.name"), @SerializedName("item_groups") ITEM_GROUPS("ordering.rei.item_groups"); private String nameTranslationKey; diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java index d5a360ee0..eec9f4bbc 100644 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java @@ -5,7 +5,6 @@ import com.google.common.collect.Maps; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.RoughlyEnoughItemsPlugin; import me.shedaniel.rei.api.*; -import me.shedaniel.rei.listeners.RecipeSync; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.RecipeManager; import net.minecraft.util.ResourceLocation; @@ -15,22 +14,19 @@ import java.util.*; import java.util.List; import java.util.stream.Collectors; -public class RecipeHelper implements RecipeSync { - - private static Map> recipeCategoryListMap; - private static List categories; - private static RecipeManager recipeManager; - private static Map speedCraftAreaSupplierMap; - private static Map> speedCraftFunctionalMap; - - public RecipeHelper() { - this.recipeCategoryListMap = Maps.newHashMap(); - this.categories = Lists.newArrayList(); - this.speedCraftAreaSupplierMap = Maps.newHashMap(); - this.speedCraftFunctionalMap = Maps.newHashMap(); +public class RecipeHelper { + + private final Map> recipeCategoryListMap = Maps.newHashMap(); + private final List categories = Lists.newArrayList(); + private RecipeManager recipeManager; + private final Map speedCraftAreaSupplierMap = Maps.newHashMap(); + private final Map> speedCraftFunctionalMap = Maps.newHashMap(); + + public static RecipeHelper getInstance() { + return RoughlyEnoughItemsCore.getRecipeHelper(); } - public static List findCraftableByItems(List inventoryItems) { + public List findCraftableByItems(List inventoryItems) { List craftables = new ArrayList<>(); for(List value : recipeCategoryListMap.values()) for(IRecipeDisplay recipeDisplay : value) { @@ -59,47 +55,53 @@ public class RecipeHelper implements RecipeSync { return craftables.stream().distinct().collect(Collectors.toList()); } - public static void registerCategory(IRecipeCategory category) { + public void registerCategory(IRecipeCategory category) { categories.add(category); - recipeCategoryListMap.put(category.getResourceLocation(), Lists.newArrayList()); + recipeCategoryListMap.put(category.getResourceLocation(), Lists.newLinkedList()); } - public static void registerRecipe(ResourceLocation categoryIdentifier, IRecipeDisplay display) { + public void registerRecipe(ResourceLocation categoryIdentifier, IRecipeDisplay display) { if (!recipeCategoryListMap.containsKey(categoryIdentifier)) return; recipeCategoryListMap.get(categoryIdentifier).add(display); } - public static Map> getRecipesFor(ItemStack stack) { + public Map> getRecipesFor(ItemStack stack) { Map> categoriesMap = new HashMap<>(); - categories.forEach(f -> categoriesMap.put(f.getResourceLocation(), new LinkedList<>())); - for(List value : recipeCategoryListMap.values()) - for(IRecipeDisplay recipeDisplay : value) + categories.forEach(f -> categoriesMap.put(f.getResourceLocation(), Lists.newArrayList())); + for(Map.Entry> entry : recipeCategoryListMap.entrySet()) { + IRecipeCategory category = getCategory(entry.getKey()); + for(IRecipeDisplay recipeDisplay : entry.getValue()) for(ItemStack outputStack : (List) recipeDisplay.getOutput()) - if (ItemStack.areItemsEqual(stack, outputStack)) + if (category.checkTags() ? ItemStack.areItemStacksEqual(stack, outputStack) : ItemStack.areItemsEqual(stack, outputStack)) categoriesMap.get(recipeDisplay.getRecipeCategory()).add(recipeDisplay); - categoriesMap.keySet().removeIf(f -> categoriesMap.get(f).isEmpty()); - Map> recipeCategoryListMap = Maps.newHashMap(); + } + Map> recipeCategoryListMap = Maps.newLinkedHashMap(); categories.forEach(category -> { - if (categoriesMap.containsKey(category.getResourceLocation())) + if (categoriesMap.containsKey(category.getResourceLocation()) && !categoriesMap.get(category.getResourceLocation()).isEmpty()) recipeCategoryListMap.put(category, categoriesMap.get(category.getResourceLocation())); }); return recipeCategoryListMap; } - public static RecipeManager getRecipeManager() { + private IRecipeCategory getCategory(ResourceLocation resourceLocation) { + return categories.stream().filter(category -> category.getResourceLocation().equals(resourceLocation)).findFirst().orElse(null); + } + + public RecipeManager getRecipeManager() { return recipeManager; } - public static Map> getUsagesFor(ItemStack stack) { + public Map> getUsagesFor(ItemStack stack) { Map> categoriesMap = new HashMap<>(); - categories.forEach(f -> categoriesMap.put(f.getResourceLocation(), new LinkedList<>())); - for(List value : recipeCategoryListMap.values()) - for(IRecipeDisplay recipeDisplay : value) { + categories.forEach(f -> categoriesMap.put(f.getResourceLocation(), Lists.newArrayList())); + for(Map.Entry> entry : recipeCategoryListMap.entrySet()) { + IRecipeCategory category = getCategory(entry.getKey()); + for(IRecipeDisplay recipeDisplay : entry.getValue()) { boolean found = false; for(List input : (List>) recipeDisplay.getInput()) { for(ItemStack itemStack : input) { - if (ItemStack.areItemsEqual(itemStack, stack)) { + if (category.checkTags() ? ItemStack.areItemStacksEqual(itemStack, stack) : ItemStack.areItemsEqual(itemStack, stack)) { categoriesMap.get(recipeDisplay.getRecipeCategory()).add(recipeDisplay); found = true; break; @@ -109,20 +111,20 @@ public class RecipeHelper implements RecipeSync { break; } } - categoriesMap.keySet().removeIf(f -> categoriesMap.get(f).isEmpty()); - Map> recipeCategoryListMap = Maps.newHashMap(); + } + Map> recipeCategoryListMap = Maps.newLinkedHashMap(); categories.forEach(category -> { - if (categoriesMap.containsKey(category.getResourceLocation())) + if (categoriesMap.containsKey(category.getResourceLocation()) && !categoriesMap.get(category.getResourceLocation()).isEmpty()) recipeCategoryListMap.put(category, categoriesMap.get(category.getResourceLocation())); }); return recipeCategoryListMap; } - public static List getCategories() { - return categories; + public List getCategories() { + return new LinkedList<>(categories); } - public static SpeedCraftAreaSupplier getSpeedCraftButtonArea(IRecipeCategory category) { + public SpeedCraftAreaSupplier getSpeedCraftButtonArea(IRecipeCategory category) { if (!speedCraftAreaSupplierMap.containsKey(category.getResourceLocation())) return bounds -> { return new Rectangle((int) bounds.getMaxX() - 16, (int) bounds.getMaxY() - 16, 10, 10); @@ -130,23 +132,22 @@ public class RecipeHelper implements RecipeSync { return speedCraftAreaSupplierMap.get(category.getResourceLocation()); } - public static void registerSpeedCraftButtonArea(ResourceLocation category, SpeedCraftAreaSupplier rectangle) { + public void registerSpeedCraftButtonArea(ResourceLocation category, SpeedCraftAreaSupplier rectangle) { speedCraftAreaSupplierMap.put(category, rectangle); } - public static List getSpeedCraftFunctional(IRecipeCategory category) { + public List getSpeedCraftFunctional(IRecipeCategory category) { if (speedCraftFunctionalMap.get(category.getResourceLocation()) == null) return Lists.newArrayList(); return speedCraftFunctionalMap.get(category.getResourceLocation()); } - public static void registerSpeedCraftFunctional(ResourceLocation category, SpeedCraftFunctional functional) { + public void registerSpeedCraftFunctional(ResourceLocation category, SpeedCraftFunctional functional) { List list = speedCraftFunctionalMap.containsKey(category) ? new LinkedList<>(speedCraftFunctionalMap.get(category)) : Lists.newLinkedList(); list.add(functional); speedCraftFunctionalMap.put(category, list); } - @Override public void recipesLoaded(RecipeManager recipeManager) { this.recipeManager = recipeManager; this.recipeCategoryListMap.clear(); @@ -158,8 +159,8 @@ public class RecipeHelper implements RecipeSync { return second.getPriority() - first.getPriority(); }); RoughlyEnoughItemsCore.LOGGER.info("Loading %d REI plugins: %s", plugins.size(), String.join(", ", plugins.stream().map(plugin -> { - ResourceLocation ResourceLocation = RoughlyEnoughItemsPlugin.getPluginResourceLocation(plugin); - return ResourceLocation == null ? "NULL" : ResourceLocation.toString(); + String resourceLocation = RoughlyEnoughItemsPlugin.getPluginResourceLocation(plugin); + return resourceLocation == null ? "NULL" : resourceLocation; }).collect(Collectors.toList()))); Collections.reverse(plugins); plugins.forEach(plugin -> { diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java index b840a473d..ac78abbf0 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 me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; import me.shedaniel.rei.client.KeyBindHelper; import me.shedaniel.rei.gui.widget.*; -import me.shedaniel.rei.listeners.IMixinGuiContainer; import net.minecraft.client.MainWindow; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; @@ -18,7 +18,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; @@ -26,34 +25,26 @@ import java.util.stream.Collectors; public class ContainerGuiOverlay extends GuiScreen { + private static final List QUEUED_TOOLTIPS = Lists.newArrayList(); public static String searchTerm = ""; private static int page = 0; private static ItemListOverlay itemListOverlay; - private final List widgets; - private final List queuedTooltips; + private final List widgets = Lists.newArrayList(); private Rectangle rectangle; - private IMixinGuiContainer containerGui; private MainWindow window; private ButtonWidget buttonLeft, buttonRight; private int lastLeft; - public ContainerGuiOverlay(GuiContainer containerGui) { - this.queuedTooltips = new ArrayList<>(); - this.containerGui = (IMixinGuiContainer) containerGui; - this.widgets = new ArrayList<>(); - } - public void onInitialized() { //Update Variables this.widgets.clear(); this.window = Minecraft.getInstance().mainWindow; - if (Minecraft.getInstance().currentScreen instanceof GuiContainer) - this.containerGui = (IMixinGuiContainer) Minecraft.getInstance().currentScreen; 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) { @@ -88,7 +79,7 @@ public class ContainerGuiOverlay extends GuiScreen { widgets.add(new ButtonWidget(10, 35, 40, 20, I18n.format("text.rei.config")) { @Override public void onPressed(int button, double mouseX, double mouseY) { - ClientHelper.openConfigWindow(containerGui.getContainerGui()); + ClientHelper.openConfigWindow(GuiHelper.getLastGuiContainer()); } }); this.widgets.add(new LabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + 10, "") { @@ -118,7 +109,7 @@ public class ContainerGuiOverlay extends GuiScreen { 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(); @@ -126,6 +117,7 @@ public class ContainerGuiOverlay extends GuiScreen { } }); + this.itemListOverlay.updateList(getItemListArea(), page, searchTerm); this.children.addAll(widgets); } @@ -133,11 +125,11 @@ public class ContainerGuiOverlay extends GuiScreen { int widthRemoved = RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton() ? 22 : 0; if (RoughlyEnoughItemsCore.getConfigHelper().sideSearchField()) return new Rectangle(rectangle.x + 2, window.getScaledHeight() - 22, rectangle.width - 6 - widthRemoved, 18); - if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidget) { - RecipeViewingWidget widget = (RecipeViewingWidget) Minecraft.getInstance().currentScreen; + if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidgetGui) { + RecipeViewingWidgetGui widget = (RecipeViewingWidgetGui) Minecraft.getInstance().currentScreen; 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.getLastMixinGuiContainer().getContainerLeft(), window.getScaledHeight() - 22, GuiHelper.getLastMixinGuiContainer().getContainerWidth() - widthRemoved, 18); } private Rectangle getCraftableToggleArea() { @@ -171,8 +163,8 @@ public class ContainerGuiOverlay extends GuiScreen { RenderHelper.disableStandardItemLighting(); this.render(mouseX, mouseY, partialTicks); RenderHelper.disableStandardItemLighting(); - queuedTooltips.forEach(queuedTooltip -> containerGui.getContainerGui().drawHoveringText(queuedTooltip.text, queuedTooltip.mouse.x, queuedTooltip.mouse.y)); - queuedTooltips.clear(); + QUEUED_TOOLTIPS.stream().filter(queuedTooltip -> queuedTooltip != null).forEach(queuedTooltip -> Minecraft.getInstance().currentScreen.drawHoveringText(queuedTooltip.text, queuedTooltip.mouse.x, queuedTooltip.mouse.y)); + QUEUED_TOOLTIPS.clear(); RenderHelper.disableStandardItemLighting(); } @@ -191,12 +183,8 @@ public class ContainerGuiOverlay extends GuiScreen { return lastString.equals(currentString); } - public void setContainerGui(IMixinGuiContainer containerGui) { - this.containerGui = containerGui; - } - public void addTooltip(QueuedTooltip queuedTooltip) { - queuedTooltips.add(queuedTooltip); + QUEUED_TOOLTIPS.add(queuedTooltip); } @Override @@ -214,10 +202,10 @@ public class ContainerGuiOverlay extends GuiScreen { } private Rectangle calculateBoundary() { - int startX = containerGui.getContainerLeft() + containerGui.getContainerWidth() + 10; + int startX = GuiHelper.getLastMixinGuiContainer().getContainerLeft() + GuiHelper.getLastMixinGuiContainer().getContainerWidth() + 10; int width = window.getScaledWidth() - startX; - if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidget) { - RecipeViewingWidget widget = (RecipeViewingWidget) Minecraft.getInstance().currentScreen; + if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidgetGui) { + RecipeViewingWidgetGui widget = (RecipeViewingWidgetGui) Minecraft.getInstance().currentScreen; startX = widget.getBounds().x + widget.getBounds().width + 10; width = window.getScaledWidth() - startX; } @@ -225,11 +213,11 @@ public class ContainerGuiOverlay extends GuiScreen { } private int getLeft() { - if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidget) { - RecipeViewingWidget widget = (RecipeViewingWidget) Minecraft.getInstance().currentScreen; + if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidgetGui) { + RecipeViewingWidgetGui widget = (RecipeViewingWidgetGui) Minecraft.getInstance().currentScreen; return widget.getBounds().x; } - return containerGui.getContainerLeft(); + return GuiHelper.getLastMixinGuiContainer().getContainerLeft(); } private int getTotalPage() { @@ -265,8 +253,8 @@ public class ContainerGuiOverlay extends GuiScreen { itemStack = ((ItemSlotWidget) widget).getCurrentStack(); break; } - if (itemStack == null && Minecraft.getInstance().currentScreen instanceof RecipeViewingWidget) { - RecipeViewingWidget recipeViewingWidget = (RecipeViewingWidget) Minecraft.getInstance().currentScreen; + if (itemStack == null && Minecraft.getInstance().currentScreen instanceof RecipeViewingWidgetGui) { + RecipeViewingWidgetGui recipeViewingWidget = (RecipeViewingWidgetGui) Minecraft.getInstance().currentScreen; for(IGuiEventListener entry : recipeViewingWidget.getChildren()) if (entry instanceof ItemSlotWidget && ((ItemSlotWidget) entry).isHighlighted(point.x, point.y)) { itemStack = ((ItemSlotWidget) entry).getCurrentStack(); @@ -274,13 +262,13 @@ public class ContainerGuiOverlay extends GuiScreen { } } if (itemStack == null && Minecraft.getInstance().currentScreen instanceof GuiContainer) - if (containerGui.getHoveredSlot() != null) - itemStack = containerGui.getHoveredSlot().getStack(); + if (GuiHelper.getLastMixinGuiContainer().getHoveredSlot() != null) + itemStack = GuiHelper.getLastMixinGuiContainer().getHoveredSlot().getStack(); if (itemStack != null && !itemStack.isEmpty()) { if (KeyBindHelper.RECIPE.matchesKey(int_1, int_2)) - return ClientHelper.executeRecipeKeyBind(this, itemStack, containerGui); + return ClientHelper.executeRecipeKeyBind(this, itemStack); else if (KeyBindHelper.USAGE.matchesKey(int_1, int_2)) - return ClientHelper.executeUsageKeyBind(this, itemStack, containerGui); + return ClientHelper.executeUsageKeyBind(this, itemStack); } if (KeyBindHelper.HIDE.matchesKey(int_1, int_2)) { GuiHelper.toggleOverlayVisible(); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java index 93e41c655..1b5e01052 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java @@ -100,8 +100,7 @@ public class ConfigWidget extends GuiScreen { @Override public void draw(int int_1, int int_2, float float_1) { RenderHelper.disableStandardItemLighting(); - this.text = I18n.format("text.rei.list_ordering_button", I18n.format(RoughlyEnoughItemsCore.getConfigHelper().getItemListOrdering().getNameTranslationKey()), - I18n.format(RoughlyEnoughItemsCore.getConfigHelper().isAscending() ? "ordering.rei.ascending" : "ordering.rei.descending")); + this.text = I18n.format("text.rei.list_ordering_button", I18n.format(RoughlyEnoughItemsCore.getConfigHelper().getItemListOrdering().getNameTranslationKey()), I18n.format(RoughlyEnoughItemsCore.getConfigHelper().isAscending() ? "ordering.rei.ascending" : "ordering.rei.descending")); String t = I18n.format("text.rei.list_ordering") + ": "; drawString(Minecraft.getInstance().fontRenderer, t, parent.width / 2 - 95 - Minecraft.getInstance().fontRenderer.getStringWidth(t), 90 + 6, -1); super.draw(int_1, int_2, float_1); 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 88f3ca694..035d5cac6 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java @@ -3,7 +3,6 @@ package me.shedaniel.rei.gui.widget; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; -import me.shedaniel.rei.listeners.IMixinGuiContainer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.ItemRenderer; @@ -20,14 +19,13 @@ public abstract class CraftableToggleButtonWidget extends ButtonWidget { protected static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); private ItemRenderer itemRenderer; - private IMixinGuiContainer containerGui; - public CraftableToggleButtonWidget(IMixinGuiContainer 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 = Minecraft.getInstance().getItemRenderer(); } - public CraftableToggleButtonWidget(IMixinGuiContainer 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 = Minecraft.getInstance().getItemRenderer(); } @@ -51,9 +49,7 @@ public abstract class CraftableToggleButtonWidget extends ButtonWidget { } private void drawTooltip() { - GuiHelper.getLastOverlay() - .addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.format(RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() - ? "text.rei.showing_craftable" : "text.rei.showing_all")))); + GuiHelper.getLastOverlay().addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.format(RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() ? "text.rei.showing_craftable" : "text.rei.showing_all")))); } } 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 06bf4d687..d2c7ef467 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java @@ -3,8 +3,6 @@ package me.shedaniel.rei.gui.widget; import com.google.common.collect.Lists; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.client.*; -import me.shedaniel.rei.listeners.ClientLoaded; -import me.shedaniel.rei.listeners.IMixinGuiContainer; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.Gui; @@ -24,15 +22,13 @@ import java.util.stream.Stream; public class ItemListOverlay extends Gui implements IWidget { - private IMixinGuiContainer containerGui; private List widgets = new ArrayList<>(); private int width, height, page; - private Rectangle rectangle; + private Rectangle rectangle, listArea; private List currentDisplayed; - public ItemListOverlay(IMixinGuiContainer containerGui, int page) { + public ItemListOverlay(int page) { this.currentDisplayed = Lists.newArrayList(); - this.containerGui = containerGui; this.width = 0; this.height = 0; this.page = page; @@ -47,28 +43,29 @@ public class ItemListOverlay extends Gui implements IWidget { widgets.forEach(widget -> widget.draw(int_1, int_2, float_1)); EntityPlayerSP player = Minecraft.getInstance().player; if (rectangle.contains(ClientHelper.getMouseLocation()) && ClientHelper.isCheating() && !player.inventory.getItemStack().isEmpty() && Minecraft.getInstance().isSingleplayer()) - GuiHelper.getOverlay(containerGui.getContainerGui()).addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.format("text.rei.delete_items")))); + GuiHelper.getLastOverlay().addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.format("text.rei.delete_items")))); } public void updateList(int page, String searchTerm) { updateList(rectangle, page, searchTerm); } - public void updateList(Rectangle rect, int page, String searchTerm) { - this.rectangle = rect; + public void updateList(Rectangle bounds, int page, String searchTerm) { + this.rectangle = bounds; if (ClientHelper.getItemList().isEmpty()) - RoughlyEnoughItemsCore.getListeners(ClientLoaded.class).forEach(ClientLoaded::clientLoaded); + RoughlyEnoughItemsCore.getClientHelper().clientLoaded(); currentDisplayed = processSearchTerm(searchTerm, ClientHelper.getItemList(), GuiHelper.inventoryStacks); this.widgets.clear(); this.page = page; - calculateListSize(rect); - double startX = rect.getCenterX() - width * 9; - double startY = rect.getCenterY() - height * 9; + calculateListSize(rectangle); + double startX = rectangle.getCenterX() - width * 9; + double startY = rectangle.getCenterY() - height * 9; + this.listArea = new Rectangle((int) startX, (int) startY, width * 18, height * 18); for(int i = 0; i < getTotalSlotsPerPage(); i++) { int j = i + page * getTotalSlotsPerPage(); if (j >= currentDisplayed.size()) break; - widgets.add(new ItemSlotWidget((int) (startX + (i % width) * 18), (int) (startY + MathHelper.floor(i / width) * 18), currentDisplayed.get(j), false, true, containerGui) { + ItemSlotWidget slotWidget = new ItemSlotWidget((int) (startX + (i % width) * 18), (int) (startY + MathHelper.floor(i / width) * 18), currentDisplayed.get(j), false, true) { @Override protected void drawToolTip(ItemStack itemStack) { EntityPlayerSP player = Minecraft.getInstance().player; @@ -78,23 +75,23 @@ public class ItemListOverlay extends Gui implements IWidget { @Override public boolean onMouseClick(int button, double mouseX, double mouseY) { - if (getBounds().contains(mouseX, mouseY)) { + if (isHighlighted(mouseX, mouseY)) { if (ClientHelper.isCheating()) { if (getCurrentStack() != null && !getCurrentStack().isEmpty()) { ItemStack cheatedStack = getCurrentStack().copy(); cheatedStack.setCount(button == 0 ? 1 : button == 1 ? cheatedStack.getMaxStackSize() : cheatedStack.getCount()); return ClientHelper.tryCheatingStack(cheatedStack); } - } else { - if (button == 0) - return ClientHelper.executeRecipeKeyBind(GuiHelper.getOverlay(containerGui.getContainerGui()), getCurrentStack().copy(), containerGui); - else if (button == 1) - return ClientHelper.executeUsageKeyBind(GuiHelper.getOverlay(containerGui.getContainerGui()), getCurrentStack().copy(), containerGui); - } + } else if (button == 0) + return ClientHelper.executeRecipeKeyBind(GuiHelper.getLastOverlay(), getCurrentStack().copy()); + else if (button == 1) + return ClientHelper.executeUsageKeyBind(GuiHelper.getLastOverlay(), getCurrentStack().copy()); } return false; } - }); + }; + if (this.rectangle.contains(slotWidget.getBounds())) + widgets.add(slotWidget); } } @@ -140,7 +137,7 @@ public class ItemListOverlay extends Gui implements IWidget { stacks.addAll(os); List workingItems = RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() && inventoryItems.size() > 0 ? new ArrayList<>() : new LinkedList<>(ol); if (RoughlyEnoughItemsCore.getConfigHelper().craftableOnly()) { - RecipeHelper.findCraftableByItems(inventoryItems).forEach(workingItems::add); + RecipeHelper.getInstance().findCraftableByItems(inventoryItems).forEach(workingItems::add); workingItems.addAll(inventoryItems); } final List finalWorkingItems = workingItems; 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 e2d6a6bdb..127341a39 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java @@ -3,7 +3,6 @@ package me.shedaniel.rei.gui.widget; import com.google.common.collect.Lists; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; -import me.shedaniel.rei.listeners.IMixinGuiContainer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.ItemRenderer; @@ -26,24 +25,22 @@ public class ItemSlotWidget extends Gui implements HighlightableWidget { private List itemList = new LinkedList<>(); private boolean drawBackground, showToolTips, clickToMoreRecipes; private int x, y; - private IMixinGuiContainer containerGui; - public ItemSlotWidget(int x, int y, ItemStack itemStack, boolean drawBackground, boolean showToolTips, IMixinGuiContainer containerGui) { - this(x, y, Arrays.asList(itemStack), drawBackground, showToolTips, containerGui); + public ItemSlotWidget(int x, int y, ItemStack itemStack, boolean drawBackground, boolean showToolTips) { + this(x, y, Arrays.asList(itemStack), drawBackground, showToolTips); } - public ItemSlotWidget(int x, int y, List itemList, boolean drawBackground, boolean showToolTips, IMixinGuiContainer containerGui) { + public ItemSlotWidget(int x, int y, List itemList, boolean drawBackground, boolean showToolTips) { this.itemList = itemList; this.drawBackground = drawBackground; this.showToolTips = showToolTips; this.x = x; this.y = y; - this.containerGui = containerGui; this.clickToMoreRecipes = false; } - public ItemSlotWidget(int x, int y, List itemList, boolean drawBackground, boolean showToolTips, IMixinGuiContainer containerGui, boolean clickToMoreRecipes) { - this(x, y, itemList, drawBackground, showToolTips, containerGui); + public ItemSlotWidget(int x, int y, List itemList, boolean drawBackground, boolean showToolTips, boolean clickToMoreRecipes) { + this(x, y, itemList, drawBackground, showToolTips); this.clickToMoreRecipes = clickToMoreRecipes; } @@ -69,11 +66,7 @@ public class ItemSlotWidget extends Gui implements Highligh