From ef82d0325c672712a24481e51e0152eea531a773 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Sat, 30 Sep 2017 13:22:00 +0100 Subject: [PATCH] Added the ability for the Lexica Botania to swap between various items that a recipe can match based on time. Finally. Closes #2372 --- .../lexicon/page/PageCraftingRecipe.java | 32 +++++++++++-------- .../common/lexicon/page/PagePetalRecipe.java | 22 ++++++++----- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/main/java/vazkii/botania/common/lexicon/page/PageCraftingRecipe.java b/src/main/java/vazkii/botania/common/lexicon/page/PageCraftingRecipe.java index 8a0d4d4a7..de12965e0 100644 --- a/src/main/java/vazkii/botania/common/lexicon/page/PageCraftingRecipe.java +++ b/src/main/java/vazkii/botania/common/lexicon/page/PageCraftingRecipe.java @@ -54,7 +54,7 @@ public class PageCraftingRecipe extends PageRecipe { public PageCraftingRecipe(String unlocalizedName, List recipes) { super(unlocalizedName); this.recipes = recipes; - + for(ResourceLocation res : recipes) if(res == null) throw new IllegalArgumentException("Null recipes arent allowed"); @@ -136,23 +136,25 @@ public class PageCraftingRecipe extends PageRecipe { public void renderCraftingRecipe(IGuiLexiconEntry gui, IRecipe recipe) { if(recipe == null) return; - + if(recipe instanceof ShapedRecipes || recipe instanceof ShapedOreRecipe) { oreDictRecipe = recipe instanceof ShapedOreRecipe; int width = oreDictRecipe ? ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, (ShapedOreRecipe) recipe, "width") - : ((ShapedRecipes) recipe).getWidth(); - int height = oreDictRecipe - ? ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, (ShapedOreRecipe) recipe, "height") - : ((ShapedRecipes) recipe).getHeight(); + : ((ShapedRecipes) recipe).getWidth(); + int height = oreDictRecipe + ? ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, (ShapedOreRecipe) recipe, "height") + : ((ShapedRecipes) recipe).getHeight(); - for(int y = 0; y < height; y++) - for(int x = 0; x < width; x++) { - Ingredient input = recipe.getIngredients().get(y * width + x); - if(input != Ingredient.EMPTY) - renderItemAtGridPos(gui, 1 + x, 1 + y, input.getMatchingStacks()[0], true); // TODO 1.12 this isn't just used for OD anymore. need to cycle through all matching stacks - } + for(int y = 0; y < height; y++) + for(int x = 0; x < width; x++) { + Ingredient input = recipe.getIngredients().get(y * width + x); + if(input != Ingredient.EMPTY) { + ItemStack[] stacks = input.getMatchingStacks(); + renderItemAtGridPos(gui, 1 + x, 1 + y, stacks[(ticksElapsed / 40) % stacks.length], true); + } + } } else if(recipe instanceof ShapelessRecipes || recipe instanceof ShapelessOreRecipe) { shapelessRecipe = true; oreDictRecipe = recipe instanceof ShapelessOreRecipe; @@ -166,8 +168,10 @@ public class PageCraftingRecipe extends PageRecipe { break drawGrid; Ingredient input = recipe.getIngredients().get(index); - if(input != Ingredient.EMPTY) - renderItemAtGridPos(gui, 1 + x, 1 + y, input.getMatchingStacks()[0], true); // TODO 1.12 this isn't just used for OD anymore. need to cycle through all matching stacks + if(input != Ingredient.EMPTY) { + ItemStack[] stacks = input.getMatchingStacks(); + renderItemAtGridPos(gui, 1 + x, 1 + y, stacks[(ticksElapsed / 40) % stacks.length], true); + } } } } diff --git a/src/main/java/vazkii/botania/common/lexicon/page/PagePetalRecipe.java b/src/main/java/vazkii/botania/common/lexicon/page/PagePetalRecipe.java index deb521f4c..b74a79368 100644 --- a/src/main/java/vazkii/botania/common/lexicon/page/PagePetalRecipe.java +++ b/src/main/java/vazkii/botania/common/lexicon/page/PagePetalRecipe.java @@ -10,6 +10,12 @@ */ package vazkii.botania.common.lexicon.page; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.lwjgl.opengl.GL11; + import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; @@ -17,11 +23,11 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.oredict.OreDictionary; -import org.lwjgl.opengl.GL11; import vazkii.botania.api.internal.IGuiLexiconEntry; import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.lexicon.LexiconRecipeMappings; @@ -31,10 +37,6 @@ import vazkii.botania.client.lib.LibResources; import vazkii.botania.common.block.ModBlocks; import vazkii.botania.common.core.handler.ConfigHandler; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - public class PagePetalRecipe extends PageRecipe { private static final ResourceLocation petalOverlay = new ResourceLocation(LibResources.GUI_PETAL_OVERLAY); @@ -70,11 +72,15 @@ public class PagePetalRecipe extends PageRecipe { List inputs = recipe.getInputs(); int degreePerInput = (int) (360F / inputs.size()); float currentDegree = ConfigHandler.lexiconRotatingItems ? GuiScreen.isShiftKeyDown() ? ticksElapsed : ticksElapsed + ClientTickHandler.partialTicks : 0; - + float baseDegree = currentDegree; + for(Object obj : inputs) { Object input = obj; - if(input instanceof String) - input = OreDictionary.getOres((String) input).get(0); + if(input instanceof String) { + NonNullList list = OreDictionary.getOres((String) input); + int size = list.size(); + input = list.get(size - (int) (baseDegree / 40) % size - 1); + } renderItemAtAngle(gui, currentDegree, (ItemStack) input);