From a93e2aa92384f595dcb5907f5b88a220c6735cf0 Mon Sep 17 00:00:00 2001 From: botn365 <42187820+botn365@users.noreply.github.com> Date: Wed, 8 Jan 2020 00:12:46 +0100 Subject: ChemPlant & Catalyst Consumption (#598) % Make some Itemstacks static. % Higher tier coils speed up ChemPlant. % Redused catalyst consumption in ChemPlant. $ Some clean up. $ Fix that recipes without catalyst wont start. $ Redone catalyst code for it to better work with parrallel and it not failing recipe after consumed item. % Formatting/Spelling % Greatly improved the ChemPlant's Tooltip. % Tooltip update. % Made the tooltip a little bit clearer. Co-authored-by: Alkalus <3060479+draknyte1@users.noreply.github.com> --- .../chemplant/GregtechMTE_ChemicalPlant.java | 372 +++++++++++++++++++-- 1 file changed, 344 insertions(+), 28 deletions(-) (limited to 'src/Java/gtPlusPlus/xmod/gregtech/common/tileentities') 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 654d036bf8..81a25b3266 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,41 +1,63 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.chemplant; import static gregtech.api.enums.GT_Values.E; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; +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.ItemList; +import gregtech.api.enums.Materials; 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.interfaces.tileentity.IHasWorldObjectAndCoords; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.Recipe_GT; +import gtPlusPlus.api.helpers.GregtechPlusPlus_API.Multiblock_API; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.minecraft.multi.SpecialMultiBehaviour; +import gtPlusPlus.core.item.chemistry.AgriculturalChem; +import gtPlusPlus.core.item.chemistry.GenericChem; +import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; 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 net.minecraft.block.Block; +import net.minecraft.item.Item; 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 mSolidCasingTier = 0; private int mMachineCasingTier = 0; private int mPipeCasingTier = 0; private int mCoilTier = 0; + /** * Internal Recipe Map which holds the actual recipes, backed by the real map, shown by NEI. */ @@ -78,13 +100,30 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { @Override public String[] getTooltip() { return new String[] { - "Heavy Industry, now right at your doorstep!", "Controller Block for the Chemical Plant", - "27 Coils", - "18 Pipe Casings", - "57 Tiered Machine Casings", + "Heavy Industry, now right at your doorstep!", + "Solid Casings dictate Chemical Plant tier", + "Machine Casings dictate Hatch tier", + "Higher tier coils speed up the machine", + "CuNi 50% , FeAlCr 100% , Ni4Cr 150% , ...", + "Higher tier pipe casings boost parallel and reduce catalyst consumption", + "+2 parallel per tier, 20% extra chance of not damaging catalyst per tier", + "27x Coils", + "18x Pipe Casings", + "57x Tiered Machine Casings", "80+ Solid Casings", - "Hatch tier is limited to Machine Casing tier", + "Construction Guide:", + "Controller is placed on a middle casing in the bottom layer", + "Hatches can only be placed on the bottom layer edges", + "7x7x7 Hollow frame of solid casings", + "5x1x5 layer of solid casings (fills in top layer)", + "5x1x5 layer of machine casings (fills in bottom layer)", + "In the central 3x5x3:", + "3x1x3 layer of Coils, surrounded by ring of Machine Casings", + "3x1x3 layer of Pipe Casings", + "3x1x3 layer of Coils", + "3x1x3 layer of Pipe Casings", + "3x1x3 layer of Coils, surrounded by ring of Machine Casings", }; } @@ -121,7 +160,6 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { aOriginalTexture = Textures.BlockIcons.CASING_BLOCKS[11]; } - if (aSide == aFacing) { return new ITexture[]{aOriginalTexture, new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; } @@ -158,7 +196,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { @Override public int getEuDiscountForParallelism() { - return 0; + return 100; } private int getSolidCasingTier() { @@ -699,24 +737,6 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { } - - - - - - - - - - - - - - - - - - @Override public int getMaxEfficiency(final ItemStack aStack) { return 10000; @@ -741,6 +761,15 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { public String getCustomGUIResourceName() { return null; } + + // Same speed bonus as pyro oven + public int getSpeedBonus() { + return 50 * (this.mCoilTier - 2); + } + + public int getMaxCatalystDurability() { + return 50; + } @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { @@ -758,10 +787,297 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { } @Override - public boolean checkRecipe(final ItemStack aStack) { - return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 0); + public boolean checkRecipe(final ItemStack aStack) { + return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), getSpeedBonus()); } + + + @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, FluidStack[] aFluidInputs, + int aMaxParallelRecipes, int aEUPercent, + int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) { + + // Based on the Processing Array. A bit overkill, but very flexible. + + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + 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; + } + + + if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) { + log("BAD RETURN - 2"); + return false; + } + + // checks if it has enough catalyst durabilety + ArrayListtCatalysts = null; + int tMaxParrallelCatalyst = aMaxParallelRecipes; + ItemStack tCatalystRecipe = findCatalyst(tRecipe.mInputs); + if (tCatalystRecipe != null) { + log("needs catalyst"); + tCatalysts = new ArrayList(); + tMaxParrallelCatalyst = getCatalysts(aItemInputs, tCatalystRecipe, aMaxParallelRecipes,tCatalysts); + } + + if (tMaxParrallelCatalyst == 0) { + log("found not enough catalists catalyst"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + log("aEUPercent "+aEUPercent); + log("mEUt "+tRecipe.mEUt); + + int parallelRecipes = 0; + + log("parallelRecipes: "+parallelRecipes); + log("aMaxParallelRecipes: "+tMaxParrallelCatalyst); + log("tTotalEUt: "+tTotalEUt); + log("tVoltage: "+tVoltage); + log("tEnergy: "+tEnergy); + log("tRecipeEUt: "+tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < tMaxParrallelCatalyst && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + log("Broke at "+parallelRecipes+"."); + break; + } + log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + return false; + } + + if (tCatalysts != null) { + log("damaging catalyst"); + for (int j = 0;j aOutPut) { + int allowedParrallel = 0; + for (final ItemStack aInput : aItemInputs) { + if (aRecipeCatalyst.isItemEqual(aInput)) { + if (aInput.stackSize == 1) { + int damage = getDamage(aInput) + aMaxParrallel; + if (damage >getMaxCatalystDuarbilerty() ) { + aOutPut.add(aInput); + allowedParrallel += aMaxParrallel + (getMaxCatalystDuarbilerty() - damage); + if (allowedParrallel >aMaxParrallel ) { + return aMaxParrallel; + } + continue; + } + } + aOutPut.add(aInput); + return aMaxParrallel; + } + } + return allowedParrallel; + } + + private ItemStack findCatalyst(ItemStack[] aItemInputs) { + if (aItemInputs != null) { + for (final ItemStack aInput : aItemInputs) { + if (aInput != null) { + if (aInput.isItemEqual(GenericChem.mRedCatalyst)) + return aInput; + else if (aInput.isItemEqual(GenericChem.mYellowCatalyst)) + return aInput; + else if (aInput.isItemEqual(GenericChem.mBlueCatalyst)) + return aInput; + else if (aInput.isItemEqual(GenericChem.mOrangeCatalyst)) + return aInput; + else if (aInput.isItemEqual(GenericChem.mPurpleCatalyst)) + return aInput; + else if (aInput.isItemEqual(AgriculturalChem.mGreenCatalyst)) + return aInput; + else if (aInput.isItemEqual(GenericChem.mBrownCatalyst)) + return aInput; + } + } + } + return null; + } + + + private void damageCatalyst(ItemStack aStack) { + if (MathUtils.randFloat(0, 10000000)/10000000f < (1.2f - (0.2 * this.mPipeCasingTier))) { + int damage = getDamage(aStack) + 1; + log("damage catalyst "+damage); + if (damage >= getMaxCatalystDurability()) { + log("consume catalyst"); + ItemStack emptyCatalyst = ItemUtils.getSimpleStack(AgriculturalChem.mCatalystCarrier,1); + addOutput(emptyCatalyst); + setDamage(aStack,0); + aStack.stackSize -= 1; + } + else { + setDamage(aStack,damage); + } + } + else + log("not consuming catalyst"); + } + } + + private int getDamage(ItemStack aStack) { + if (aStack.getTagCompound() == null || aStack.getTagCompound().hasNoTags()) { + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setInteger("Damage", 0); + tagMain.setTag("catalyst", tagNBT); + aStack.setTagCompound(tagMain); + } + NBTTagCompound aNBT = aStack.getTagCompound(); + return aNBT.getCompoundTag("catalyst").getInteger("Damage"); + } + + private void setDamage(ItemStack aStack,int aAmount) { + NBTTagCompound aNBT = aStack.getTagCompound(); + aNBT = aNBT.getCompoundTag("catalyst"); + aNBT.setInteger("Damage", aAmount); + } + @SideOnly(Side.CLIENT) -- cgit