From 22f1bd384688c34eff7eea942614e35c5aa409c1 Mon Sep 17 00:00:00 2001 From: koolkrafter5 Date: Sun, 25 May 2025 14:50:55 -0400 Subject: [PATCH] Add an Alchemic Calcinator handler for NEI (#87) --- .../client/nei/IMCForNEI.java | 8 +- .../client/nei/NEICalcinatorHandler.java | 206 ++++++++++++++++++ .../client/nei/NEIConfig.java | 7 + .../client/nei/NEIMeteorRecipeHandler.java | 5 + .../alchemicalwizardry/gui/nei/arrow.png | Bin 0 -> 292 bytes .../alchemicalwizardry/gui/nei/calcinator.png | Bin 0 -> 1763 bytes 6 files changed, 223 insertions(+), 3 deletions(-) create mode 100644 src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java create mode 100644 src/main/resources/assets/alchemicalwizardry/gui/nei/arrow.png create mode 100644 src/main/resources/assets/alchemicalwizardry/gui/nei/calcinator.png diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/IMCForNEI.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/IMCForNEI.java index 5a3c6b96..ccf4f435 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/IMCForNEI.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/IMCForNEI.java @@ -7,12 +7,14 @@ import cpw.mods.fml.common.event.FMLInterModComms; public class IMCForNEI { public static void IMCSender() { - sendHandler("alchemicalwizardry.meteor", "AWWayofTime:masterStone", 181); + sendHandler("alchemicalwizardry.meteor", "AWWayofTime:masterStone", 181, 1); + sendHandler("alchemicalwizardry.calcinator", "AWWayofTime:blockAlchemicCalcinator", 55, 5); sendCatalyst("alchemicalwizardry.meteor", "AWWayofTime:masterStone"); sendCatalyst("alchemicalwizardry.bindingritual", "AWWayofTime:masterStone"); + sendCatalyst("alchemicalwizardry.calcinator", "AWWayofTime:blockAlchemicCalcinator"); } - private static void sendHandler(String handlerName, String stack, int height) { + private static void sendHandler(String handlerName, String stack, int height, int recipesPerPage) { NBTTagCompound NBT = new NBTTagCompound(); NBT.setString("handler", handlerName); NBT.setString("modName", "Blood Magic"); @@ -20,7 +22,7 @@ public class IMCForNEI { NBT.setBoolean("modRequired", true); NBT.setString("itemName", stack); NBT.setInteger("handlerHeight", height); - NBT.setInteger("maxRecipesPerPage", 1); + NBT.setInteger("maxRecipesPerPage", recipesPerPage); FMLInterModComms.sendMessage("NotEnoughItems", "registerHandlerInfo", NBT); } diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java new file mode 100644 index 00000000..e48b38e5 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEICalcinatorHandler.java @@ -0,0 +1,206 @@ +package WayofTime.alchemicalWizardry.client.nei; + +import static WayofTime.alchemicalWizardry.client.ClientUtils.mc; +import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.ARROW_TEXTURE; + +import java.awt.Rectangle; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.util.Constants; + +import org.lwjgl.opengl.GL11; + +import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent; +import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainer; +import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry; +import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.TemplateRecipeHandler; + +public class NEICalcinatorHandler extends TemplateRecipeHandler { + + public class CachedReagentInfo extends CachedRecipe { + + private final Reagent reagent; + private final int amount; + private final int color; + + public CachedReagentInfo(ReagentStack reagent) { + this.reagent = reagent.reagent; + this.amount = reagent.amount; + this.color = reagent.reagent.getColourRed() << 16 | reagent.reagent.getColourGreen() << 8 + | reagent.reagent.getColourBlue(); + } + + @Override + public PositionedStack getResult() { + return new PositionedStack(ReagentRegistry.getItemForReagent(reagent), 32, 6); + } + + public Reagent getReagent() { + return reagent; + } + + public int getAmount() { + return amount; + } + + 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 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); + } + + 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 cycleTick = cycleticks % totalCycle; + + int fillWidth; + if (cycleTick < fillTime) { + fillWidth = cycleTick * arrowWidth / fillTime; + } else { + fillWidth = arrowWidth; + } + + TextureManager texManager = mc.getTextureManager(); + texManager.bindTexture(ARROW_TEXTURE); + + Tessellator tessellator = Tessellator.instance; + + 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); + + 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, 0, 0, 0); + + tessellator.draw(); + + GL11.glDisable(GL11.GL_BLEND); + } + + @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; + } + } + + @Override + public void loadCraftingRecipes(String outputId, Object... results) { + if (outputId.equals("alchemicalwizardry.calcinator") && getClass() == NEICalcinatorHandler.class) { + for (ReagentStack reagent : ReagentRegistry.itemToReagentMap.values()) { + arecipes.add(new CachedReagentInfo(reagent)); + } + } else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadCraftingRecipes(ItemStack result) { + checkReagents(result); + } + + @Override + public void loadUsageRecipes(ItemStack ingredient) { + checkReagents(ingredient); + } + + private void checkReagents(ItemStack result) { + 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)); + } + } + } + } + + @Override + public int recipiesPerPage() { + return 5; + } + + @Override + public void drawExtras(int recipe) { + NEICalcinatorHandler.CachedReagentInfo reagentInfo = (CachedReagentInfo) this.arecipes.get(recipe); + reagentInfo.onDraw(30, 0); + } + + @Override + public String getOverlayIdentifier() { + return "alchemicalwizardry.calcinator"; + } + + @Override + public void loadTransferRects() { + transferRects.add(new RecipeTransferRect(new Rectangle(54, 23, 23, 16), "alchemicalwizardry.calcinator")); + } + + @Override + public String getGuiTexture() { + return new ResourceLocation("alchemicalwizardry", "gui/nei/calcinator.png").toString(); + } + + @Override + public String getRecipeName() { + return "Alchemic Calcinator"; + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java index 6baa9fba..a39f349c 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb; import codechicken.nei.ItemList; @@ -15,6 +16,10 @@ public class NEIConfig implements IConfigureNEI { private static ArrayList bloodOrbs = null; private static ArrayList byCapacity = null; + public static final ResourceLocation ARROW_TEXTURE = new ResourceLocation( + "alchemicalwizardry", + "gui/nei/arrow.png"); + public static ArrayList getBloodOrbs() { if (bloodOrbs == null) { synchronized (NEIConfig.class) { @@ -72,6 +77,8 @@ public class NEIConfig implements IConfigureNEI { API.registerUsageHandler(new NEIBindingRitualHandler()); API.registerRecipeHandler(new NEIMeteorRecipeHandler()); API.registerUsageHandler(new NEIMeteorRecipeHandler()); + API.registerRecipeHandler(new NEICalcinatorHandler()); + API.registerUsageHandler(new NEICalcinatorHandler()); } @Override diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java index 310e9fb7..746dd838 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java @@ -244,6 +244,11 @@ public class NEIMeteorRecipeHandler extends TemplateRecipeHandler { return false; } + @Override + public int recipiesPerPage() { + return 1; + } + @Override public String getGuiTexture() { return new ResourceLocation("alchemicalwizardry", "gui/nei/meteor.png").toString(); diff --git a/src/main/resources/assets/alchemicalwizardry/gui/nei/arrow.png b/src/main/resources/assets/alchemicalwizardry/gui/nei/arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..cc128289dd1b11fc90e27d1cb562977e087ca8e6 GIT binary patch literal 292 zcmeAS@N?(olHy`uVBq!ia0vp^54nJ=qZCRW5rVYGN2%PiKnkC`%4x{QA=L`Yv&dNg)%%{ z978NlZ@uKmcff&#HJ~cW??`Ux)h!eKUOrf_{-2jIpkrp_muC%0N=tZLJh(r!Zei43 zB3j{WP|aK4++ktVI6s9a;aRn-%a*N5f|1i!Yi(O|F#Y>x%>`TUFu#53pRnW))3H;V aua`5)3K!aCZQKY70|rl5KbLh*2~7YxK3m`b literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/alchemicalwizardry/gui/nei/calcinator.png b/src/main/resources/assets/alchemicalwizardry/gui/nei/calcinator.png new file mode 100644 index 0000000000000000000000000000000000000000..ebae815a965a4abcfefaf98101cc135d5fd47ea9 GIT binary patch literal 1763 zcmcIkc~H_>9DlHggt2IOlxew=C1hF+Yi)v{X<`bIXO;)qp{YSCk=X&3ojYk(nwIyL z$7&u)=4K^KB}o~ET8NpJmS&=2x>Azt&t`V^pQh=beQ(~p_x*g|_j0l**&fVG(bnC;EJy@>=Vkl|h)ZlHIjBhGbtLCCDVw4itZ>~S*# zmT-;2gFt<*C*58DJz~D;T$E25Ed(-L>gnd|)_S!MQUn z7IDVOJFw&+{Q1s4CT97<)^)#Bh2AlCxVss3bh9nW1bwt=IqN$4fMV7w#O?xeq@VUD z*J@(~wmE^utIr~yZrXJrD@UepdZWI^VbpQNsbO--l;i28V}dA}lCmQxV^RGf{K7+{ zuTvZbo!N15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