diff options
author | miozune <miozune@gmail.com> | 2022-08-02 18:23:15 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-02 16:23:15 +0700 |
commit | 4eeee867cb1a0d09fdbb77f05a94be65be7751c3 (patch) | |
tree | fab1bb9b283c847b99f17b5a1203ed91bb61543d /src/main/java/pers/gwyog/gtneioreplugin/plugin | |
parent | 8d107e3f476534032f321a941891f2c567119ac1 (diff) | |
download | GT5-Unofficial-4eeee867cb1a0d09fdbb77f05a94be65be7751c3.tar.gz GT5-Unofficial-4eeee867cb1a0d09fdbb77f05a94be65be7751c3.tar.bz2 GT5-Unofficial-4eeee867cb1a0d09fdbb77f05a94be65be7751c3.zip |
Underground fluid NEI (#20)
* Underground fluid NEI
* updateBuildScript
Diffstat (limited to 'src/main/java/pers/gwyog/gtneioreplugin/plugin')
7 files changed, 242 insertions, 10 deletions
diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/IMCForNEI.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/IMCForNEI.java new file mode 100644 index 0000000000..bcba2eed1a --- /dev/null +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/IMCForNEI.java @@ -0,0 +1,57 @@ +package pers.gwyog.gtneioreplugin.plugin; + +import cpw.mods.fml.common.event.FMLInterModComms; +import net.minecraft.nbt.NBTTagCompound; +import pers.gwyog.gtneioreplugin.GTNEIOrePlugin; + +public class IMCForNEI { + public static void IMCSender() { + // Though these 2 are already registered in NEI jar, we need to re-register + // because new DimensionDisplayItems made tabs a bit taller. + sendHandler("pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5VeinStat", "gregtech:gt.blockores:386"); + + sendHandler("pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5SmallOreStat", "gregtech:gt.blockores:85"); + + sendHandler( + "pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5UndergroundFluid", + "gregtech:gt.metaitem.01:32619"); + sendCatalyst( + "pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5UndergroundFluid", + "gregtech:gt.blockmachines:1157"); + sendCatalyst( + "pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5UndergroundFluid", + "gregtech:gt.blockmachines:141"); + sendCatalyst( + "pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5UndergroundFluid", + "gregtech:gt.blockmachines:142"); + sendCatalyst( + "pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5UndergroundFluid", + "gregtech:gt.blockmachines:148"); + } + + private static void sendHandler(String name, String itemStack) { + NBTTagCompound aNBT = new NBTTagCompound(); + aNBT.setString("handler", name); + aNBT.setString("modName", GTNEIOrePlugin.NAME); + aNBT.setString("modId", GTNEIOrePlugin.MODID); + aNBT.setBoolean("modRequired", true); + aNBT.setString("itemName", itemStack); + aNBT.setInteger("handlerHeight", 160); + aNBT.setInteger("handlerWidth", 166); + aNBT.setInteger("maxRecipesPerPage", 2); + aNBT.setInteger("yShift", 0); + FMLInterModComms.sendMessage("NotEnoughItems", "registerHandlerInfo", aNBT); + } + + private static void sendCatalyst(String name, String itemStack, int priority) { + NBTTagCompound aNBT = new NBTTagCompound(); + aNBT.setString("handlerID", name); + aNBT.setString("itemName", itemStack); + aNBT.setInteger("priority", priority); + FMLInterModComms.sendMessage("NotEnoughItems", "registerCatalystInfo", aNBT); + } + + private static void sendCatalyst(String name, String itemStack) { + sendCatalyst(name, itemStack, 0); + } +} diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/NEIPluginConfig.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/NEIPluginConfig.java index ee76cff2d2..17193b07fe 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/plugin/NEIPluginConfig.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/NEIPluginConfig.java @@ -4,6 +4,7 @@ import codechicken.nei.api.API; import codechicken.nei.api.IConfigureNEI; import pers.gwyog.gtneioreplugin.GTNEIOrePlugin; import pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5SmallOreStat; +import pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5UndergroundFluid; import pers.gwyog.gtneioreplugin.plugin.gregtech5.PluginGT5VeinStat; public class NEIPluginConfig implements IConfigureNEI { @@ -22,9 +23,12 @@ public class NEIPluginConfig implements IConfigureNEI { public void loadConfig() { PluginGT5VeinStat pluginVeinStat = new PluginGT5VeinStat(); PluginGT5SmallOreStat pluginSmallOreStat = new PluginGT5SmallOreStat(); + PluginGT5UndergroundFluid pluginGT5UndergroundFluid = new PluginGT5UndergroundFluid(); API.registerRecipeHandler(pluginVeinStat); API.registerUsageHandler(pluginVeinStat); API.registerRecipeHandler(pluginSmallOreStat); API.registerUsageHandler(pluginSmallOreStat); + API.registerRecipeHandler(pluginGT5UndergroundFluid); + API.registerUsageHandler(pluginGT5UndergroundFluid); } } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/PluginBase.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/PluginBase.java index de36d22bc9..71c770a86b 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/plugin/PluginBase.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/PluginBase.java @@ -25,7 +25,7 @@ public abstract class PluginBase extends TemplateRecipeHandler { @Override public void loadTransferRects() { - int stringLength = GuiDraw.getStringWidth(EnumChatFormatting.BOLD + I18n.format("gui.nei.seeAll")); + int stringLength = GuiDraw.getStringWidth(EnumChatFormatting.BOLD + I18n.format("gtnop.gui.nei.seeAll")); transferRects.add(new RecipeTransferRect( new Rectangle(getGuiWidth() - stringLength - 3, 5, stringLength, 9), getOutputId())); } @@ -35,4 +35,12 @@ public abstract class PluginBase extends TemplateRecipeHandler { public int getGuiWidth() { return 166; } + + /** + * Draw the "see all recipes" transfer label + */ + protected void drawSeeAllRecipesLabel() { + GuiDraw.drawStringR( + EnumChatFormatting.BOLD + I18n.format("gtnop.gui.nei.seeAll"), getGuiWidth() - 3, 5, 0x404040, false); + } } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java index 6abc3ea96c..1c7e14db79 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java @@ -8,7 +8,6 @@ import gregtech.api.util.GT_LanguageManager; import java.awt.Point; import java.awt.Rectangle; import net.minecraft.client.resources.I18n; -import net.minecraft.util.EnumChatFormatting; import pers.gwyog.gtneioreplugin.plugin.PluginBase; import pers.gwyog.gtneioreplugin.util.GuiRecipeHelper; @@ -89,12 +88,4 @@ public abstract class PluginGT5Base extends PluginBase { protected void drawDimNames(String dimNames) { GuiDraw.drawString(I18n.format("gtnop.gui.nei.worldNames") + ": ", 2, 100, 0x404040, false); } - - /** - * Draw the "see all recipes" transfer label - */ - protected void drawSeeAllRecipesLabel() { - GuiDraw.drawStringR( - EnumChatFormatting.BOLD + I18n.format("gtnop.gui.nei.seeAll"), getGuiWidth() - 3, 5, 0x404040, false); - } } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5UndergroundFluid.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5UndergroundFluid.java new file mode 100644 index 0000000000..0cdf2b53b7 --- /dev/null +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5UndergroundFluid.java @@ -0,0 +1,165 @@ +package pers.gwyog.gtneioreplugin.plugin.gregtech5; + +import codechicken.lib.gui.GuiDraw; +import codechicken.nei.PositionedStack; +import gregtech.api.util.GT_Utility; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import net.minecraft.client.resources.I18n; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import pers.gwyog.gtneioreplugin.plugin.PluginBase; +import pers.gwyog.gtneioreplugin.plugin.item.ItemDimensionDisplay; +import pers.gwyog.gtneioreplugin.util.GT5UndergroundFluidHelper; +import pers.gwyog.gtneioreplugin.util.GT5UndergroundFluidHelper.UndergroundFluidWrapper; + +public class PluginGT5UndergroundFluid extends PluginBase { + + private static final int lineSpace = 20; + private static final int xDimensionDisplay = 30; + private static final int halfItemLength = 16 / 2; + + @Override + public void loadCraftingRecipes(String outputId, Object... results) { + if (outputId.equals(getOutputId())) { + for (Map.Entry<String, List<UndergroundFluidWrapper>> entry : + GT5UndergroundFluidHelper.getAllEntries().entrySet()) { + Fluid fluid = FluidRegistry.getFluid(entry.getKey()); + if (fluid != null) { + this.arecipes.add(new CachedUndergroundFluidRecipe(fluid, entry.getValue())); + } + } + } else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadCraftingRecipes(ItemStack result) { + Fluid fluid = null; + FluidStack containerFluid = GT_Utility.getFluidForFilledItem(result, true); + if (containerFluid != null) { + fluid = containerFluid.getFluid(); + } + if (fluid == null) { + FluidStack displayFluid = GT_Utility.getFluidFromDisplayStack(result); + if (displayFluid != null) { + fluid = displayFluid.getFluid(); + } + } + if (fluid == null) return; + + List<UndergroundFluidWrapper> wrappers = GT5UndergroundFluidHelper.getEntry(fluid.getName()); + if (wrappers != null) { + this.arecipes.add(new CachedUndergroundFluidRecipe(fluid, wrappers)); + } + } + + @Override + public void loadUsageRecipes(ItemStack ingredient) { + String dimension = ItemDimensionDisplay.getDimension(ingredient); + if (dimension != null) { + for (Map.Entry<String, List<UndergroundFluidWrapper>> entry : + GT5UndergroundFluidHelper.getAllEntries().entrySet()) { + boolean found = false; + for (UndergroundFluidWrapper wrapper : entry.getValue()) { + if (wrapper.dimension.equals(dimension)) { + found = true; + break; + } + } + if (found) { + Fluid fluid = FluidRegistry.getFluid(entry.getKey()); + if (fluid != null) { + this.arecipes.add(new CachedUndergroundFluidRecipe(fluid, entry.getValue())); + } + } + } + } + } + + @Override + public void drawExtras(int recipeIndex) { + drawSeeAllRecipesLabel(); + + int xChance = 85; + int xAmount = 140; + int yHeader = 30; + int black = 0x404040; + + GuiDraw.drawStringC(I18n.format("gtnop.gui.nei.dimension") + ":", xDimensionDisplay, yHeader, black, false); + GuiDraw.drawStringC(I18n.format("gtnop.gui.nei.chance") + ":", xChance, yHeader, black, false); + GuiDraw.drawStringC(I18n.format("gtnop.gui.nei.fluidAmount") + ":", xAmount, yHeader, black, false); + + int y = 50; + CachedUndergroundFluidRecipe recipe = (CachedUndergroundFluidRecipe) this.arecipes.get(recipeIndex); + for (int i = 0; i < recipe.dimensionDisplayItems.size(); i++) { + GuiDraw.drawStringC( + new DecimalFormat("0.#").format((double) recipe.chances.get(i) / 100) + "%", + xChance, + y, + black, + false); + GuiDraw.drawStringC( + recipe.minAmounts.get(i).toString() + "-" + + recipe.maxAmounts.get(i).toString(), + xAmount, + y, + black, + false); + y += lineSpace; + } + } + + @Override + public String getOutputId() { + return "GTOrePluginUndergroundFluid"; + } + + @Override + public String getRecipeName() { + return I18n.format("gtnop.gui.undergroundFluid.name"); + } + + private class CachedUndergroundFluidRecipe extends CachedRecipe { + + private final PositionedStack targetFluidDisplay; + private final List<PositionedStack> dimensionDisplayItems = new ArrayList<>(); + private final List<Integer> chances = new ArrayList<>(); + private final List<Integer> maxAmounts = new ArrayList<>(); + private final List<Integer> minAmounts = new ArrayList<>(); + + private CachedUndergroundFluidRecipe(Fluid fluid, List<UndergroundFluidWrapper> wrappers) { + targetFluidDisplay = + new PositionedStack(GT_Utility.getFluidDisplayStack(fluid), getGuiWidth() / 2 - halfItemLength, 3); + int y = 50 - halfItemLength; + for (UndergroundFluidWrapper wrapper : wrappers) { + ItemStack dimensionDisplay = ItemDimensionDisplay.getItem(wrapper.dimension); + if (dimensionDisplay != null) { + dimensionDisplayItems.add(new PositionedStack( + dimensionDisplay, + xDimensionDisplay - halfItemLength, + y + GuiDraw.fontRenderer.FONT_HEIGHT / 2)); + y += lineSpace; + chances.add(wrapper.chance); + maxAmounts.add(wrapper.maxAmount); + minAmounts.add(wrapper.minAmount); + } + } + } + + @Override + public PositionedStack getResult() { + return targetFluidDisplay; + } + + @Override + public List<PositionedStack> getIngredients() { + return dimensionDisplayItems; + } + } +} diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/item/ItemDimensionDisplay.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/item/ItemDimensionDisplay.java index 7584cf405c..0e5bf0c24b 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/plugin/item/ItemDimensionDisplay.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/item/ItemDimensionDisplay.java @@ -1,5 +1,7 @@ package pers.gwyog.gtneioreplugin.plugin.item; +import static pers.gwyog.gtneioreplugin.GTNEIOrePlugin.LOG; + import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import java.util.Objects; @@ -29,6 +31,9 @@ public class ItemDimensionDisplay extends ItemBlock { if (block != null) { return new ItemStack(block); } + if (dimension != null) { + LOG.warn("Unknown dimension queried for ItemDimensionDisplay: " + dimension); + } return null; } diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/renderer/ItemDimensionDisplayRenderer.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/renderer/ItemDimensionDisplayRenderer.java index 3b281713f7..b175b456b1 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/plugin/renderer/ItemDimensionDisplayRenderer.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/renderer/ItemDimensionDisplayRenderer.java @@ -62,6 +62,7 @@ public class ItemDimensionDisplayRenderer implements IItemRenderer { case "Ce": case "Eu": case "Ga": + case "Rb": return "T3"; case "Io": case "Me": @@ -71,6 +72,7 @@ public class ItemDimensionDisplayRenderer implements IItemRenderer { case "Mi": case "Ob": case "Ti": + case "Ra": return "T5"; case "Pr": case "Tr": |