From fe303bba0f139886c8838335f7bd761031c2ab95 Mon Sep 17 00:00:00 2001 From: miozune Date: Sat, 26 Feb 2022 01:29:28 +0900 Subject: [PATCH] Add NEI handler for Meteor Ritual (#17) * Add NEI handler for Meteor Ritual * gradle 1.2.7 * Sort by LP cost Co-authored-by: Martin Robertz --- build.gradle | 2 +- dependencies.gradle | 2 + .../AlchemicalWizardry.java | 5 + .../client/nei/IMCForNEI.java | 22 +++ .../client/nei/NEIConfig.java | 2 + .../client/nei/NEIMeteorRecipeHandler.java | 180 ++++++++++++++++++ .../client/nei/TooltipStack.java | 25 +++ .../alchemicalwizardry/gui/nei/meteor.png | Bin 0 -> 3077 bytes .../assets/alchemicalwizardry/lang/en_US.lang | 4 + 9 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 src/main/java/WayofTime/alchemicalWizardry/client/nei/IMCForNEI.java create mode 100644 src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java create mode 100644 src/main/java/WayofTime/alchemicalWizardry/client/nei/TooltipStack.java create mode 100644 src/main/resources/assets/alchemicalwizardry/gui/nei/meteor.png diff --git a/build.gradle b/build.gradle index b6471087..c9bb6ce7 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ buildscript { } } dependencies { - classpath 'com.github.GTNewHorizons:ForgeGradle:1.2.5' + classpath 'com.github.GTNewHorizons:ForgeGradle:1.2.7' } } diff --git a/dependencies.gradle b/dependencies.gradle index 253b000a..f302dfea 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -10,6 +10,8 @@ dependencies { compileOnly("com.github.GTNewHorizons:ForgeMultipart:1.2.7:dev") { transitive = false } + compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.1:dev") + compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.2.7-GTNH:dev") { transitive = false } diff --git a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java index 0a44d55d..3b08f1ff 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java +++ b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java @@ -13,6 +13,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import WayofTime.alchemicalWizardry.api.BlockStack; +import WayofTime.alchemicalWizardry.client.nei.IMCForNEI; import WayofTime.alchemicalWizardry.common.summoning.meteor.Meteor; import WayofTime.alchemicalWizardry.api.alchemy.AlchemicalPotionCreationHandler; import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipeRegistry; @@ -1050,6 +1051,10 @@ public class AlchemicalWizardry ItemIncense.registerIncenseRecipes(); GameRegistry.addRecipe(new ItemStack(ModBlocks.blockCrucible), "i i", "sis", " S ", 's', new ItemStack(Blocks.stone_slab), 'i', ironIngotStack, 'S', stoneStack); + + if (Loader.isModLoaded("NotEnoughItems")) { + IMCForNEI.IMCSender(); + } } @EventHandler diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/IMCForNEI.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/IMCForNEI.java new file mode 100644 index 00000000..85f557f6 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/IMCForNEI.java @@ -0,0 +1,22 @@ +package WayofTime.alchemicalWizardry.client.nei; + +import cpw.mods.fml.common.event.FMLInterModComms; +import net.minecraft.nbt.NBTTagCompound; + +public class IMCForNEI { + public static void IMCSender() { + setNBTAndSend("WayofTime.alchemicalWizardry.client.nei.NEIMeteorRecipeHandler", "AWWayofTime:masterStone", 130); + } + + private static void setNBTAndSend(String handlerName, String aBlock, int height) { + NBTTagCompound NBT = new NBTTagCompound(); + NBT.setString("handler", handlerName); + NBT.setString("modName", "Blood Magic"); + NBT.setString("modId", "AWWayofTime"); + NBT.setBoolean("modRequired", true); + NBT.setString("itemName", aBlock); + NBT.setInteger("handlerHeight", height); + NBT.setInteger("maxRecipesPerPage", 1); + FMLInterModComms.sendMessage("NotEnoughItems", "registerHandlerInfo", NBT); + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java index 88f0bc5c..802a0f8e 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIConfig.java @@ -54,6 +54,8 @@ public class NEIConfig implements IConfigureNEI { API.registerUsageHandler(new NEIBloodOrbShapelessHandler()); API.registerRecipeHandler(new NEIBindingRitualHandler()); API.registerUsageHandler(new NEIBindingRitualHandler()); + API.registerRecipeHandler(new NEIMeteorRecipeHandler()); + API.registerUsageHandler(new NEIMeteorRecipeHandler()); } @Override diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java new file mode 100644 index 00000000..169cfb58 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/NEIMeteorRecipeHandler.java @@ -0,0 +1,180 @@ +package WayofTime.alchemicalWizardry.client.nei; + +import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorParadigm; +import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorParadigmComponent; +import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorRegistry; +import codechicken.lib.gui.GuiDraw; +import codechicken.nei.NEIServerUtils; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.TemplateRecipeHandler; +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.I18n; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +public class NEIMeteorRecipeHandler extends TemplateRecipeHandler { + public class CachedMeteorRecipe extends CachedRecipe { + + private final List components; + private final List input = new ArrayList<>(); + private final List outputs = new ArrayList<>(); + private final int cost; + private final int radius; + + public CachedMeteorRecipe(MeteorParadigm meteor) { + this.components = meteor.componentList; + this.input.add(new PositionedStack(meteor.focusStack, 74, 4)); + int row = 0; + int col = 0; + for (MeteorParadigmComponent component : meteor.componentList) { + ItemStack stack = component.getValidBlockParadigm(); + List tooltips = new ArrayList<>(); + if (stack == null) { + stack = new ItemStack(Blocks.fire); + tooltips.add(String.format("no entries found for oredict \"%s\"", component.getOreDictName())); + } + tooltips.add(I18n.format("nei.recipe.meteor.chance", getFormattedChance(component.getChance()))); + this.outputs.add(new TooltipStack(stack, 3 + 18 * col, 37 + 18 * row, tooltips)); + col++; + if (col > 8) { + col = 0; + row++; + } + } + this.radius = meteor.radius; + this.cost = meteor.cost; + } + + @Override + public List getIngredients() { + return this.input; + } + + @Override + public PositionedStack getResult() { + return null; + } + + @Override + public List getOtherStacks() { + return this.outputs; + } + + public List getComponents() { + return components; + } + + public int getCost() { + return cost; + } + + public int getRadius() { + return radius; + } + } + + @Override + public void loadTransferRects() { + transferRects.add(new RecipeTransferRect(new Rectangle(75, 22, 15, 13), getOverlayIdentifier())); + } + + @Override + public void loadCraftingRecipes(String outputId, Object... results) { + if (outputId.equals(getOverlayIdentifier()) && getClass() == NEIMeteorRecipeHandler.class) { + for (MeteorParadigm meteor : getSortedMeteors()) { + arecipes.add(new CachedMeteorRecipe(meteor)); + } + } else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadCraftingRecipes(ItemStack result) { + for (MeteorParadigm meteor : getSortedMeteors()) { + if (meteor.componentList.stream().anyMatch(m -> NEIServerUtils.areStacksSameTypeCrafting(result, m.getValidBlockParadigm()))) { + arecipes.add(new CachedMeteorRecipe(meteor)); + } + } + } + + @Override + public void loadUsageRecipes(ItemStack ingredient) { + for (MeteorParadigm meteor : getSortedMeteors()) { + if (NEIServerUtils.areStacksSameTypeCrafting(ingredient, meteor.focusStack)) { + arecipes.add(new CachedMeteorRecipe(meteor)); + } + } + } + + @Override + public String getGuiTexture() { + return new ResourceLocation("alchemicalwizardry", "gui/nei/meteor.png").toString(); + } + + @Override + public String getOverlayIdentifier() { + return "alchemicalwizardry.meteor"; + } + + @Override + public void drawExtras(int recipe) { + CachedMeteorRecipe meteorRecipe = (CachedMeteorRecipe) this.arecipes.get(recipe); + int cost = meteorRecipe.getCost(); + int radius = meteorRecipe.getRadius(); + Minecraft.getMinecraft().fontRenderer.drawString(I18n.format("nei.recipe.meteor.cost", String.format("%,d", cost)), 2, 96, 0x000000); + Minecraft.getMinecraft().fontRenderer.drawString(I18n.format("nei.recipe.meteor.radius", radius), 2, 107, 0x000000); + } + + @Override + public void drawBackground(int recipe) { + GL11.glColor4f(1, 1, 1, 1); + GuiDraw.changeTexture(getGuiTexture()); + GuiDraw.drawTexturedModalRect(0, 0, 5, 11, 172, 130); + } + + @Override + public List handleItemTooltip(GuiRecipe gui, ItemStack stack, List currenttip, int recipe) { + CachedMeteorRecipe meteorRecipe = (CachedMeteorRecipe) this.arecipes.get(recipe); + for (PositionedStack pStack : meteorRecipe.outputs) { + if (!gui.isMouseOver(pStack, recipe)) continue; + if (!(pStack instanceof TooltipStack)) break; + + TooltipStack tStack = (TooltipStack) pStack; + if (Arrays.stream(tStack.items).anyMatch(s -> NEIServerUtils.areStacksSameTypeCrafting(s, stack))) { + currenttip.addAll(tStack.getTooltips()); + break; + } + } + return currenttip; + } + + @Override + public String getRecipeName() { + return I18n.format("nei.recipe.meteor.category"); + } + + private List getSortedMeteors() { + return MeteorRegistry.paradigmList + .stream() + .sorted(Comparator.comparing(m -> m.cost)) + .collect(Collectors.toList()); + } + + private String getFormattedChance(int chance) { + float percentage = (float) chance / 10; + boolean isInteger = Float.compare(percentage, (float) (chance / 10)) == 0; + if (isInteger) return String.format("%,d", (int) percentage); + else return String.format("%,.1f", percentage); + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/nei/TooltipStack.java b/src/main/java/WayofTime/alchemicalWizardry/client/nei/TooltipStack.java new file mode 100644 index 00000000..810e49dc --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/client/nei/TooltipStack.java @@ -0,0 +1,25 @@ +package WayofTime.alchemicalWizardry.client.nei; + +import codechicken.nei.PositionedStack; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class TooltipStack extends PositionedStack { + + private final List tooltips; + + public TooltipStack(Object object, int x, int y, boolean genPerms, List tooltips) { + super(object, x, y, genPerms); + this.tooltips = tooltips; + } + + public TooltipStack(Object object, int x, int y, List tooltips) { + this(object, x, y, true, tooltips); + } + + public List getTooltips() { + return tooltips; + } +} diff --git a/src/main/resources/assets/alchemicalwizardry/gui/nei/meteor.png b/src/main/resources/assets/alchemicalwizardry/gui/nei/meteor.png new file mode 100644 index 0000000000000000000000000000000000000000..b03798112b4f8fb5a93fff744815ea9b15565cb5 GIT binary patch literal 3077 zcmeH}X;2eq7{}jTHZcSbK;%$LV&y0XHBuF|K%&q}xPpKM5g{mA5dpb`aAmRHa#hfP zN5TxDaiA4cM$k~QG73RNN28?$1Qak@L}`FXfIt_gIMVTh(`oyq&g{d84=&s>eGY(*l;yn6H!-NM zEhNUk&fwt2%QW(p$C+L?ZT-ou;MB*!3_V*)cLE65~PD%^h$#=~)6WVM4OiS)O|6 z#^qA2$(~d_jr_xnQbn-l_f)WbKTLlb-@CgER2~?6T{Nke=``f(yA_SJ+PjpFQNEKQ zdbVfB30x%tCs%Rz;-7+oJxT-Ap&Tx+AG%J%%>3D4vmZoC93KfO%Nj^dFM05)SsOds z>Q;(SyVvMLlyPnxlwX+~Squ;dnqL3oU@aqbrBqys>#J^+Ovvv!j`jWmmq!lwBDf9G zgsQe&bPkUgfMaKfaW4%B!^W54bs*U_G9Fci@kzsH7;hZ)KHHQLJC(&orHt(C>^VXP zFX)p2&Yk$$<`)CK;d#J@mzTC+@8^KOAiPJREH;VisL_l=LF(m-Ywh7G^^hB`bC1uU zA^^%COlhK2$@k;Fu?q_+00ub%i8C0NSm{Ig)hwMxq!2X+T`mnwGFHWlKL~t_1%dqP z>+Ixi#|Q>Y=jIxo(q=*pbFtOlwmC5UW$@O8V3Rc)IC;bL8}XIL37iv-+;4>{S!zp~ zJ>=dlI=BP&Vk*h>th|{bkTL4#M`CWeMZ6ml{9Y2dog{x_@LLV|lR`Pr@qt+&=U%Ch+QAmKs zU@3yxsqM4*DK{MY_>q%!P>{kqxVo>dLdcK0-ObfT0SU`YrmEAwSh5GE0{rM8q*(7- zMYQ8-<5o?ZL62>;5W3hyx6d*oGQoqh<5i2NpdcKjMA=}9l0F)3 z4jJ1?>d8>P?|Z1&L(`}v#cWj)8GTW0a@C@@IHd?HY}RmxRe+Dwo_!4Y+?oWTMJ z6Cj-ubQ#i6htV*RB7A&7GYyyS-rfS>Zgv_39(Ef^Buu$)u+5@j!B~Yfn%z2$j3|^! z;Iv7vtp_FE> zV`^>U0vW$9yP%7fVB;)^cj^)Fy7!w^agdBQW{dY zxMv>6#T6W?db#f+Zkj@NYFFl(<~i5@B=r!y7~Sq+Nw?}0YTdp1Q-$llIUN4+Y4hK1 z*b!P^@D<9mf}m${0V-E2J~%_Xx=3;Qx~QjkM;THJ!@9(kSsxQVa`@