From c66db54eab5571fa9b9ce3cef0849050138e22a6 Mon Sep 17 00:00:00 2001 From: Muramasa Date: Tue, 23 Aug 2016 16:39:20 +0100 Subject: [PATCH] Fixes & work on #266 --- src/main/java/gregtech/GT_Mod.java | 1 + src/main/java/gregtech/api/GregTech_API.java | 2 +- .../java/gregtech/api/enums/Materials.java | 36 ++++++++++++++++++- .../api/interfaces/IComponentRegistrator.java | 7 ++++ .../api/items/GT_MetaGenerated_Item_X32.java | 2 +- .../ProcessingComponents.java | 14 ++++++++ .../preload/GT_Loader_MaterialProcessing.java | 2 ++ 7 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/main/java/gregtech/api/interfaces/IComponentRegistrator.java create mode 100644 src/main/java/gregtech/loaders/materialprocessing/ProcessingComponents.java diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index 4e5c3ded..95e5b5d4 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -123,6 +123,7 @@ public class GT_Mod GregTech_API.sMachineFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "MachineStats.cfg"))); GregTech_API.sWorldgenFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "WorldGeneration.cfg"))); GregTech_API.sMaterialProperties = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "MaterialProperties.cfg"))); + GregTech_API.sMaterialComponents = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "MaterialComponents.cfg"))); GregTech_API.sUnification = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "Unification.cfg"))); GregTech_API.sSpecialFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "Other.cfg"))); GregTech_API.sOPStuff = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "OverpoweredStuff.cfg"))); diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java index 99abd6a8..beae1ea0 100644 --- a/src/main/java/gregtech/api/GregTech_API.java +++ b/src/main/java/gregtech/api/GregTech_API.java @@ -169,7 +169,7 @@ public class GregTech_API { /** * The Configuration Objects */ - public static GT_Config sRecipeFile = null, sMachineFile = null, sWorldgenFile = null, sMaterialProperties = null, sUnification = null, sSpecialFile = null, sClientDataFile, sOPStuff = null, sMaterialsFile = null; + public static GT_Config sRecipeFile = null, sMachineFile = null, sWorldgenFile = null, sMaterialProperties = null, sMaterialComponents = null, sUnification = null, sSpecialFile = null, sClientDataFile, sOPStuff = null; public static int TICKS_FOR_LAG_AVERAGING = 25, MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING = 100; /** * Initialized by the Block creation. diff --git a/src/main/java/gregtech/api/enums/Materials.java b/src/main/java/gregtech/api/enums/Materials.java index cd0a28d0..b9101e5d 100644 --- a/src/main/java/gregtech/api/enums/Materials.java +++ b/src/main/java/gregtech/api/enums/Materials.java @@ -6,6 +6,7 @@ import gregtech.api.enums.TC_Aspects.TC_AspectStack; import gregtech.api.interfaces.IColorModulationContainer; import gregtech.api.interfaces.IMaterialRegistrator; import gregtech.api.interfaces.ISubTagContainer; +import gregtech.api.interfaces.IComponentRegistrator; import gregtech.api.objects.GT_FluidStack; import gregtech.api.objects.MaterialStack; import gregtech.api.util.GT_Utility; @@ -22,6 +23,7 @@ public class Materials implements IColorModulationContainer, ISubTagContainer { private static Materials[] MATERIALS_ARRAY = new Materials[]{}; private static final Map MATERIALS_MAP = new HashMap(); private static final List mMaterialRegistrators = new ArrayList(); + private static final List mComponentRegistrators = new ArrayList(); /** * This is the Default Material returned in case no Material has been found or a NullPointer has been inserted at a location where it shouldn't happen. @@ -731,6 +733,8 @@ public class Materials implements IColorModulationContainer, ISubTagContainer { public byte mToolQuality = 0; public boolean mHasPlasma = false, mHasGas = false, mCustomOre = false; public Fluid mSolid = null, mFluid = null, mGas = null, mPlasma = null; + public List mComponents = new LinkedList<>(Arrays.asList(OrePrefixes.dustTiny, OrePrefixes.dustSmall, OrePrefixes.dust, OrePrefixes.dustImpure, OrePrefixes.dustPure, OrePrefixes.crushed, OrePrefixes.crushedPurified, OrePrefixes.crushedCentrifuged, OrePrefixes.gem, OrePrefixes.nugget, OrePrefixes.ingot, OrePrefixes.ingotHot, OrePrefixes.ingotDouble, OrePrefixes.ingotTriple, OrePrefixes.ingotQuadruple, OrePrefixes.ingotQuintuple, OrePrefixes.plate, OrePrefixes.plateDouble, OrePrefixes.plateTriple, OrePrefixes.plateQuadruple, OrePrefixes.plateQuintuple, OrePrefixes.plateDense, OrePrefixes.stick, OrePrefixes.lens, OrePrefixes.round, OrePrefixes.bolt, OrePrefixes.screw, OrePrefixes.ring, OrePrefixes.foil, OrePrefixes.cell, OrePrefixes.cellPlasma, OrePrefixes.toolHeadSword, OrePrefixes.toolHeadPickaxe, OrePrefixes.toolHeadShovel, OrePrefixes.toolHeadAxe, OrePrefixes.toolHeadHoe, OrePrefixes.toolHeadHammer, OrePrefixes.toolHeadFile, OrePrefixes.toolHeadSaw, OrePrefixes.toolHeadDrill, OrePrefixes.toolHeadChainsaw, OrePrefixes.toolHeadWrench, OrePrefixes.toolHeadUniversalSpade, OrePrefixes.toolHeadSense, OrePrefixes.toolHeadPlow, OrePrefixes.toolHeadArrow, OrePrefixes.toolHeadBuzzSaw, OrePrefixes.turbineBlade, OrePrefixes.wireFine, OrePrefixes.gearGtSmall, OrePrefixes.rotor, OrePrefixes.stickLong, OrePrefixes.springSmall, OrePrefixes.spring, OrePrefixes.arrowGtWood, OrePrefixes.arrowGtPlastic, OrePrefixes.gemChipped, OrePrefixes.gemFlawed, OrePrefixes.gemFlawless, OrePrefixes.gemExquisite, OrePrefixes.gearGt, OrePrefixes.crateGtDust, OrePrefixes.crateGtIngot, OrePrefixes.crateGtGem, OrePrefixes.crateGtPlate)); + public static List mDefaultComponents = new LinkedList<>(Arrays.asList(OrePrefixes.dustTiny, OrePrefixes.dustSmall, OrePrefixes.dust, OrePrefixes.dustImpure, OrePrefixes.dustPure, OrePrefixes.crushed, OrePrefixes.crushedPurified, OrePrefixes.crushedCentrifuged, OrePrefixes.gem, OrePrefixes.nugget, OrePrefixes.ingot, OrePrefixes.ingotHot, OrePrefixes.ingotDouble, OrePrefixes.ingotTriple, OrePrefixes.ingotQuadruple, OrePrefixes.ingotQuintuple, OrePrefixes.plate, OrePrefixes.plateDouble, OrePrefixes.plateTriple, OrePrefixes.plateQuadruple, OrePrefixes.plateQuintuple, OrePrefixes.plateDense, OrePrefixes.stick, OrePrefixes.lens, OrePrefixes.round, OrePrefixes.bolt, OrePrefixes.screw, OrePrefixes.ring, OrePrefixes.foil, OrePrefixes.cell, OrePrefixes.cellPlasma, OrePrefixes.toolHeadSword, OrePrefixes.toolHeadPickaxe, OrePrefixes.toolHeadShovel, OrePrefixes.toolHeadAxe, OrePrefixes.toolHeadHoe, OrePrefixes.toolHeadHammer, OrePrefixes.toolHeadFile, OrePrefixes.toolHeadSaw, OrePrefixes.toolHeadDrill, OrePrefixes.toolHeadChainsaw, OrePrefixes.toolHeadWrench, OrePrefixes.toolHeadUniversalSpade, OrePrefixes.toolHeadSense, OrePrefixes.toolHeadPlow, OrePrefixes.toolHeadArrow, OrePrefixes.toolHeadBuzzSaw, OrePrefixes.turbineBlade, OrePrefixes.wireFine, OrePrefixes.gearGtSmall, OrePrefixes.rotor, OrePrefixes.stickLong, OrePrefixes.springSmall, OrePrefixes.spring, OrePrefixes.arrowGtWood, OrePrefixes.arrowGtPlastic, OrePrefixes.gemChipped, OrePrefixes.gemFlawed, OrePrefixes.gemFlawless, OrePrefixes.gemExquisite, OrePrefixes.gearGt, OrePrefixes.crateGtDust, OrePrefixes.crateGtIngot, OrePrefixes.crateGtGem, OrePrefixes.crateGtPlate)); /** * This Fluid is used as standard Unit for Molten Materials. 1296 is a Molten Block, that means 144 is one Material Unit worth of fluid. @@ -1413,6 +1417,16 @@ public class Materials implements IColorModulationContainer, ISubTagContainer { if (GT_Mod.gregtechproxy.mChangeHarvestLevels && aMaterial.mToolQuality > 0 && aMaterial.mMetaItemSubID < GT_Mod.gregtechproxy.mHarvestLevel.length && aMaterial.mMetaItemSubID >= 0) { GT_Mod.gregtechproxy.mHarvestLevel[aMaterial.mMetaItemSubID] = GregTech_API.sMaterialProperties.get(aConfigPath, "HarvestLevel", aMaterial.mToolQuality); } + if (aMaterial.mMetaItemSubID >= 0) { + for (IComponentRegistrator aRegistrator : mComponentRegistrators) { + aRegistrator.registerComponents(aMaterial); + } + aConfigPath = aConfigPath.replace("materials", "components"); + for (OrePrefixes aPrefix : mDefaultComponents) { + boolean aComponent = GregTech_API.sMaterialComponents.get(aConfigPath, aPrefix.toString(), aMaterial.mComponents.contains(aPrefix)); + if (!aComponent) aMaterial.mComponents.remove(aPrefix); + } + } } aConfigPathSB.setLength(0); } @@ -1422,10 +1436,20 @@ public class Materials implements IColorModulationContainer, ISubTagContainer { this(aMetaItemSubID, aIconSet, aToolSpeed, aDurability, aToolQuality, aUnificatable, aDefaultLocalName, "ore", false, "null"); } + public static String getFixedName(String aDefaultLocalName) { + if (aDefaultLocalName.contains(" ")) aDefaultLocalName = aDefaultLocalName.replaceAll(" ", ""); + switch (aDefaultLocalName) { + case "Uranium": return "Uranium238"; + case "Plutonium": return "Plutonium244"; + case "Ash": return "Ashes"; + default: return aDefaultLocalName; + } + } + public Materials(int aMetaItemSubID, TextureSet aIconSet, float aToolSpeed, int aDurability, int aToolQuality, boolean aUnificatable, String aDefaultLocalName, String aConfigSection, boolean aCustomOre, String aCustomID) { mMetaItemSubID = aMetaItemSubID; mDefaultLocalName = aDefaultLocalName; - mName = aDefaultLocalName.contains(" ") ? aDefaultLocalName.replaceAll(" ", "") : aDefaultLocalName; + mName = getFixedName(aDefaultLocalName); MATERIALS_MAP.put(mName, this); mCustomOre = aCustomOre; mCustomID = aCustomID; @@ -1549,6 +1573,8 @@ public class Materials implements IColorModulationContainer, ISubTagContainer { } public static Materials get(String aMaterialName) { + //System.out.println("S:" + aMaterialName + " - M:" + getMaterialsMap().get(aMaterialName)); + if (aMaterialName.equals("")) return Materials._NULL; return getMaterialsMap().get(aMaterialName); } @@ -1627,6 +1653,14 @@ public class Materials implements IColorModulationContainer, ISubTagContainer { return mMaterialRegistrators.add(aRegistrator); } + /** + * Adds a Class implementing IComponentRegistrator to the master list + */ + public static boolean add(IComponentRegistrator aRegistrator) { + if (aRegistrator == null) return false; + return mComponentRegistrators.add(aRegistrator); + } + /** * Adds an ItemStack to this Material. */ diff --git a/src/main/java/gregtech/api/interfaces/IComponentRegistrator.java b/src/main/java/gregtech/api/interfaces/IComponentRegistrator.java new file mode 100644 index 00000000..7abf3027 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IComponentRegistrator.java @@ -0,0 +1,7 @@ +package gregtech.api.interfaces; + +import gregtech.api.enums.Materials; + +public interface IComponentRegistrator { + void registerComponents(Materials aMaterial); +} diff --git a/src/main/java/gregtech/api/items/GT_MetaGenerated_Item_X32.java b/src/main/java/gregtech/api/items/GT_MetaGenerated_Item_X32.java index 38ed38bd..bf9f3b5b 100644 --- a/src/main/java/gregtech/api/items/GT_MetaGenerated_Item_X32.java +++ b/src/main/java/gregtech/api/items/GT_MetaGenerated_Item_X32.java @@ -49,7 +49,7 @@ public abstract class GT_MetaGenerated_Item_X32 extends GT_MetaGenerated_Item { OrePrefixes tPrefix = mGeneratedPrefixList[i / 1000]; if (tPrefix == null) continue; Materials tMaterial = GregTech_API.sGeneratedMaterials[i % 1000]; - if (tMaterial == null) continue; + if (tMaterial == null || !tMaterial.mComponents.contains(tPrefix)) continue; if (doesMaterialAllowGeneration(tPrefix, tMaterial)) { ItemStack tStack = new ItemStack(this, 1, i); GT_LanguageManager.addStringLocalization(getUnlocalizedName(tStack) + ".name", getDefaultLocalization(tPrefix, tMaterial, i)); diff --git a/src/main/java/gregtech/loaders/materialprocessing/ProcessingComponents.java b/src/main/java/gregtech/loaders/materialprocessing/ProcessingComponents.java new file mode 100644 index 00000000..1fef19dd --- /dev/null +++ b/src/main/java/gregtech/loaders/materialprocessing/ProcessingComponents.java @@ -0,0 +1,14 @@ +package gregtech.loaders.materialprocessing; + +import gregtech.api.enums.Materials; + +public class ProcessingComponents implements gregtech.api.interfaces.IComponentRegistrator { + public ProcessingComponents() { + Materials.add(this); + } + + @Override + public void registerComponents(Materials aMaterial) { + //Disable components by default + } +} diff --git a/src/main/java/gregtech/loaders/preload/GT_Loader_MaterialProcessing.java b/src/main/java/gregtech/loaders/preload/GT_Loader_MaterialProcessing.java index d7ec2365..ff901bcc 100644 --- a/src/main/java/gregtech/loaders/preload/GT_Loader_MaterialProcessing.java +++ b/src/main/java/gregtech/loaders/preload/GT_Loader_MaterialProcessing.java @@ -1,11 +1,13 @@ package gregtech.loaders.preload; import gregtech.api.util.GT_Log; +import gregtech.loaders.materialprocessing.ProcessingComponents; import gregtech.loaders.materialprocessing.ProcessingConfig; public class GT_Loader_MaterialProcessing implements Runnable { public void run() { GT_Log.out.println("GT_Mod: Register Material processing."); new ProcessingConfig(); + new ProcessingComponents(); } }