diff options
Diffstat (limited to 'src')
5 files changed, 861 insertions, 448 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java b/src/Java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java index fd4659c543..726ff080b6 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java @@ -48,6 +48,7 @@ import gtPlusPlus.xmod.gregtech.loaders.ProcessingElectricButcherKnife; import gtPlusPlus.xmod.gregtech.loaders.ProcessingElectricLighter; import gtPlusPlus.xmod.gregtech.loaders.ProcessingElectricSnips; import gtPlusPlus.xmod.gregtech.loaders.ProcessingToolHeadChoocher; +import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_AlgaeFarm; import gtPlusPlus.xmod.gregtech.recipes.RecipesToRemove; import gtPlusPlus.xmod.gregtech.registration.gregtech.GregtechConduits; import gtPlusPlus.xmod.gregtech.registration.gregtech.GregtechNitroDieselFix; @@ -141,6 +142,7 @@ public class HANDLER_GT { RecipesToRemove.go(); convertPyroToCokeOven(); Meta_GT_Proxy.fixIC2FluidNames(); + RecipeLoader_AlgaeFarm.generateRecipes(); } private static void convertPyroToCokeOven() { diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java index fe9e3ee9a0..03b8768240 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -469,15 +469,30 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult public String getSound() { return ""; } + public boolean canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes) { + return canBufferOutputs(aRecipe, aParallelRecipes, true); + } + + public boolean canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes, boolean aAllow16SlotWithoutCheck) { Logger.INFO("Determining if we have space to buffer outputs. Parallel: "+aParallelRecipes); // Null recipe or a recipe with lots of outputs? // E.G. Gendustry custom comb with a billion centrifuge outputs? - // Do it anyway. + // Do it anyway, provided the multi allows it. Default behaviour is aAllow16SlotWithoutCheck = true. if (aRecipe == null || aRecipe.mOutputs.length > 16) { - return aRecipe == null ? false : true; + if (aRecipe == null) { + return false; + } + else if (aRecipe.mOutputs.length > 16) { + if (aAllow16SlotWithoutCheck) { + return true; + } + else { + // Do nothing, we want to check this recipe properly. + } + } } // Do we even need to check for item outputs? diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java index 81afe2b147..18cf892698 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java @@ -3,13 +3,13 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.a import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import org.apache.commons.lang3.ArrayUtils; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.GregTech_API; -import gregtech.api.enums.GT_Values; import gregtech.api.enums.TAE; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -18,17 +18,14 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import gregtech.api.util.Recipe_GT; import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.api.objects.data.WeightedCollection; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.item.chemistry.AgriculturalChem; -import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_AlgaeFarm; import ic2.core.init.BlocksItems; import ic2.core.init.InternalName; import net.minecraft.block.Block; @@ -116,7 +113,7 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase { @Override public int getMaxParallelRecipes() { - return (this.mLevel+1) * 5; + return 2; } @Override @@ -161,13 +158,9 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase { return false; } else { - mLevel = aCasingMeta; + mLevel = this.getCasingTierOnClientSide(); } - - - /* - * if (!(aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir))) { return false; } - */ + int aID = TAE.getIndexFromPage(1, 15); int tAmount = 0; check : for (int i = mOffsetX_Lower; i <= mOffsetX_Upper; ++i) { for (int j = mOffsetZ_Lower; j <= mOffsetZ_Upper; ++j) { @@ -175,8 +168,8 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase { if ((h != 0) || ((((xDir + i != 0) || (zDir + j != 0))) && (((i != 0) || (j != 0))))) { IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); - Logger.INFO("X: " + i + " | Z: " + j+" | Tier: "+mLevel); - if (h == -1 && tTileEntity != null && addToMachineList(tTileEntity, mLevel)) { + Logger.INFO("X: " + i + " | Z: " + j+" | Tier: "+aID); + if (h == -1 && tTileEntity != null && addToMachineList(tTileEntity, aID)) { continue; } else if (h != -1 && tTileEntity != null) { @@ -231,14 +224,15 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase { } if ((tAmount >= 64)) { Logger.INFO("Made structure."); + this.getBaseMetaTileEntity().getWorld().markBlockForUpdate(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord()); } else { Logger.INFO("Did not make structure."); } return (tAmount >= 64); } - public boolean checkForWater() { - + public boolean checkForWater() { + // Get Facing direction IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; @@ -341,7 +335,12 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase { @Override public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPreTick(aBaseMetaTileEntity, aTick); - this.fixAllMaintenanceIssue(); + this.fixAllMaintenanceIssue(); + // Silly Client Syncing + if (aBaseMetaTileEntity.isClientSide()) { + this.mLevel = getCasingTierOnClientSide(); + } + } @Override @@ -357,20 +356,10 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase { if (this.mLevel < 0) { Logger.INFO("Bad Tier."); return false; - } - - if (mRecipeCache.isEmpty()) { - Logger.INFO("Generating Recipes."); - generateRecipes(); } - if (mRecipeCache.isEmpty() || !checkForWater()) { - if (mRecipeCache.isEmpty()) { - Logger.INFO("No Recipes."); - } - if (!checkForWater()) { - Logger.INFO("Not enough Water."); - } + if (!checkForWater()) { + Logger.INFO("Not enough Water."); return false; } @@ -382,7 +371,7 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase { Logger.INFO("Running checkRecipeGeneric(0)"); - GT_Recipe tRecipe = getTieredRecipeFromCache(this.mLevel, isUsingCompost(aItemInputs)); + GT_Recipe tRecipe = RecipeLoader_AlgaeFarm.getTieredRecipeFromCache(this.mLevel, isUsingCompost(aItemInputs)); this.mLastRecipe = tRecipe; @@ -390,7 +379,7 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase { return false; } - if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) { + if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes, false)) { return false; } @@ -486,139 +475,29 @@ public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase { } return false; } - - private GT_Recipe generateBaseRecipe(boolean aUsingCompost, int aTier) { - - // Type Safety - if (this.mLevel < 0 || aTier < 0 || this.mLevel != aTier) { - return null; + + @SideOnly(Side.CLIENT) + private final int getCasingTierOnClientSide() { + if (this == null || this.getBaseMetaTileEntity().getWorld() == null) { + return 0; } - - final int[] aInvertedNumbers = new int[] { - 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 - }; - - WeightedCollection<Float> aOutputTimeMulti = new WeightedCollection<Float>(); - for (int i=100;i> 0;i--) { - float aValue = 0; - if (i < 10) { - aValue = 3f; - } - else if (i < 20) { - aValue = 2f; + try { + Block aInitStructureCheck; + int aInitStructureCheckMeta; + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, -1, 0); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, -1, 0); + if (aInitStructureCheck == GregTech_API.sBlockCasings1) { + return aInitStructureCheckMeta; } - else { - aValue = 1f; - } - aOutputTimeMulti.put(i, aValue); + return 0; } - - final int[] aDurations = new int[] { - 432000, - 378000, - 216000, - 162000, - 108000, - 81000, - 54000, - 40500, - 27000, - 20250, - 13500, - 6750, - 3375, - 1686, - 843, - 421 - }; - - ItemStack[] aInputs = new ItemStack[] {}; - - if (aUsingCompost) { - // Make it use 4 compost per tier if we have some available - ItemStack aCompost = ItemUtils.getSimpleStack(AgriculturalChem.mCompost, aTier * 4); - aInputs = new ItemStack[] {aCompost}; - // Boost Tier by one if using compost so it gets a speed boost - aTier++; + catch (Throwable t) { + t.printStackTrace(); + return 0; } - - // We set these elsewhere - ItemStack[] aOutputs = new ItemStack[] { - - }; - - GT_Recipe tRecipe = new Recipe_GT( - false, - aInputs, - aOutputs, - (Object) null, - new int[] {}, - new FluidStack[] {GT_Values.NF}, - new FluidStack[] {GT_Values.NF}, - (int) (aDurations[aTier] * aOutputTimeMulti.get()), // Time - 0, - 0); - - tRecipe.mSpecialValue = tRecipe.hashCode(); - - return tRecipe; } - - private static ItemStack[] getOutputForTier(int aTier){ - ItemStack[] aOutputs = new ItemStack[16]; - - - - - WeightedCollection<ItemStack> aCollection = new WeightedCollection<ItemStack>(); - - return aOutputs; - } - - - - - private static final HashMap<Integer, AutoMap<GT_Recipe>> mRecipeCache = new HashMap<Integer, AutoMap<GT_Recipe>>(); - private static final HashMap<Integer, AutoMap<GT_Recipe>> mRecipeCompostCache = new HashMap<Integer, AutoMap<GT_Recipe>>(); - - private final void generateRecipes() { - for (int i=0;i<10;i++) { - getTieredRecipeFromCache(i, false); - } - for (int i=0;i<10;i++) { - getTieredRecipeFromCache(i, true); - } - } - - public GT_Recipe getTieredRecipeFromCache(int aTier, boolean aCompost) { - HashMap<Integer, AutoMap<GT_Recipe>> aMap = aCompost ? mRecipeCompostCache : mRecipeCache; - String aComp = aCompost ? "(Compost)" : ""; - - AutoMap<GT_Recipe> aTemp = aMap.get(aTier); - if (aTemp == null || aTemp.isEmpty()) { - aTemp = new AutoMap<GT_Recipe>(); - aMap.put(aTier, aTemp); - Logger.INFO("Tier "+aTier+aComp+" had no recipes, initialising new map."); - } - if (aTemp.size() < 500) { - Logger.INFO("Tier "+aTier+aComp+" has less than 500 recipes, generating "+(500 - aTemp.size())+"."); - for (int i=aTemp.size();i<500;i++) { - aTemp.put(generateBaseRecipe(aCompost, aTier)); - } - } - int aIndex = MathUtils.randInt(0, aTemp.isEmpty() ? 1 : aTemp.size()); - Logger.INFO("Using recipe with index of "+aIndex+". "+aComp); - return aTemp.get(aIndex); - } - - - - - - - - - + } 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 251df46e45..1d7ccc1060 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 @@ -1,36 +1,35 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.chemplant; -import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.ArrayUtils; - +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.GregTech_API; -import gregtech.api.enums.TAE; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.block.ModBlocks; -import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; +import gtPlusPlus.xmod.gregtech.common.StaticFields59; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; -import ic2.core.init.BlocksItems; -import ic2.core.init.InternalName; import net.minecraft.block.Block; -import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidStack; public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { - private int mLevel = -1; + private int mSolidCasingTier = 0; + private int mMachineCasingTier = 0; + private int mPipeCasingTier = 0; + private int mCoilTier = 0; public GregtechMTE_ChemicalPlant(final int aID, final String aName, final String aNameRegional) { super(aID, aName, aNameRegional); @@ -69,7 +68,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { "1x Output Bus", "1x Input Bus (optional)", "1x Input Hatch (fill with water)", - }; + }; } @Override @@ -80,19 +79,41 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { @Override public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - int aID = TAE.getIndexFromPage(1, 15); - if (mLevel > -1) { - aID = mLevel; - } + ITexture aOriginalTexture; + + // Check things exist client side (The worst code ever) + if (aBaseMetaTileEntity.getWorld() != null) { + + } + // Check the Tier Client Side + int aTier = mSolidCasingTier; + + if (aTier == 1) { + aOriginalTexture = Textures.BlockIcons.CASING_BLOCKS[16]; + } + else if (aTier == 2) { + aOriginalTexture = Textures.BlockIcons.CASING_BLOCKS[49]; + } + else if (aTier == 3) { + aOriginalTexture = Textures.BlockIcons.CASING_BLOCKS[50]; + } + else if (aTier == 4) { + aOriginalTexture = Textures.BlockIcons.CASING_BLOCKS[48]; + } + else { + aOriginalTexture = Textures.BlockIcons.CASING_BLOCKS[11]; + } + + if (aSide == aFacing) { - return new ITexture[]{Textures.BlockIcons.CASING_BLOCKS[aID], new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Default_Active : TexturesGtBlock.Overlay_Machine_Controller_Default)}; + return new ITexture[]{aOriginalTexture, new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; } - return new ITexture[]{Textures.BlockIcons.CASING_BLOCKS[aID]}; + return new ITexture[]{aOriginalTexture}; } @Override public boolean hasSlotInGUI() { - return true; + return false; } @Override @@ -107,7 +128,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { @Override public int getMaxParallelRecipes() { - return (this.mLevel+1) * 10; + return 2 * getPipeCasingTier(); } @Override @@ -115,190 +136,562 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { return 0; } - @Override - public boolean checkMultiblock(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { + private int getSolidCasingTier() { + return mSolidCasingTier; + } - this.mLevel = 0; + private int getMachineCasingTier() { + return mMachineCasingTier; + } + private int getPipeCasingTier() { + return mPipeCasingTier; + } + private int getCoilTier() { + return mCoilTier; + } + private int getCasingTextureID() { + // Check the Tier Client Side + int aTier = mSolidCasingTier; - // Get Facing direction - int mCurrentDirectionX; - int mCurrentDirectionZ; + if (aTier == 1) { + return 16; + } + else if (aTier == 2) { + return 49; + } + else if (aTier == 3) { + return 50; + } + else if (aTier == 4) { + return 48; + } + else { + return 11; + } + } - int mOffsetX_Lower = 0; - int mOffsetX_Upper = 0; - int mOffsetZ_Lower = 0; - int mOffsetZ_Upper = 0; + public boolean addToMachineList(IGregTechTileEntity aTileEntity) { + int aMaxTier = getMachineCasingTier(); + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_TieredMachineBlock) { + GT_MetaTileEntity_TieredMachineBlock aMachineBlock = (GT_MetaTileEntity_TieredMachineBlock) aMetaTileEntity; + int aTileTier = aMachineBlock.mTier; + if (aTileTier > aMaxTier) { + Logger.INFO("Hatch tier too high."); + return false; + } + else { + return addToMachineList(aTileEntity, getCasingTextureID()); + } + } + else { + Logger.INFO("Bad Tile Entity being added to hatch map."); // Shouldn't ever happen, but.. ya know.. + return false; + } + } - mCurrentDirectionX = 4; - mCurrentDirectionZ = 4; + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mSolidCasingTier", this.mSolidCasingTier); + aNBT.setInteger("mMachineCasingTier", this.mMachineCasingTier); + aNBT.setInteger("mPipeCasingTier", this.mPipeCasingTier); + aNBT.setInteger("mCoilTier", this.mCoilTier); + } - mOffsetX_Lower = -4; - mOffsetX_Upper = 4; - mOffsetZ_Lower = -4; - mOffsetZ_Upper = 4; + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mSolidCasingTier = aNBT.getInteger("mSolidCasingTier"); + mMachineCasingTier = aNBT.getInteger("mMachineCasingTier"); + mPipeCasingTier = aNBT.getInteger("mPipeCasingTier"); + mCoilTier = aNBT.getInteger("mCoilTier"); + } - final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX - * mCurrentDirectionX; - final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ - * mCurrentDirectionZ; + private static boolean isBlockSolidCasing(Block aBlock, int aMeta) { + if (aBlock == null) { + return false; + } + if (aBlock == GregTech_API.sBlockCasings2 && aMeta == 0) { + return true; + } + if (aBlock == GregTech_API.sBlockCasings4) { + int aMetaStainlessCasing = 1; + int aMetaTitaniumCasing = 2; + int aMetaTungstenCasing = 0; + if (aMeta == aMetaStainlessCasing || aMeta == aMetaTitaniumCasing || aMeta == aMetaTungstenCasing) { + return true; + } + } + return false; + } + private static boolean isBlockMachineCasing(Block aBlock, int aMeta) { + Block aCasingBlock1 = GregTech_API.sBlockCasings1; + if (aBlock == aCasingBlock1) { + if (aMeta > 9 || aMeta < 0) { + return false; + } + else { + return true; + } + } + else { + return false; + } + } + private static boolean isBlockPipeCasing(Block aBlock, int aMeta) { + Block aCasingBlock2 = GregTech_API.sBlockCasings2; + if (aBlock == aCasingBlock2) { + int aMetaBronzePipeCasing = 12; + int aMetaSteelPipeCasing = 13; + int aMetaTitaniumPipeCasing = 14; + int aMetaTungstenPipeCasing = 15; + if (aMeta > aMetaTungstenPipeCasing || aMeta < aMetaBronzePipeCasing) { + return false; + } + else { + return true; + } + } + else { + return false; + } + } - // Get Expected Tier - Block aCasingBlock = aBaseMetaTileEntity.getBlockAtSide((byte) 0); - int aCasingMeta = aBaseMetaTileEntity.getMetaIDAtSide((byte) 0); + private static AutoMap<Integer> mValidCoilMetaCache; - // Bad Casings - if ((aCasingBlock != GregTech_API.sBlockCasings1) || aCasingMeta > 9) { - return false; + private static boolean isBlockCoil(Block aBlock, int aMeta) { + Block aCasingBlock; + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + aCasingBlock = StaticFields59.getBlockCasings5(); } else { - mLevel = aCasingMeta; + aCasingBlock = GregTech_API.sBlockCasings1; + } + // Cache the meta values for later + if (mValidCoilMetaCache == null || mValidCoilMetaCache.isEmpty()) { + AutoMap<Integer> aValidCoilMeta = new AutoMap<Integer>(); + // Only use the right meta values available. + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + aValidCoilMeta = Meta_GT_Proxy.GT_ValidHeatingCoilMetas; + } + else { + aValidCoilMeta.put(12); + aValidCoilMeta.put(13); + aValidCoilMeta.put(14); + } + mValidCoilMetaCache = aValidCoilMeta; + } + if (aBlock == aCasingBlock) { + for (int i: mValidCoilMetaCache.values()) { + if (i == aMeta) { + return true; + } + } } + return false; + } + + + @Override + public boolean checkMultiblock(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack) { + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 3; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 3; - /* - * if (!(aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir))) { return false; } - */ int tAmount = 0; - check : for (int i = mOffsetX_Lower; i <= mOffsetX_Upper; ++i) { - for (int j = mOffsetZ_Lower; j <= mOffsetZ_Upper; ++j) { - for (int h = -1; h < 2; ++h) { - if ((h != 0) || ((((xDir + i != 0) || (zDir + j != 0))) && (((i != 0) || (j != 0))))) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); - - Logger.INFO("X: " + i + " | Z: " + j+" | Tier: "+mLevel); - if (h == -1 && tTileEntity != null && addToMachineList(tTileEntity, mLevel)) { - continue; - } - else if (h != -1 && tTileEntity != null) { - Logger.INFO("Found hatch in wrong place, expected casing."); - return false; - } + Logger.INFO("Checking ChemPlant Structure"); - Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + // Require Air above controller + boolean aAirCheck = aBaseMetaTileEntity.getAirOffset(0, 1, 0); - if ((tBlock == ModBlocks.blockCasings2Misc) && (tMeta == 15) && (h >= 0)) { - ++tAmount; - } - else if ((tBlock == GregTech_API.sBlockCasings1) && (tMeta == mLevel) && (h == -1)) { - ++tAmount; - } - else if ((tBlock == GregTech_API.sBlockCasings1) && (tMeta != mLevel) && (h == -1)) { - Logger.INFO("Found wrong tiered casing."); - return false; - } - else { - if ((i != mOffsetX_Lower && j != mOffsetZ_Lower && i != mOffsetX_Upper - && j != mOffsetZ_Upper) && (h == 0 || h == 1)) { - continue; - } else { - if (tBlock.getLocalizedName().contains("gt.blockmachines") || tBlock == Blocks.water - || tBlock == Blocks.flowing_water - || tBlock == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater)) { - continue; - - } else { - Logger.INFO("[x] Did not form - Found: " + tBlock.getLocalizedName() + " | " - + tBlock.getDamageValue(aBaseMetaTileEntity.getWorld(), - aBaseMetaTileEntity.getXCoord() + i, - aBaseMetaTileEntity.getYCoord(), - aBaseMetaTileEntity.getZCoord() + j) - + " | Special Meta: " - + (tTileEntity == null ? "0" : tTileEntity.getMetaTileID())); - Logger.INFO("[x] Did not form - Found: " - + (aBaseMetaTileEntity.getXCoord() + xDir + i) + " | " - + aBaseMetaTileEntity.getYCoord() + " | " - + (aBaseMetaTileEntity.getZCoord() + zDir + j)); - break check; - } - } + if (!aAirCheck) { + Logger.INFO("No Air Above Controller"); + return false; + } else { - } + //String aName = aInitStructureCheck != null ? ItemUtils.getLocalizedNameOfBlock(aInitStructureCheck, aInitStructureCheckMeta) : "Air"; + + mSolidCasingTier = getSolidCasingTierCheck(aBaseMetaTileEntity, xDir, zDir); + mMachineCasingTier = getMachineCasingTierCheck(aBaseMetaTileEntity, xDir, zDir); + + Logger.INFO("Initial Casing Check Complete, Solid Casing Tier: "+mSolidCasingTier+", Machine Casing Tier: "+mMachineCasingTier); + + int aSolidCasingCount = 0; + int aMachineCasingCount = 0; + int aPipeCount = 0; + int aCoilCount = 0; + aSolidCasingCount = checkSolidCasings(aBaseMetaTileEntity, aStack, xDir, zDir); + aMachineCasingCount = checkMachineCasings(aBaseMetaTileEntity, aStack, xDir, zDir); + aPipeCount = checkPipes(aBaseMetaTileEntity, aStack, xDir, zDir); + aCoilCount = checkCoils(aBaseMetaTileEntity, aStack, xDir, zDir); + + Logger.INFO("Casing Counts: "); + Logger.INFO("Solid: "+aSolidCasingCount+", Machine: "+aMachineCasingCount); + Logger.INFO("Pipe: "+aPipeCount+", Coil: "+aCoilCount); + + + Logger.INFO("Casing Tiers: "); + Logger.INFO("Solid: "+getSolidCasingTier()+", Machine: "+getMachineCasingTier()); + Logger.INFO("Pipe: "+getPipeCasingTier()+", Coil: "+getCoilTier()); + + // Attempt to sync fields here, so that it updates client side values. + aBaseMetaTileEntity.getWorld().markBlockForUpdate(aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getZCoord()); + + + + // Minimum 80/93 Solid Casings + if (aSolidCasingCount < 80) { + Logger.INFO("Not enough solid casings. Found "+aSolidCasingCount+", require: 80."); + return false; + } + if (aMachineCasingCount != 57) { + Logger.INFO("Not enough machine casings. Found "+aMachineCasingCount+", require: 57."); + return false; + } + if (aPipeCount != 18) { + Logger.INFO("Not enough pipe casings. Found "+aPipeCount+", require: 18."); + return false; + } + if (aCoilCount != 27) { + Logger.INFO("Not enough coils. Found "+aCoilCount+", require: 27."); + return false; + } + + Logger.INFO("Structure Check Complete!"); + + return true; + } + } + + + public int checkCoils(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack, int aOffsetX, int aOffsetZ) { + int tAmount = 0; + int aCurrentCoilMeta = -1; + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + for (int h = 0; h < 8; h++) { + if (h == 1 || h == 3 || h == 5) { + Block aBlock = aBaseMetaTileEntity.getBlockOffset(aOffsetX + i, h, aOffsetZ + j); + int aMeta = aBaseMetaTileEntity.getMetaIDOffset(aOffsetX + i, h, aOffsetZ + j); + if (isBlockCoil(aBlock, aMeta)) { + if (aCurrentCoilMeta < 0) { + aCurrentCoilMeta = aMeta; + } + if (aCurrentCoilMeta != aMeta) { + return tAmount; + } + else { + tAmount++; + } + } } } } } - if ((tAmount >= 64)) { - Logger.INFO("Made structure."); - } else { - Logger.INFO("Did not make structure."); + + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + this.mCoilTier = (aCurrentCoilMeta+1); } - return (tAmount >= 64); + else { + if (aCurrentCoilMeta == 12) { + this.mCoilTier = 1; + } + else if (aCurrentCoilMeta == 13) { + this.mCoilTier = 2; + } + else if (aCurrentCoilMeta == 14) { + this.mCoilTier = 3; + } + else { + this.mCoilTier = 0; + } + } + + return tAmount; } - public boolean checkForWater() { - // Get Facing direction - IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); - int mDirectionX = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int mCurrentDirectionX; - int mCurrentDirectionZ; - int mOffsetX_Lower = 0; - int mOffsetX_Upper = 0; - int mOffsetZ_Lower = 0; - int mOffsetZ_Upper = 0; + public int checkPipes(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack, int aOffsetX, int aOffsetZ) { + int tAmount = 0; + int aCurrentPipeMeta = -1; + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + for (int h = 0; h < 8; h++) { + if (h == 2 || h == 4) { + Block aBlock = aBaseMetaTileEntity.getBlockOffset(aOffsetX + i, h, aOffsetZ + j); + int aMeta = aBaseMetaTileEntity.getMetaIDOffset(aOffsetX + i, h, aOffsetZ + j); + if (isBlockPipeCasing(aBlock, aMeta)) { + if (aCurrentPipeMeta < 0) { + aCurrentPipeMeta = aMeta; + } + if (aCurrentPipeMeta != aMeta) { + return tAmount; + } + else { + tAmount++; + } + } + } + } + } + } - mCurrentDirectionX = 4; - mCurrentDirectionZ = 4; + if (aCurrentPipeMeta == 12) { + this.mPipeCasingTier = 1; + } + else if (aCurrentPipeMeta == 13) { + this.mPipeCasingTier = 2; + } + else if (aCurrentPipeMeta == 14) { + this.mPipeCasingTier = 3; + } + else if (aCurrentPipeMeta == 15) { + this.mPipeCasingTier = 4; + } + else { + this.mPipeCasingTier = 0; + } - mOffsetX_Lower = -4; - mOffsetX_Upper = 4; - mOffsetZ_Lower = -4; - mOffsetZ_Upper = 4; + return tAmount; + } - // if (aBaseMetaTileEntity.fac) - final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX - * mCurrentDirectionX; - final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ - * mCurrentDirectionZ; + public int checkSolidCasings(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack, int aOffsetX, int aOffsetZ) { int tAmount = 0; - for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { - for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { - for (int h = 0; h < 2; h++) { - Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - // byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); - if (tBlock == Blocks.air || tBlock == Blocks.flowing_water || tBlock == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater)) { - if (this.getStoredFluids() != null) { - for (FluidStack stored : this.getStoredFluids()) { - if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { - if (stored.amount >= 1000) { - // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); - stored.amount -= 1000; - Block fluidUsed = Blocks.water; - aBaseMetaTileEntity.getWorld().setBlock( - aBaseMetaTileEntity.getXCoord() + xDir + i, - aBaseMetaTileEntity.getYCoord() + h, - aBaseMetaTileEntity.getZCoord() + zDir + j, fluidUsed); - - } - } - } + + // Only check a 7x7 ring + for (int i = -3; i < 4; i++) { + for (int j = -3; j < 4; j++) { + // If we are on the 7x7 ring, proceed + if (i == -3 || i == 3 || j == -3 || j == 3) { + IGregTechTileEntity aTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(aOffsetX + i, 0, aOffsetZ + j); + Block aBlock = aBaseMetaTileEntity.getBlockOffset(aOffsetX + i, 0, aOffsetZ + j); + int aMeta = aBaseMetaTileEntity.getMetaIDOffset(aOffsetX + i, 0, aOffsetZ + j); + + if (aTileEntity != null) { + + if (this.addToMachineList(aTileEntity)) { + tAmount++; } + else { + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + Logger.INFO("Error counting Bottom Layer Casing Ring. Bad Tile Entity. Found "+aTileEntity.getInventoryName()); + return tAmount; + } + //Handle controller + if (aMetaTileEntity instanceof GregtechMTE_ChemicalPlant) { + continue; + } + else { + Logger.INFO("Error counting Bottom Layer Casing Ring. Bad Tile Entity. Found "+aMetaTileEntity.getInventoryName()); + return tAmount; + } + } } - tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - if (tBlock == Blocks.water || tBlock == Blocks.flowing_water) { - ++tAmount; - // Logger.INFO("Found Water"); - } + else { + if (isBlockSolidCasing(aBlock, aMeta)) { + tAmount++; + } + else { + Logger.INFO("Error counting Bottom Layer Casing Ring. Found "+aBlock.getLocalizedName()+":"+aMeta); + return tAmount; + } + } + } + } + } + + // Check 5 layers Pillars + for (int r=1;r<6;r++) { + // Check Each Pillar/Corner + for (int aPillar=0;aPillar<4;aPillar++) { + int i = 0; + int j = 0; + if (aPillar == 0) { + i = -3; + j = -3; + } + else if (aPillar == 1) { + i = 3; + j = 3; + } + else if (aPillar == 2) { + i = -3; + j = 3; + } + else if (aPillar == 3) { + i = 3; + j = -3; + } + Block aBlock = aBaseMetaTileEntity.getBlockOffset(aOffsetX + i, r, aOffsetZ + j); + int aMeta = aBaseMetaTileEntity.getMetaIDOffset(aOffsetX + i, r, aOffsetZ + j); + if (isBlockSolidCasing(aBlock, aMeta)) { + tAmount++; + } + else { + Logger.INFO("Error counting Pillars. Found "+ItemUtils.getLocalizedNameOfBlock(aBlock, aMeta)); + return tAmount; + } + } + } + + + // Check top layer 7x7 + for (int i = -3; i < 4; i++) { + for (int j = -3; j < 4; j++) { + Block aBlock = aBaseMetaTileEntity.getBlockOffset(aOffsetX + i, 6, aOffsetZ + j); + int aMeta = aBaseMetaTileEntity.getMetaIDOffset(aOffsetX + i, 6, aOffsetZ + j); + if (isBlockSolidCasing(aBlock, aMeta)) { + tAmount++; + } + else { + Logger.INFO("Error counting Top Layer casings. Found "+ItemUtils.getLocalizedNameOfBlock(aBlock, aMeta)); + return tAmount; } } } - - boolean isValidWater = tAmount >= 60; - - if (isValidWater) { - Logger.INFO("Filled structure."); - return true; + + return tAmount; + } + + + public int checkMachineCasings(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack, int aOffsetX, int aOffsetZ) { + int tAmount = 0; + int aHeight = 0; + // Iterate once for each layer + for (int aIteration=0;aIteration<3;aIteration++) { + // Dynamically set height + aHeight = (aIteration == 0 ? 0 : aIteration == 1 ? 1 : 5); + // Only check a 5x5 area + for (int i = -2; i < 3; i++) { + for (int j = -2; j < 3; j++) { + // If we are on the 5x5 ring, proceed + if (i == -2 || i == 2 || j == -2 || j == 2) { + // If the second axis is on the outer ring, continue + if (i < -2 || i > 2 || j < -2 || j > 2) { + continue; + } + Block aBlock = aBaseMetaTileEntity.getBlockOffset(aOffsetX + i, aHeight, aOffsetZ + j); + int aMeta = aBaseMetaTileEntity.getMetaIDOffset(aOffsetX + i, aHeight, aOffsetZ + j); + if (isBlockMachineCasing(aBlock, aMeta)) { + tAmount++; + } + else { + return tAmount; + } + } + } + } + } + + // Check bottom layer inner 3x3 + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + Block aBlock = aBaseMetaTileEntity.getBlockOffset(aOffsetX + i, 0, aOffsetZ + j); + int aMeta = aBaseMetaTileEntity.getMetaIDOffset(aOffsetX + i, 0, aOffsetZ + j); + if (isBlockMachineCasing(aBlock, aMeta)) { + tAmount++; + } + else { + return tAmount; + } + } } - else { - return false; + + return tAmount; + } + + public int getSolidCasingTierCheck(IGregTechTileEntity aBaseMetaTileEntity, int xDir, int zDir) { + Block aInitStructureCheck; + int aInitStructureCheckMeta; + if (xDir == 0) { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(zDir, 0, 0); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(zDir, 0, 0); + } + else { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 0, xDir); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, 0, xDir); } + if (aInitStructureCheck == GregTech_API.sBlockCasings2) { + int aMetaSteelCasing = 0; + if (aInitStructureCheckMeta == aMetaSteelCasing) { + return 1; + } + } + else if (aInitStructureCheck == GregTech_API.sBlockCasings4) { + int aMetaStainlessCasing = 1; + int aMetaTitaniumCasing = 2; + int aMetaTungstenCasing = 0; + if (aInitStructureCheckMeta == aMetaStainlessCasing) { + return 2; + } + else if (aInitStructureCheckMeta == aMetaTitaniumCasing) { + return 3; + } + else if (aInitStructureCheckMeta == aMetaTungstenCasing) { + return 4; + } + } + return 0; + } + + public int getMachineCasingTierCheck(IGregTechTileEntity aBaseMetaTileEntity, int xDir, int zDir) { + Block aInitStructureCheck; + int aInitStructureCheckMeta; + Logger.INFO(""+xDir+", "+zDir); + if (xDir == 0) { + if (zDir > 0) { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 0, 1); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, 0, 1); + } + else { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 0, -1); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, 0, -1); + } + + } + else { + if (xDir > 0) { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(1, 0, 0); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(1, 0, 0); + } + else { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(-1, 0, 0); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(-1, 0, 0); + } + } + + if (isBlockMachineCasing(aInitStructureCheck, aInitStructureCheckMeta)) { + Logger.INFO("Using Meta "+aInitStructureCheckMeta); + return aInitStructureCheckMeta; + } + return 0; } + + + + + + + + + + + + + + + + + + + @Override public int getMaxEfficiency(final ItemStack aStack) { return 10000; @@ -327,12 +720,16 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPostTick(aBaseMetaTileEntity, aTick); + // Silly Client Syncing + if (aBaseMetaTileEntity.isClientSide()) { + this.mSolidCasingTier = getCasingTierOnClientSide(); + } + } @Override public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPreTick(aBaseMetaTileEntity, aTick); - this.fixAllMaintenanceIssue(); } @Override @@ -340,134 +737,55 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 0); } - public boolean checkRecipeGeneric( - ItemStack[] aItemInputs, FluidStack[] aFluidInputs, - int aMaxParallelRecipes, int aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { - - if (this.mLevel < 0) { - Logger.INFO("Bad Tier."); - return false; - } - - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - Logger.INFO("Running checkRecipeGeneric(0)"); - GT_Recipe tRecipe = null; + @SideOnly(Side.CLIENT) + private final int getCasingTierOnClientSide() { - this.mLastRecipe = tRecipe; - - if (tRecipe == null) { - return false; - } - - if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) { - return false; + if (this == null || this.getBaseMetaTileEntity().getWorld() == null) { + return 0; } - - - // -- Try not to fail after this point - inputs have already been consumed! -- - - - - // Convert speed bonus to duration multiplier - // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. - aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); - float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); - this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor * 24); - - this.mEUt = 0; - - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - // Overclock - if (this.mEUt <= 16) { - this.mEUt = (this.mEUt * (1 << mLevel - 1) * (1 << mLevel - 1)); - this.mMaxProgresstime = (this.mMaxProgresstime / (1 << mLevel - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(mLevel - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } - } - - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; - for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { - if (tRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= aMaxParallelRecipes; + try { + Block aInitStructureCheck; + int aInitStructureCheckMeta; + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 3; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 3; + if (xDir == 0) { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(zDir, 0, 0); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(zDir, 0, 0); } - } - - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; - for (int h = 0; h < tRecipe.mOutputs.length; h++) { - if (tRecipe.getOutput(h) != null) { - tOutputItems[h] = tRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; + else { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 0, xDir); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, 0, xDir); } - } - - // Set output item stack sizes (taking output chance into account) - for (int f = 0; f < tOutputItems.length; f++) { - if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { - for (int g = 0; g < aMaxParallelRecipes; g++) { - if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) - tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + if (aInitStructureCheck == GregTech_API.sBlockCasings2) { + int aMetaSteelCasing = 0; + if (aInitStructureCheckMeta == aMetaSteelCasing) { + return 1; } } - } - - tOutputItems = removeNulls(tOutputItems); - - // Sanitize item stack size, splitting any stacks greater than max stack size - List<ItemStack> splitStacks = new ArrayList<ItemStack>(); - for (ItemStack tItem : tOutputItems) { - while (tItem.getMaxStackSize() < tItem.stackSize) { - ItemStack tmp = tItem.copy(); - tmp.stackSize = tmp.getMaxStackSize(); - tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); - splitStacks.add(tmp); + else if (aInitStructureCheck == GregTech_API.sBlockCasings4) { + int aMetaStainlessCasing = 1; + int aMetaTitaniumCasing = 2; + int aMetaTungstenCasing = 0; + if (aInitStructureCheckMeta == aMetaStainlessCasing) { + return 2; + } + else if (aInitStructureCheckMeta == aMetaTitaniumCasing) { + return 3; + } + else if (aInitStructureCheckMeta == aMetaTungstenCasing) { + return 4; + } } + return 0; } - - if (splitStacks.size() > 0) { - ItemStack[] tmp = new ItemStack[splitStacks.size()]; - tmp = splitStacks.toArray(tmp); - tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + catch (Throwable t) { + t.printStackTrace(); + return 0; } - // Strip empty stacks - List<ItemStack> tSList = new ArrayList<ItemStack>(); - for (ItemStack tS : tOutputItems) { - if (tS.stackSize > 0) tSList.add(tS); - } - tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); - - // Commit outputs - this.mOutputItems = tOutputItems; - this.mOutputFluids = tOutputFluids; - updateSlots(); - - // Play sounds (GT++ addition - GT multiblocks play no sounds) - startProcess(); - - Logger.INFO("GOOD RETURN - 1"); - return true; - } @@ -477,7 +795,4 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { - - - } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/loaders/recipe/RecipeLoader_AlgaeFarm.java b/src/Java/gtPlusPlus/xmod/gregtech/loaders/recipe/RecipeLoader_AlgaeFarm.java new file mode 100644 index 0000000000..8a4ae1344a --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/loaders/recipe/RecipeLoader_AlgaeFarm.java @@ -0,0 +1,202 @@ +package gtPlusPlus.xmod.gregtech.loaders.recipe; + +import java.util.HashMap; + +import gregtech.api.enums.GT_Values; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.Recipe_GT; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.data.WeightedCollection; +import gtPlusPlus.core.item.chemistry.AgriculturalChem; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class RecipeLoader_AlgaeFarm { + + private static final HashMap<Integer, AutoMap<GT_Recipe>> mRecipeCache = new HashMap<Integer, AutoMap<GT_Recipe>>(); + private static final HashMap<Integer, AutoMap<GT_Recipe>> mRecipeCompostCache = new HashMap<Integer, AutoMap<GT_Recipe>>(); + + public static final void generateRecipes() { + for (int i=0;i<10;i++) { + getTieredRecipeFromCache(i, false); + } + for (int i=0;i<10;i++) { + getTieredRecipeFromCache(i, true); + } + } + + public static GT_Recipe getTieredRecipeFromCache(int aTier, boolean aCompost) { + HashMap<Integer, AutoMap<GT_Recipe>> aMap = aCompost ? mRecipeCompostCache : mRecipeCache; + String aComp = aCompost ? "(Compost)" : ""; + + AutoMap<GT_Recipe> aTemp = aMap.get(aTier); + if (aTemp == null || aTemp.isEmpty()) { + aTemp = new AutoMap<GT_Recipe>(); + aMap.put(aTier, aTemp); + Logger.INFO("Tier "+aTier+aComp+" had no recipes, initialising new map."); + } + if (aTemp.size() < 500) { + Logger.INFO("Tier "+aTier+aComp+" has less than 500 recipes, generating "+(500 - aTemp.size())+"."); + for (int i=aTemp.size();i<500;i++) { + aTemp.put(generateBaseRecipe(aCompost, aTier)); + } + } + int aIndex = MathUtils.randInt(0, aTemp.isEmpty() ? 1 : aTemp.size()); + Logger.INFO("Using recipe with index of "+aIndex+". "+aComp); + return aTemp.get(aIndex); + } + + private static GT_Recipe generateBaseRecipe(boolean aUsingCompost, int aTier) { + + // Type Safety + if (aTier < 0) { + return null; + } + + WeightedCollection<Float> aOutputTimeMulti = new WeightedCollection<Float>(); + for (int i=100;i> 0;i--) { + float aValue = 0; + if (i < 10) { + aValue = 3f; + } + else if (i < 20) { + aValue = 2f; + } + else { + aValue = 1f; + } + aOutputTimeMulti.put(i, aValue); + } + + final int[] aDurations = new int[] { + 432000, + 378000, + 216000, + 162000, + 108000, + 81000, + 54000, + 40500, + 27000, + 20250, + 13500, + 6750, + 3375, + 1686, + 843, + 421 + }; + + ItemStack[] aInputs = new ItemStack[] {}; + + if (aUsingCompost) { + // Make it use 4 compost per tier if we have some available + ItemStack aCompost = ItemUtils.getSimpleStack(AgriculturalChem.mCompost, aTier * 4); + aInputs = new ItemStack[] {aCompost}; + // Boost Tier by one if using compost so it gets a speed boost + aTier++; + } + + // We set these elsewhere + ItemStack[] aOutputs = getOutputsForTier(aTier); + + GT_Recipe tRecipe = new Recipe_GT( + false, + aInputs, + aOutputs, + (Object) null, + new int[] {}, + new FluidStack[] {GT_Values.NF}, + new FluidStack[] {GT_Values.NF}, + (int) (aDurations[aTier] * aOutputTimeMulti.get()), // Time + 0, + 0); + + tRecipe.mSpecialValue = tRecipe.hashCode(); + + return tRecipe; + } + + private static ItemStack[] getOutputsForTier(int aTier) { + + // Create an Automap to dump contents into + AutoMap<ItemStack> aOutputMap = new AutoMap<ItemStack>(); + + // Add loot relevant to tier and also add any from lower tiers. + if (aTier >= 0) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mAlgaeBiosmass, MathUtils.randInt(16, 32))); + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mAlgaeBiosmass, MathUtils.randInt(32, 64))); + if (MathUtils.randInt(0, 10) > 9) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(8, 16))); + } + } + if (aTier >= 1) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mAlgaeBiosmass, MathUtils.randInt(16, 32))); + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(16, 32))); + if (MathUtils.randInt(0, 10) > 9) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(4, 8))); + } + } + if (aTier >= 2) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(8, 16))); + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(16, 32))); + if (MathUtils.randInt(0, 10) > 9) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(4, 8))); + } + } + if (aTier >= 3) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGreenAlgaeBiosmass, MathUtils.randInt(16, 32))); + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, MathUtils.randInt(2, 8))); + if (MathUtils.randInt(0, 10) > 9) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, MathUtils.randInt(8, 16))); + } + } + if (aTier >= 4) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, MathUtils.randInt(16, 32))); + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, MathUtils.randInt(32, 64))); + if (MathUtils.randInt(0, 10) > 9) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, MathUtils.randInt(4, 8))); + } + } + if (aTier >= 5) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mBrownAlgaeBiosmass, MathUtils.randInt(16, 32))); + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, MathUtils.randInt(16, 32))); + if (MathUtils.randInt(0, 10) > 9) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, MathUtils.randInt(1, 2))); + } + } + // Tier 6 is Highest for outputs + if (aTier >= 6) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, MathUtils.randInt(16, 32))); + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, MathUtils.randInt(8, 16))); + if (MathUtils.randInt(0, 10) > 9) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, MathUtils.randInt(8, 16))); + } + } + + // Iterate a special loop at higher tiers to provide more Red/Gold Algae. + for (int i=0;i<(9-aTier);i++) { + if (aTier >= (6+i)) { + int aMulti = i + 1; + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mGoldenBrownAlgaeBiosmass, MathUtils.randInt(4, 8*aMulti))); + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, MathUtils.randInt(4, 8*aMulti))); + if (MathUtils.randInt(0, 10) > 8) { + aOutputMap.put(ItemUtils.getSimpleStack(AgriculturalChem.mRedAlgaeBiosmass, MathUtils.randInt(8, 16*aMulti))); + } + } + } + + // Map the AutoMap contents to an Itemstack Array. + ItemStack[] aOutputs = new ItemStack[aOutputMap.size()]; + for (int i=0;i<aOutputMap.size();i++) { + aOutputs[i] = aOutputMap.get(i); + } + + // Return filled ItemStack Array. + return aOutputs; + } + +} |