diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-08-29 16:04:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-29 16:04:28 +0200 |
commit | 7d1f51a8937e0a86486267437d444696e81e8aa0 (patch) | |
tree | a5b145e7271998f7b4b968a2212ed487e54a92b5 /src/main/java/gtPlusPlus/api/helpers | |
parent | 5267969156d30b4bb5f4cb2279ebb49db6bd40e2 (diff) | |
download | GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.gz GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.bz2 GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.zip |
Buildscript + Spotless (#318)
* Convert AES.java to readable class
* Buildscript
* Spotless
Diffstat (limited to 'src/main/java/gtPlusPlus/api/helpers')
-rw-r--r-- | src/main/java/gtPlusPlus/api/helpers/GregtechPlusPlus_API.java | 387 | ||||
-rw-r--r-- | src/main/java/gtPlusPlus/api/helpers/MaterialHelper.java | 151 |
2 files changed, 278 insertions, 260 deletions
diff --git a/src/main/java/gtPlusPlus/api/helpers/GregtechPlusPlus_API.java b/src/main/java/gtPlusPlus/api/helpers/GregtechPlusPlus_API.java index 5cf323c7e2..99e14cae01 100644 --- a/src/main/java/gtPlusPlus/api/helpers/GregtechPlusPlus_API.java +++ b/src/main/java/gtPlusPlus/api/helpers/GregtechPlusPlus_API.java @@ -1,7 +1,5 @@ package gtPlusPlus.api.helpers; -import java.util.HashMap; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.WeightedCollection; import gtPlusPlus.api.objects.minecraft.multi.SpecialMultiBehaviour; @@ -9,205 +7,198 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy_RTG; import gtPlusPlus.xmod.gregtech.api.util.SpecialBehaviourTooltipHandler; +import java.util.HashMap; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; public class GregtechPlusPlus_API { - - - public static class MolecularTransformer_API { - - public static boolean addRecipe(ItemStack aInput, ItemStack aOutput, int aDuration, int aEU) { - return CORE.RA.addMolecularTransformerRecipe(aInput, aOutput, aDuration, aEU, 1); - } - - } - - public static class Multiblock_API { - - private static final HashMap<String, SpecialMultiBehaviour> mSpecialBehaviourItemMap = new HashMap<String, SpecialMultiBehaviour>(); - - /** - * Register a special behaviour for GT++ Multis to listen use. - * @param aBehaviour - An Object which has extended {@link SpecialMultiBehaviour}'s base implementation. - * @return - Did this behaviour register properly? - */ - public static boolean registerSpecialMultiBehaviour(SpecialMultiBehaviour aBehaviour) { - if (aBehaviour.getTriggerItem() == null || aBehaviour.getTriggerItemTooltip() == null || aBehaviour.getTriggerItemTooltip().length() <= 0) { - Logger.INFO("Failed to attach custom multiblock logic to "+ItemUtils.getItemName(aBehaviour.getTriggerItem())); - return false; - } - mSpecialBehaviourItemMap.put("UniqueKey_"+aBehaviour.hashCode(), aBehaviour); - SpecialBehaviourTooltipHandler.addTooltipForItem(aBehaviour.getTriggerItem(), aBehaviour.getTriggerItemTooltip()); - Logger.INFO("Attached custom multiblock logic to "+ItemUtils.getItemName(aBehaviour.getTriggerItem())); - return true; - } - - public static final HashMap<String, SpecialMultiBehaviour> getSpecialBehaviourItemMap() { - return mSpecialBehaviourItemMap; - } - - /** - * Allows RTG Fuel pellets from other mods to be used in the RTG hatch. - * @param aStack - The Pellet Stack, sanitsed after passing through. - * @param aFuelValue - The Fuel Value of the Pellet to be added to the energy storage. - * @return - Did register? - */ - public static boolean registerPelletForRtgHatch(ItemStack aStack, long aFuelValue) { - return GT_MetaTileEntity_Hatch_Energy_RTG.registerPelletForHatch(aStack, aFuelValue); - } - - } - - public static class VoidMiner_API { - - private static final HashMap<Integer, HashMap<String, WeightedCollection<Block>>> mMinerLootCache; - - static { - mMinerLootCache = new HashMap<Integer, HashMap<String, WeightedCollection<Block>>>(); - } - - - /** - * - * Registers an ore block for a dimension. Uses a default weight of 100. - * @param aDim - The Dimension ID - * @param aOredictName - The OreDict name of the Ore to be mined. - * @return - If there was a valid Block found in the OreDict for the provided name. - */ - public static boolean registerOreForVoidMiner(int aDim, String aOredictName) { - return registerOreForVoidMiner(aDim, aOredictName, 100); - } - - /** - * - * Registers an ore block for a dimension. Uses a default weight of 100. - * @param aDim - The Dimension ID - * @param aOredictName - The OreDict name of the Ore to be mined. - * @param aWeight - The weight of this ore Block. - * @return - If there was a valid Block found in the OreDict for the provided name. - */ - public static boolean registerOreForVoidMiner(int aDim, String aOredictName, int aWeight) { - Block b = null; - ItemStack[] aValidItems = ItemUtils.validItemsForOreDict(aOredictName); - for (ItemStack g : aValidItems) { - if (g != null) { - b = Block.getBlockFromItem(g.getItem()); - if (b != null) { - break; - } - } - } - if (b != null) { - registerOreForVoidMiner(aDim, b, aWeight); - return true; - } - return false; - } - - - /** - * Registers an ore block for a dimension. Uses a default weight of 100. - * @param aDim - The Dimension ID - * @param aOreBlock - The Ore Block to be mined. - */ - public static void registerOreForVoidMiner(int aDim, Block aOreBlock) { - registerOreForVoidMiner(aDim, aOreBlock, 100); - } - - /** - * Registers an ore block for a dimension. - * @param aDim - The Dimension ID - * @param aOreBlock - The Ore Block to be mined. - * @param aWeight - The weight of this ore Block. - */ - public static void registerOreForVoidMiner(int aDim, Block aOreBlock, int aWeight) { - GregtechPlusPlus_API_Internal.writeBlockToDimensionInCache(aDim, 0, aOreBlock, aWeight); - } - - /** - * Registers a surface block for a dimension. Uses a default weight of 100. - * @param aDim - The Dimension ID - * @param aDirtBlock - The Dirt/Grass Block to be mined. - */ - public static void registerEarthSurfaceForVoidMiner(int aDim, Block aDirtBlock) { - registerEarthSurfaceForVoidMiner(aDim, aDirtBlock, 100); - } - - /** - * Registers a surface block for a dimension. - * @param aDim - The Dimension ID - * @param aDirtBlock - The Dirt/Grass Block to be mined. - * @param aWeight - The weight of this Dirt/Grass Block. - */ - public static void registerEarthSurfaceForVoidMiner(int aDim, Block aDirtBlock, int aWeight) { - GregtechPlusPlus_API_Internal.writeBlockToDimensionInCache(aDim, 0, aDirtBlock, aWeight); - } - - /** - * Registers a stone block for a dimension. Uses a default weight of 100. - * @param aDim - The Dimension ID - * @param aStoneBlock - The Stone Block to be mined. - */ - public static void registerEarthStoneForVoidMiner(int aDim, Block aStoneBlock) { - registerEarthStoneForVoidMiner(aDim, aStoneBlock, 100); - } - - /** - * Registers a stone block for a dimension. - * @param aDim - The Dimension ID - * @param aStoneBlock - The Stone Block to be mined. - * @param aWeight - The weight of this Stone Block. - */ - public static void registerEarthStoneForVoidMiner(int aDim, Block aStoneBlock, int aWeight) { - GregtechPlusPlus_API_Internal.writeBlockToDimensionInCache(aDim, 0, aStoneBlock, aWeight); - } - - - - - public static WeightedCollection<Block> getAllRegisteredOresForDimension(int aDim) { - return mMinerLootCache.get(aDim).get("ore"); - } - - public static WeightedCollection<Block> getAllRegisteredDirtTypesForDimension(int aDim) { - return mMinerLootCache.get(aDim).get("dirt"); - } - - public static WeightedCollection<Block> getAllRegisteredStoneTypesForDimension(int aDim) { - return mMinerLootCache.get(aDim).get("stone"); - } - - public static final HashMap<Integer, HashMap<String, WeightedCollection<Block>>> getVoidMinerLootCache() { - return mMinerLootCache; - } - - } - - - private static class GregtechPlusPlus_API_Internal { - - private static void writeBlockToDimensionInCache(int aDim, int aType, Block aBlock, int aWeight) { - HashMap<String, WeightedCollection<Block>> aDimMap = VoidMiner_API.mMinerLootCache.get(aDim); - if (aDimMap == null) { - aDimMap = new HashMap<String, WeightedCollection<Block>>(); - } - WeightedCollection<Block> aMappedBlocks = getBlockMap(aType, aDimMap); - aMappedBlocks.put(aWeight, aBlock); - - } - - private static WeightedCollection<Block> getBlockMap(int aType, HashMap<String, WeightedCollection<Block>> aDimMap){ - WeightedCollection<Block> aMappedBlocks; - String aTypeName = ((aType == 0) ? "ore" : (aType == 1) ? "dirt" : (aType == 2) ? "stone" : "error"); - aMappedBlocks = aDimMap.get(aTypeName); - if (aMappedBlocks == null) { - aMappedBlocks = new WeightedCollection<Block>(); - } - return aMappedBlocks; - } - - } - + public static class MolecularTransformer_API { + + public static boolean addRecipe(ItemStack aInput, ItemStack aOutput, int aDuration, int aEU) { + return CORE.RA.addMolecularTransformerRecipe(aInput, aOutput, aDuration, aEU, 1); + } + } + + public static class Multiblock_API { + + private static final HashMap<String, SpecialMultiBehaviour> mSpecialBehaviourItemMap = + new HashMap<String, SpecialMultiBehaviour>(); + + /** + * Register a special behaviour for GT++ Multis to listen use. + * @param aBehaviour - An Object which has extended {@link SpecialMultiBehaviour}'s base implementation. + * @return - Did this behaviour register properly? + */ + public static boolean registerSpecialMultiBehaviour(SpecialMultiBehaviour aBehaviour) { + if (aBehaviour.getTriggerItem() == null + || aBehaviour.getTriggerItemTooltip() == null + || aBehaviour.getTriggerItemTooltip().length() <= 0) { + Logger.INFO("Failed to attach custom multiblock logic to " + + ItemUtils.getItemName(aBehaviour.getTriggerItem())); + return false; + } + mSpecialBehaviourItemMap.put("UniqueKey_" + aBehaviour.hashCode(), aBehaviour); + SpecialBehaviourTooltipHandler.addTooltipForItem( + aBehaviour.getTriggerItem(), aBehaviour.getTriggerItemTooltip()); + Logger.INFO("Attached custom multiblock logic to " + ItemUtils.getItemName(aBehaviour.getTriggerItem())); + return true; + } + + public static final HashMap<String, SpecialMultiBehaviour> getSpecialBehaviourItemMap() { + return mSpecialBehaviourItemMap; + } + + /** + * Allows RTG Fuel pellets from other mods to be used in the RTG hatch. + * @param aStack - The Pellet Stack, sanitsed after passing through. + * @param aFuelValue - The Fuel Value of the Pellet to be added to the energy storage. + * @return - Did register? + */ + public static boolean registerPelletForRtgHatch(ItemStack aStack, long aFuelValue) { + return GT_MetaTileEntity_Hatch_Energy_RTG.registerPelletForHatch(aStack, aFuelValue); + } + } + + public static class VoidMiner_API { + + private static final HashMap<Integer, HashMap<String, WeightedCollection<Block>>> mMinerLootCache; + + static { + mMinerLootCache = new HashMap<Integer, HashMap<String, WeightedCollection<Block>>>(); + } + + /** + * + * Registers an ore block for a dimension. Uses a default weight of 100. + * @param aDim - The Dimension ID + * @param aOredictName - The OreDict name of the Ore to be mined. + * @return - If there was a valid Block found in the OreDict for the provided name. + */ + public static boolean registerOreForVoidMiner(int aDim, String aOredictName) { + return registerOreForVoidMiner(aDim, aOredictName, 100); + } + + /** + * + * Registers an ore block for a dimension. Uses a default weight of 100. + * @param aDim - The Dimension ID + * @param aOredictName - The OreDict name of the Ore to be mined. + * @param aWeight - The weight of this ore Block. + * @return - If there was a valid Block found in the OreDict for the provided name. + */ + public static boolean registerOreForVoidMiner(int aDim, String aOredictName, int aWeight) { + Block b = null; + ItemStack[] aValidItems = ItemUtils.validItemsForOreDict(aOredictName); + for (ItemStack g : aValidItems) { + if (g != null) { + b = Block.getBlockFromItem(g.getItem()); + if (b != null) { + break; + } + } + } + if (b != null) { + registerOreForVoidMiner(aDim, b, aWeight); + return true; + } + return false; + } + + /** + * Registers an ore block for a dimension. Uses a default weight of 100. + * @param aDim - The Dimension ID + * @param aOreBlock - The Ore Block to be mined. + */ + public static void registerOreForVoidMiner(int aDim, Block aOreBlock) { + registerOreForVoidMiner(aDim, aOreBlock, 100); + } + + /** + * Registers an ore block for a dimension. + * @param aDim - The Dimension ID + * @param aOreBlock - The Ore Block to be mined. + * @param aWeight - The weight of this ore Block. + */ + public static void registerOreForVoidMiner(int aDim, Block aOreBlock, int aWeight) { + GregtechPlusPlus_API_Internal.writeBlockToDimensionInCache(aDim, 0, aOreBlock, aWeight); + } + + /** + * Registers a surface block for a dimension. Uses a default weight of 100. + * @param aDim - The Dimension ID + * @param aDirtBlock - The Dirt/Grass Block to be mined. + */ + public static void registerEarthSurfaceForVoidMiner(int aDim, Block aDirtBlock) { + registerEarthSurfaceForVoidMiner(aDim, aDirtBlock, 100); + } + + /** + * Registers a surface block for a dimension. + * @param aDim - The Dimension ID + * @param aDirtBlock - The Dirt/Grass Block to be mined. + * @param aWeight - The weight of this Dirt/Grass Block. + */ + public static void registerEarthSurfaceForVoidMiner(int aDim, Block aDirtBlock, int aWeight) { + GregtechPlusPlus_API_Internal.writeBlockToDimensionInCache(aDim, 0, aDirtBlock, aWeight); + } + + /** + * Registers a stone block for a dimension. Uses a default weight of 100. + * @param aDim - The Dimension ID + * @param aStoneBlock - The Stone Block to be mined. + */ + public static void registerEarthStoneForVoidMiner(int aDim, Block aStoneBlock) { + registerEarthStoneForVoidMiner(aDim, aStoneBlock, 100); + } + + /** + * Registers a stone block for a dimension. + * @param aDim - The Dimension ID + * @param aStoneBlock - The Stone Block to be mined. + * @param aWeight - The weight of this Stone Block. + */ + public static void registerEarthStoneForVoidMiner(int aDim, Block aStoneBlock, int aWeight) { + GregtechPlusPlus_API_Internal.writeBlockToDimensionInCache(aDim, 0, aStoneBlock, aWeight); + } + + public static WeightedCollection<Block> getAllRegisteredOresForDimension(int aDim) { + return mMinerLootCache.get(aDim).get("ore"); + } + + public static WeightedCollection<Block> getAllRegisteredDirtTypesForDimension(int aDim) { + return mMinerLootCache.get(aDim).get("dirt"); + } + + public static WeightedCollection<Block> getAllRegisteredStoneTypesForDimension(int aDim) { + return mMinerLootCache.get(aDim).get("stone"); + } + + public static final HashMap<Integer, HashMap<String, WeightedCollection<Block>>> getVoidMinerLootCache() { + return mMinerLootCache; + } + } + + private static class GregtechPlusPlus_API_Internal { + + private static void writeBlockToDimensionInCache(int aDim, int aType, Block aBlock, int aWeight) { + HashMap<String, WeightedCollection<Block>> aDimMap = VoidMiner_API.mMinerLootCache.get(aDim); + if (aDimMap == null) { + aDimMap = new HashMap<String, WeightedCollection<Block>>(); + } + WeightedCollection<Block> aMappedBlocks = getBlockMap(aType, aDimMap); + aMappedBlocks.put(aWeight, aBlock); + } + + private static WeightedCollection<Block> getBlockMap( + int aType, HashMap<String, WeightedCollection<Block>> aDimMap) { + WeightedCollection<Block> aMappedBlocks; + String aTypeName = ((aType == 0) ? "ore" : (aType == 1) ? "dirt" : (aType == 2) ? "stone" : "error"); + aMappedBlocks = aDimMap.get(aTypeName); + if (aMappedBlocks == null) { + aMappedBlocks = new WeightedCollection<Block>(); + } + return aMappedBlocks; + } + } } diff --git a/src/main/java/gtPlusPlus/api/helpers/MaterialHelper.java b/src/main/java/gtPlusPlus/api/helpers/MaterialHelper.java index 9d2e894d99..3f14a9de03 100644 --- a/src/main/java/gtPlusPlus/api/helpers/MaterialHelper.java +++ b/src/main/java/gtPlusPlus/api/helpers/MaterialHelper.java @@ -1,76 +1,103 @@ package gtPlusPlus.api.helpers; -import net.minecraft.item.ItemStack; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Fluid; import gregtech.api.util.GT_OreDictUnificator; import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.recipe.common.CI; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.ItemUtils; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import net.minecraft.item.ItemStack; public class MaterialHelper { - public static ItemStack getComponentFromMaterial(OrePrefixes oreprefix, Material material, int amount){ - return ItemUtils.getOrePrefixStack(oreprefix, material, amount); - } - public static ItemStack getComponentFromGtMaterial(OrePrefixes oreprefix, Materials material, int amount){ - return ItemUtils.getGregtechOreStack(oreprefix, material, amount); - } - - /** - * Generates a 16 Fluid Pipe - * @see {@code Example: Copper 16x Pipe (Materials.Copper, Materials.Copper.mName, "Copper", ID, 60, 1000, true)} - * @param aMaterial - Pipe Material - * @param name - Pipe Internal name - * @param displayName - Pipe Display Name - * @param aID - Pipe's Meta ID - * @param baseCapacity - Pipes Base Capacity - * @param heatCapacity - Pipe Max Temp - * @param gasProof - Is Gas Proof? - * @return A boolean which corresponds to whether or not the Pipe was registered to the Ore Dictionary. - */ - public static boolean generateHexadecuplePipe(Materials aMaterial, String name, String displayName, int aID, - int baseCapacity, int heatCapacity, boolean gasProof) { - if (Utils.getGregtechVersionAsInt() >= 50930) { - try { - Class<GT_MetaPipeEntity_Fluid> aPipeEntity = GT_MetaPipeEntity_Fluid.class; - Constructor<GT_MetaPipeEntity_Fluid> constructor = aPipeEntity - .getConstructor(new Class[] { int.class, String.class, String.class, float.class, - Materials.class, int.class, int.class, boolean.class, int.class }); - if (constructor != null) { - GT_MetaPipeEntity_Fluid aPipe; - aPipe = constructor.newInstance(aID, "GT_Pipe_" + name + "_Hexadecuple", - "Hexadecuple " + displayName + " Fluid Pipe", 1.0F, aMaterial, baseCapacity, heatCapacity, - gasProof, 16); - return GT_OreDictUnificator.registerOre("pipeHexadecuple" + aMaterial, aPipe.getStackForm(1L)); - } + public static ItemStack getComponentFromMaterial(OrePrefixes oreprefix, Material material, int amount) { + return ItemUtils.getOrePrefixStack(oreprefix, material, amount); + } + + public static ItemStack getComponentFromGtMaterial(OrePrefixes oreprefix, Materials material, int amount) { + return ItemUtils.getGregtechOreStack(oreprefix, material, amount); + } + + /** + * Generates a 16 Fluid Pipe + * @see {@code Example: Copper 16x Pipe (Materials.Copper, Materials.Copper.mName, "Copper", ID, 60, 1000, true)} + * @param aMaterial - Pipe Material + * @param name - Pipe Internal name + * @param displayName - Pipe Display Name + * @param aID - Pipe's Meta ID + * @param baseCapacity - Pipes Base Capacity + * @param heatCapacity - Pipe Max Temp + * @param gasProof - Is Gas Proof? + * @return A boolean which corresponds to whether or not the Pipe was registered to the Ore Dictionary. + */ + public static boolean generateHexadecuplePipe( + Materials aMaterial, + String name, + String displayName, + int aID, + int baseCapacity, + int heatCapacity, + boolean gasProof) { + if (Utils.getGregtechVersionAsInt() >= 50930) { + try { + Class<GT_MetaPipeEntity_Fluid> aPipeEntity = GT_MetaPipeEntity_Fluid.class; + Constructor<GT_MetaPipeEntity_Fluid> constructor = aPipeEntity.getConstructor(new Class[] { + int.class, + String.class, + String.class, + float.class, + Materials.class, + int.class, + int.class, + boolean.class, + int.class + }); + if (constructor != null) { + GT_MetaPipeEntity_Fluid aPipe; + aPipe = constructor.newInstance( + aID, + "GT_Pipe_" + name + "_Hexadecuple", + "Hexadecuple " + displayName + " Fluid Pipe", + 1.0F, + aMaterial, + baseCapacity, + heatCapacity, + gasProof, + 16); + return GT_OreDictUnificator.registerOre("pipeHexadecuple" + aMaterial, aPipe.getStackForm(1L)); + } + + } catch (NoSuchMethodException + | SecurityException + | InstantiationException + | IllegalAccessException + | IllegalArgumentException + | InvocationTargetException e) { + } + } + return false; + } + + public static ItemStack getCells(Materials aMaterial, int i) { + return ItemUtils.getOrePrefixStack(OrePrefixes.cell, aMaterial, i); + } + + public static ItemStack getDust(Materials aMaterial, int i) { + return ItemUtils.getOrePrefixStack(OrePrefixes.dust, aMaterial, i); + } + + public static ItemStack getDustSmall(Materials aMaterial, int i) { + return ItemUtils.getOrePrefixStack(OrePrefixes.dustSmall, aMaterial, i); + } + + public static ItemStack getDustTiny(Materials aMaterial, int i) { + return ItemUtils.getOrePrefixStack(OrePrefixes.dustTiny, aMaterial, i); + } - } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { - } - } - return false; - } - - public static ItemStack getCells(Materials aMaterial, int i) { - return ItemUtils.getOrePrefixStack(OrePrefixes.cell, aMaterial, i); - } - public static ItemStack getDust(Materials aMaterial, int i) { - return ItemUtils.getOrePrefixStack(OrePrefixes.dust, aMaterial, i); - } - public static ItemStack getDustSmall(Materials aMaterial, int i) { - return ItemUtils.getOrePrefixStack(OrePrefixes.dustSmall, aMaterial, i); - } - public static ItemStack getDustTiny(Materials aMaterial, int i) { - return ItemUtils.getOrePrefixStack(OrePrefixes.dustTiny, aMaterial, i); - } - public static ItemStack getGems(Materials aMaterial, int i) { - return ItemUtils.getOrePrefixStack(OrePrefixes.gem, aMaterial, i); - } + public static ItemStack getGems(Materials aMaterial, int i) { + return ItemUtils.getOrePrefixStack(OrePrefixes.gem, aMaterial, i); + } } |