From 3e1f4333a51513b440b32adfe9b698590fbf76f5 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Dec 2018 20:10:36 +0800 Subject: Better stuff --- src/main/java/me/shedaniel/ClientListener.java | 49 ++-- src/main/java/me/shedaniel/api/IAEIPlugin.java | 9 - .../java/me/shedaniel/api/IDisplayCategory.java | 8 +- src/main/java/me/shedaniel/api/IREIPlugin.java | 9 + .../java/me/shedaniel/gui/AEIRenderHelper.java | 235 -------------------- src/main/java/me/shedaniel/gui/Drawable.java | 4 +- src/main/java/me/shedaniel/gui/GuiItemList.java | 136 ++++++++---- .../java/me/shedaniel/gui/REIRenderHelper.java | 247 +++++++++++++++++++++ src/main/java/me/shedaniel/gui/RecipeGui.java | 106 ++++++--- src/main/java/me/shedaniel/gui/SearchArgument.java | 35 +++ src/main/java/me/shedaniel/gui/widget/AEISlot.java | 181 --------------- src/main/java/me/shedaniel/gui/widget/Button.java | 4 +- src/main/java/me/shedaniel/gui/widget/Control.java | 19 ++ src/main/java/me/shedaniel/gui/widget/REISlot.java | 182 +++++++++++++++ src/main/java/me/shedaniel/gui/widget/Tab.java | 101 +++++++++ src/main/java/me/shedaniel/gui/widget/TextBox.java | 10 +- .../java/me/shedaniel/gui/widget/WidgetArrow.java | 4 + .../java/me/shedaniel/impl/AEIRecipeManager.java | 157 ------------- .../java/me/shedaniel/impl/REIRecipeManager.java | 157 +++++++++++++ .../listenerdefinitions/MinecraftResize.java | 2 +- .../listenerdefinitions/PotionCraftingAdder.java | 8 + .../shedaniel/listeners/DrawContainerListener.java | 16 +- .../java/me/shedaniel/listeners/InitListener.java | 3 +- .../me/shedaniel/listeners/ResizeListener.java | 6 +- .../mixins/MixinGuiContainerCreative.java | 1 + .../me/shedaniel/mixins/MixinMinecraftResize.java | 9 +- .../me/shedaniel/mixins/MixinPotionBrewing.java | 21 ++ .../java/me/shedaniel/plugin/RandomRecipe.java | 33 +++ .../me/shedaniel/plugin/TestRandomCategory.java | 72 ++++++ .../java/me/shedaniel/plugin/VanillaPlugin.java | 64 ++++-- .../plugin/crafting/VanillaCraftingCategory.java | 21 +- .../plugin/furnace/VanillaFurnaceCategory.java | 24 +- .../plugin/potion/VanillaPotionCategory.java | 189 ++++++++++++++++ .../plugin/potion/VanillaPotionRecipe.java | 48 ++++ 34 files changed, 1442 insertions(+), 728 deletions(-) delete mode 100755 src/main/java/me/shedaniel/api/IAEIPlugin.java create mode 100755 src/main/java/me/shedaniel/api/IREIPlugin.java delete mode 100755 src/main/java/me/shedaniel/gui/AEIRenderHelper.java create mode 100755 src/main/java/me/shedaniel/gui/REIRenderHelper.java create mode 100644 src/main/java/me/shedaniel/gui/SearchArgument.java delete mode 100755 src/main/java/me/shedaniel/gui/widget/AEISlot.java create mode 100755 src/main/java/me/shedaniel/gui/widget/REISlot.java create mode 100644 src/main/java/me/shedaniel/gui/widget/Tab.java delete mode 100755 src/main/java/me/shedaniel/impl/AEIRecipeManager.java create mode 100755 src/main/java/me/shedaniel/impl/REIRecipeManager.java create mode 100644 src/main/java/me/shedaniel/listenerdefinitions/PotionCraftingAdder.java create mode 100644 src/main/java/me/shedaniel/mixins/MixinPotionBrewing.java create mode 100644 src/main/java/me/shedaniel/plugin/RandomRecipe.java create mode 100644 src/main/java/me/shedaniel/plugin/TestRandomCategory.java create mode 100644 src/main/java/me/shedaniel/plugin/potion/VanillaPotionCategory.java create mode 100755 src/main/java/me/shedaniel/plugin/potion/VanillaPotionRecipe.java (limited to 'src/main/java/me') diff --git a/src/main/java/me/shedaniel/ClientListener.java b/src/main/java/me/shedaniel/ClientListener.java index 9d52addd5..d6c4017c7 100755 --- a/src/main/java/me/shedaniel/ClientListener.java +++ b/src/main/java/me/shedaniel/ClientListener.java @@ -1,12 +1,14 @@ package me.shedaniel; -import me.shedaniel.api.IAEIPlugin; -import me.shedaniel.gui.AEIRenderHelper; -import me.shedaniel.impl.AEIRecipeManager; +import me.shedaniel.api.IREIPlugin; +import me.shedaniel.gui.REIRenderHelper; +import me.shedaniel.impl.REIRecipeManager; import me.shedaniel.library.KeyBindManager; import me.shedaniel.listenerdefinitions.DoneLoading; import me.shedaniel.listenerdefinitions.RecipeLoadListener; import net.minecraft.client.settings.KeyBinding; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; @@ -16,34 +18,43 @@ import net.minecraft.util.registry.IRegistry; import java.awt.event.KeyEvent; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class ClientListener implements DoneLoading, RecipeLoadListener { public static KeyBinding recipeKeybind; public static KeyBinding hideKeybind; public static KeyBinding useKeybind; - private List plugins; + 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); + recipeKeybind = KeyBindManager.createKeybinding("key.rei.recipe", KeyEvent.VK_R, "key.rei.category", REIRenderHelper::recipeKeybind); + hideKeybind = KeyBindManager.createKeybinding("key.rei.hide", KeyEvent.VK_O, "key.rei.category", REIRenderHelper::hideKeybind); + useKeybind = KeyBindManager.createKeybinding("key.rei.use", KeyEvent.VK_U, "key.rei.category", REIRenderHelper::useKeybind); buildItemList(); } private void buildItemList() { - if (!IRegistry.ITEM.isEmpty()) { - IRegistry.ITEM.forEach(item -> processItem((Item) item)); - } - + if (!IRegistry.ITEM.isEmpty()) + IRegistry.ITEM.forEach(this::processItem); + if (!IRegistry.ENCHANTMENT.isEmpty()) + IRegistry.ENCHANTMENT.forEach(enchantment -> { + for(int i = enchantment.getMinLevel(); i < enchantment.getMaxLevel(); i++) { + ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK); + Map map = new HashMap<>(); + map.put(enchantment, i); + EnchantmentHelper.setEnchantments(map, stack); + processItemStack(stack); + } + }); } private void processItem(Item item) { @@ -52,15 +63,19 @@ public class ClientListener implements DoneLoading, RecipeLoadListener { 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); - } +// if (item == Items.ENCHANTED_BOOK) { +// item.fillItemGroup(ItemGroup.TOOLS, items); +// items.forEach(stackList::add); +// } } } + private void processItemStack(ItemStack item) { + stackList.add(item); + } + @Override public void recipesLoaded(net.minecraft.item.crafting.RecipeManager recipeManager) { - AEIRecipeManager.instance().RecipesLoaded(recipeManager); + REIRecipeManager.instance().RecipesLoaded(recipeManager); } } diff --git a/src/main/java/me/shedaniel/api/IAEIPlugin.java b/src/main/java/me/shedaniel/api/IAEIPlugin.java deleted file mode 100755 index 9f5b5da6e..000000000 --- a/src/main/java/me/shedaniel/api/IAEIPlugin.java +++ /dev/null @@ -1,9 +0,0 @@ -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 index f5cb02a4d..7e41920bd 100755 --- a/src/main/java/me/shedaniel/api/IDisplayCategory.java +++ b/src/main/java/me/shedaniel/api/IDisplayCategory.java @@ -1,7 +1,9 @@ package me.shedaniel.api; -import me.shedaniel.gui.widget.AEISlot; import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.REISlot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import java.util.List; @@ -17,11 +19,13 @@ public interface IDisplayCategory { public void resetRecipes(); - public List setupDisplay(int number); + public List setupDisplay(int number); public boolean canDisplay(T recipe); public void drawExtras(); public void addWidget(List controls, int number); + + public ItemStack getCategoryIcon(); } diff --git a/src/main/java/me/shedaniel/api/IREIPlugin.java b/src/main/java/me/shedaniel/api/IREIPlugin.java new file mode 100755 index 000000000..98060163d --- /dev/null +++ b/src/main/java/me/shedaniel/api/IREIPlugin.java @@ -0,0 +1,9 @@ +package me.shedaniel.api; + +/** + * Created by James on 7/27/2018. + */ +public interface IREIPlugin { + + public void register(); +} diff --git a/src/main/java/me/shedaniel/gui/AEIRenderHelper.java b/src/main/java/me/shedaniel/gui/AEIRenderHelper.java deleted file mode 100755 index 3ffbc7d82..000000000 --- a/src/main/java/me/shedaniel/gui/AEIRenderHelper.java +++ /dev/null @@ -1,235 +0,0 @@ -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 index 8fffc17af..76d49e049 100755 --- a/src/main/java/me/shedaniel/gui/Drawable.java +++ b/src/main/java/me/shedaniel/gui/Drawable.java @@ -22,10 +22,10 @@ public abstract class Drawable implements IDrawable { public abstract void draw(); public boolean isHighlighted() { - Point mousePoint = AEIRenderHelper.getMouseLoc(); + Point mousePoint = REIRenderHelper.getMouseLoc(); if (rect.contains(mousePoint.x, mousePoint.y)) { if (this instanceof Control) - AEIRenderHelper.aeiGui.setLastHovered((Control) this); + REIRenderHelper.reiGui.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 index 80666f2cb..f23ab9f85 100755 --- a/src/main/java/me/shedaniel/gui/GuiItemList.java +++ b/src/main/java/me/shedaniel/gui/GuiItemList.java @@ -1,9 +1,9 @@ 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.REISlot; import me.shedaniel.gui.widget.TextBox; import me.shedaniel.listenerdefinitions.IMixinGuiContainer; import net.minecraft.client.MainWindow; @@ -19,13 +19,17 @@ import net.minecraft.util.text.TextComponentTranslation; import java.awt.*; import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class GuiItemList extends Drawable { public static final int FOOTERSIZE = 44; private GuiContainer overlayedGui; private static int page = 0; - private ArrayList displaySlots; + private ArrayList displaySlots; protected ArrayList controls; private boolean needsResize = false; Button buttonLeft; @@ -60,14 +64,14 @@ public class GuiItemList extends Drawable { } private static Rectangle calculateRect(GuiContainer overlayedGui) { - MainWindow res = AEIRenderHelper.getResolution(); + MainWindow res = REIRenderHelper.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(); + MainWindow res = REIRenderHelper.getResolution(); if (overlayedGui != Minecraft.getInstance().currentScreen) { if (Minecraft.getInstance().currentScreen instanceof GuiContainer) { @@ -117,25 +121,42 @@ public class GuiItemList extends Drawable { } private void calculateSlots() { - int x = rect.x; - int y = rect.y + 20; - MainWindow res = AEIRenderHelper.getResolution(); + int x = rect.x, y = rect.y + 20; + MainWindow res = REIRenderHelper.getResolution(); displaySlots.clear(); - int xOffset = 4; - int yOffset = 4; + int xOffset = 0, yOffset = 0, row = 0, perRow = 0, currentX = 0, currentY = 0; 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; + if (row == 0) + perRow++; + if (x + xOffset + 22 > res.getScaledWidth()) { + xOffset = 0; yOffset += 18; + row++; } if (y + yOffset + 9 + FOOTERSIZE > rect.height) { + xOffset = 0; + yOffset = 0; break; } } + x += (rect.width - perRow * 18) / 2; + y += (rect.height - FOOTERSIZE - 2 - row * 18) / 2; + while (true) { + REISlot slot = new REISlot(x + xOffset, y + yOffset); + slot.setCheatable(true); + xOffset += 18; + currentX++; + displaySlots.add(slot); + if (currentX >= perRow) { + xOffset = 0; + yOffset += 18; + currentX = 0; + currentY++; + } + if (currentY >= row) + break; + } } @Override @@ -196,52 +217,70 @@ public class GuiItemList extends Drawable { private String getCheatModeText() { if (cheatMode) { - TextComponentTranslation cheat = new TextComponentTranslation("text.aei.cheat", new Object[]{null}); + TextComponentTranslation cheat = new TextComponentTranslation("text.rei.cheat", new Object[]{null}); return cheat.getFormattedText(); } - TextComponentTranslation noCheat = new TextComponentTranslation("text.aei.nocheat", new Object[]{null}); + TextComponentTranslation noCheat = new TextComponentTranslation("text.rei.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); - } - } - } + List stacks = new ArrayList<>(); + Arrays.stream(searchText.split("\\|")).forEachOrdered(s -> { + List arguments = new ArrayList<>(); + while (s.startsWith(" ")) s = s.substring(1); + while (s.endsWith(" ")) s = s.substring(0, s.length()); + if (s.startsWith("@-") || s.startsWith("-@")) + arguments.add(new SearchArgument(SearchArgument.ArgumentType.MOD, s.substring(2), false)); + else if (s.startsWith("@")) + arguments.add(new SearchArgument(SearchArgument.ArgumentType.MOD, s.substring(1), true)); + else if (s.startsWith("#-") || s.startsWith("-#")) + arguments.add(new SearchArgument(SearchArgument.ArgumentType.TOOLTIP, s.substring(2), false)); + else if (s.startsWith("#")) + arguments.add(new SearchArgument(SearchArgument.ArgumentType.TOOLTIP, s.substring(1), true)); + else if (s.startsWith("-")) + arguments.add(new SearchArgument(SearchArgument.ArgumentType.TEXT, s.substring(1), false)); + else + arguments.add(new SearchArgument(SearchArgument.ArgumentType.TEXT, s, true)); + ClientListener.stackList.stream().filter(itemStack -> filterItem(itemStack, arguments)).forEachOrdered(stacks::add); + }); + view.addAll(stacks.stream().distinct().collect(Collectors.toList())); page = 0; fillSlots(); } + private boolean filterItem(ItemStack itemStack, List arguments) { + String mod = getMod(itemStack); + List toolTipsList = REIRenderHelper.getOverlayedGui().getItemToolTip(itemStack); + String toolTipsMixed = toolTipsList.stream().skip(1).collect(Collectors.joining()).toLowerCase(); + String allMixed = Stream.of(itemStack.getDisplayName().getString(), toolTipsMixed).collect(Collectors.joining()).toLowerCase(); + for(SearchArgument searchArgument : arguments.stream().filter(searchArgument -> !searchArgument.isInclude()).collect(Collectors.toList())) { + if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.MOD)) + if (mod.toLowerCase().contains(searchArgument.getText().toLowerCase())) + return false; + if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.TOOLTIP)) + if (toolTipsMixed.contains(searchArgument.getText().toLowerCase())) + return false; + if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.TEXT)) + if (allMixed.contains(searchArgument.getText().toLowerCase())) + return false; + } + for(SearchArgument searchArgument : arguments.stream().filter(SearchArgument::isInclude).collect(Collectors.toList())) { + if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.MOD)) + if (!mod.toLowerCase().contains(searchArgument.getText().toLowerCase())) + return false; + if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.TOOLTIP)) + if (!toolTipsMixed.contains(searchArgument.getText().toLowerCase())) + return false; + if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.TEXT)) + if (!allMixed.contains(searchArgument.getText().toLowerCase())) + return false; + } + return true; + } + public void tick() { controls.forEach(f -> f.tick()); } @@ -261,4 +300,5 @@ public class GuiItemList extends Drawable { } return ""; } + } diff --git a/src/main/java/me/shedaniel/gui/REIRenderHelper.java b/src/main/java/me/shedaniel/gui/REIRenderHelper.java new file mode 100755 index 000000000..74f8c1b02 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/REIRenderHelper.java @@ -0,0 +1,247 @@ +package me.shedaniel.gui; + +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.IFocusable; +import me.shedaniel.gui.widget.REISlot; +import me.shedaniel.impl.REIRecipeManager; +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 org.dimdev.riftloader.RiftLoader; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + + +/** + * Created by James on 7/28/2018. + */ +public class REIRenderHelper { + static Point mouseLoc; + static public GuiItemList reiGui; + 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 String tryGettingModName(String modid) { + 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); + } + + public static void drawREI(GuiContainer overlayedGui) { + REIRenderHelper.overlayedGui = overlayedGui; + if (reiGui == null) { + reiGui = new GuiItemList(overlayedGui); + } + reiGui.draw(); + renderTooltips(); + } + + public static void resize(int scaledWidth, int scaledHeight) { + if (reiGui != null) { + reiGui.resize(); + } + if (overlayedGui instanceof RecipeGui) { + overlayedGui.onResize(Minecraft.getInstance(), scaledWidth, scaledHeight); + } + } + + 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 (reiGui.visible) { + for(Control control : reiGui.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 (!reiGui.visible) + return false; + if (direction > 0 && reiGui.buttonLeft.isEnabled()) + reiGui.buttonLeft.onClick.apply(0); + else if (direction < 0 && reiGui.buttonRight.isEnabled()) + reiGui.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() { + reiGui.updateView(); + } + + public static void tick() { + if (reiGui != null && Minecraft.getInstance().currentScreen == overlayedGui) + reiGui.tick(); + } + + public static void recipeKeybind() { + if (!(Minecraft.getInstance().currentScreen instanceof GuiContainer)) + return; + Control control = reiGui.getLastHovered(); + if (control != null && control.isHighlighted() && control instanceof REISlot) { + REISlot slot = (REISlot) control; + REIRecipeManager.instance().displayRecipesFor(slot.getStack()); + return; + } + if (((IMixinGuiContainer) overlayedGui).getHoveredSlot() != null) { + ItemStack stack = ((IMixinGuiContainer) overlayedGui).getHoveredSlot().getStack(); + REIRecipeManager.instance().displayRecipesFor(stack); + } + + } + + public static void useKeybind() { + if (!(Minecraft.getInstance().currentScreen instanceof GuiContainer)) + return; + Control control = reiGui.getLastHovered(); + if (control != null && control.isHighlighted() && control instanceof REISlot) { + REISlot slot = (REISlot) control; + REIRecipeManager.instance().displayUsesFor(slot.getStack()); + return; + } + if (((IMixinGuiContainer) overlayedGui).getHoveredSlot() != null) { + ItemStack stack = ((IMixinGuiContainer) overlayedGui).getHoveredSlot().getStack(); + REIRecipeManager.instance().displayUsesFor(stack); + } + + } + + public static void hideKeybind() { + if (Minecraft.getInstance().currentScreen == overlayedGui && reiGui != null) { + reiGui.visible = !reiGui.visible; + } + } +} diff --git a/src/main/java/me/shedaniel/gui/RecipeGui.java b/src/main/java/me/shedaniel/gui/RecipeGui.java index 6cdd9542a..43cb8333d 100755 --- a/src/main/java/me/shedaniel/gui/RecipeGui.java +++ b/src/main/java/me/shedaniel/gui/RecipeGui.java @@ -2,14 +2,17 @@ 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 me.shedaniel.gui.widget.REISlot; +import me.shedaniel.gui.widget.Tab; +import me.shedaniel.impl.REIRecipeManager; 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.client.renderer.RenderHelper; import net.minecraft.inventory.Container; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; @@ -20,6 +23,8 @@ import java.util.List; import java.util.Map; public class RecipeGui extends GuiContainer { + + private static final ResourceLocation CREATIVE_INVENTORY_TABS = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png"); private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("almostenoughitems", "textures/gui/recipecontainer.png"); private final MainWindow mainWindow; private final Container container; @@ -28,12 +33,15 @@ public class RecipeGui extends GuiContainer { private int guiWidth = 176; private int guiHeight = 222; ArrayList categories = new ArrayList<>(); - private int categoryPointer = 0; + private int categoryTabPage = 0; + private IDisplayCategory selectedCategory; private int recipePointer = 0; - private List slots; + private List slots; private int cycleCounter = 0; private int[] itemPointer; List controls = new LinkedList<>(); + private List tabs; + private boolean tabsEnabled = false; public RecipeGui(Container p_i1072_1_, GuiScreen prevScreen, Map> recipes) { super(new RecipeContainer()); @@ -49,7 +57,17 @@ public class RecipeGui extends GuiContainer { } private void setupCategories() { - categories.addAll(recipes.keySet()); + for(IDisplayCategory adapter : REIRecipeManager.instance().getDisplayAdapters()) + if (recipes.containsKey(adapter)) + categories.add(adapter); + selectedCategory = categories.get(0); + categoryTabPage = 0; + tabs = new ArrayList<>(); + for(int i = 0; i < 6; i++) + tabs.add(new Tab(i, 0, 0, 0, 28, 32)); + tabs.forEach(tab -> tab.setOnClick(i -> { + return onClickTab(tab.getId()); + })); updateRecipe(); } @@ -58,7 +76,7 @@ public class RecipeGui extends GuiContainer { 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, selectedCategory.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); } @@ -70,7 +88,7 @@ public class RecipeGui extends GuiContainer { @Override public void tick() { super.tick(); - slots.forEach(AEISlot::tick); + slots.forEach(REISlot::tick); controls.forEach(Control::tick); } @@ -82,6 +100,7 @@ public class RecipeGui extends GuiContainer { } private void updateRecipe() { + int categoryPointer = categories.indexOf(selectedCategory); IRecipe recipe = recipes.get(categories.get(categoryPointer)).get(recipePointer); categories.get(categoryPointer).resetRecipes(); categories.get(categoryPointer).addRecipe(recipe); @@ -95,9 +114,7 @@ public class RecipeGui extends GuiContainer { guiLeft = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2)); guiTop = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); - for(AEISlot slot : slots) { - slot.move(guiLeft, guiTop); - } + slots.forEach(reiSlot -> reiSlot.move(guiLeft, guiTop)); Button btnCategoryLeft = new Button(guiLeft + 10, guiTop + 5, 15, 20, "<"); Button btnCategoryRight = new Button(guiLeft + guiWidth - 25, guiTop + 5, 15, 20, ">"); @@ -114,7 +131,7 @@ public class RecipeGui extends GuiContainer { controls.clear(); controls.add(btnCategoryLeft); controls.add(btnCategoryRight); - if (categories.size() <= 2) { + if (categories.size() <= 1) { btnCategoryLeft.setEnabled(false); btnCategoryRight.setEnabled(false); } @@ -129,15 +146,46 @@ public class RecipeGui extends GuiContainer { List newControls = new LinkedList<>(); categories.get(categoryPointer).addWidget(newControls, 0); - if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) { + 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); + + updateTabs(); + } + + private void updateTabs() { + tabsEnabled = guiTop - 28 > 4; + if (tabsEnabled) { + tabs.forEach(tab -> tab.moveTo(guiLeft + 4, guiLeft + 2 + tabs.indexOf(tab) * 28, guiTop - 28)); + for(int i = 0; i < tabs.size(); i++) { + int ref = i + categoryTabPage * 6; + if (categories.size() > ref) { + tabs.get(i).setItem(categories.get(ref).getCategoryIcon(), categories.get(ref).getDisplayName(), categories.get(ref).equals(selectedCategory)); + } else tabs.get(i).setItem(null, null, false); + } + controls.addAll(tabs); + } + } + + private boolean onClickTab(int index) { + System.out.println(index); + if (index + categoryTabPage * 6 == categories.indexOf(selectedCategory)) + return false; + selectedCategory = categories.get(index + categoryTabPage * 6); + return false; } @Override protected void drawGuiContainerBackgroundLayer(float v, int i, int i1) { + //Tabs + if (tabsEnabled) { + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + RenderHelper.enableGUIStandardItemLighting(); + this.mc.getTextureManager().bindTexture(CREATIVE_INVENTORY_TABS); + tabs.stream().filter(tab -> tab.getId() + categoryTabPage * 6 == categories.indexOf(selectedCategory)).forEach(Tab::drawTab); + } + drawDefaultBackground(); GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(CHEST_GUI_TEXTURE); @@ -146,18 +194,20 @@ public class RecipeGui extends GuiContainer { 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(); + slots.forEach(REISlot::draw); + + if (tabsEnabled) + tabs.stream().filter(tab -> tab.getId() + categoryTabPage * 6 != categories.indexOf(selectedCategory)).forEach(tab -> { + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + RenderHelper.enableGUIStandardItemLighting(); + this.mc.getTextureManager().bindTexture(CREATIVE_INVENTORY_TABS); + tab.drawTab(); + }); } @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) { + if (p_keyPressed_1_ == 259 && prevScreen != null && REIRenderHelper.focusedControl == null) { Minecraft.getInstance().displayGuiScreen(prevScreen); return true; } @@ -172,20 +222,24 @@ public class RecipeGui extends GuiContainer { private boolean btnCategoryLeft(int button) { recipePointer = 0; + int categoryPointer = categories.indexOf(selectedCategory); categoryPointer--; - if (categoryPointer < 0) { + if (categoryPointer < 0) categoryPointer = categories.size() - 1; - } + selectedCategory = categories.get(categoryPointer); + categoryTabPage = categoryPointer / 6; updateRecipe(); return true; } private boolean btnCategoryRight(int button) { recipePointer = 0; + int categoryPointer = categories.indexOf(selectedCategory); categoryPointer++; - if (categoryPointer >= categories.size()) { + if (categoryPointer >= categories.size()) categoryPointer = 0; - } + selectedCategory = categories.get(categoryPointer); + categoryTabPage = categoryPointer / 6; updateRecipe(); return true; } @@ -201,7 +255,7 @@ public class RecipeGui extends GuiContainer { private boolean btnRecipeRight(int button) { recipePointer += 2; - if (recipePointer >= recipes.get(categories.get(categoryPointer)).size()) { + if (recipePointer >= recipes.get(selectedCategory).size()) { recipePointer = 0; } updateRecipe(); @@ -213,6 +267,6 @@ public class RecipeGui extends GuiContainer { } private int getTotalPages() { - return MathHelper.clamp(riseDoublesToInt(recipes.get(categories.get(categoryPointer)).size() / 2), 1, Integer.MAX_VALUE); + return MathHelper.clamp(riseDoublesToInt(recipes.get(selectedCategory).size() / 2), 1, Integer.MAX_VALUE); } } diff --git a/src/main/java/me/shedaniel/gui/SearchArgument.java b/src/main/java/me/shedaniel/gui/SearchArgument.java new file mode 100644 index 000000000..253f87814 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/SearchArgument.java @@ -0,0 +1,35 @@ +package me.shedaniel.gui; + +public class SearchArgument { + + public enum ArgumentType { + TEXT, MOD, TOOLTIP + } + + private ArgumentType argumentType; + private String text; + private boolean include; + + public SearchArgument(ArgumentType argumentType, String text, boolean include) { + this.argumentType = argumentType; + this.text = text; + this.include = include; + } + + public ArgumentType getArgumentType() { + return argumentType; + } + + public String getText() { + return text; + } + + public boolean isInclude() { + return include; + } + + @Override + public String toString() { + return String.format("Argument[%s]: name = %s, include = %b", argumentType.name(), text, include); + } +} diff --git a/src/main/java/me/shedaniel/gui/widget/AEISlot.java b/src/main/java/me/shedaniel/gui/widget/AEISlot.java deleted file mode 100755 index bc3569699..000000000 --- a/src/main/java/me/shedaniel/gui/widget/AEISlot.java +++ /dev/null @@ -1,181 +0,0 @@ -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 index 3cb68a2ba..df43893ff 100755 --- a/src/main/java/me/shedaniel/gui/widget/Button.java +++ b/src/main/java/me/shedaniel/gui/widget/Button.java @@ -1,6 +1,6 @@ package me.shedaniel.gui.widget; -import me.shedaniel.gui.AEIRenderHelper; +import me.shedaniel.gui.REIRenderHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiContainer; @@ -36,7 +36,7 @@ public class Button extends Control { public void draw() { GlStateManager.pushMatrix(); GlStateManager.disableLighting(); - GuiContainer gui = AEIRenderHelper.getOverlayedGui(); + GuiContainer gui = REIRenderHelper.getOverlayedGui(); Minecraft lvt_4_1_ = Minecraft.getInstance(); FontRenderer lvt_5_1_ = lvt_4_1_.fontRenderer; lvt_4_1_.getTextureManager().bindTexture(BUTTON_TEXTURES); diff --git a/src/main/java/me/shedaniel/gui/widget/Control.java b/src/main/java/me/shedaniel/gui/widget/Control.java index 32763caa6..dd674e605 100755 --- a/src/main/java/me/shedaniel/gui/widget/Control.java +++ b/src/main/java/me/shedaniel/gui/widget/Control.java @@ -91,6 +91,25 @@ public abstract class Control extends Drawable { lvt_9_1_.draw(); } + protected void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float zLevel) { + 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), zLevel).tex((double) ((float) (u + 0) * 0.00390625F), (double) ((float) (v + height) * 0.00390625F)).endVertex(); + lvt_10_1_.pos((double) (x + width), (double) (y + height), zLevel).tex((double) ((float) (u + width) * 0.00390625F), (double) ((float) (v + height) * 0.00390625F)).endVertex(); + lvt_10_1_.pos((double) (x + width), (double) (y + 0), zLevel).tex((double) ((float) (u + width) * 0.00390625F), (double) ((float) (v + 0) * 0.00390625F)).endVertex(); + lvt_10_1_.pos((double) (x + 0), (double) (y + 0), zLevel).tex((double) ((float) (u + 0) * 0.00390625F), (double) ((float) (v + 0) * 0.00390625F)).endVertex(); + lvt_9_1_.draw(); + } + + public void tick() { } + + public void setOnClick(IntFunction onClick) { + this.onClick = onClick; + } + } diff --git a/src/main/java/me/shedaniel/gui/widget/REISlot.java b/src/main/java/me/shedaniel/gui/widget/REISlot.java new file mode 100755 index 000000000..2a2c65569 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/REISlot.java @@ -0,0 +1,182 @@ +package me.shedaniel.gui.widget; + +import com.google.common.collect.Lists; +import me.shedaniel.gui.REIRenderHelper; +import me.shedaniel.impl.REIRecipeManager; +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 REISlot 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 REISlot(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(); + } + + protected void drawTooltip() { + List toolTip = getTooltip(); + toolTip.add("§9§o" + getMod()); + Point mouse = REIRenderHelper.getMouseLoc(); + REIRenderHelper.addToolTip(toolTip, mouse.x, mouse.y); + } + + private boolean onClick(int button) { + EntityPlayer player = Minecraft.getInstance().player; + if (REIRenderHelper.reiGui.canCheat() && !(player.inventory.getItemStack().isEmpty())) { + //Delete the itemstack. + Minecraft.getInstance().getConnection().sendPacket(new DeletePacket()); + return true; + } + if (!player.inventory.getItemStack().isEmpty()) { + return false; + } + + if (REIRenderHelper.reiGui.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 { + REIRenderHelper.recipeKeybind(); + } + return false; + } + + + private void drawStack(int x, int y) { + GuiContainer gui = REIRenderHelper.getOverlayedGui(); + REIRenderHelper.getItemRender().zLevel = 200.0F; + REIRenderHelper.getItemRender().renderItemAndEffectIntoGUI(getStack(), x, y); + assert gui != null; + if (((IMixinGuiContainer) gui).getDraggedStack().isEmpty()) + REIRenderHelper.getItemRender().renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, getStack(), x, y - 0, ""); + else + REIRenderHelper.getItemRender().renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, getStack(), x, y - 8, ""); + REIRenderHelper.getItemRender().zLevel = 0.0F; + } + + public String getMod() { + if (!getStack().isEmpty()) { + ResourceLocation location = IRegistry.ITEM.getKey(getStack().getItem()); + assert location != null; + return REIRenderHelper.tryGettingModName(location.getNamespace()); + } + return ""; + } + + protected List getTooltip() { + Minecraft mc = Minecraft.getInstance(); + GuiContainer gui = REIRenderHelper.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; + } + + pub