diff options
Diffstat (limited to 'src/Java/gtPlusPlus/xmod')
4 files changed, 396 insertions, 34 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java index 23f7b2a6a0..ea74e650dd 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/nbthandlers/GT_MetaTileEntity_Hatch_Catalysts.java @@ -10,15 +10,15 @@ import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_Hatch_Catalysts extends GT_MetaTileEntity_Hatch_NbtConsumable { public GT_MetaTileEntity_Hatch_Catalysts(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional, 7, 16, "Dedicated Catalyst Storage", false); + super(aID, aName, aNameRegional, 0, 16, "Dedicated Catalyst Storage", false); } public GT_MetaTileEntity_Hatch_Catalysts(String aName, String aDescription, ITexture[][][] aTextures) { - super(aName, 7, 16, aDescription, false, aTextures); + super(aName, 0, 16, aDescription, false, aTextures); } public GT_MetaTileEntity_Hatch_Catalysts(String aName, String[] aDescription, ITexture[][][] aTextures) { - super(aName, 7, 16, aDescription[0], false, aTextures); + super(aName, 0, 16, aDescription[0], false, aTextures); } @Override diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java index 4119a0df8c..66620e8109 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java @@ -48,9 +48,9 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { private int mCoilTier = 0; private ArrayList<GT_MetaTileEntity_Hatch_Catalysts> mCatalystBuses = new ArrayList<GT_MetaTileEntity_Hatch_Catalysts>(); - + private static final HashMap<Integer, Triplet<Block, Integer, Integer>> mTieredBlockRegistry = new HashMap<Integer, Triplet<Block, Integer, Integer>>(); - + public GregtechMTE_ChemicalPlant(final int aID, final String aName, final String aNameRegional) { super(aID, aName, aNameRegional); } @@ -58,7 +58,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { public GregtechMTE_ChemicalPlant(final String aName) { super(aName); } - + public static boolean registerMachineCasingForTier(int aTier, Block aBlock, int aMeta, int aCasingTextureID) { int aSize = mTieredBlockRegistry.size(); int aSize2 = aSize; @@ -70,7 +70,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { aSize = mTieredBlockRegistry.size(); return aSize > aSize2; } - + private static Block getBlockForTier(int aTier) { if (!mTieredBlockRegistry.containsKey(aTier)) { return Blocks.bedrock; @@ -142,6 +142,9 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { @Override public GT_Recipe.GT_Recipe_Map getRecipeMap() { + if (GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.mRecipeList.size() == 0) { + generateRecipes(); + } return GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT; } @@ -368,6 +371,10 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { log("Not enough coils. Found "+aCoilCount+", require: 27."); return false; } + /*if (mCatalystBuses.size() != 1) { + log("A Catalyst Bus is Required."); + return false; + }*/ log("Structure Check Complete!"); @@ -761,34 +768,47 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { long tEnergy = getMaxInputEnergy(); log("Running checkRecipeGeneric(0)"); + //GT_Recipe tRecipe = findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + GT_Recipe tRecipe = findRecipe(mLastRecipe, gregtech.api.enums.GT_Values.V[tTier], getSolidCasingTier(), aItemInputs, aFluidInputs); + + + + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + // checks if it has a catalyst with enough durability ItemStack tCatalystRecipe = findCatalyst(aItemInputs); - if (tCatalystRecipe == null) { - log("does not have catalyst"); - return false; + boolean aDoesRecipeNeedCatalyst = false; + for (ItemStack aInputItem : tRecipe.mInputs) { + if (ItemUtils.isCatalyst(aInputItem)) { + aDoesRecipeNeedCatalyst = true; + break; + } + } + if (aDoesRecipeNeedCatalyst) { + if (tCatalystRecipe == null) { + log("does not have catalyst"); + return false; + } + if (mCatalystBuses.size() != 1) { + log("does not have correct number of catalyst hatchs. (Required 1, found "+mCatalystBuses.size()+")"); + return false; + } } - - GT_Recipe tRecipe = findRecipe( - getBaseMetaTileEntity(), mLastRecipe, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); log("Running checkRecipeGeneric(1)"); // Remember last recipe - an optimization for findRecipe() this.mLastRecipe = tRecipe; - - if (tRecipe == null) { - log("BAD RETURN - 1"); - return false; - } - if (tRecipe.mSpecialValue > this.mSolidCasingTier) { log("solid tier is too low"); return false; } - aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); if (aMaxParallelRecipes == 0) { log("BAD RETURN - 2"); @@ -929,7 +949,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { log("damaging catalyst"); damageCatalyst(tCatalystRecipe, parallelRecipes); } - + // Commit outputs this.mOutputItems = tOutputItems; this.mOutputFluids = tOutputFluids; @@ -942,6 +962,159 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { return true; } + private static final HashMap<Long, AutoMap<GT_Recipe>> mTieredRecipeMap = new HashMap<Long, AutoMap<GT_Recipe>>(); + private static final AutoMap<GT_Recipe> aTier0Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier1Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier2Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier3Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier4Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier5Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier6Recipes = new AutoMap<GT_Recipe>(); + private static final AutoMap<GT_Recipe> aTier7Recipes = new AutoMap<GT_Recipe>(); + private static boolean mInitRecipeCache = false; + + private static void initRecipeCaches() { + if (!mInitRecipeCache) { + mTieredRecipeMap.put((long) 0, aTier0Recipes); + mTieredRecipeMap.put((long) 1, aTier1Recipes); + mTieredRecipeMap.put((long) 2, aTier2Recipes); + mTieredRecipeMap.put((long) 3, aTier3Recipes); + mTieredRecipeMap.put((long) 4, aTier4Recipes); + mTieredRecipeMap.put((long) 5, aTier5Recipes); + mTieredRecipeMap.put((long) 6, aTier6Recipes); + mTieredRecipeMap.put((long) 7, aTier7Recipes); + for (GT_Recipe aRecipe : GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.mRecipeList) { + if (aRecipe != null) { + switch (aRecipe.mSpecialValue) { + case 0: + aTier0Recipes.add(aRecipe); + continue; + case 1: + aTier1Recipes.add(aRecipe); + continue; + case 2: + aTier2Recipes.add(aRecipe); + continue; + case 3: + aTier3Recipes.add(aRecipe); + continue; + case 4: + aTier4Recipes.add(aRecipe); + continue; + case 5: + aTier5Recipes.add(aRecipe); + continue; + case 6: + aTier6Recipes.add(aRecipe); + continue; + case 7: + aTier7Recipes.add(aRecipe); + continue; + } + } + } + mInitRecipeCache = true; + } + } + + private static boolean areInputsEqual(GT_Recipe aComparator, ItemStack[] aInputs, FluidStack[] aFluids) { + int aInputCount = aComparator.mInputs.length; + if (aInputCount > 0) { + //Logger.INFO("Looking for recipe with "+aInputCount+" Items"); + int aMatchingInputs = 0; + recipe : for (ItemStack a : aComparator.mInputs) { + for (ItemStack b : aInputs) { + if (a.getItem() == b.getItem()) { + if (a.getItemDamage() == b.getItemDamage()) { + //Logger.INFO("Found matching Item Input - "+b.getUnlocalizedName()); + aMatchingInputs++; + continue recipe; + } + } + } + } + if (aMatchingInputs != aInputCount) { + return false; + } + } + int aFluidInputCount = aComparator.mFluidInputs.length; + if (aFluidInputCount > 0) { + //Logger.INFO("Looking for recipe with "+aFluidInputCount+" Fluids"); + int aMatchingFluidInputs = 0; + recipe : for (FluidStack b : aComparator.mFluidInputs) { + //Logger.INFO("Checking for fluid "+b.getLocalizedName()); + for (FluidStack a : aFluids) { + if (GT_Utility.areFluidsEqual(a, b)) { + //Logger.INFO("Found matching Fluid Input - "+b.getLocalizedName()); + aMatchingFluidInputs++; + continue recipe; + } + else { + //Logger.INFO("Found fluid which did not match - "+a.getLocalizedName()); + } + } + } + if (aMatchingFluidInputs != aFluidInputCount) { + return false; + } + } + Logger.INFO("Recipes Match!"); + return true; + } + + public GT_Recipe findRecipe(final GT_Recipe aRecipe, final long aVoltage, final long aSpecialValue, ItemStack[] aInputs, final FluidStack[] aFluids) { + if (!mInitRecipeCache) { + initRecipeCaches(); + } + if (this.getRecipeMap().mRecipeList.isEmpty()) { + log("No Recipes in Map to search through."); + return null; + } + else { + log("Checking tier "+aSpecialValue+" recipes and below. Using Input Voltage of "+aVoltage+"V."); + log("We have "+aInputs.length+" Items and "+aFluids.length+" Fluids."); + // Try check the cached recipe first + if (aRecipe != null) { + if (areInputsEqual(aRecipe, aInputs, aFluids)) { + if (aRecipe.mEUt <= aVoltage) { + Logger.INFO("Using cached recipe."); + return aRecipe; + } + } + } + + // Get all recipes for the tier + AutoMap<AutoMap<GT_Recipe>> aMasterMap = new AutoMap<AutoMap<GT_Recipe>>(); + for (long i=0;i<=aSpecialValue;i++) { + aMasterMap.add(mTieredRecipeMap.get(i)); + } + GT_Recipe aFoundRecipe = null; + + // Iterate the tiers recipes until we find the one with all inputs matching + master : for (AutoMap<GT_Recipe> aTieredMap : aMasterMap) { + for (GT_Recipe aRecipeToCheck : aTieredMap) { + if (areInputsEqual(aRecipeToCheck, aInputs, aFluids)) { + log("Found recipe with matching inputs!"); + if (aRecipeToCheck.mSpecialValue <= aSpecialValue) { + if (aRecipeToCheck.mEUt <= aVoltage) { + aFoundRecipe = aRecipeToCheck; + break master; + } + } + } + } + } + + // If we found a recipe, return it + if (aFoundRecipe != null) { + log("Found valid recipe."); + return aFoundRecipe; + } + } + log("Did not find valid recipe."); + return null; + } + private int getCatalysts(ItemStack[] aItemInputs, ItemStack aRecipeCatalyst, int aMaxParrallel, ArrayList<ItemStack> aOutPut) { int allowedParrallel = 0; for (final ItemStack aInput : aItemInputs) { @@ -986,8 +1159,8 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { log("not consuming catalyst"); } } - - + + } @@ -1041,18 +1214,18 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { /* * Catalyst Handling */ - - + + @Override - public ArrayList<ItemStack> getStoredInputs() { + public ArrayList<ItemStack> getStoredInputs() { ArrayList<ItemStack> tItems = super.getStoredInputs(); - for (GT_MetaTileEntity_Hatch_Catalysts tHatch : mCatalystBuses) { - tHatch.mRecipeMap = getRecipeMap(); - if (isValidMetaTileEntity(tHatch)) { - tItems.addAll(tHatch.getContentUsageSlots()); - } - } + for (GT_MetaTileEntity_Hatch_Catalysts tHatch : mCatalystBuses) { + tHatch.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tHatch)) { + tItems.addAll(tHatch.getContentUsageSlots()); + } + } return tItems; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_MultisUsingFluidInsteadOfCells.java b/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_MultisUsingFluidInsteadOfCells.java new file mode 100644 index 0000000000..b94dbfa51f --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_MultisUsingFluidInsteadOfCells.java @@ -0,0 +1,182 @@ +package gtPlusPlus.xmod.gregtech.loaders; + +import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map_Internal; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class RecipeGen_MultisUsingFluidInsteadOfCells { + + + private static ItemStack mEmptyCell; + private static AutoMap<ItemStack> mItemsToIgnore = new AutoMap<ItemStack>(); + private static boolean mInit = false; + + private static void init() { + if (!mInit) { + mInit = true; + mItemsToIgnore.add(ItemUtils.simpleMetaStack(CI.emptyCells(1).getItem(), 8, 1)); + + + } + } + + private static boolean doesItemMatchIgnoringStackSize(ItemStack a, ItemStack b) { + if (a == null || b == null) { + return false; + } + if (a.getItem() == b.getItem()) { + if (a.getItemDamage() == b.getItemDamage()) { + return true; + } + } + return false; + } + + private static boolean isEmptyCell(ItemStack aCell) { + if (aCell == null) { + return false; + } + if (mEmptyCell == null) { + mEmptyCell = CI.emptyCells(1); + } + if (mEmptyCell != null) { + ItemStack aTempStack = mEmptyCell.copy(); + aTempStack.stackSize = aCell.stackSize; + if (GT_Utility.areStacksEqual(aTempStack, aCell)) { + return true; + } + } + return false; + } + + private synchronized static FluidStack getFluidFromItemStack(final ItemStack ingot) { + if (ingot == null) { + return null; + } + FluidStack aFluid = GT_Utility.getFluidForFilledItem(ingot, true); + if (aFluid != null) { + return aFluid; + } + return null; + } + + public synchronized static int generateRecipesNotUsingCells(GT_Recipe_Map aInputs, GTPP_Recipe_Map_Internal aOutputs) { + init(); + int aRecipesHandled = 0; + int aInvalidRecipesToConvert = 0; + int aOriginalCount = aInputs.mRecipeList.size(); + + recipe : for (GT_Recipe x : aInputs.mRecipeList) { + if (x != null) { + + ItemStack[] aInputItems = x.mInputs.clone(); + ItemStack[] aOutputItems = x.mOutputs.clone(); + FluidStack[] aInputFluids = x.mFluidInputs.clone(); + FluidStack[] aOutputFluids = x.mFluidOutputs.clone(); + + AutoMap<ItemStack> aInputItemsMap = new AutoMap<ItemStack>(); + AutoMap<ItemStack> aOutputItemsMap = new AutoMap<ItemStack>(); + AutoMap<FluidStack> aInputFluidsMap = new AutoMap<FluidStack>(); + AutoMap<FluidStack> aOutputFluidsMap = new AutoMap<FluidStack>(); + + // Iterate Inputs, Convert valid items into fluids + inputs : for (ItemStack aInputStack : aInputItems) { + FluidStack aFoundFluid = getFluidFromItemStack(aInputStack); + if (aFoundFluid == null) { + for (ItemStack aBadStack : mItemsToIgnore) { + if (doesItemMatchIgnoringStackSize(aInputStack, aBadStack)) { + continue recipe; // Skip this recipe entirely if we find an item we don't like + } + } + if (!isEmptyCell(aInputStack)) { + aInputItemsMap.add(aInputStack); + } + } + else { + aFoundFluid.amount = aFoundFluid.amount * aInputStack.stackSize; + aInputFluidsMap.add(aFoundFluid); + } + } + // Iterate Outputs, Convert valid items into fluids + outputs: for (ItemStack aOutputStack : aOutputItems) { + FluidStack aFoundFluid = getFluidFromItemStack(aOutputStack); + if (aFoundFluid == null) { + for (ItemStack aBadStack : mItemsToIgnore) { + if (doesItemMatchIgnoringStackSize(aOutputStack, aBadStack)) { + continue recipe; // Skip this recipe entirely if we find an item we don't like + } + } + if (!isEmptyCell(aOutputStack)) { + aOutputItemsMap.add(aOutputStack); + } + } + else { + aFoundFluid.amount = aFoundFluid.amount * aOutputStack.stackSize; + aOutputFluidsMap.add(aFoundFluid); + } + } + // Add Input fluids second + for (FluidStack aInputFluid : aInputFluids) { + aInputFluidsMap.add(aInputFluid); + } + // Add Output fluids second + for (FluidStack aOutputFluid : aOutputFluids) { + aOutputFluidsMap.add(aOutputFluid); + } + + // Make some new Arrays + ItemStack[] aNewItemInputs = new ItemStack[aInputItemsMap.size()]; + ItemStack[] aNewItemOutputs = new ItemStack[aOutputItemsMap.size()]; + FluidStack[] aNewFluidInputs = new FluidStack[aInputFluidsMap.size()]; + FluidStack[] aNewFluidOutputs = new FluidStack[aOutputFluidsMap.size()]; + + // Add AutoMap contents to Arrays + for (int i = 0; i < aInputItemsMap.size(); i++) { + aNewItemInputs[i] = aInputItemsMap.get(i); + } + for (int i = 0; i < aOutputItemsMap.size(); i++) { + aNewItemOutputs[i] = aOutputItemsMap.get(i); + } + for (int i = 0; i < aInputFluidsMap.size(); i++) { + aNewFluidInputs[i] = aInputFluidsMap.get(i); + } + for (int i = 0; i < aOutputFluidsMap.size(); i++) { + aNewFluidOutputs[i] = aOutputFluidsMap.get(i); + } + + // Add Recipe to map + GT_Recipe aNewRecipe = new GTPP_Recipe( + false, + aNewItemInputs, + aNewItemOutputs, + x.mSpecialItems, + x.mChances, + aNewFluidInputs, + aNewFluidOutputs, + x.mDuration, + x.mEUt, + x.mSpecialValue); + aOutputs.add(aNewRecipe); + aRecipesHandled++; + } + else { + aInvalidRecipesToConvert++; + } + } + + Logger.INFO("Generated Recipes for "+aOutputs.mNEIName); + Logger.INFO("Original Map contains "+aOriginalCount+" recipes."); + Logger.INFO("Output Map contains "+aRecipesHandled+" recipes."); + Logger.INFO("There were "+aInvalidRecipesToConvert+" invalid recipes."); + return aRecipesHandled; + } + +} diff --git a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechSimpleWasher.java b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechSimpleWasher.java index d3c1368ad3..d2087b22f4 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechSimpleWasher.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechSimpleWasher.java @@ -41,11 +41,18 @@ public class GregtechSimpleWasher { } private static boolean generateDirtyDustRecipes(){ + boolean disablePlat = CORE.GTNH; int mRecipeCount = 0; // Generate Recipe Map for the Dust Washer. ItemStack dustClean; ItemStack dustDirty; - for (Materials v : Materials.values()) { + for (Materials v : Materials.values()) { + if (disablePlat) { + if (v == Materials.Platinum || v == Materials.Osmium || v == Materials.Iridium || v == Materials.Palladium) { + continue; + } + } + dustClean = GT_OreDictUnificator.get(OrePrefixes.dust, v, 1L); dustDirty = GT_OreDictUnificator.get(OrePrefixes.dustImpure, v, 1L); if (dustClean != null && dustDirty != null) { |