From 21f5f6857d1f20eedb6d2c110d3e51d877ddf585 Mon Sep 17 00:00:00 2001 From: koolkrafter5 Date: Mon, 18 Aug 2025 05:29:53 -0400 Subject: [PATCH 1/3] Fix some issues in NEI handlers Let blood orbs be scrolled in the alchemy recipe handler and calicnator handler (needs open PR for NEI to be merged to let other stacks to be scrolled, but this compiles fine without it) Remove double-checked locking in NEIConfig::getBloodOrbs Cache more values in CachedReagentInfo Don't cache color value because it can change depending on implementation of .getColorX Fix state leaking in CachedReagentInfo Fix problem when finding recipes for empty belljars --- .../client/nei/NEIAlchemyRecipeHandler.java | 25 ++-- .../client/nei/NEIAltarRecipeHandler.java | 6 +- .../client/nei/NEIBindingRitualHandler.java | 2 +- .../client/nei/NEICalcinatorHandler.java | 131 ++++++++++-------- .../client/nei/NEIConfig.java | 16 +-- 5 files changed, 91 insertions(+), 89 deletions(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIAlchemyRecipeHandler.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIAlchemyRecipeHandler.java index 924a3653..07aef6e8 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIAlchemyRecipeHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIAlchemyRecipeHandler.java @@ -5,6 +5,7 @@ import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.getBloodOrbs; import java.awt.Rectangle; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import net.minecraft.client.gui.inventory.GuiContainer; @@ -29,15 +30,14 @@ public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler { public class CachedAlchemyRecipe extends CachedRecipe { - ArrayList orbs; - PositionedStack output; - List inputs; - int lp; + private final PositionedStack orbs; + private final PositionedStack output; + private final List inputs; + private final int lp; public CachedAlchemyRecipe(AlchemyRecipe recipe, ItemStack orb) { this(recipe); - this.orbs = new ArrayList<>(); - orbs.add(orb); + this.orbs.setPermutationToRender(orb); } public CachedAlchemyRecipe(AlchemyRecipe recipe) { @@ -51,12 +51,13 @@ public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler { this.inputs = inputs; this.output = new PositionedStack(recipe.getResult(), 76, 25); this.lp = recipe.getAmountNeeded() * 100; - this.orbs = new ArrayList<>(); + List orbStacks = new ArrayList<>(); for (Item orb : getBloodOrbs()) { if (((IBloodOrb) orb).getOrbLevel() >= recipe.getOrbLevel()) { - orbs.add(new ItemStack(orb)); + orbStacks.add(new ItemStack(orb)); } } + orbs = new PositionedStack(orbStacks, 136, 47); } @Override @@ -70,12 +71,8 @@ public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler { } @Override - public PositionedStack getOtherStack() { - if (orbs == null || orbs.isEmpty()) return null; - PositionedStack stack = new PositionedStack(orbs, 136, 47, false); - stack.setPermutationToRender((cycleticks / 48) % orbs.size()); - stack.setMaxSize(1); - return stack; + public List getOtherStacks() { + return getCycledIngredients(cycleticks / 20, Collections.singletonList(orbs)); } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIAltarRecipeHandler.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIAltarRecipeHandler.java index be3b93b7..4283e13c 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIAltarRecipeHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIAltarRecipeHandler.java @@ -25,10 +25,10 @@ public class NEIAltarRecipeHandler extends TemplateRecipeHandler { public class CachedAltarRecipe extends CachedRecipe { - PositionedStack input; + private final PositionedStack input; // PositionedStack inputItems; - PositionedStack output; - int tier, lp_amount, consumption, drain; + private final PositionedStack output; + private final int tier, lp_amount, consumption, drain; public CachedAltarRecipe(AltarRecipe recipe) { // inputItems = new PositionedStack(recipe.input, 38, 2, false); diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIBindingRitualHandler.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIBindingRitualHandler.java index 661d63ec..d2bad9a2 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIBindingRitualHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIBindingRitualHandler.java @@ -29,7 +29,7 @@ public class NEIBindingRitualHandler extends TemplateRecipeHandler { public class CachedBindingRecipe extends CachedRecipe { - PositionedStack input, output; + private final PositionedStack input, output; public CachedBindingRecipe(BindingRecipe recipe) { input = new PositionedStack(recipe.requiredItem, 37, 21, false); diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java index e48b38e5..ac024a9f 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java @@ -2,10 +2,12 @@ package WayofTime.alchemicalWizardry.client.nei; import static WayofTime.alchemicalWizardry.client.ClientUtils.mc; import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.ARROW_TEXTURE; +import static codechicken.lib.gui.GuiDraw.fontRenderer; import java.awt.Rectangle; +import java.util.Collections; +import java.util.List; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.item.ItemStack; @@ -28,19 +30,39 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler { public class CachedReagentInfo extends CachedRecipe { private final Reagent reagent; + private final PositionedStack stack; + private final PositionedStack orbs; private final int amount; - private final int color; + + private final String amountText; + private final int amountTextWidth; + + private final String nameText; + private final int nameTextWidth; + + private static final int ARROW_WIDTH = 24; + private static final int ARROW_HEIGHT = 16; + private static final int FILL_TIME = 192; + private static final int HOLD_TIME = 8; public CachedReagentInfo(ReagentStack reagent) { this.reagent = reagent.reagent; + this.stack = new PositionedStack(ReagentRegistry.getItemForReagent(reagent.reagent), 32, 6); this.amount = reagent.amount; - this.color = reagent.reagent.getColourRed() << 16 | reagent.reagent.getColourGreen() << 8 - | reagent.reagent.getColourBlue(); + + ItemStack[] orbStacks = NEIConfig.getBloodOrbs().stream().map(ItemStack::new).toArray(ItemStack[]::new); + this.orbs = new PositionedStack(orbStacks, 32, 33); + + this.amountText = String.format("%,d AR", amount); + this.amountTextWidth = fontRenderer.getStringWidth(amountText); + + this.nameText = this.reagent.name; + this.nameTextWidth = fontRenderer.getStringWidth(nameText); } @Override public PositionedStack getResult() { - return new PositionedStack(ReagentRegistry.getItemForReagent(reagent), 32, 6); + return stack; } public Reagent getReagent() { @@ -54,39 +76,29 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler { public void onDraw(int x, int y) { drawColoredProgressBar(x, y); - String amountText = String.format("%,d AR", amount); - FontRenderer fontRenderer = mc.fontRenderer; - - int textWidth = fontRenderer.getStringWidth(amountText); - int textX = x + 84 - (textWidth / 2); + int textX = x + 84 - (amountTextWidth / 2); int textY = y + 19; - fontRenderer.drawString(amountText, textX, textY, 0x000000); - textWidth = fontRenderer.getStringWidth(reagent.name); - textX = x + 84 - (textWidth / 2); - textY = y + 29; - - fontRenderer.drawString(reagent.name, textX, textY, color); + textX = x + 84 - (nameTextWidth / 2); + textY += 10; + int color = reagent.getColourRed() << 16 | reagent.getColourGreen() << 8 | reagent.getColourBlue(); + fontRenderer.drawString(nameText, textX, textY, color); } private void drawColoredProgressBar(int x, int y) { int arrowX = x + 25; int arrowY = y + 19; - int arrowWidth = 24; - int arrowHeight = 16; - int fillTime = 192; - int holdTime = 8; - int totalCycle = fillTime + holdTime; + int totalCycle = FILL_TIME + HOLD_TIME; int cycleTick = cycleticks % totalCycle; int fillWidth; - if (cycleTick < fillTime) { - fillWidth = cycleTick * arrowWidth / fillTime; + if (cycleTick < FILL_TIME) { + fillWidth = cycleTick * ARROW_WIDTH / FILL_TIME; } else { - fillWidth = arrowWidth; + fillWidth = ARROW_WIDTH; } TextureManager texManager = mc.getTextureManager(); @@ -94,35 +106,30 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler { Tessellator tessellator = Tessellator.instance; + GL11.glPushMatrix(); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - float r = ((color >> 16) & 0xFF) / 255f; - float g = ((color >> 8) & 0xFF) / 255f; - float b = (color & 0xFF) / 255f; - - GL11.glColor4f(r, g, b, 1.0f); + GL11.glColor4ub((byte) reagent.getColourRed(), (byte) reagent.getColourGreen(), (byte) reagent.getColourBlue(), (byte) 255); tessellator.startDrawingQuads(); - - tessellator.addVertexWithUV(arrowX, arrowY + arrowHeight, 0, 0, 1); - tessellator.addVertexWithUV(arrowX + fillWidth, arrowY + arrowHeight, 0, fillWidth / (float) arrowWidth, 1); - tessellator.addVertexWithUV(arrowX + fillWidth, arrowY, 0, fillWidth / (float) arrowWidth, 0); + tessellator.addVertexWithUV(arrowX, arrowY + ARROW_HEIGHT, 0, 0, 1); + tessellator.addVertexWithUV(arrowX + fillWidth, arrowY + ARROW_HEIGHT, 0, + fillWidth / (float) ARROW_WIDTH, 1); + tessellator.addVertexWithUV(arrowX + fillWidth, arrowY, 0, + fillWidth / (float) ARROW_WIDTH, 0); tessellator.addVertexWithUV(arrowX, arrowY, 0, 0, 0); - tessellator.draw(); - GL11.glDisable(GL11.GL_BLEND); + GL11.glPopAttrib(); + GL11.glPopMatrix(); } @Override - public PositionedStack getOtherStack() { - ItemStack[] orbStacks = NEIConfig.getBloodOrbs().stream().map(ItemStack::new).toArray(ItemStack[]::new); - - PositionedStack stack = new PositionedStack(orbStacks, 32, 33, true); - stack.setPermutationToRender((cycleticks / 20) % orbStacks.length); - - return stack; + public List getIngredients() { + return getCycledIngredients(cycleticks / 20, Collections.singletonList(this.orbs)); } } @@ -151,24 +158,26 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler { ReagentStack rs = ReagentRegistry.getReagentStackForItem(result); if (rs != null) { arecipes.add(new CachedReagentInfo(rs)); - } else { // Check reagents in crystal belljars or other reagent storages - NBTTagCompound tagCompound = result.getTagCompound(); - if (tagCompound == null || tagCompound.hasNoTags()) { - return; - } - NBTTagList tagList = tagCompound.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND); - if (tagList.tagList.isEmpty()) { - return; - } - for (int i = 0; i < tagList.tagCount(); i++) { - // Get the proper size of the ReagentStack created by melting the item for this reagent - NBTTagCompound savedTag = tagList.getCompoundTagAt(i); - ReagentStack reagent = ReagentContainer.readFromNBT(savedTag).getReagent(); - ItemStack reagentItem = ReagentRegistry.getItemForReagent(reagent.reagent); - ReagentStack reagentStackForItem = ReagentRegistry.getReagentStackForItem(reagentItem); - if (reagentStackForItem != null) { - arecipes.add(new CachedReagentInfo(reagentStackForItem)); - } + return; + } + // Check reagents in crystal belljars or other reagent storages + NBTTagCompound tagCompound = result.getTagCompound(); + if (tagCompound == null || tagCompound.hasNoTags()) { + return; + } + NBTTagList tagList = tagCompound.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND); + if (tagList.tagList.isEmpty()) { + return; + } + for (int i = 0; i < tagList.tagCount(); i++) { + // Get the proper size of the ReagentStack created by melting the item for this reagent + NBTTagCompound savedTag = tagList.getCompoundTagAt(i); + ReagentStack reagent = ReagentContainer.readFromNBT(savedTag).getReagent(); + if (reagent == null) continue; + ItemStack reagentItem = ReagentRegistry.getItemForReagent(reagent.reagent); + ReagentStack reagentStackForItem = ReagentRegistry.getReagentStackForItem(reagentItem); + if (reagentStackForItem != null) { + arecipes.add(new CachedReagentInfo(reagentStackForItem)); } } } @@ -191,7 +200,7 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler { @Override public void loadTransferRects() { - transferRects.add(new RecipeTransferRect(new Rectangle(54, 23, 23, 16), "alchemicalwizardry.calcinator")); + transferRects.add(new RecipeTransferRect(new Rectangle(55, 18, 24, 17), "alchemicalwizardry.calcinator")); } @Override diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java index a39f349c..c23c2663 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java @@ -20,13 +20,9 @@ public class NEIConfig implements IConfigureNEI { "alchemicalwizardry", "gui/nei/arrow.png"); - public static ArrayList getBloodOrbs() { + public synchronized static ArrayList getBloodOrbs() { if (bloodOrbs == null) { - synchronized (NEIConfig.class) { - if (bloodOrbs == null) { - bloodOrbs = collectAllBloodOrbs(); - } - } + bloodOrbs = collectAllBloodOrbs(); } return bloodOrbs; } @@ -39,7 +35,7 @@ public class NEIConfig implements IConfigureNEI { } } if (bloodOrbsTemp.isEmpty()) { - // If there is NEI no cache - go to item registry + // If there is no NEI cache - go to item registry for (Object anItemRegistry : Item.itemRegistry) { Item item = (Item) anItemRegistry; if (item instanceof IBloodOrb) { @@ -50,12 +46,12 @@ public class NEIConfig implements IConfigureNEI { return bloodOrbsTemp; } - public static ArrayList getOrbsByCapacity() { + public synchronized static ArrayList getOrbsByCapacity() { if (byCapacity == null) { byCapacity = new ArrayList<>(getBloodOrbs()); byCapacity.sort((a, b) -> { - if (a instanceof IBloodOrb && b instanceof IBloodOrb) { - return Integer.compare(((IBloodOrb) a).getMaxEssence(), ((IBloodOrb) b).getMaxEssence()); + if (a instanceof IBloodOrb orbA && b instanceof IBloodOrb orbB) { + return Integer.compare(orbA.getMaxEssence(), orbB.getMaxEssence()); } return 0; }); From b6c10e52d2648a7b19a5207574683e2ff9ba87ec Mon Sep 17 00:00:00 2001 From: koolkrafter5 Date: Mon, 18 Aug 2025 05:30:17 -0400 Subject: [PATCH 2/3] This equates to `this == o` which is the same as super --- .../alchemicalWizardry/api/alchemy/energy/Reagent.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java b/src/main/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java index fba621a1..915ecc08 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java +++ b/src/main/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java @@ -38,8 +38,4 @@ public class Reagent { return colourIntensity; } - @Override - public boolean equals(Object o) { - return o instanceof Reagent && this == o && name.equals(((Reagent) o).name); - } } From 0534a90ef804a2c1e5edd5be244e34613734f3c7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 05:36:14 -0400 Subject: [PATCH 3/3] Spotless apply for branch update-handlers for #105 (#106) Co-authored-by: GitHub GTNH Actions <> --- .../client/nei/NEICalcinatorHandler.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java index ac024a9f..204a1946 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java @@ -112,14 +112,17 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler { GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glColor4ub((byte) reagent.getColourRed(), (byte) reagent.getColourGreen(), (byte) reagent.getColourBlue(), (byte) 255); + GL11.glColor4ub( + (byte) reagent.getColourRed(), + (byte) reagent.getColourGreen(), + (byte) reagent.getColourBlue(), + (byte) 255); tessellator.startDrawingQuads(); tessellator.addVertexWithUV(arrowX, arrowY + ARROW_HEIGHT, 0, 0, 1); - tessellator.addVertexWithUV(arrowX + fillWidth, arrowY + ARROW_HEIGHT, 0, - fillWidth / (float) ARROW_WIDTH, 1); - tessellator.addVertexWithUV(arrowX + fillWidth, arrowY, 0, - fillWidth / (float) ARROW_WIDTH, 0); + tessellator + .addVertexWithUV(arrowX + fillWidth, arrowY + ARROW_HEIGHT, 0, fillWidth / (float) ARROW_WIDTH, 1); + tessellator.addVertexWithUV(arrowX + fillWidth, arrowY, 0, fillWidth / (float) ARROW_WIDTH, 0); tessellator.addVertexWithUV(arrowX, arrowY, 0, 0, 0); tessellator.draw();