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 | |
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')
10 files changed, 432 insertions, 15 deletions
diff --git a/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java b/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java index 55a8680555..9876e07276 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java @@ -11,9 +11,11 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import pers.gwyog.gtneioreplugin.plugin.IMCForNEI; import pers.gwyog.gtneioreplugin.plugin.block.ModBlocks; import pers.gwyog.gtneioreplugin.util.GT5OreLayerHelper; import pers.gwyog.gtneioreplugin.util.GT5OreSmallHelper; +import pers.gwyog.gtneioreplugin.util.GT5UndergroundFluidHelper; import pers.gwyog.gtneioreplugin.util.GuiRecipeHelper; @Mod( @@ -75,6 +77,7 @@ public class GTNEIOrePlugin { @EventHandler public void init(FMLInitializationEvent event) { ModBlocks.init(); + IMCForNEI.IMCSender(); } @EventHandler @@ -82,6 +85,7 @@ public class GTNEIOrePlugin { if (event.getSide() == Side.CLIENT) { new GT5OreLayerHelper(); new GT5OreSmallHelper(); + new GT5UndergroundFluidHelper(); new GuiRecipeHelper(); if (csv) { new pers.gwyog.gtneioreplugin.util.CSVMaker().run(); 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": diff --git a/src/main/java/pers/gwyog/gtneioreplugin/util/DimensionHelper.java b/src/main/java/pers/gwyog/gtneioreplugin/util/DimensionHelper.java index 90d49d7e35..74f726dac1 100644 --- a/src/main/java/pers/gwyog/gtneioreplugin/util/DimensionHelper.java +++ b/src/main/java/pers/gwyog/gtneioreplugin/util/DimensionHelper.java @@ -5,6 +5,7 @@ import static pers.gwyog.gtneioreplugin.GTNEIOrePlugin.maxTooltipLines; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.stream.Collectors; import net.minecraft.client.resources.I18n; public class DimensionHelper { @@ -29,6 +30,7 @@ public class DimensionHelper { "GalaxySpace_Ceres", "GalaxySpace_Europa", "GalaxySpace_Ganymede", + "Ross128b", // T4 "GalaxySpace_Io", "GalaxySpace_Mercury", @@ -38,6 +40,7 @@ public class DimensionHelper { "GalaxySpace_Miranda", "GalaxySpace_Oberon", "GalaxySpace_Titan", + "Ross128ba", // T6 "GalaxySpace_Proteus", "GalaxySpace_Triton", @@ -56,6 +59,14 @@ public class DimensionHelper { "GalaxySpace_VegaB", }; + public static String[] DimNameTrimmed = Arrays.stream(DimName) + .map(n -> n.replaceAll("GalacticraftCore_", "") + .replaceAll("GalacticraftMars_", "") + .replaceAll("GalaxySpace_", "") + .replaceAll("Vanilla_", "Vanilla ")) + .collect(Collectors.toList()) + .toArray(new String[0]); + public static String[] DimNameDisplayed = { // first 2 letters if one word else 1 letter of every word, except capital letter in // name, then 1rst + capital Moon = Mo, BarnardC = BC, EndAsteroid = EA @@ -78,6 +89,7 @@ public class DimensionHelper { "Ce", // GalaxySpace_Ceres "Eu", // GalaxySpace_Europa "Ga", // GalaxySpace_Ganymede + "Rb", // Ross128b // T4 "Io", // GalaxySpace_Io "Me", // GalaxySpace_Mercury @@ -87,6 +99,7 @@ public class DimensionHelper { "Mi", // GalaxySpace_Miranda "Ob", // GalaxySpace_Oberon "Ti", // GalaxySpace_Titan + "Ra", // Ross128ba // T6 "Pr", // GalaxySpace_Proteus "Tr", // GalaxySpace_Triton @@ -113,11 +126,7 @@ public class DimensionHelper { String s = dims[j]; for (int i = 0; i < DimNameDisplayed.length; i++) { if (s.equals(DimNameDisplayed[i])) { - String k = DimName[i] - .replaceAll("GalacticraftCore_", "") - .replaceAll("GalacticraftMars_", "") - .replaceAll("GalaxySpace_", "") - .replaceAll("Vanilla_", "Vanilla "); + String k = DimNameTrimmed[i]; s = I18n.format("gtnop.world." + k); switch (k) { case "Moon": @@ -133,6 +142,7 @@ public class DimensionHelper { case "Ceres": case "Europa": case "Ganymede": + case "Ross128b": s = "T3: " + s; break; case "Io": @@ -144,6 +154,7 @@ public class DimensionHelper { case "Miranda": case "Oberon": case "Titan": + case "Ross128ba": s = "T5: " + s; break; case "Proteus": diff --git a/src/main/java/pers/gwyog/gtneioreplugin/util/GT5UndergroundFluidHelper.java b/src/main/java/pers/gwyog/gtneioreplugin/util/GT5UndergroundFluidHelper.java new file mode 100644 index 0000000000..731867953d --- /dev/null +++ b/src/main/java/pers/gwyog/gtneioreplugin/util/GT5UndergroundFluidHelper.java @@ -0,0 +1,170 @@ +package pers.gwyog.gtneioreplugin.util; + +import static pers.gwyog.gtneioreplugin.GTNEIOrePlugin.LOG; + +import com.google.common.collect.BiMap; +import gregtech.GT_Mod; +import gregtech.api.objects.GT_UO_Dimension; +import gregtech.api.objects.GT_UO_DimensionList; +import gregtech.api.objects.GT_UO_Fluid; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import net.minecraft.world.WorldProvider; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; + +public class GT5UndergroundFluidHelper { + + /** + * Need to store fluid name instead of fluid + * because fluid instance might be different between gas and liquid + */ + private static final Map<String, List<UndergroundFluidWrapper>> fluidMap = new HashMap<>(); + + @SuppressWarnings("unchecked") + public GT5UndergroundFluidHelper() { + try { + Field fieldDimensionList = GT_UO_DimensionList.class.getDeclaredField("fDimensionList"); + fieldDimensionList.setAccessible(true); + BiMap<String, GT_UO_Dimension> dimensionList = + (BiMap<String, GT_UO_Dimension>) fieldDimensionList.get(GT_Mod.gregtechproxy.mUndergroundOil); + for (Map.Entry<String, GT_UO_Dimension> dimensionEntry : dimensionList.entrySet()) { + String rawDimension = dimensionEntry.getKey(); + String dimension = null; + try { + dimension = getDimensionFromID(Integer.parseInt(rawDimension)); + } catch (NumberFormatException ignored) { + Field fieldProviders = DimensionManager.class.getDeclaredField("providers"); + fieldProviders.setAccessible(true); + Hashtable<Integer, Class<? extends WorldProvider>> providers = + (Hashtable<Integer, Class<? extends WorldProvider>>) fieldProviders.get(null); + + // some short dimension names like Io might be caught by multiple dimension classes, + // so we'll check them all. + // List<WorldProvider> dimensionCandidates = providers.values() + List<Class<? extends WorldProvider>> dimensionCandidates = providers.values().stream() + .filter(p -> p.getName().contains(rawDimension)) + .collect(Collectors.toList()); + loop: + for (Class<? extends WorldProvider> candidate : dimensionCandidates) { + for (int i = 0; i < DimensionHelper.DimNameTrimmed.length; i++) { + if (DimensionHelper.DimNameTrimmed[i].equalsIgnoreCase( + candidate.newInstance().getDimensionName())) { + dimension = DimensionHelper.DimNameDisplayed[i]; + break loop; + } + } + } + } + + if (dimension == null) { + dimension = getDimensionForEdgeCase(rawDimension); + if (dimension == null) { + LOG.warn("Unknown dimension found in GT5 config: " + rawDimension); + continue; + } + } + + Field fieldFluids = GT_UO_Dimension.class.getDeclaredField("fFluids"); + fieldFluids.setAccessible(true); + BiMap<String, GT_UO_Fluid> fluids = + (BiMap<String, GT_UO_Fluid>) fieldFluids.get(dimensionEntry.getValue()); + + int maxChance = 0; + for (Map.Entry<String, GT_UO_Fluid> fluidEntry : fluids.entrySet()) { + maxChance += fluidEntry.getValue().Chance; + } + + for (Map.Entry<String, GT_UO_Fluid> fluidEntry : fluids.entrySet()) { + Fluid fluid = FluidRegistry.getFluid(fluidEntry.getKey()); + if (fluid != null) { + UndergroundFluidWrapper wrapper = new UndergroundFluidWrapper( + dimension, + fluidEntry.getValue().Chance * 10000 / maxChance, + fluidEntry.getValue().MaxAmount, + fluidEntry.getValue().MinAmount); + if (fluidMap.containsKey(fluid.getName())) { + fluidMap.get(fluid.getName()).add(wrapper); + } else { + fluidMap.put(fluid.getName(), new ArrayList<>(Collections.singletonList(wrapper))); + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + for (List<UndergroundFluidWrapper> wrappers : fluidMap.values()) { + wrappers.sort(Comparator.comparingInt( + w -> Arrays.asList(DimensionHelper.DimNameDisplayed).indexOf(w.dimension))); + } + } + + public static List<UndergroundFluidWrapper> getEntry(String fluidName) { + return fluidMap.get(fluidName); + } + + public static Map<String, List<UndergroundFluidWrapper>> getAllEntries() { + return fluidMap; + } + + @SuppressWarnings("SwitchStatementWithTooFewBranches") + private String getDimensionFromID(int id) { + switch (id) { + case 0: + return "Ow"; + default: + return null; + } + } + + private String getDimensionForEdgeCase(String rawDimension) { + switch (rawDimension) { + case "aCentauriBb": + return "CB"; + case "BarnardaC": + return "BC"; + case "BarnardaE": + return "BE"; + case "BarnardaF": + return "BF"; + case "TCetiE": + return "TE"; + default: + LOG.warn("Unknown dimension name while parsing: " + rawDimension); + return null; + } + } + + public static class UndergroundFluidWrapper { + + /** + * Using {@link DimensionHelper#DimNameDisplayed} + */ + public final String dimension; + /** + * Chance of this fluid field being generated. 10000 means 100% of the dimension + */ + public final int chance; + + public final int maxAmount; + public final int minAmount; + + public UndergroundFluidWrapper(String dimension, int chance, int maxAmount, int minAmount) { + this.dimension = dimension; + this.chance = chance; + this.maxAmount = maxAmount; + this.minAmount = minAmount; + } + } +} |