From 63fdcc76da7e2d7cbd79d327c6dd72404708f64f Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 5 Jan 2019 22:14:37 +0800 Subject: Buggy Autocrafting --- src/main/java/me/shedaniel/gui/RecipeGui.java | 20 ++++--- src/main/java/me/shedaniel/gui/widget/Button.java | 2 +- .../java/me/shedaniel/gui/widget/SmallButton.java | 61 ++++++++++++++++++++++ 3 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 src/main/java/me/shedaniel/gui/widget/SmallButton.java (limited to 'src/main/java/me/shedaniel/gui') diff --git a/src/main/java/me/shedaniel/gui/RecipeGui.java b/src/main/java/me/shedaniel/gui/RecipeGui.java index cf2c87572..7f655c23f 100755 --- a/src/main/java/me/shedaniel/gui/RecipeGui.java +++ b/src/main/java/me/shedaniel/gui/RecipeGui.java @@ -1,6 +1,7 @@ package me.shedaniel.gui; import com.mojang.blaze3d.platform.GlStateManager; +import me.shedaniel.api.DisplayCategoryCraftable; import me.shedaniel.api.IDisplayCategory; import me.shedaniel.api.IRecipe; import me.shedaniel.gui.widget.Button; @@ -53,6 +54,10 @@ public class RecipeGui extends ContainerGui { setupCategories(); } + public Gui getPrevScreen() { + return prevScreen; + } + private void setupCategories() { for(IDisplayCategory adapter : REIRecipeManager.instance().getDisplayAdapters()) if (recipes.containsKey(adapter)) @@ -101,9 +106,7 @@ public class RecipeGui extends ContainerGui { } private void updateRecipe() { - int categoryPointer = categories.indexOf(selectedCategory); - - IRecipe recipe = recipes.get(categories.get(categoryPointer)).get(recipePointer); + IRecipe recipe = recipes.get(selectedCategory).get(recipePointer); selectedCategory.resetRecipes(); selectedCategory.addRecipe(recipe); slots = selectedCategory.setupDisplay(0); @@ -161,9 +164,14 @@ public class RecipeGui extends ContainerGui { controls.add(btnRecipeRight); List newControls = new LinkedList<>(); - categories.get(categoryPointer).addWidget(newControls, 0); - if (recipes.get(categories.get(categoryPointer)).size() >= recipePointer + 2) - categories.get(categoryPointer).addWidget(newControls, 1); + selectedCategory.addWidget(newControls, 0); + if (selectedCategory instanceof DisplayCategoryCraftable) + ((DisplayCategoryCraftable) selectedCategory).registerAutoCraftButton(newControls, this, getPrevScreen(), recipe, 0); + if (recipes.get(selectedCategory).size() >= recipePointer + 2) { + selectedCategory.addWidget(newControls, 1); + if (selectedCategory instanceof DisplayCategoryCraftable) + ((DisplayCategoryCraftable) selectedCategory).registerAutoCraftButton(newControls, this, getPrevScreen(), recipes.get(selectedCategory).get(recipePointer + 1), 1); + } newControls.forEach(f -> f.move(left, top)); controls.addAll(newControls); diff --git a/src/main/java/me/shedaniel/gui/widget/Button.java b/src/main/java/me/shedaniel/gui/widget/Button.java index 0c23a91db..e4339fd64 100755 --- a/src/main/java/me/shedaniel/gui/widget/Button.java +++ b/src/main/java/me/shedaniel/gui/widget/Button.java @@ -13,6 +13,7 @@ import java.awt.*; * Created by James on 7/29/2018. */ public class Button extends Control { + private String buttonText; protected static final Identifier BUTTON_TEXTURES = new Identifier("textures/gui/widgets.png"); @@ -61,5 +62,4 @@ public class Button extends Control { GlStateManager.popMatrix(); } - } diff --git a/src/main/java/me/shedaniel/gui/widget/SmallButton.java b/src/main/java/me/shedaniel/gui/widget/SmallButton.java new file mode 100644 index 000000000..5eff8d206 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/SmallButton.java @@ -0,0 +1,61 @@ +package me.shedaniel.gui.widget; + +import com.mojang.blaze3d.platform.GlStateManager; +import me.shedaniel.gui.REIRenderHelper; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.FontRenderer; +import net.minecraft.client.gui.ContainerGui; +import net.minecraft.util.Identifier; + +import java.awt.*; + +public class SmallButton extends Control { + + private String buttonText; + protected static final Identifier BUTTON_TEXTURES = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); + + + public SmallButton(int x, int y, int width, int height, String buttonText) { + super(x, y, width, height); + this.buttonText = buttonText; + } + + public SmallButton(Rectangle rect, String buttonText) { + super(rect); + this.buttonText = buttonText; + } + + public void setString(String text) { + buttonText = text; + } + + + @Override + public void draw() { + GlStateManager.pushMatrix(); + GlStateManager.disableLighting(); + ContainerGui gui = REIRenderHelper.getOverlayedGui(); + MinecraftClient lvt_4_1_ = MinecraftClient.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.SrcBlendFactor.SRC_ALPHA, GlStateManager.DstBlendFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcBlendFactor.ONE, GlStateManager.DstBlendFactor.ZERO); + GlStateManager.blendFunc(GlStateManager.SrcBlendFactor.SRC_ALPHA, GlStateManager.DstBlendFactor.ONE_MINUS_SRC_ALPHA); + gui.drawTexturedRect(rect.x, rect.y, 18 + 44, 222 + hoverState * 10, rect.width, rect.height); + int lvt_7_1_ = 14737632; + + gui.drawStringCentered(lvt_5_1_, this.buttonText, rect.x + rect.width / 2, rect.y + (rect.height - 8) / 2, lvt_7_1_); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + } + +} -- cgit