diff options
Diffstat (limited to 'src/Java/gtPlusPlus/core')
6 files changed, 130 insertions, 33 deletions
diff --git a/src/Java/gtPlusPlus/core/common/CommonProxy.java b/src/Java/gtPlusPlus/core/common/CommonProxy.java index 8a1ef34b68..de0cfe4711 100644 --- a/src/Java/gtPlusPlus/core/common/CommonProxy.java +++ b/src/Java/gtPlusPlus/core/common/CommonProxy.java @@ -7,6 +7,8 @@ import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.entity.Entity; +import gregtech.api.enums.ItemList; + import gtPlusPlus.GTplusplus; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.minecraft.ChunkManager; @@ -21,6 +23,7 @@ import gtPlusPlus.core.item.ModItems; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.CORE.ConfigSwitches; import gtPlusPlus.core.lib.LoadedMods; +import gtPlusPlus.core.material.Material; import gtPlusPlus.core.recipe.RECIPES_Old_Circuits; import gtPlusPlus.core.recipe.common.CI; import gtPlusPlus.core.tileentities.ModTileEntities; @@ -34,6 +37,7 @@ import net.minecraftforge.common.ForgeChunkManager; public class CommonProxy { public static Meta_GT_Proxy GtProxy; + private boolean mFluidsGenerated = false; public CommonProxy(){ //Should Register Gregtech Materials I've Made @@ -92,7 +96,10 @@ public class CommonProxy { Logger.INFO("[Proxy] Calling Render registrator."); registerRenderThings(); - + if (!mFluidsGenerated && ItemList.valueOf("Cell_Empty").hasBeenSet()) { + Material.generateQueuedFluids(); + mFluidsGenerated = true; + } } public void init(final FMLInitializationEvent e) { @@ -100,7 +107,15 @@ public class CommonProxy { if (CORE.DEBUG){ DEBUG_INIT.registerHandlers(); } - + if (!mFluidsGenerated && ItemList.valueOf("Cell_Empty").hasBeenSet()) { + Material.generateQueuedFluids(); + mFluidsGenerated = true; + } + else { + Logger.INFO("[ERROR] Did not generate fluids at all."); + Logger.WARNING("[ERROR] Did not generate fluids at all."); + Logger.ERROR("[ERROR] Did not generate fluids at all."); + } CI.init(); /** diff --git a/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java b/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java index 4066592f88..7f35c3b9b9 100644 --- a/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java +++ b/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java @@ -4,6 +4,7 @@ import static gtPlusPlus.core.lib.LoadedMods.Gregtech; import java.util.LinkedList; import java.util.Queue; +import java.util.Set; import net.minecraft.item.ItemStack; @@ -16,9 +17,11 @@ import gtPlusPlus.core.handler.Recipes.LateRegistrationHandler; import gtPlusPlus.core.handler.Recipes.RegistrationHandler; import gtPlusPlus.core.item.ModItems; import gtPlusPlus.core.lib.LoadedMods; +import gtPlusPlus.core.material.MaterialGenerator; import gtPlusPlus.core.recipe.*; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.RecipeUtils; +import gtPlusPlus.xmod.gregtech.loaders.RecipeGen_Recycling; import gtPlusPlus.xmod.gregtech.registration.gregtech.*; public class COMPAT_HANDLER { @@ -167,6 +170,14 @@ public class COMPAT_HANDLER { } public static void startLoadingGregAPIBasedRecipes(){ - RECIPES_GREGTECH.run(); + //Add hand-made recipes + RECIPES_GREGTECH.run(); + //Add autogenerated Recipes from Item Components + for (Set<Runnable> m : MaterialGenerator.mRecipeMapsToGenerate) { + for (Runnable r : m) { + r.run(); + } + } + RecipeGen_Recycling.executeGenerators(); } } diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index 13c7e99887..f02e21291a 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -3,6 +3,8 @@ package gtPlusPlus.core.material; import static gregtech.api.enums.GT_Values.M; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; import net.minecraft.block.Block; import net.minecraft.init.Blocks; @@ -27,6 +29,8 @@ import net.minecraftforge.fluids.FluidStack; public class Material { + public static final Set<Material> mMaterialMap = new HashSet<Material>(); + private String unlocalizedName; private String localizedName; @@ -117,6 +121,11 @@ public class Material { } public Material(final String materialName, final MaterialState defaultState, final TextureSet set, final long durability, final short[] rgba, final int meltingPoint, final int boilingPoint, final long protons, final long neutrons, final boolean blastFurnace, final String chemicalSymbol, final int radiationLevel, boolean generateCells, boolean generateFluid, final MaterialStack... inputs){ + + if (mMaterialMap.add(this)) { + //Placeholder + } + try { this.unlocalizedName = Utils.sanitizeString(materialName); this.localizedName = materialName; @@ -293,7 +302,7 @@ public class Material { this.vMoltenFluid = FluidUtils.getFluidStack(localizedName, 1).getFluid(); } else if (isValid == null || isValid == Materials._NULL){ - this.vMoltenFluid = this.generateFluid(); + queueFluidGeneration(); } else { if (isValid.mFluid != null){ @@ -303,7 +312,7 @@ public class Material { this.vMoltenFluid = isValid.mGas; } else { - this.vMoltenFluid = this.generateFluid(); + queueFluidGeneration(); } } @@ -744,6 +753,21 @@ public class Material { } + public final boolean queueFluidGeneration() { + return isFluidQueued = true; + } + + public final static void generateQueuedFluids() { + for (Material m : mMaterialMap) { + if (m.isFluidQueued) { + m.vMoltenFluid = m.generateFluid(); + } + } + } + + //If we need a fluid, let's just queue it for later. + public boolean isFluidQueued = false; + public final Fluid generateFluid(){ if (this.materialState == MaterialState.ORE){ return null; @@ -817,6 +841,24 @@ public class Material { } } + FluidStack aTest1 = FluidUtils.getFluidStack("molten."+Utils.sanitizeString(this.getLocalizedName()), 1); + FluidStack aTest2 = FluidUtils.getFluidStack("fluid."+Utils.sanitizeString(this.getLocalizedName()), 1); + FluidStack aTest3 = FluidUtils.getFluidStack(Utils.sanitizeString(this.getLocalizedName()), 1); + + if (aTest1 != null) { + Logger.INFO("Found FluidRegistry entry for "+"molten."+Utils.sanitizeString(this.getLocalizedName())); + return aTest1.getFluid(); + } + if (aTest2 != null) { + Logger.INFO("Found FluidRegistry entry for "+"fluid."+Utils.sanitizeString(this.getLocalizedName())); + return aTest2.getFluid(); + } + if (aTest3 != null) { + Logger.INFO("Found FluidRegistry entry for "+Utils.sanitizeString(this.getLocalizedName())); + return aTest3.getFluid(); + } + + Logger.INFO("Generating our own fluid."); //Generate a Cell if we need to if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+this.getUnlocalizedName(), 1) == null){ @@ -837,7 +879,7 @@ public class Material { this.materialState.ID(), this.getMeltingPointK(), ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+this.getUnlocalizedName(), 1), - ItemList.Cell_Empty.get(1L, new Object[0]), + ItemUtils.getEmptyCell(), 1000); } else if (this.materialState == MaterialState.LIQUID){ @@ -848,7 +890,7 @@ public class Material { this.materialState.ID(), this.getMeltingPointK(), ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+this.getUnlocalizedName(), 1), - ItemList.Cell_Empty.get(1L, new Object[0]), + ItemUtils.getEmptyCell(), 1000); } else if (this.materialState == MaterialState.GAS){ @@ -859,7 +901,7 @@ public class Material { this.materialState.ID(), this.getMeltingPointK(), ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+this.getUnlocalizedName(), 1), - ItemList.Cell_Empty.get(1L, new Object[0]), + ItemUtils.getEmptyCell(), 1000); } else { //Plasma diff --git a/src/Java/gtPlusPlus/core/material/MaterialGenerator.java b/src/Java/gtPlusPlus/core/material/MaterialGenerator.java index 4dc7987448..f1155c33f5 100644 --- a/src/Java/gtPlusPlus/core/material/MaterialGenerator.java +++ b/src/Java/gtPlusPlus/core/material/MaterialGenerator.java @@ -1,9 +1,12 @@ package gtPlusPlus.core.material; +import java.util.Set; + import net.minecraft.block.Block; import net.minecraft.item.Item; import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.block.base.BasicBlock.BlockTypes; import gtPlusPlus.core.block.base.BlockBaseModular; import gtPlusPlus.core.block.base.BlockBaseOre; @@ -29,6 +32,20 @@ import gtPlusPlus.xmod.gregtech.loaders.*; public class MaterialGenerator { + public static final AutoMap<Set<Runnable>> mRecipeMapsToGenerate = new AutoMap<Set<Runnable>>(); + + static { + mRecipeMapsToGenerate.put(RecipeGen_DustGeneration.mRecipeGenMap); + mRecipeMapsToGenerate.put(RecipeGen_MaterialProcessing.mRecipeGenMap); + mRecipeMapsToGenerate.put(RecipeGen_Fluids.mRecipeGenMap); + mRecipeMapsToGenerate.put(RecipeGen_ShapedCrafting.mRecipeGenMap); + mRecipeMapsToGenerate.put(RecipeGen_Assembler.mRecipeGenMap); + mRecipeMapsToGenerate.put(RecipeGen_Extruder.mRecipeGenMap); + mRecipeMapsToGenerate.put(RecipeGen_Plates.mRecipeGenMap); + mRecipeMapsToGenerate.put(RecipeGen_AlloySmelter.mRecipeGenMap); + mRecipeMapsToGenerate.put(RecipeGen_BlastSmelter.mRecipeGenMap); + } + public static void generate(final Material matInfo){ generate(matInfo, true); } @@ -133,17 +150,18 @@ public class MaterialGenerator { } //Add A jillion Recipes - old code - RecipeGen_AlloySmelter.generateRecipes(matInfo); - RecipeGen_Assembler.generateRecipes(matInfo); + new RecipeGen_AlloySmelter(matInfo); + new RecipeGen_Assembler(matInfo); if (generateBlastSmelterRecipes){ - RecipeGen_BlastSmelter.generateARecipe(matInfo); + new RecipeGen_BlastSmelter(matInfo); } - RecipeGen_DustGeneration.generateRecipes(matInfo); - RecipeGen_Extruder.generateRecipes(matInfo); - RecipeGen_Fluids.generateRecipes(matInfo); - RecipeGen_Plates.generateRecipes(matInfo); - RecipeGen_ShapedCrafting.generateRecipes(matInfo); - RecipeGen_MaterialProcessing.generateRecipes(matInfo); + new RecipeGen_Extruder(matInfo); + new RecipeGen_Fluids(matInfo); + new RecipeGen_Plates(matInfo); + new RecipeGen_ShapedCrafting(matInfo); + new RecipeGen_MaterialProcessing(matInfo); + + new RecipeGen_DustGeneration(matInfo); new RecipeGen_Recycling(matInfo); return true; @@ -179,9 +197,16 @@ public class MaterialGenerator { } //Add A jillion Recipes - old code + try { RecipeGen_DustGeneration.addMixerRecipe_Standalone(matInfo); - RecipeGen_Fluids.generateRecipes(matInfo); - RecipeGen_MaterialProcessing.generateRecipes(matInfo); + new RecipeGen_Fluids(matInfo); + new RecipeGen_MaterialProcessing(matInfo); + } + catch (Throwable t) { + Logger.INFO("Failed to generate some recipes for "+materialName); + Logger.ERROR("Failed to generate some recipes for "+materialName); + t.printStackTrace(); + } //RecipeGen_Recycling.generateRecipes(matInfo); } @@ -216,15 +241,15 @@ public class MaterialGenerator { if (generatePlates) { temp = new BaseItemPlate(matInfo); temp = new BaseItemPlateDouble(matInfo); - RecipeGen_Plates.generateRecipes(matInfo); - RecipeGen_Extruder.generateRecipes(matInfo); - RecipeGen_Assembler.generateRecipes(matInfo); + new RecipeGen_Plates(matInfo); + new RecipeGen_Extruder(matInfo); + new RecipeGen_Assembler(matInfo); } - RecipeGen_ShapedCrafting.generateRecipes(matInfo); - RecipeGen_Fluids.generateRecipes(matInfo); - RecipeGen_MaterialProcessing.generateRecipes(matInfo); - RecipeGen_DustGeneration.generateRecipes(matInfo, true); + new RecipeGen_ShapedCrafting(matInfo); + new RecipeGen_Fluids(matInfo); + new RecipeGen_MaterialProcessing(matInfo); + new RecipeGen_DustGeneration(matInfo, true); new RecipeGen_Recycling(matInfo); } catch (final Throwable t){ diff --git a/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java index b5a53cce36..f7f3906d18 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java @@ -282,7 +282,7 @@ public class FluidUtils { 3, 10000, temp, - ItemList.Cell_Empty.get(1L, new Object[0]), + ItemUtils.getEmptyCell(), 1000); } return null; @@ -397,7 +397,7 @@ public class FluidUtils { if (aStack.getItem().hasContainerItem(aStack)) { return aStack.getItem().getContainerItem(aStack); } - if (equal(aStack, ItemList.Cell_Empty.get(1), true)) { + if (equal(aStack, ItemUtils.getEmptyCell(), true)) { return null; } if (aCheckIFluidContainerItems && (aStack.getItem() instanceof IFluidContainerItem) && (((IFluidContainerItem)aStack.getItem()).getCapacity(aStack) > 0)) { @@ -436,7 +436,7 @@ public class FluidUtils { 4, MeltingPoint, ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1), - ItemList.Cell_Empty.get(1L, new Object[0]), + ItemUtils.getEmptyCell(), 1000); //Disable this, not sure why it exists //TODO @@ -481,7 +481,7 @@ public class FluidUtils { 4, MeltingPoint, ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1), - ItemList.Cell_Empty.get(1L, new Object[0]), + ItemUtils.getEmptyCell(), 1000); if (dustStack != null){ @@ -522,7 +522,7 @@ public class FluidUtils { 4, MeltingPoint, ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1), - ItemList.Cell_Empty.get(1L, new Object[0]), + ItemUtils.getEmptyCell(), 1000); } else { diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index f9eb9de310..43fc6d3cc4 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -11,6 +11,7 @@ import net.minecraft.item.Item.ToolMaterial; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; +import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.util.GT_ModHandler; @@ -94,7 +95,10 @@ public class ItemUtils { return getEmptyCell(1); } - public static ItemStack getEmptyCell(int i){ + public static ItemStack getEmptyCell(int i){ + if (ItemList.Cell_Empty.hasBeenSet()) { + return ItemList.Cell_Empty.get(1L, new Object[0]); + } final ItemStack temp = GT_ModHandler.getModItem("IC2", "itemCellEmpty", i, 0); return temp != null ? temp : null; } @@ -378,7 +382,7 @@ public class ItemUtils { }; } - RecipeGen_DustGeneration.generateRecipes(material); + new RecipeGen_DustGeneration(material); return output; } |