Compare commits

...
2 Commits
Author SHA1 Message Date
Martin Robertz de91d028ac update 2025-10-19 20:47:05 +02:00
koolkrafter5andgithub-actions[bot] b2330003f7 Fix some issues in NEI handlers (#105)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-10-19 18:27:16 +02:00
8 changed files with 100 additions and 99 deletions

No files matched your search

+5 -5
View File
@@ -23,16 +23,16 @@
*/ */
dependencies { dependencies {
api("com.github.GTNewHorizons:waila:1.8.13:dev") api("com.github.GTNewHorizons:waila:1.8.14:dev")
api("com.github.GTNewHorizons:NotEnoughItems:2.7.87-GTNH:dev") api("com.github.GTNewHorizons:NotEnoughItems:2.7.91-GTNH:dev")
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.457:dev") {transitive = false } compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.474:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:Botania:1.12.25-GTNH:api") {transitive = false } compileOnly("com.github.GTNewHorizons:Botania:1.12.27-GTNH:api") {transitive = false }
compileOnly("com.github.GTNewHorizons:ForestryMC:4.10.17:api") {transitive = false } compileOnly("com.github.GTNewHorizons:ForestryMC:4.10.17:api") {transitive = false }
compileOnly("com.github.GTNewHorizons:ForgeMultipart:1.6.8:dev") {transitive = false } compileOnly("com.github.GTNewHorizons:ForgeMultipart:1.6.8:dev") {transitive = false }
compileOnly("com.github.GTNewHorizons:Chisel:2.16.13-GTNH:api") {transitive = false } compileOnly("com.github.GTNewHorizons:Chisel:2.16.14-GTNH:api") {transitive = false }
compileOnly("com.github.GTNewHorizons:ZenScript:1.0.0-GTNH") {transitive = false } compileOnly("com.github.GTNewHorizons:ZenScript:1.0.0-GTNH") {transitive = false }
compileOnly("com.github.GTNewHorizons:CraftTweaker:3.4.2:dev") {transitive = false } compileOnly("com.github.GTNewHorizons:CraftTweaker:3.4.2:dev") {transitive = false }
+1 -1
View File
@@ -17,7 +17,7 @@ pluginManagement {
} }
plugins { plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.42' id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.44'
} }
@@ -38,8 +38,4 @@ public class Reagent {
return colourIntensity; return colourIntensity;
} }
@Override
public boolean equals(Object o) {
return o instanceof Reagent && this == o && name.equals(((Reagent) o).name);
}
} }
@@ -5,6 +5,7 @@ import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.getBloodOrbs;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainer;
@@ -29,15 +30,14 @@ public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler {
public class CachedAlchemyRecipe extends CachedRecipe { public class CachedAlchemyRecipe extends CachedRecipe {
ArrayList<ItemStack> orbs; private final PositionedStack orbs;
PositionedStack output; private final PositionedStack output;
List<PositionedStack> inputs; private final List<PositionedStack> inputs;
int lp; private final int lp;
public CachedAlchemyRecipe(AlchemyRecipe recipe, ItemStack orb) { public CachedAlchemyRecipe(AlchemyRecipe recipe, ItemStack orb) {
this(recipe); this(recipe);
this.orbs = new ArrayList<>(); this.orbs.setPermutationToRender(orb);
orbs.add(orb);
} }
public CachedAlchemyRecipe(AlchemyRecipe recipe) { public CachedAlchemyRecipe(AlchemyRecipe recipe) {
@@ -51,12 +51,13 @@ public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler {
this.inputs = inputs; this.inputs = inputs;
this.output = new PositionedStack(recipe.getResult(), 76, 25); this.output = new PositionedStack(recipe.getResult(), 76, 25);
this.lp = recipe.getAmountNeeded() * 100; this.lp = recipe.getAmountNeeded() * 100;
this.orbs = new ArrayList<>(); List<ItemStack> orbStacks = new ArrayList<>();
for (Item orb : getBloodOrbs()) { for (Item orb : getBloodOrbs()) {
if (((IBloodOrb) orb).getOrbLevel() >= recipe.getOrbLevel()) { if (((IBloodOrb) orb).getOrbLevel() >= recipe.getOrbLevel()) {
orbs.add(new ItemStack(orb)); orbStacks.add(new ItemStack(orb));
} }
} }
orbs = new PositionedStack(orbStacks, 136, 47);
} }
@Override @Override
@@ -70,12 +71,8 @@ public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler {
} }
@Override @Override
public PositionedStack getOtherStack() { public List<PositionedStack> getOtherStacks() {
if (orbs == null || orbs.isEmpty()) return null; return getCycledIngredients(cycleticks / 20, Collections.singletonList(orbs));
PositionedStack stack = new PositionedStack(orbs, 136, 47, false);
stack.setPermutationToRender((cycleticks / 48) % orbs.size());
stack.setMaxSize(1);
return stack;
} }
} }
@@ -25,10 +25,10 @@ public class NEIAltarRecipeHandler extends TemplateRecipeHandler {
public class CachedAltarRecipe extends CachedRecipe { public class CachedAltarRecipe extends CachedRecipe {
PositionedStack input; private final PositionedStack input;
// PositionedStack inputItems; // PositionedStack inputItems;
PositionedStack output; private final PositionedStack output;
int tier, lp_amount, consumption, drain; private final int tier, lp_amount, consumption, drain;
public CachedAltarRecipe(AltarRecipe recipe) { public CachedAltarRecipe(AltarRecipe recipe) {
// inputItems = new PositionedStack(recipe.input, 38, 2, false); // inputItems = new PositionedStack(recipe.input, 38, 2, false);
@@ -29,7 +29,7 @@ public class NEIBindingRitualHandler extends TemplateRecipeHandler {
public class CachedBindingRecipe extends CachedRecipe { public class CachedBindingRecipe extends CachedRecipe {
PositionedStack input, output; private final PositionedStack input, output;
public CachedBindingRecipe(BindingRecipe recipe) { public CachedBindingRecipe(BindingRecipe recipe) {
input = new PositionedStack(recipe.requiredItem, 37, 21, false); input = new PositionedStack(recipe.requiredItem, 37, 21, false);
@@ -2,10 +2,12 @@ package WayofTime.alchemicalWizardry.client.nei;
import static WayofTime.alchemicalWizardry.client.ClientUtils.mc; import static WayofTime.alchemicalWizardry.client.ClientUtils.mc;
import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.ARROW_TEXTURE; import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.ARROW_TEXTURE;
import static codechicken.lib.gui.GuiDraw.fontRenderer;
import java.awt.Rectangle; 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.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@@ -28,19 +30,39 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler {
public class CachedReagentInfo extends CachedRecipe { public class CachedReagentInfo extends CachedRecipe {
private final Reagent reagent; private final Reagent reagent;
private final PositionedStack stack;
private final PositionedStack orbs;
private final int amount; 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) { public CachedReagentInfo(ReagentStack reagent) {
this.reagent = reagent.reagent; this.reagent = reagent.reagent;
this.stack = new PositionedStack(ReagentRegistry.getItemForReagent(reagent.reagent), 32, 6);
this.amount = reagent.amount; 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 @Override
public PositionedStack getResult() { public PositionedStack getResult() {
return new PositionedStack(ReagentRegistry.getItemForReagent(reagent), 32, 6); return stack;
} }
public Reagent getReagent() { public Reagent getReagent() {
@@ -54,39 +76,29 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler {
public void onDraw(int x, int y) { public void onDraw(int x, int y) {
drawColoredProgressBar(x, y); drawColoredProgressBar(x, y);
String amountText = String.format("%,d AR", amount); int textX = x + 84 - (amountTextWidth / 2);
FontRenderer fontRenderer = mc.fontRenderer;
int textWidth = fontRenderer.getStringWidth(amountText);
int textX = x + 84 - (textWidth / 2);
int textY = y + 19; int textY = y + 19;
fontRenderer.drawString(amountText, textX, textY, 0x000000); fontRenderer.drawString(amountText, textX, textY, 0x000000);
textWidth = fontRenderer.getStringWidth(reagent.name); textX = x + 84 - (nameTextWidth / 2);
textX = x + 84 - (textWidth / 2); textY += 10;
textY = y + 29; int color = reagent.getColourRed() << 16 | reagent.getColourGreen() << 8 | reagent.getColourBlue();
fontRenderer.drawString(nameText, textX, textY, color);
fontRenderer.drawString(reagent.name, textX, textY, color);
} }
private void drawColoredProgressBar(int x, int y) { private void drawColoredProgressBar(int x, int y) {
int arrowX = x + 25; int arrowX = x + 25;
int arrowY = y + 19; int arrowY = y + 19;
int arrowWidth = 24;
int arrowHeight = 16;
int fillTime = 192; int totalCycle = FILL_TIME + HOLD_TIME;
int holdTime = 8;
int totalCycle = fillTime + holdTime;
int cycleTick = cycleticks % totalCycle; int cycleTick = cycleticks % totalCycle;
int fillWidth; int fillWidth;
if (cycleTick < fillTime) { if (cycleTick < FILL_TIME) {
fillWidth = cycleTick * arrowWidth / fillTime; fillWidth = cycleTick * ARROW_WIDTH / FILL_TIME;
} else { } else {
fillWidth = arrowWidth; fillWidth = ARROW_WIDTH;
} }
TextureManager texManager = mc.getTextureManager(); TextureManager texManager = mc.getTextureManager();
@@ -94,35 +106,33 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler {
Tessellator tessellator = Tessellator.instance; Tessellator tessellator = Tessellator.instance;
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
float r = ((color >> 16) & 0xFF) / 255f; GL11.glColor4ub(
float g = ((color >> 8) & 0xFF) / 255f; (byte) reagent.getColourRed(),
float b = (color & 0xFF) / 255f; (byte) reagent.getColourGreen(),
(byte) reagent.getColourBlue(),
GL11.glColor4f(r, g, b, 1.0f); (byte) 255);
tessellator.startDrawingQuads(); tessellator.startDrawingQuads();
tessellator.addVertexWithUV(arrowX, arrowY + ARROW_HEIGHT, 0, 0, 1);
tessellator.addVertexWithUV(arrowX, arrowY + arrowHeight, 0, 0, 1); tessellator
tessellator.addVertexWithUV(arrowX + fillWidth, arrowY + arrowHeight, 0, fillWidth / (float) arrowWidth, 1); .addVertexWithUV(arrowX + fillWidth, arrowY + ARROW_HEIGHT, 0, fillWidth / (float) ARROW_WIDTH, 1);
tessellator.addVertexWithUV(arrowX + fillWidth, arrowY, 0, fillWidth / (float) arrowWidth, 0); tessellator.addVertexWithUV(arrowX + fillWidth, arrowY, 0, fillWidth / (float) ARROW_WIDTH, 0);
tessellator.addVertexWithUV(arrowX, arrowY, 0, 0, 0); tessellator.addVertexWithUV(arrowX, arrowY, 0, 0, 0);
tessellator.draw(); tessellator.draw();
GL11.glDisable(GL11.GL_BLEND); GL11.glPopAttrib();
GL11.glPopMatrix();
} }
@Override @Override
public PositionedStack getOtherStack() { public List<PositionedStack> getIngredients() {
ItemStack[] orbStacks = NEIConfig.getBloodOrbs().stream().map(ItemStack::new).toArray(ItemStack[]::new); return getCycledIngredients(cycleticks / 20, Collections.singletonList(this.orbs));
PositionedStack stack = new PositionedStack(orbStacks, 32, 33, true);
stack.setPermutationToRender((cycleticks / 20) % orbStacks.length);
return stack;
} }
} }
@@ -151,24 +161,26 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler {
ReagentStack rs = ReagentRegistry.getReagentStackForItem(result); ReagentStack rs = ReagentRegistry.getReagentStackForItem(result);
if (rs != null) { if (rs != null) {
arecipes.add(new CachedReagentInfo(rs)); arecipes.add(new CachedReagentInfo(rs));
} else { // Check reagents in crystal belljars or other reagent storages return;
NBTTagCompound tagCompound = result.getTagCompound(); }
if (tagCompound == null || tagCompound.hasNoTags()) { // Check reagents in crystal belljars or other reagent storages
return; NBTTagCompound tagCompound = result.getTagCompound();
} if (tagCompound == null || tagCompound.hasNoTags()) {
NBTTagList tagList = tagCompound.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND); return;
if (tagList.tagList.isEmpty()) { }
return; NBTTagList tagList = tagCompound.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND);
} if (tagList.tagList.isEmpty()) {
for (int i = 0; i < tagList.tagCount(); i++) { return;
// Get the proper size of the ReagentStack created by melting the item for this reagent }
NBTTagCompound savedTag = tagList.getCompoundTagAt(i); for (int i = 0; i < tagList.tagCount(); i++) {
ReagentStack reagent = ReagentContainer.readFromNBT(savedTag).getReagent(); // Get the proper size of the ReagentStack created by melting the item for this reagent
ItemStack reagentItem = ReagentRegistry.getItemForReagent(reagent.reagent); NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
ReagentStack reagentStackForItem = ReagentRegistry.getReagentStackForItem(reagentItem); ReagentStack reagent = ReagentContainer.readFromNBT(savedTag).getReagent();
if (reagentStackForItem != null) { if (reagent == null) continue;
arecipes.add(new CachedReagentInfo(reagentStackForItem)); ItemStack reagentItem = ReagentRegistry.getItemForReagent(reagent.reagent);
} ReagentStack reagentStackForItem = ReagentRegistry.getReagentStackForItem(reagentItem);
if (reagentStackForItem != null) {
arecipes.add(new CachedReagentInfo(reagentStackForItem));
} }
} }
} }
@@ -191,7 +203,7 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler {
@Override @Override
public void loadTransferRects() { 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 @Override
@@ -20,13 +20,9 @@ public class NEIConfig implements IConfigureNEI {
"alchemicalwizardry", "alchemicalwizardry",
"gui/nei/arrow.png"); "gui/nei/arrow.png");
public static ArrayList<Item> getBloodOrbs() { public synchronized static ArrayList<Item> getBloodOrbs() {
if (bloodOrbs == null) { if (bloodOrbs == null) {
synchronized (NEIConfig.class) { bloodOrbs = collectAllBloodOrbs();
if (bloodOrbs == null) {
bloodOrbs = collectAllBloodOrbs();
}
}
} }
return bloodOrbs; return bloodOrbs;
} }
@@ -39,7 +35,7 @@ public class NEIConfig implements IConfigureNEI {
} }
} }
if (bloodOrbsTemp.isEmpty()) { 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) { for (Object anItemRegistry : Item.itemRegistry) {
Item item = (Item) anItemRegistry; Item item = (Item) anItemRegistry;
if (item instanceof IBloodOrb) { if (item instanceof IBloodOrb) {
@@ -50,12 +46,12 @@ public class NEIConfig implements IConfigureNEI {
return bloodOrbsTemp; return bloodOrbsTemp;
} }
public static ArrayList<Item> getOrbsByCapacity() { public synchronized static ArrayList<Item> getOrbsByCapacity() {
if (byCapacity == null) { if (byCapacity == null) {
byCapacity = new ArrayList<>(getBloodOrbs()); byCapacity = new ArrayList<>(getBloodOrbs());
byCapacity.sort((a, b) -> { byCapacity.sort((a, b) -> {
if (a instanceof IBloodOrb && b instanceof IBloodOrb) { if (a instanceof IBloodOrb orbA && b instanceof IBloodOrb orbB) {
return Integer.compare(((IBloodOrb) a).getMaxEssence(), ((IBloodOrb) b).getMaxEssence()); return Integer.compare(orbA.getMaxEssence(), orbB.getMaxEssence());
} }
return 0; return 0;
}); });