From 15f6cc9eb567b6ef685bc6c1a6f3364270300914 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Dec 2018 13:17:31 +0800 Subject: from aei but like jei now --- src/main/java/me/shedaniel/ClientListener.java | 66 ++++++ src/main/java/me/shedaniel/Core.java | 33 +++ src/main/java/me/shedaniel/api/IAEIPlugin.java | 9 + .../java/me/shedaniel/api/IDisplayCategory.java | 27 +++ src/main/java/me/shedaniel/api/IDisplayHelper.java | 7 + src/main/java/me/shedaniel/api/IDrawable.java | 10 + src/main/java/me/shedaniel/api/IRecipe.java | 15 ++ src/main/java/me/shedaniel/api/IRecipeManager.java | 20 ++ .../java/me/shedaniel/api/TriBooleanProducer.java | 8 + .../java/me/shedaniel/gui/AEIRenderHelper.java | 235 ++++++++++++++++++ src/main/java/me/shedaniel/gui/Drawable.java | 33 +++ src/main/java/me/shedaniel/gui/GuiItemList.java | 264 +++++++++++++++++++++ .../java/me/shedaniel/gui/RecipeContainer.java | 13 + src/main/java/me/shedaniel/gui/RecipeGui.java | 218 +++++++++++++++++ src/main/java/me/shedaniel/gui/widget/AEISlot.java | 181 ++++++++++++++ src/main/java/me/shedaniel/gui/widget/Button.java | 72 ++++++ src/main/java/me/shedaniel/gui/widget/Control.java | 96 ++++++++ .../java/me/shedaniel/gui/widget/IFocusable.java | 10 + src/main/java/me/shedaniel/gui/widget/TextBox.java | 71 ++++++ .../java/me/shedaniel/gui/widget/WidgetArrow.java | 38 +++ .../java/me/shedaniel/impl/AEIRecipeManager.java | 157 ++++++++++++ .../java/me/shedaniel/library/KeyBindManager.java | 58 +++++ src/main/java/me/shedaniel/library/Sink.java | 6 + .../shedaniel/listenerdefinitions/CharInput.java | 9 + .../shedaniel/listenerdefinitions/DoneLoading.java | 8 + .../listenerdefinitions/DrawContainer.java | 10 + .../listenerdefinitions/GuiCickListener.java | 8 + .../shedaniel/listenerdefinitions/GuiKeyDown.java | 9 + .../listenerdefinitions/IMixinGuiContainer.java | 14 ++ .../listenerdefinitions/MinecraftResize.java | 8 + .../listenerdefinitions/MouseScrollListener.java | 5 + .../listenerdefinitions/PreLoadOptions.java | 9 + .../listenerdefinitions/RecipeLoadListener.java | 7 + .../shedaniel/listeners/DrawContainerListener.java | 60 +++++ .../java/me/shedaniel/listeners/InitListener.java | 22 ++ .../me/shedaniel/listeners/ResizeListener.java | 14 ++ .../java/me/shedaniel/mixins/MixinDoneLoading.java | 22 ++ .../me/shedaniel/mixins/MixinGuiContainer.java | 98 ++++++++ .../mixins/MixinGuiContainerCreative.java | 93 ++++++++ .../me/shedaniel/mixins/MixinKeyboardListener.java | 27 +++ .../me/shedaniel/mixins/MixinMinecraftResize.java | 23 ++ .../me/shedaniel/mixins/MixinRecipeManager.java | 26 ++ .../java/me/shedaniel/mixins/SettingsMixin.java | 44 ++++ .../java/me/shedaniel/network/CheatPacket.java | 45 ++++ .../java/me/shedaniel/network/DeletePacket.java | 32 +++ .../java/me/shedaniel/plugin/VanillaPlugin.java | 43 ++++ .../plugin/crafting/VanillaCraftingCategory.java | 106 +++++++++ .../plugin/crafting/VanillaCraftingRecipe.java | 16 ++ .../crafting/VanillaShapedCraftingRecipe.java | 55 +++++ .../crafting/VanillaShapelessCraftingRecipe.java | 57 +++++ .../plugin/furnace/VanillaFurnaceCategory.java | 83 +++++++ .../plugin/furnace/VanillaFurnaceRecipe.java | 42 ++++ 52 files changed, 2642 insertions(+) create mode 100755 src/main/java/me/shedaniel/ClientListener.java create mode 100755 src/main/java/me/shedaniel/Core.java create mode 100755 src/main/java/me/shedaniel/api/IAEIPlugin.java create mode 100755 src/main/java/me/shedaniel/api/IDisplayCategory.java create mode 100755 src/main/java/me/shedaniel/api/IDisplayHelper.java create mode 100755 src/main/java/me/shedaniel/api/IDrawable.java create mode 100755 src/main/java/me/shedaniel/api/IRecipe.java create mode 100755 src/main/java/me/shedaniel/api/IRecipeManager.java create mode 100755 src/main/java/me/shedaniel/api/TriBooleanProducer.java create mode 100755 src/main/java/me/shedaniel/gui/AEIRenderHelper.java create mode 100755 src/main/java/me/shedaniel/gui/Drawable.java create mode 100755 src/main/java/me/shedaniel/gui/GuiItemList.java create mode 100755 src/main/java/me/shedaniel/gui/RecipeContainer.java create mode 100755 src/main/java/me/shedaniel/gui/RecipeGui.java create mode 100755 src/main/java/me/shedaniel/gui/widget/AEISlot.java create mode 100755 src/main/java/me/shedaniel/gui/widget/Button.java create mode 100755 src/main/java/me/shedaniel/gui/widget/Control.java create mode 100755 src/main/java/me/shedaniel/gui/widget/IFocusable.java create mode 100755 src/main/java/me/shedaniel/gui/widget/TextBox.java create mode 100755 src/main/java/me/shedaniel/gui/widget/WidgetArrow.java create mode 100755 src/main/java/me/shedaniel/impl/AEIRecipeManager.java create mode 100755 src/main/java/me/shedaniel/library/KeyBindManager.java create mode 100755 src/main/java/me/shedaniel/library/Sink.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/CharInput.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/DoneLoading.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/DrawContainer.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/GuiCickListener.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/GuiKeyDown.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/IMixinGuiContainer.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/MinecraftResize.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/MouseScrollListener.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/PreLoadOptions.java create mode 100755 src/main/java/me/shedaniel/listenerdefinitions/RecipeLoadListener.java create mode 100755 src/main/java/me/shedaniel/listeners/DrawContainerListener.java create mode 100755 src/main/java/me/shedaniel/listeners/InitListener.java create mode 100755 src/main/java/me/shedaniel/listeners/ResizeListener.java create mode 100755 src/main/java/me/shedaniel/mixins/MixinDoneLoading.java create mode 100755 src/main/java/me/shedaniel/mixins/MixinGuiContainer.java create mode 100644 src/main/java/me/shedaniel/mixins/MixinGuiContainerCreative.java create mode 100755 src/main/java/me/shedaniel/mixins/MixinKeyboardListener.java create mode 100755 src/main/java/me/shedaniel/mixins/MixinMinecraftResize.java create mode 100755 src/main/java/me/shedaniel/mixins/MixinRecipeManager.java create mode 100755 src/main/java/me/shedaniel/mixins/SettingsMixin.java create mode 100755 src/main/java/me/shedaniel/network/CheatPacket.java create mode 100755 src/main/java/me/shedaniel/network/DeletePacket.java create mode 100755 src/main/java/me/shedaniel/plugin/VanillaPlugin.java create mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaCraftingCategory.java create mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaCraftingRecipe.java create mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaShapedCraftingRecipe.java create mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaShapelessCraftingRecipe.java create mode 100755 src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java create mode 100755 src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceRecipe.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/ClientListener.java b/src/main/java/me/shedaniel/ClientListener.java new file mode 100755 index 000000000..9d52addd5 --- /dev/null +++ b/src/main/java/me/shedaniel/ClientListener.java @@ -0,0 +1,66 @@ +package me.shedaniel; + +import me.shedaniel.api.IAEIPlugin; +import me.shedaniel.gui.AEIRenderHelper; +import me.shedaniel.impl.AEIRecipeManager; +import me.shedaniel.library.KeyBindManager; +import me.shedaniel.listenerdefinitions.DoneLoading; +import me.shedaniel.listenerdefinitions.RecipeLoadListener; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraft.util.registry.IRegistry; + +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.List; + +public class ClientListener implements DoneLoading, RecipeLoadListener { + public static KeyBinding recipeKeybind; + public static KeyBinding hideKeybind; + public static KeyBinding useKeybind; + + private List plugins; + public static List stackList; + + @Override + public void onDoneLoading() { + + plugins = new ArrayList<>(); + stackList = new ArrayList<>(); + + recipeKeybind = KeyBindManager.createKeybinding("key.aei.recipe", KeyEvent.VK_R, "key.aei.category", AEIRenderHelper::recipeKeybind); + hideKeybind = KeyBindManager.createKeybinding("key.aei.hide", KeyEvent.VK_O, "key.aei.category", AEIRenderHelper::hideKeybind); + useKeybind = KeyBindManager.createKeybinding("key.aei.use", KeyEvent.VK_U, "key.aei.category", AEIRenderHelper::useKeybind); + + buildItemList(); + } + + private void buildItemList() { + if (!IRegistry.ITEM.isEmpty()) { + IRegistry.ITEM.forEach(item -> processItem((Item) item)); + } + + } + + private void processItem(Item item) { + NonNullList items = NonNullList.create(); + try { + item.fillItemGroup(item.getGroup(), items); + items.forEach(stackList::add); + } catch (NullPointerException e) { + if (item == Items.ENCHANTED_BOOK) { + item.fillItemGroup(ItemGroup.TOOLS, items); + items.forEach(stackList::add); + } + } + } + + @Override + public void recipesLoaded(net.minecraft.item.crafting.RecipeManager recipeManager) { + AEIRecipeManager.instance().RecipesLoaded(recipeManager); + } +} diff --git a/src/main/java/me/shedaniel/Core.java b/src/main/java/me/shedaniel/Core.java new file mode 100755 index 000000000..61f985db1 --- /dev/null +++ b/src/main/java/me/shedaniel/Core.java @@ -0,0 +1,33 @@ +package me.shedaniel; + +import me.shedaniel.network.CheatPacket; +import me.shedaniel.network.DeletePacket; +import net.minecraft.network.EnumPacketDirection; +import org.dimdev.rift.listener.PacketAdder; + +/** + * Created by James on 7/27/2018. + */ +public class Core implements PacketAdder { + @Override + public void registerHandshakingPackets(PacketRegistrationReceiver receiver) { + } + + @Override + public void registerPlayPackets(PacketRegistrationReceiver receiver) { + receiver.registerPacket(EnumPacketDirection.SERVERBOUND, CheatPacket.class); + receiver.registerPacket(EnumPacketDirection.SERVERBOUND, DeletePacket.class); + } + + @Override + public void registerStatusPackets(PacketRegistrationReceiver receiver) { + + } + + @Override + public void registerLoginPackets(PacketRegistrationReceiver receiver) { + + } + + +} diff --git a/src/main/java/me/shedaniel/api/IAEIPlugin.java b/src/main/java/me/shedaniel/api/IAEIPlugin.java new file mode 100755 index 000000000..9f5b5da6e --- /dev/null +++ b/src/main/java/me/shedaniel/api/IAEIPlugin.java @@ -0,0 +1,9 @@ +package me.shedaniel.api; + +/** + * Created by James on 7/27/2018. + */ +public interface IAEIPlugin { + + public void register(); +} diff --git a/src/main/java/me/shedaniel/api/IDisplayCategory.java b/src/main/java/me/shedaniel/api/IDisplayCategory.java new file mode 100755 index 000000000..f5cb02a4d --- /dev/null +++ b/src/main/java/me/shedaniel/api/IDisplayCategory.java @@ -0,0 +1,27 @@ +package me.shedaniel.api; + +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Control; + +import java.util.List; + +/** + * Created by James on 8/7/2018. + */ +public interface IDisplayCategory { + public String getId(); + + public String getDisplayName(); + + public void addRecipe(T recipe); + + public void resetRecipes(); + + public List setupDisplay(int number); + + public boolean canDisplay(T recipe); + + public void drawExtras(); + + public void addWidget(List controls, int number); +} diff --git a/src/main/java/me/shedaniel/api/IDisplayHelper.java b/src/main/java/me/shedaniel/api/IDisplayHelper.java new file mode 100755 index 000000000..6f230d3b5 --- /dev/null +++ b/src/main/java/me/shedaniel/api/IDisplayHelper.java @@ -0,0 +1,7 @@ +package me.shedaniel.api; + +/** + * Created by James on 8/7/2018. + */ +public interface IDisplayHelper { +} diff --git a/src/main/java/me/shedaniel/api/IDrawable.java b/src/main/java/me/shedaniel/api/IDrawable.java new file mode 100755 index 000000000..102b7e1c5 --- /dev/null +++ b/src/main/java/me/shedaniel/api/IDrawable.java @@ -0,0 +1,10 @@ +package me.shedaniel.api; + +/** + * Created by James on 8/7/2018. + */ +public interface IDrawable { + public void draw(); + + public boolean isHighlighted(); +} diff --git a/src/main/java/me/shedaniel/api/IRecipe.java b/src/main/java/me/shedaniel/api/IRecipe.java new file mode 100755 index 000000000..6359c351a --- /dev/null +++ b/src/main/java/me/shedaniel/api/IRecipe.java @@ -0,0 +1,15 @@ +package me.shedaniel.api; + +import java.util.List; + +/** + * Created by James on 7/27/2018. + */ +public interface IRecipe { + + public String getId(); + + public List getOutput(); + + public List> getInput(); +} diff --git a/src/main/java/me/shedaniel/api/IRecipeManager.java b/src/main/java/me/shedaniel/api/IRecipeManager.java new file mode 100755 index 000000000..355a1cd4d --- /dev/null +++ b/src/main/java/me/shedaniel/api/IRecipeManager.java @@ -0,0 +1,20 @@ +package me.shedaniel.api; + +import net.minecraft.item.ItemStack; + +import java.util.List; +import java.util.Map; + +/** + * Created by James on 8/5/2018. + */ +public interface IRecipeManager { + + public void addRecipe(String id, IRecipe recipe); + + public void addRecipe(String id, List recipes); + + public void addDisplayAdapter(IDisplayCategory adapter); + + public Map> getRecipesFor(ItemStack stack); +} diff --git a/src/main/java/me/shedaniel/api/TriBooleanProducer.java b/src/main/java/me/shedaniel/api/TriBooleanProducer.java new file mode 100755 index 000000000..0925fee75 --- /dev/null +++ b/src/main/java/me/shedaniel/api/TriBooleanProducer.java @@ -0,0 +1,8 @@ +package me.shedaniel.api; + +/** + * Created by James on 8/4/2018. + */ +public interface TriBooleanProducer { + public boolean accept(int first, int second, int third); +} diff --git a/src/main/java/me/shedaniel/gui/AEIRenderHelper.java b/src/main/java/me/shedaniel/gui/AEIRenderHelper.java new file mode 100755 index 000000000..3ffbc7d82 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/AEIRenderHelper.java @@ -0,0 +1,235 @@ +package me.shedaniel.gui; + +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.IFocusable; +import me.shedaniel.impl.AEIRecipeManager; +import me.shedaniel.library.KeyBindManager; +import me.shedaniel.listenerdefinitions.IMixinGuiContainer; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.item.ItemStack; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + + +/** + * Created by James on 7/28/2018. + */ +public class AEIRenderHelper { + static Point mouseLoc; + static public GuiItemList aeiGui; + static GuiContainer overlayedGui; + static List tooltipsToRender = new ArrayList<>(); + + public static void setMouseLoc(int x, int y) { + mouseLoc = new Point(x, y); + } + + static public IFocusable focusedControl; + + public static Point getMouseLoc() { + return mouseLoc; + } + + public static MainWindow getResolution() { + + return Minecraft.getInstance().mainWindow; + } + + public static void drawAEI(GuiContainer overlayedGui) { + AEIRenderHelper.overlayedGui = overlayedGui; + if (aeiGui == null) { + aeiGui = new GuiItemList(overlayedGui); + } + aeiGui.draw(); + renderTooltips(); + } + + public static void resize() { + if (aeiGui != null) { + aeiGui.resize(); + } + if (overlayedGui instanceof RecipeGui) { + overlayedGui.onResize(Minecraft.getInstance(), 0, 0); + } + } + + public static ItemRenderer getItemRender() { + return Minecraft.getInstance().getItemRenderer(); + } + + public static FontRenderer getFontRenderer() { + return Minecraft.getInstance().fontRenderer; + } + + public static GuiContainer getOverlayedGui() { + if (overlayedGui instanceof GuiContainer) + return overlayedGui; + return null; + } + + public static void addToolTip(List text, int x, int y) { + tooltipsToRender.add(new TooltipData(text, x, y)); + } + + + private static void renderTooltips() { + GlStateManager.pushMatrix(); + GlStateManager.enableLighting(); + for(TooltipData tooltipData : tooltipsToRender) { + getOverlayedGui().drawHoveringText(tooltipData.text, tooltipData.x, tooltipData.y); + } + GlStateManager.disableLighting(); + tooltipsToRender.clear(); + GlStateManager.popMatrix(); + + } + + public static boolean mouseClick(int x, int y, int button) { + if (aeiGui.visible) { + for(Control control : aeiGui.controls) { + if (control.isHighlighted() && control.isEnabled() && control.onClick != null) { + if (focusedControl != null) + focusedControl.setFocused(false); + if (control instanceof IFocusable) { + focusedControl = (IFocusable) control; + ((IFocusable) control).setFocused(true); + } + return control.onClick.apply(button); + } + } + if (focusedControl != null) { + focusedControl.setFocused(false); + focusedControl = null; + } + } + if (overlayedGui instanceof RecipeGui) { + List controls = ((RecipeGui) overlayedGui).controls; + Optional ctrl = controls.stream().filter(Control::isHighlighted).filter(Control::isEnabled).findFirst(); + if (ctrl.isPresent()) { + try { + return ctrl.get().onClick.apply(button); + } catch (Exception e) { + } + } + } + return false; + } + + public static boolean keyDown(int typedChar, int keyCode, int unknown) { + boolean handled = false; + if (focusedControl != null && focusedControl instanceof Control) { + Control control = (Control) focusedControl; + if (control.onKeyDown != null) { + handled = control.onKeyDown.accept(typedChar, keyCode, unknown); + } + if (control.charPressed != null) + if (typedChar == 256) { + ((IFocusable) control).setFocused(false); + focusedControl = null; + } + handled = true; + } + if (!handled) { + return KeyBindManager.processGuiKeybinds(typedChar); + } + return handled; + } + + public static boolean charInput(long num, int keyCode, int unknown) { + if (focusedControl != null && focusedControl instanceof Control) { + Control control = (Control) focusedControl; + if (control.charPressed != null) { + int numChars = Character.charCount(keyCode); + if (num == numChars) + control.charPressed.accept((char) keyCode, unknown); + else { + char[] chars = Character.toChars(keyCode); + for(int x = 0; x < chars.length; x++) { + control.charPressed.accept(chars[x], unknown); + } + } + return true; + } + } + return false; + } + + public static boolean mouseScrolled(double direction) { + if (!aeiGui.visible) + return false; + if (direction > 0 && aeiGui.buttonLeft.isEnabled()) + aeiGui.buttonLeft.onClick.apply(0); + else if (direction < 0 && aeiGui.buttonRight.isEnabled()) + aeiGui.buttonRight.onClick.apply(0); + return true; + } + + private static class TooltipData { + + private final List text; + private final int x; + private final int y; + + public TooltipData(List text, int x, int y) { + this.text = text; + this.x = x; + this.y = y; + } + } + + public static void updateSearch() { + aeiGui.updateView(); + } + + public static void tick() { + if (aeiGui != null && Minecraft.getInstance().currentScreen == overlayedGui) + aeiGui.tick(); + } + + public static void recipeKeybind() { + if (!(Minecraft.getInstance().currentScreen instanceof GuiContainer)) + return; + Control control = aeiGui.getLastHovered(); + if (control != null && control.isHighlighted() && control instanceof AEISlot) { + AEISlot slot = (AEISlot) control; + AEIRecipeManager.instance().displayRecipesFor(slot.getStack()); + return; + } + if (((IMixinGuiContainer) overlayedGui).getHoveredSlot() != null) { + ItemStack stack = ((IMixinGuiContainer) overlayedGui).getHoveredSlot().getStack(); + AEIRecipeManager.instance().displayRecipesFor(stack); + } + + } + + public static void useKeybind() { + if (!(Minecraft.getInstance().currentScreen instanceof GuiContainer)) + return; + Control control = aeiGui.getLastHovered(); + if (control != null && control.isHighlighted() && control instanceof AEISlot) { + AEISlot slot = (AEISlot) control; + AEIRecipeManager.instance().displayUsesFor(slot.getStack()); + return; + } + if (((IMixinGuiContainer) overlayedGui).getHoveredSlot() != null) { + ItemStack stack = ((IMixinGuiContainer) overlayedGui).getHoveredSlot().getStack(); + AEIRecipeManager.instance().displayUsesFor(stack); + } + + } + + public static void hideKeybind() { + if (Minecraft.getInstance().currentScreen == overlayedGui && aeiGui != null) { + aeiGui.visible = !aeiGui.visible; + } + } +} diff --git a/src/main/java/me/shedaniel/gui/Drawable.java b/src/main/java/me/shedaniel/gui/Drawable.java new file mode 100755 index 000000000..8fffc17af --- /dev/null +++ b/src/main/java/me/shedaniel/gui/Drawable.java @@ -0,0 +1,33 @@ +package me.shedaniel.gui; + +import me.shedaniel.api.IDrawable; +import me.shedaniel.gui.widget.Control; + +import java.awt.*; + +/** + * Created by James on 7/28/2018. + */ +public abstract class Drawable implements IDrawable { + protected Rectangle rect; + + public Drawable(int x, int y, int width, int height) { + rect = new Rectangle(x, y, width, height); + } + + public Drawable(Rectangle rect) { + this.rect = rect; + } + + public abstract void draw(); + + public boolean isHighlighted() { + Point mousePoint = AEIRenderHelper.getMouseLoc(); + if (rect.contains(mousePoint.x, mousePoint.y)) { + if (this instanceof Control) + AEIRenderHelper.aeiGui.setLastHovered((Control) this); + return true; + } + return false; + } +} diff --git a/src/main/java/me/shedaniel/gui/GuiItemList.java b/src/main/java/me/shedaniel/gui/GuiItemList.java new file mode 100755 index 000000000..80666f2cb --- /dev/null +++ b/src/main/java/me/shedaniel/gui/GuiItemList.java @@ -0,0 +1,264 @@ +package me.shedaniel.gui; + +import me.shedaniel.ClientListener; +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Button; +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.TextBox; +import me.shedaniel.listenerdefinitions.IMixinGuiContainer; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.registry.IRegistry; +import net.minecraft.util.text.TextComponentTranslation; + +import java.awt.*; +import java.util.ArrayList; + +public class GuiItemList extends Drawable { + + public static final int FOOTERSIZE = 44; + private GuiContainer overlayedGui; + private static int page = 0; + private ArrayList displaySlots; + protected ArrayList controls; + private boolean needsResize = false; + Button buttonLeft; + Button buttonRight; + Button buttonCheating; + TextBox searchBox; + private ArrayList view; + private Control lastHovered; + protected boolean visible = true; + private int oldGuiLeft = 0; + private boolean cheatMode = false; + + public GuiItemList(GuiContainer overlayedGui) { + super(calculateRect(overlayedGui)); + displaySlots = new ArrayList<>(); + controls = new ArrayList<>(); + this.overlayedGui = overlayedGui; + view = new ArrayList<>(); + resize(); + } + + public boolean canCheat() { + EntityPlayer player = Minecraft.getInstance().player; + if (cheatMode) { + if (!player.hasPermissionLevel(1)) { + cheatClicked(0); + return false; + } + return true; + } + return false; + } + + private static Rectangle calculateRect(GuiContainer overlayedGui) { + MainWindow res = AEIRenderHelper.getResolution(); + int startX = (((IMixinGuiContainer) overlayedGui).getGuiLeft() + ((IMixinGuiContainer) overlayedGui).getXSize()) + 10; + int width = res.getScaledWidth() - startX; + return new Rectangle(startX, 0, width, res.getScaledHeight()); + } + + protected void resize() { + MainWindow res = AEIRenderHelper.getResolution(); + + if (overlayedGui != Minecraft.getInstance().currentScreen) { + if (Minecraft.getInstance().currentScreen instanceof GuiContainer) { + overlayedGui = (GuiContainer) Minecraft.getInstance().currentScreen; + + } else { + needsResize = true; + return; + } + } + oldGuiLeft = ((IMixinGuiContainer) overlayedGui).getGuiLeft(); + rect = calculateRect(overlayedGui); + page = 0; + buttonLeft = new Button(rect.x, rect.y + 3, 16, 20, "<"); + buttonLeft.onClick = this::btnLeftClicked; + buttonRight = new Button(rect.x + rect.width - 18, rect.y + 3, 16, 20, ">"); + buttonRight.onClick = this::btnRightClicked; + controls.clear(); + controls.add(buttonLeft); + controls.add(buttonRight); + String savedText = ""; + if (searchBox != null) { + savedText = searchBox.getText(); + } + searchBox = new TextBox(rect.x, rect.height - 31, rect.width - 4, 18); + searchBox.setText(savedText); + controls.add(searchBox); + buttonCheating = new Button(5, 5, 45, 20, getCheatModeText()); + buttonCheating.onClick = this::cheatClicked; + controls.add(buttonCheating); + calculateSlots(); + updateView(); + fillSlots(); + controls.addAll(displaySlots); + } + + private void fillSlots() { + page = MathHelper.clamp(page, 0, (int) Math.floor(view.size() / displaySlots.size())); + int firstSlot = page * displaySlots.size(); + for(int i = 0; i < displaySlots.size(); i++) { + if (firstSlot + i < view.size() && firstSlot + i >= 0) { + displaySlots.get(i).setStack(view.get(firstSlot + i)); + } else { + displaySlots.get(i).setStack(ItemStack.EMPTY); + } + } + } + + private void calculateSlots() { + int x = rect.x; + int y = rect.y + 20; + MainWindow res = AEIRenderHelper.getResolution(); + displaySlots.clear(); + int xOffset = 4; + int yOffset = 4; + while (true) { + AEISlot slot = new AEISlot(x + xOffset, y + yOffset); + slot.setCheatable(true); + xOffset += 18; + displaySlots.add(slot); + if (x + xOffset + 18 > res.getScaledWidth()) { + xOffset = 4; + yOffset += 18; + } + if (y + yOffset + 9 + FOOTERSIZE > rect.height) { + break; + } + } + } + + @Override + public void draw() { + if (!visible) + return; + if (needsResize == true) + resize(); + if (oldGuiLeft != ((IMixinGuiContainer) overlayedGui).getGuiLeft()) + resize(); + GlStateManager.pushMatrix(); + updateButtons(); + controls.forEach(Control::draw); + String header = String.format("%s/%s", page + 1, ((int) Math.floor(view.size() / displaySlots.size())) + 1); + Minecraft.getInstance().fontRenderer.drawStringWithShadow(header, rect.x + (rect.width / 2) - (Minecraft.getInstance().fontRenderer.getStringWidth(header) / 2), rect.y + 10, -1); + GlStateManager.popMatrix(); + } + + private void updateButtons() { + if (page == 0) + buttonLeft.setEnabled(false); + else + buttonLeft.setEnabled(true); + if (displaySlots.size() + displaySlots.size() * page >= view.size()) + buttonRight.setEnabled(false); + else + buttonRight.setEnabled(true); + } + + + public boolean btnRightClicked(int button) { + if (button == 0) { + page++; + fillSlots(); + return true; + } + return false; + } + + public boolean btnLeftClicked(int button) { + if (button == 0) { + page--; + fillSlots(); + return true; + } + return false; + } + + public boolean cheatClicked(int button) { + if (button == 0) { + cheatMode = !cheatMode; + + buttonCheating.setString(getCheatModeText()); + return true; + } + return false; + } + + private String getCheatModeText() { + if (cheatMode) { + TextComponentTranslation cheat = new TextComponentTranslation("text.aei.cheat", new Object[]{null}); + return cheat.getFormattedText(); + } + TextComponentTranslation noCheat = new TextComponentTranslation("text.aei.nocheat", new Object[]{null}); + return noCheat.getFormattedText(); + } + + protected void updateView() { + String searchText = searchBox.getText(); + String modText = null; + if (searchText.contains("@")) { + int nextBreak = searchText.indexOf(' ', searchText.indexOf('@')); + if (nextBreak == 0 || nextBreak == -1) + nextBreak = searchText.length(); + modText = searchText.substring(searchText.indexOf('@'), nextBreak); + searchText = searchText.replace(modText, "").trim(); + modText = modText.replace("@", "").toLowerCase(); + } + + view.clear(); + if (searchText.equals("") || searchText == null) { + for(ItemStack stack : ClientListener.stackList) { + if (modText != null) { + if (getMod(stack).contains(modText)) { + view.add(stack); + } + } else { + view.add(stack); + } + } + } else { + for(ItemStack stack : ClientListener.stackList) { + if (stack.getItem().getName().getString().toLowerCase().contains(searchText)) + if (modText != null) { + if (getMod(stack).contains(modText)) { + view.add(stack); + } + } else { + view.add(stack); + } + } + } + page = 0; + fillSlots(); + } + + public void tick() { + controls.forEach(f -> f.tick()); + } + + public void setLastHovered(Control ctrl) { + lastHovered = ctrl; + } + + public Control getLastHovered() { + return lastHovered; + } + + private String getMod(ItemStack stack) { + if (stack != null && !stack.isEmpty()) { + ResourceLocation location = IRegistry.ITEM.getKey(stack.getItem()); + return location.getNamespace(); + } + return ""; + } +} diff --git a/src/main/java/me/shedaniel/gui/RecipeContainer.java b/src/main/java/me/shedaniel/gui/RecipeContainer.java new file mode 100755 index 000000000..f8605a45c --- /dev/null +++ b/src/main/java/me/shedaniel/gui/RecipeContainer.java @@ -0,0 +1,13 @@ +package me.shedaniel.gui; + + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; + +public class RecipeContainer extends Container { + + @Override + public boolean canInteractWith(EntityPlayer entityPlayer) { + return true; + } +} diff --git a/src/main/java/me/shedaniel/gui/RecipeGui.java b/src/main/java/me/shedaniel/gui/RecipeGui.java new file mode 100755 index 000000000..6cdd9542a --- /dev/null +++ b/src/main/java/me/shedaniel/gui/RecipeGui.java @@ -0,0 +1,218 @@ +package me.shedaniel.gui; + +import me.shedaniel.api.IDisplayCategory; +import me.shedaniel.api.IRecipe; +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Button; +import me.shedaniel.gui.widget.Control; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.inventory.Container; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class RecipeGui extends GuiContainer { + private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("almostenoughitems", "textures/gui/recipecontainer.png"); + private final MainWindow mainWindow; + private final Container container; + private final GuiScreen prevScreen; + private final Map> recipes; + private int guiWidth = 176; + private int guiHeight = 222; + ArrayList categories = new ArrayList<>(); + private int categoryPointer = 0; + private int recipePointer = 0; + private List slots; + private int cycleCounter = 0; + private int[] itemPointer; + List controls = new LinkedList<>(); + + public RecipeGui(Container p_i1072_1_, GuiScreen prevScreen, Map> recipes) { + super(new RecipeContainer()); + this.container = p_i1072_1_; + this.prevScreen = prevScreen; + this.recipes = recipes; + this.mc = Minecraft.getInstance(); + this.itemRender = mc.getItemRenderer(); + this.fontRenderer = mc.fontRenderer; + this.mainWindow = Minecraft.getInstance().mainWindow; + + setupCategories(); + } + + private void setupCategories() { + categories.addAll(recipes.keySet()); + updateRecipe(); + } + + + @Override + public void render(int mouseX, int mouseY, float partialTicks) { + super.render(mouseX, mouseY, partialTicks); + int y = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); + drawCenteredString(this.fontRenderer, categories.get(categoryPointer).getDisplayName(), guiLeft + guiWidth / 2, y + 11, -1); + drawCenteredString(this.fontRenderer, String.format("%d/%d", 1 + getCurrentPage(), getTotalPages()), guiLeft + guiWidth / 2, y + 34, -1); + controls.forEach(Control::draw); + } + + private int getCurrentPage() { + return recipePointer / 2; + } + + @Override + public void tick() { + super.tick(); + slots.forEach(AEISlot::tick); + controls.forEach(Control::tick); + } + + + @Override + public void onResize(Minecraft p_onResize_1_, int p_onResize_2_, int p_onResize_3_) { + super.onResize(p_onResize_1_, p_onResize_2_, p_onResize_3_); + updateRecipe(); + } + + private void updateRecipe() { + IRecipe recipe = recipes.get(categories.get(categoryPointer)).get(recipePointer); + categories.get(categoryPointer).resetRecipes(); + categories.get(categoryPointer).addRecipe(recipe); + slots = categories.get(categoryPointer).setupDisplay(0); + if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) { + IRecipe recipe2 = recipes.get(categories.get(categoryPointer)).get(recipePointer + 1); + categories.get(categoryPointer).addRecipe(recipe2); + slots.addAll(categories.get(categoryPointer).setupDisplay(1)); + } + + guiLeft = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2)); + guiTop = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); + + for(AEISlot slot : slots) { + slot.move(guiLeft, guiTop); + } + + Button btnCategoryLeft = new Button(guiLeft + 10, guiTop + 5, 15, 20, "<"); + Button btnCategoryRight = new Button(guiLeft + guiWidth - 25, guiTop + 5, 15, 20, ">"); + btnCategoryRight.onClick = this::btnCategoryRight; + btnCategoryLeft.onClick = this::btnCategoryLeft; + + Button btnRecipeLeft = new Button(guiLeft + 10, guiTop + 28, 15, 20, "<"); + Button btnRecipeRight = new Button(guiLeft + guiWidth - 25, guiTop + 28, 15, 20, ">"); + btnRecipeLeft.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && recipePointer > 0); + btnRecipeRight.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && getCurrentPage() + 1 < getTotalPages()); + btnRecipeRight.onClick = this::btnRecipeRight; + btnRecipeLeft.onClick = this::btnRecipeLeft; + + controls.clear(); + controls.add(btnCategoryLeft); + controls.add(btnCategoryRight); + if (categories.size() <= 2) { + btnCategoryLeft.setEnabled(false); + btnCategoryRight.setEnabled(false); + } + + controls.add(btnRecipeLeft); + controls.add(btnRecipeRight); + + itemPointer = new int[9]; + for(int i = 0; i < itemPointer.length; i++) { + itemPointer[i] = 0; + } + + List newControls = new LinkedList<>(); + categories.get(categoryPointer).addWidget(newControls, 0); + if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) { + categories.get(categoryPointer).addWidget(newControls, 1); + } + newControls.forEach(f -> f.move(guiLeft, guiTop)); + controls.addAll(newControls); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float v, int i, int i1) { + drawDefaultBackground(); + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(CHEST_GUI_TEXTURE); + + int lvt_4_1_ = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2)); + int lvt_5_1_ = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); + + this.drawTexturedModalRect(lvt_4_1_, lvt_5_1_, 0, 0, this.guiWidth, this.guiHeight); + slots.forEach(AEISlot::draw); + } + + + @Override + protected void initGui() { + super.initGui(); + } + + @Override + public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) { + if (p_keyPressed_1_ == 259 && prevScreen != null && AEIRenderHelper.focusedControl == null) { + Minecraft.getInstance().displayGuiScreen(prevScreen); + return true; + } + + return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + } + + private boolean btnCategoryLeft(int button) { + recipePointer = 0; + categoryPointer--; + if (categoryPointer < 0) { + categoryPointer = categories.size() - 1; + } + updateRecipe(); + return true; + } + + private boolean btnCategoryRight(int button) { + recipePointer = 0; + categoryPointer++; + if (categoryPointer >= categories.size()) { + categoryPointer = 0; + } + updateRecipe(); + return true; + } + + private boolean btnRecipeLeft(int button) { + recipePointer -= 2; + if (recipePointer < 0) { + recipePointer = (getTotalPages() - 1) * 2; + } + updateRecipe(); + return true; + } + + private boolean btnRecipeRight(int button) { + recipePointer += 2; + if (recipePointer >= recipes.get(categories.get(categoryPointer)).size()) { + recipePointer = 0; + } + updateRecipe(); + return true; + } + + private int riseDoublesToInt(double i) { + return (int) (i + (i % 1 == 0 ? 0 : 1)); + } + + private int getTotalPages() { + return MathHelper.clamp(riseDoublesToInt(recipes.get(categories.get(categoryPointer)).size() / 2), 1, Integer.MAX_VALUE); + } +} diff --git a/src/main/java/me/shedaniel/gui/widget/AEISlot.java b/src/main/java/me/shedaniel/gui/widget/AEISlot.java new file mode 100755 index 000000000..bc3569699 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/AEISlot.java @@ -0,0 +1,181 @@ +package me.shedaniel.gui.widget; + +import com.google.common.collect.Lists; +import me.shedaniel.gui.AEIRenderHelper; +import me.shedaniel.listenerdefinitions.IMixinGuiContainer; +import me.shedaniel.network.CheatPacket; +import me.shedaniel.network.DeletePacket; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.IRegistry; + +import java.awt.*; +import java.util.LinkedList; +import java.util.List; + +/** + * Created by James on 7/28/2018. + */ +public class AEISlot extends Control { + private static final ResourceLocation RECIPE_GUI = new ResourceLocation("almostenoughitems", "textures/gui/recipecontainer.png"); + private boolean cheatable = false; + private List itemList = new LinkedList<>(); + private int itemListPointer = 0; + private long displayCounter = 0; + + public boolean isDrawBackground() { + return drawBackground; + } + + private String extraTooltip; + + + @Override + public void tick() { + if (itemList.size() > 1) { + displayCounter++; + if (displayCounter % 10 == 0) + if (itemListPointer + 1 >= itemList.size()) + itemListPointer = 0; + else itemListPointer++; + } + } + + public void setStackList(List newItemList) { + itemList = newItemList; + itemListPointer = 0; + displayCounter = 0; + } + + public void setExtraTooltip(String toolTip) { + extraTooltip = toolTip; + } + + public void setDrawBackground(boolean drawBackground) { + this.drawBackground = drawBackground; + } + + private boolean drawBackground = false; + private Point backgroundUV = new Point(0, 222); + + public AEISlot(int x, int y) { + super(x, y, 18, 18); + this.onClick = this::onClick; + } + + public ItemStack getStack() { + if (itemList.isEmpty()) { + return ItemStack.EMPTY; + } + return itemList.get(itemListPointer); + } + + public void setStack(ItemStack stack) { + itemList.clear(); + if (stack != null) + itemList.add(stack); + itemListPointer = 0; + } + + @Override + public void draw() { + if (drawBackground) { + Minecraft.getInstance().getTextureManager().bindTexture(RECIPE_GUI); + drawTexturedModalRect(rect.x - 1, rect.y - 1, backgroundUV.x, backgroundUV.y, rect.width, rect.height); + } + if (getStack().isEmpty()) + return; + RenderHelper.enableGUIStandardItemLighting(); + + drawStack(rect.x, rect.y); + if (isHighlighted()) + drawTooltip(); + } + + private void drawTooltip() { + List toolTip = getTooltip(); + toolTip.add("ยง9" + getMod()); + Point mouse = AEIRenderHelper.getMouseLoc(); + AEIRenderHelper.addToolTip(toolTip, mouse.x, mouse.y); + } + + private boolean onClick(int button) { + EntityPlayer player = Minecraft.getInstance().player; + if (AEIRenderHelper.aeiGui.canCheat() && !(player.inventory.getItemStack().isEmpty())) { + //Delete the itemstack. + Minecraft.getInstance().getConnection().sendPacket(new DeletePacket()); + return true; + } + if (!player.inventory.getItemStack().isEmpty()) { + return false; + } + + if (AEIRenderHelper.aeiGui.canCheat() && this.cheatable) { + if (getStack() != null && !getStack().isEmpty()) { + ItemStack cheatedStack = getStack().copy(); + if (button == 0) + cheatedStack.setCount(1); + if (button == 1) { + cheatedStack.setCount(cheatedStack.getMaxStackSize()); + } + Minecraft.getInstance().getConnection().sendPacket(new CheatPacket(cheatedStack)); + return true; + } + } else { + AEIRenderHelper.recipeKeybind(); + } + return false; + } + + + private void drawStack(int x, int y) { + GuiContainer gui = AEIRenderHelper.getOverlayedGui(); + AEIRenderHelper.getItemRender().zLevel = 200.0F; + AEIRenderHelper.getItemRender().renderItemAndEffectIntoGUI(getStack(), x, y); + assert gui != null; + if (((IMixinGuiContainer) gui).getDraggedStack().isEmpty()) + AEIRenderHelper.getItemRender().renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, getStack(), x, y - 0, ""); + else + AEIRenderHelper.getItemRender().renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, getStack(), x, y - 8, ""); + AEIRenderHelper.getItemRender().zLevel = 0.0F; + } + + public String getMod() { + if (!getStack().isEmpty()) { + ResourceLocation location = IRegistry.ITEM.getKey(getStack().getItem()); + assert location != null; + return location.getNamespace(); + } + return ""; + } + + private List getTooltip() { + Minecraft mc = Minecraft.getInstance(); + GuiContainer gui = AEIRenderHelper.getOverlayedGui(); + List toolTip = Lists.newArrayList(); + if (gui != null) { + toolTip = gui.getItemToolTip(getStack()); + } else { + toolTip.add(getStack().getDisplayName().getFormattedText()); + } + if (extraTooltip != null) { + toolTip.add(extraTooltip); + } + + return toolTip; + } + + public boolean isCheatable() { + return cheatable; + } + + public void setCheatable(boolean cheatable) { + this.cheatable = cheatable; + } + + +} diff --git a/src/main/java/me/shedaniel/gui/widget/Button.java b/src/main/java/me/shedaniel/gui/widget/Button.java new file mode 100755 index 000000000..3cb68a2ba --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/Button.java @@ -0,0 +1,72 @@ +package me.shedaniel.gui.widget; + +import me.shedaniel.gui.AEIRenderHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; + +import java.awt.*; + +/** + * Created by James on 7/29/2018. + */ +public class Button extends Control { + private String buttonText; + protected static final ResourceLocation BUTTON_TEXTURES = new ResourceLocation("textures/gui/widgets.png"); + + + public Button(int x, int y, int width, int height, String buttonText) { + super(x, y, width, height); + this.buttonText = buttonText; + } + + public Button(Rectangle rect, String buttonText) { + super(rect); + this.buttonText = buttonText; + } + + public void setString(String text) { + buttonText = text; + } + + + @Override + public void draw() { + GlStateManager.pushMatrix(); + GlStateManager.disableLighting(); + GuiContainer gui = AEIRenderHelper.getOverlayedGui(); + Minecraft lvt_4_1_ = Minecraft.getInstance(); + FontRenderer lvt_5_1_ = lvt_4_1_.fontRenderer; + lvt_4_1_.getTextureManager().bindTexture(BUTTON_TEXTURES); + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + int hoverState = (byte) 0; + if (this.isEnabled()) { + if (!this.isHighlighted()) + hoverState = (byte) 1; + else + hoverState = (byte) 2; + } + + GlStateManager.enableBlend(); + GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + gui.drawTexturedModalRect(rect.x, rect.y, 0, 46 + hoverState * 20, rect.width / 2, rect.height); + gui.drawTexturedModalRect(rect.x + rect.width / 2, rect.y, 200 - rect.width / 2, 46 + hoverState * 20, rect.width / 2, rect.height); + //this.mouseDragged(lvt_4_1_, p_194828_1_, p_194828_2_); + int lvt_7_1_ = 14737632; +// if(!this.enabled) { +// lvt_7_1_ = 10526880; +// } else if(this.hovered) { +// lvt_7_1_ = 16777120; +// } + + + gui.drawCenteredString(lvt_5_1_, this.buttonText, rect.x + rect.width / 2, rect.y + (rect.height - 8) / 2, lvt_7_1_); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + } + + +} diff --git a/src/main/java/me/shedaniel/gui/widget/Control.java b/src/main/java/me/shedaniel/gui/widget/Control.java new file mode 100755 index 000000000..32763caa6 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/Control.java @@ -0,0 +1,96 @@ +package me.shedaniel.gui.widget; + +import me.shedaniel.api.TriBooleanProducer; +import me.shedaniel.gui.Drawable; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; + +import java.awt.*; +import java.util.function.BiConsumer; +import java.util.function.IntFunction; + +/** + * Created by James on 7/29/2018. + */ +public abstract class Control extends Drawable { + private boolean enabled = true; + public IntFunction onClick; + public TriBooleanProducer onKeyDown; + public BiConsumer charPressed; + + public Control(int x, int y, int width, int height) { + super(x, y, width, height); + } + + public Control(Rectangle rect) { + super(rect); + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public void move(int x, int y) { + rect.x += x; + rect.y += y; + //rect.move(x+rect.x,rect.y+y);//Why the fuck? + } + + protected static void drawRect(int p_drawRect_0_, int p_drawRect_1_, int p_drawRect_2_, int p_drawRect_3_, int p_drawRect_4_) { + int lvt_5_3_; + if (p_drawRect_0_ < p_drawRect_2_) { + lvt_5_3_ = p_drawRect_0_; + p_drawRect_0_ = p_drawRect_2_; + p_drawRect_2_ = lvt_5_3_; + } + + if (p_drawRect_1_ < p_drawRect_3_) { + lvt_5_3_ = p_drawRect_1_; + p_drawRect_1_ = p_drawRect_3_; + p_drawRect_3_ = lvt_5_3_; + } + + float lvt_5_3_1 = (float) (p_drawRect_4_ >> 24 & 255) / 255.0F; + float lvt_6_1_ = (float) (p_drawRect_4_ >> 16 & 255) / 255.0F; + float lvt_7_1_ = (float) (p_drawRect_4_ >> 8 & 255) / 255.0F; + float lvt_8_1_ = (float) (p_drawRect_4_ & 255) / 255.0F; + Tessellator lvt_9_1_ = Tessellator.getInstance(); + BufferBuilder lvt_10_1_ = lvt_9_1_.getBuffer(); + GlStateManager.enableAlphaTest(); + GlStateManager.enableBlend(); + GlStateManager.disableTexture2D(); + GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.color4f(lvt_6_1_, lvt_7_1_, lvt_8_1_, lvt_5_3_1); + lvt_10_1_.begin(7, DefaultVertexFormats.POSITION); + lvt_10_1_.pos((double) p_drawRect_0_, (double) p_drawRect_3_, 0.0D).endVertex(); + lvt_10_1_.pos((double) p_drawRect_2_, (double) p_drawRect_3_, 0.0D).endVertex(); + lvt_10_1_.pos((double) p_drawRect_2_, (double) p_drawRect_1_, 0.0D).endVertex(); + lvt_10_1_.pos((double) p_drawRect_0_, (double) p_drawRect_1_, 0.0D).endVertex(); + lvt_9_1_.draw(); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.disableAlphaTest(); + } + + protected void drawTexturedModalRect(int x, int y, int u, int v, int width, int height) { + float lvt_7_1_ = 0.00390625F; + float lvt_8_1_ = 0.00390625F; + Tessellator lvt_9_1_ = Tessellator.getInstance(); + BufferBuilder lvt_10_1_ = lvt_9_1_.getBuffer(); + lvt_10_1_.begin(7, DefaultVertexFormats.POSITION_TEX); + lvt_10_1_.pos((double) (x + 0), (double) (y + height), (double) 200).tex((double) ((float) (u + 0) * 0.00390625F), (double) ((float) (v + height) * 0.00390625F)).endVertex(); + lvt_10_1_.pos((double) (x + width), (double) (y + height), (double) 200).tex((double) ((float) (u + width) * 0.00390625F), (double) ((float) (v + height) * 0.00390625F)).endVertex(); + lvt_10_1_.pos((double) (x + width), (double) (y + 0), (double) 200).tex((double) ((float) (u + width) * 0.00390625F), (double) ((float) (v + 0) * 0.00390625F)).endVertex(); + lvt_10_1_.pos((double) (x + 0), (double) (y + 0), (double) 200).tex((double) ((float) (u + 0) * 0.00390625F), (double) ((float) (v + 0) * 0.00390625F)).endVertex(); + lvt_9_1_.draw(); + } + + public void tick() { + } +} diff --git a/src/main/java/me/shedaniel/gui/widget/IFocusable.java b/src/main/java/me/shedaniel/gui/widget/IFocusable.java new file mode 100755 index 000000000..54a0b9426 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/IFocusable.java @@ -0,0 +1,10 @@ +package me.shedaniel.gui.widget; + +/** + * Created by James on 8/3/2018. + */ +public interface IFocusable { + public boolean hasFocus(); + + public void setFocused(boolean val); +} diff --git a/src/main/java/me/shedaniel/gui/widget/TextBox.java b/src/main/java/me/shedaniel/gui/widget/TextBox.java new file mode 100755 index 000000000..40cf9924b --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/TextBox.java @@ -0,0 +1,71 @@ +package me.shedaniel.gui.widget; + +import me.shedaniel.gui.AEIRenderHelper; +import net.minecraft.client.gui.GuiTextField; + +import java.awt.*; + +/** + * Created by James on 8/3/2018. + */ +public class TextBox extends Control implements IFocusable { + + private GuiTextField textField; + + public TextBox(int x, int y, int width, int height) { + super(x, y, width, height); + textField = new GuiTextField(-1, AEIRenderHelper.getFontRenderer(), x, y, width, height); + this.onClick = this::doMouseClick; + this.onKeyDown = this::onKeyPressed; + this.charPressed = this::charTyped; + } + + @Override + public void draw() { + textField.drawTextField(0, 0, 0); + } + + @Override + public boolean hasFocus() { + return textField.isFocused(); + } + + @Override + public void setFocused(boolean val) { + textField.setFocused(val); + } + + protected boolean doMouseClick(int button) { + Point mouseLoc = AEIRenderHelper.getMouseLoc(); + if (!hasFocus()) + setFocused(true); + return textField.mouseClicked(mouseLoc.x, mouseLoc.y, 0); + } + + protected boolean onKeyPressed(int first, int second, int third) { + boolean handled = textField.keyPressed(first, second, third); + if (handled) { + AEIRenderHelper.updateSearch(); + } + + return handled; + } + + public String getText() { + return textField.getText(); + } + + public void setText(String value) { + textField.setText(value); + } + + protected void charTyped(char p_charTyped_1_, int p_charTyped_2_) { + textField.charTyped(p_charTyped_1_, p_charTyped_2_); + AEIRenderHelper.updateSearch(); + } + + @Override + public void tick() { + textField.tick(); + } +} diff --git a/src/main/java/me/shedaniel/gui/widget/WidgetArrow.java b/src/main/java/me/shedaniel/gui/widget/WidgetArrow.java new file mode 100755 index 000000000..9cc76738d --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/WidgetArrow.java @@ -0,0 +1,38 @@ +package me.shedaniel.gui.widget; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.ResourceLocation; + +public class WidgetArrow extends Control { + private static final ResourceLocation RECIPE_GUI = new ResourceLocation("almostenoughitems", "textures/gui/recipecontainer.png"); + private int progress = 0; + private int updateTick = 0; + private boolean animated; + + public WidgetArrow(int x, int y, boolean animated) { + super(x, y, 22, 18); + this.animated = animated; + } + + @Override + public void draw() { + Minecraft.getInstance().getTextureManager().bindTexture(RECIPE_GUI); + this.drawTexturedModalRect(rect.x, rect.y, 18, 222, 22, 18); + if (animated) { + int width = (int) ((progress / 10f) * 22); + this.drawTexturedModalRect(rect.x - 1, rect.y - 1, 40, 222, width, 18); + } + } + + @Override + public void tick() { + updateTick++; + if (updateTick >= 20) { + updateTick = 0; + + progress++; + if (progress > 10) + progress = 0; + } + } +} diff --git a/src/main/java/me/shedaniel/impl/AEIRecipeManager.java b/src/main/java/me/shedaniel/impl/AEIRecipeManager.java new file mode 100755 index 000000000..5d25bbd47 --- /dev/null +++ b/src/main/java/me/shedaniel/impl/AEIRecipeManager.java @@ -0,0 +1,157 @@ +package me.shedaniel.impl; + +import me.shedaniel.api.IAEIPlugin; +import me.shedaniel.api.IDisplayCategory; +import me.shedaniel.api.IRecipe; +import me.shedaniel.api.IRecipeManager; +import me.shedaniel.gui.RecipeGui; +import net.minecraft.client.Minecraft; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.RecipeManager; +import net.minecraft.item.crafting.ShapelessRecipe; +import net.minecraft.util.ResourceLocation; +import org.dimdev.riftloader.RiftLoader; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * Created by James on 8/7/2018. + */ +public class AEIRecipeManager implements IRecipeManager { + private Map> recipeList; + private List displayAdapters; + public static RecipeManager recipeManager; + + private static AEIRecipeManager myInstance; + + private AEIRecipeManager() { + recipeList = new HashMap<>(); + displayAdapters = new LinkedList<>(); + } + + public static AEIRecipeManager instance() { + if (myInstance == null) { + System.out.println("Newing me up."); + myInstance = new AEIRecipeManager(); + } + return myInstance; + } + + @Override + public void addRecipe(String id, IRecipe recipe) { + if (recipeList.containsKey(id)) { + recipeList.get(id).add(recipe); + } else { + List recipes = new LinkedList<>(); + recipeList.put(id, recipes); + recipes.add(recipe); + } + + + } + + @Override + public void addRecipe(String id, List recipes) { + if (recipeList.containsKey(id)) { + recipeList.get(id).addAll(recipes); + } else { + List newRecipeList = new LinkedList<>(); + recipeList.put(id, newRecipeList); + newRecipeList.addAll(recipes); + } + } + + @Override + public void addDisplayAdapter(IDisplayCategory adapter) { + displayAdapters.add(adapter); + } + + @Override + public Map> getRecipesFor(ItemStack stack) { + Map> categories = new HashMap<>(); + displayAdapters.forEach(f -> categories.put(f, new LinkedList<>())); + for(List value : recipeList.values()) { + for(IRecipe iRecipe : value) { + for(Object o : iRecipe.getOutput()) { + if (o instanceof ItemStack) { + if (ItemStack.areItemsEqual(stack, (ItemStack) o)) { + for(IDisplayCategory iDisplayCategory : categories.keySet()) { + if (iDisplayCategory.getId() == iRecipe.getId()) { + categories.get(iDisplayCategory).add(iRecipe); + } + } + } + } + } + } + } + categories.keySet().removeIf(f -> categories.get(f).isEmpty()); + return categories; + } + + public Map> getUsesFor(ItemStack stack) { + Map> categories = new HashMap<>(); + displayAdapters.forEach(f -> categories.put(f, new LinkedList<>())); + for(List value : recipeList.values()) { + for(IRecipe iRecipe : value) { + boolean found = false; + f