Skip to content

Commit b233000

Browse files
koolkrafter5github-actions[bot]
authored andcommitted
Fix some issues in NEI handlers (#105)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent f6e054c commit b233000

6 files changed

Lines changed: 94 additions & 93 deletions

File tree

src/main/java/WayofTime/alchemicalWizardry/api/alchemy/energy/Reagent.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,4 @@ public int getColourIntensity() {
3838
return colourIntensity;
3939
}
4040

41-
@Override
42-
public boolean equals(Object o) {
43-
return o instanceof Reagent && this == o && name.equals(((Reagent) o).name);
44-
}
4541
}

src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIAlchemyRecipeHandler.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.awt.Rectangle;
77
import java.util.ArrayList;
8+
import java.util.Collections;
89
import java.util.List;
910

1011
import net.minecraft.client.gui.inventory.GuiContainer;
@@ -29,15 +30,14 @@ public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler {
2930

3031
public class CachedAlchemyRecipe extends CachedRecipe {
3132

32-
ArrayList<ItemStack> orbs;
33-
PositionedStack output;
34-
List<PositionedStack> inputs;
35-
int lp;
33+
private final PositionedStack orbs;
34+
private final PositionedStack output;
35+
private final List<PositionedStack> inputs;
36+
private final int lp;
3637

3738
public CachedAlchemyRecipe(AlchemyRecipe recipe, ItemStack orb) {
3839
this(recipe);
39-
this.orbs = new ArrayList<>();
40-
orbs.add(orb);
40+
this.orbs.setPermutationToRender(orb);
4141
}
4242

4343
public CachedAlchemyRecipe(AlchemyRecipe recipe) {
@@ -51,12 +51,13 @@ public CachedAlchemyRecipe(AlchemyRecipe recipe) {
5151
this.inputs = inputs;
5252
this.output = new PositionedStack(recipe.getResult(), 76, 25);
5353
this.lp = recipe.getAmountNeeded() * 100;
54-
this.orbs = new ArrayList<>();
54+
List<ItemStack> orbStacks = new ArrayList<>();
5555
for (Item orb : getBloodOrbs()) {
5656
if (((IBloodOrb) orb).getOrbLevel() >= recipe.getOrbLevel()) {
57-
orbs.add(new ItemStack(orb));
57+
orbStacks.add(new ItemStack(orb));
5858
}
5959
}
60+
orbs = new PositionedStack(orbStacks, 136, 47);
6061
}
6162

6263
@Override
@@ -70,12 +71,8 @@ public PositionedStack getResult() {
7071
}
7172

7273
@Override
73-
public PositionedStack getOtherStack() {
74-
if (orbs == null || orbs.isEmpty()) return null;
75-
PositionedStack stack = new PositionedStack(orbs, 136, 47, false);
76-
stack.setPermutationToRender((cycleticks / 48) % orbs.size());
77-
stack.setMaxSize(1);
78-
return stack;
74+
public List<PositionedStack> getOtherStacks() {
75+
return getCycledIngredients(cycleticks / 20, Collections.singletonList(orbs));
7976
}
8077
}
8178

src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIAltarRecipeHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public class NEIAltarRecipeHandler extends TemplateRecipeHandler {
2525

2626
public class CachedAltarRecipe extends CachedRecipe {
2727

28-
PositionedStack input;
28+
private final PositionedStack input;
2929
// PositionedStack inputItems;
30-
PositionedStack output;
31-
int tier, lp_amount, consumption, drain;
30+
private final PositionedStack output;
31+
private final int tier, lp_amount, consumption, drain;
3232

3333
public CachedAltarRecipe(AltarRecipe recipe) {
3434
// inputItems = new PositionedStack(recipe.input, 38, 2, false);

src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIBindingRitualHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class NEIBindingRitualHandler extends TemplateRecipeHandler {
2929

3030
public class CachedBindingRecipe extends CachedRecipe {
3131

32-
PositionedStack input, output;
32+
private final PositionedStack input, output;
3333

3434
public CachedBindingRecipe(BindingRecipe recipe) {
3535
input = new PositionedStack(recipe.requiredItem, 37, 21, false);

src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java

Lines changed: 73 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import static WayofTime.alchemicalWizardry.client.ClientUtils.mc;
44
import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.ARROW_TEXTURE;
5+
import static codechicken.lib.gui.GuiDraw.fontRenderer;
56

67
import java.awt.Rectangle;
8+
import java.util.Collections;
9+
import java.util.List;
710

8-
import net.minecraft.client.gui.FontRenderer;
911
import net.minecraft.client.renderer.Tessellator;
1012
import net.minecraft.client.renderer.texture.TextureManager;
1113
import net.minecraft.item.ItemStack;
@@ -28,19 +30,39 @@ public class NEICalcinatorHandler extends TemplateRecipeHandler {
2830
public class CachedReagentInfo extends CachedRecipe {
2931

3032
private final Reagent reagent;
33+
private final PositionedStack stack;
34+
private final PositionedStack orbs;
3135
private final int amount;
32-
private final int color;
36+
37+
private final String amountText;
38+
private final int amountTextWidth;
39+
40+
private final String nameText;
41+
private final int nameTextWidth;
42+
43+
private static final int ARROW_WIDTH = 24;
44+
private static final int ARROW_HEIGHT = 16;
45+
private static final int FILL_TIME = 192;
46+
private static final int HOLD_TIME = 8;
3347

3448
public CachedReagentInfo(ReagentStack reagent) {
3549
this.reagent = reagent.reagent;
50+
this.stack = new PositionedStack(ReagentRegistry.getItemForReagent(reagent.reagent), 32, 6);
3651
this.amount = reagent.amount;
37-
this.color = reagent.reagent.getColourRed() << 16 | reagent.reagent.getColourGreen() << 8
38-
| reagent.reagent.getColourBlue();
52+
53+
ItemStack[] orbStacks = NEIConfig.getBloodOrbs().stream().map(ItemStack::new).toArray(ItemStack[]::new);
54+
this.orbs = new PositionedStack(orbStacks, 32, 33);
55+
56+
this.amountText = String.format("%,d AR", amount);
57+
this.amountTextWidth = fontRenderer.getStringWidth(amountText);
58+
59+
this.nameText = this.reagent.name;
60+
this.nameTextWidth = fontRenderer.getStringWidth(nameText);
3961
}
4062

4163
@Override
4264
public PositionedStack getResult() {
43-
return new PositionedStack(ReagentRegistry.getItemForReagent(reagent), 32, 6);
65+
return stack;
4466
}
4567

4668
public Reagent getReagent() {
@@ -54,75 +76,63 @@ public int getAmount() {
5476
public void onDraw(int x, int y) {
5577
drawColoredProgressBar(x, y);
5678

57-
String amountText = String.format("%,d AR", amount);
58-
FontRenderer fontRenderer = mc.fontRenderer;
59-
60-
int textWidth = fontRenderer.getStringWidth(amountText);
61-
int textX = x + 84 - (textWidth / 2);
79+
int textX = x + 84 - (amountTextWidth / 2);
6280
int textY = y + 19;
63-
6481
fontRenderer.drawString(amountText, textX, textY, 0x000000);
6582

66-
textWidth = fontRenderer.getStringWidth(reagent.name);
67-
textX = x + 84 - (textWidth / 2);
68-
textY = y + 29;
69-
70-
fontRenderer.drawString(reagent.name, textX, textY, color);
83+
textX = x + 84 - (nameTextWidth / 2);
84+
textY += 10;
85+
int color = reagent.getColourRed() << 16 | reagent.getColourGreen() << 8 | reagent.getColourBlue();
86+
fontRenderer.drawString(nameText, textX, textY, color);
7187
}
7288

7389
private void drawColoredProgressBar(int x, int y) {
7490
int arrowX = x + 25;
7591
int arrowY = y + 19;
76-
int arrowWidth = 24;
77-
int arrowHeight = 16;
7892

79-
int fillTime = 192;
80-
int holdTime = 8;
81-
int totalCycle = fillTime + holdTime;
93+
int totalCycle = FILL_TIME + HOLD_TIME;
8294

8395
int cycleTick = cycleticks % totalCycle;
8496

8597
int fillWidth;
86-
if (cycleTick < fillTime) {
87-
fillWidth = cycleTick * arrowWidth / fillTime;
98+
if (cycleTick < FILL_TIME) {
99+
fillWidth = cycleTick * ARROW_WIDTH / FILL_TIME;
88100
} else {
89-
fillWidth = arrowWidth;
101+
fillWidth = ARROW_WIDTH;
90102
}
91103

92104
TextureManager texManager = mc.getTextureManager();
93105
texManager.bindTexture(ARROW_TEXTURE);
94106

95107
Tessellator tessellator = Tessellator.instance;
96108

109+
GL11.glPushMatrix();
110+
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
111+
97112
GL11.glEnable(GL11.GL_BLEND);
98113
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
99114

100-
float r = ((color >> 16) & 0xFF) / 255f;
101-
float g = ((color >> 8) & 0xFF) / 255f;
102-
float b = (color & 0xFF) / 255f;
103-
104-
GL11.glColor4f(r, g, b, 1.0f);
115+
GL11.glColor4ub(
116+
(byte) reagent.getColourRed(),
117+
(byte) reagent.getColourGreen(),
118+
(byte) reagent.getColourBlue(),
119+
(byte) 255);
105120

106121
tessellator.startDrawingQuads();
107-
108-
tessellator.addVertexWithUV(arrowX, arrowY + arrowHeight, 0, 0, 1);
109-
tessellator.addVertexWithUV(arrowX + fillWidth, arrowY + arrowHeight, 0, fillWidth / (float) arrowWidth, 1);
110-
tessellator.addVertexWithUV(arrowX + fillWidth, arrowY, 0, fillWidth / (float) arrowWidth, 0);
122+
tessellator.addVertexWithUV(arrowX, arrowY + ARROW_HEIGHT, 0, 0, 1);
123+
tessellator
124+
.addVertexWithUV(arrowX + fillWidth, arrowY + ARROW_HEIGHT, 0, fillWidth / (float) ARROW_WIDTH, 1);
125+
tessellator.addVertexWithUV(arrowX + fillWidth, arrowY, 0, fillWidth / (float) ARROW_WIDTH, 0);
111126
tessellator.addVertexWithUV(arrowX, arrowY, 0, 0, 0);
112-
113127
tessellator.draw();
114128

115-
GL11.glDisable(GL11.GL_BLEND);
129+
GL11.glPopAttrib();
130+
GL11.glPopMatrix();
116131
}
117132

118133
@Override
119-
public PositionedStack getOtherStack() {
120-
ItemStack[] orbStacks = NEIConfig.getBloodOrbs().stream().map(ItemStack::new).toArray(ItemStack[]::new);
121-
122-
PositionedStack stack = new PositionedStack(orbStacks, 32, 33, true);
123-
stack.setPermutationToRender((cycleticks / 20) % orbStacks.length);
124-
125-
return stack;
134+
public List<PositionedStack> getIngredients() {
135+
return getCycledIngredients(cycleticks / 20, Collections.singletonList(this.orbs));
126136
}
127137
}
128138

@@ -151,24 +161,26 @@ private void checkReagents(ItemStack result) {
151161
ReagentStack rs = ReagentRegistry.getReagentStackForItem(result);
152162
if (rs != null) {
153163
arecipes.add(new CachedReagentInfo(rs));
154-
} else { // Check reagents in crystal belljars or other reagent storages
155-
NBTTagCompound tagCompound = result.getTagCompound();
156-
if (tagCompound == null || tagCompound.hasNoTags()) {
157-
return;
158-
}
159-
NBTTagList tagList = tagCompound.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND);
160-
if (tagList.tagList.isEmpty()) {
161-
return;
162-
}
163-
for (int i = 0; i < tagList.tagCount(); i++) {
164-
// Get the proper size of the ReagentStack created by melting the item for this reagent
165-
NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
166-
ReagentStack reagent = ReagentContainer.readFromNBT(savedTag).getReagent();
167-
ItemStack reagentItem = ReagentRegistry.getItemForReagent(reagent.reagent);
168-
ReagentStack reagentStackForItem = ReagentRegistry.getReagentStackForItem(reagentItem);
169-
if (reagentStackForItem != null) {
170-
arecipes.add(new CachedReagentInfo(reagentStackForItem));
171-
}
164+
return;
165+
}
166+
// Check reagents in crystal belljars or other reagent storages
167+
NBTTagCompound tagCompound = result.getTagCompound();
168+
if (tagCompound == null || tagCompound.hasNoTags()) {
169+
return;
170+
}
171+
NBTTagList tagList = tagCompound.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND);
172+
if (tagList.tagList.isEmpty()) {
173+
return;
174+
}
175+
for (int i = 0; i < tagList.tagCount(); i++) {
176+
// Get the proper size of the ReagentStack created by melting the item for this reagent
177+
NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
178+
ReagentStack reagent = ReagentContainer.readFromNBT(savedTag).getReagent();
179+
if (reagent == null) continue;
180+
ItemStack reagentItem = ReagentRegistry.getItemForReagent(reagent.reagent);
181+
ReagentStack reagentStackForItem = ReagentRegistry.getReagentStackForItem(reagentItem);
182+
if (reagentStackForItem != null) {
183+
arecipes.add(new CachedReagentInfo(reagentStackForItem));
172184
}
173185
}
174186
}
@@ -191,7 +203,7 @@ public String getOverlayIdentifier() {
191203

192204
@Override
193205
public void loadTransferRects() {
194-
transferRects.add(new RecipeTransferRect(new Rectangle(54, 23, 23, 16), "alchemicalwizardry.calcinator"));
206+
transferRects.add(new RecipeTransferRect(new Rectangle(55, 18, 24, 17), "alchemicalwizardry.calcinator"));
195207
}
196208

197209
@Override

src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ public class NEIConfig implements IConfigureNEI {
2020
"alchemicalwizardry",
2121
"gui/nei/arrow.png");
2222

23-
public static ArrayList<Item> getBloodOrbs() {
23+
public synchronized static ArrayList<Item> getBloodOrbs() {
2424
if (bloodOrbs == null) {
25-
synchronized (NEIConfig.class) {
26-
if (bloodOrbs == null) {
27-
bloodOrbs = collectAllBloodOrbs();
28-
}
29-
}
25+
bloodOrbs = collectAllBloodOrbs();
3026
}
3127
return bloodOrbs;
3228
}
@@ -39,7 +35,7 @@ private static ArrayList<Item> collectAllBloodOrbs() {
3935
}
4036
}
4137
if (bloodOrbsTemp.isEmpty()) {
42-
// If there is NEI no cache - go to item registry
38+
// If there is no NEI cache - go to item registry
4339
for (Object anItemRegistry : Item.itemRegistry) {
4440
Item item = (Item) anItemRegistry;
4541
if (item instanceof IBloodOrb) {
@@ -50,12 +46,12 @@ private static ArrayList<Item> collectAllBloodOrbs() {
5046
return bloodOrbsTemp;
5147
}
5248

53-
public static ArrayList<Item> getOrbsByCapacity() {
49+
public synchronized static ArrayList<Item> getOrbsByCapacity() {
5450
if (byCapacity == null) {
5551
byCapacity = new ArrayList<>(getBloodOrbs());
5652
byCapacity.sort((a, b) -> {
57-
if (a instanceof IBloodOrb && b instanceof IBloodOrb) {
58-
return Integer.compare(((IBloodOrb) a).getMaxEssence(), ((IBloodOrb) b).getMaxEssence());
53+
if (a instanceof IBloodOrb orbA && b instanceof IBloodOrb orbB) {
54+
return Integer.compare(orbA.getMaxEssence(), orbB.getMaxEssence());
5955
}
6056
return 0;
6157
});

0 commit comments

Comments
 (0)