diff options
author | Alkalus <draknyte1@hotmail.com> | 2021-05-20 23:07:24 +0000 |
---|---|---|
committer | Alkalus <draknyte1@hotmail.com> | 2021-05-20 23:07:24 +0000 |
commit | 7881c840421c191e8c4249fc303e184fa1cbf9a8 (patch) | |
tree | 0e1f8d8d19ca14e14dfb16c1ed49750935612dfa /src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines | |
parent | de40c882cb16535deae1c29b22f1a535747db536 (diff) | |
parent | 5316a0ffcbc403e17a06d4c9e28d57e202f0aafe (diff) | |
download | GT5-Unofficial-7881c840421c191e8c4249fc303e184fa1cbf9a8.tar.gz GT5-Unofficial-7881c840421c191e8c4249fc303e184fa1cbf9a8.tar.bz2 GT5-Unofficial-7881c840421c191e8c4249fc303e184fa1cbf9a8.zip |
Merged in MultiFixes (pull request #11)
MultiFixes
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines')
10 files changed, 1569 insertions, 283 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java index 33c6bacbd4..eb01823151 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java @@ -21,6 +21,7 @@ import gregtech.common.items.GT_MetaGenerated_Tool_01; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.item.general.ItemAirFilter; +import gtPlusPlus.core.item.general.ItemBasicScrubberTurbine; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; @@ -44,7 +45,7 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi protected int SLOT_ROTOR = 4; protected int SLOT_FILTER = 5; protected static boolean mPollutionEnabled = true; - + protected boolean mSaveRotor = false; public GregtechMetaAtmosphericReconditioner(int aID, String aName, String aNameRegional, int aTier) { @@ -78,20 +79,21 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi @Override public String[] getDescription() { - + boolean highTier = this.mTier >= 7; - + String[] A = new String[]{ this.mDescription, highTier ? "Will attempt to remove 1/4 pollution from 8 surrounding chunks" : "", highTier ? "If these chunks are not loaded, they will be ignored" : "", - "Requires a turbine rotor and an Air Filter [T1/T2] to run.", - "The turbine rotor must be manually inserted/replaced", - "Can be configured with a soldering iron to change modes", - "Low Efficiency: Removes half pollution, Turbine takes 50% dmg", - "High Efficiency: Removes full pollution, Turbine takes 100% dmg", - "Turbine Rotor will not break in LE mode", - }; + "Requires a turbine rotor and an Air Filter [T1/T2] to run.", + "The turbine rotor must be manually inserted/replaced", + "Can be configured with a soldering iron to change modes", + "Low Efficiency: Removes half pollution, Turbine takes 50% dmg", + "High Efficiency: Removes full pollution, Turbine takes 100% dmg", + "Turbine Rotor will not break in LE mode", + "Insert an equal tier Conveyor Module to enable automation" + }; if (!mPollutionEnabled) { String[] B = new String[] { "===============================================", @@ -176,10 +178,10 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi aBaseMetaTileEntity.setActive(false); this.sendSound((byte) -122); } - + //Only try once/sec. if (!isIdle && aTick % 20L == 0L){ - + //Check if machine can work. if ((aBaseMetaTileEntity.isAllowedToWork())){ @@ -195,13 +197,13 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi this.sendSound((byte) -122); } } - + //If Active. if (aBaseMetaTileEntity.isActive()){ //Do nothing if there is no pollution. if(this.mHasPollution && mCurrentPollution > 0){ - + //Only check every 30s. if (!isIdle && aTick % (20L * 30) == 0L){ mPollutionEnabled = PollutionUtils.mPollution(); @@ -210,9 +212,9 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi PollutionUtils.nullifyPollution(this.getBaseMetaTileEntity()); } } - - - + + + //Use a Turbine if(hasRotor(stackRotor) && hasAirFilter(stackFilter)){ @@ -238,7 +240,7 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi int mAirSides = getFreeSpaces(); int reduction = 0; - + //If no sides are free, how will you process the atmosphere? if (mAirSides > 0){ reduction += (((Math.max((tTier-2), 1)*2)*50)*mAirSides); //Was originally *100 @@ -251,7 +253,7 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi Logger.WARNING("reduction[3]:"+reduction); mPollutionReduction = reduction; - + //Set a temp to remove variable to aleviate duplicate code. int toRemove = 0; @@ -268,6 +270,7 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi //We are good to clean if (toRemove > 0){ if (damageTurbineRotor() && damageAirFilter()){ + Logger.INFO("Removing "+toRemove+" pollution"); removePollution(mSaveRotor ? (toRemove/2) : toRemove); Logger.WARNING("mNewPollution[4]:"+getCurrentChunkPollution()); } @@ -293,21 +296,21 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi } } //End of 1/sec action block. else { - + if (hasRotor(stackRotor) && hasAirFilter(stackFilter) && this.mHasPollution && !isIdle && aBaseMetaTileEntity.isAllowedToWork()){ aBaseMetaTileEntity.setActive(true); } else if (isIdle || !this.mHasPollution || mCurrentPollution <= 0 || stackRotor == null || stackFilter == null || !hasRotor(stackRotor) || !hasAirFilter(stackFilter)){ aBaseMetaTileEntity.setActive(false); } - + } if (this.getBaseMetaTileEntity().isActive()) { if (MathUtils.randInt(0, 5) <= 2) { this.sendSound((byte) -120); } } - + } //End of is serverside block. } @@ -363,9 +366,12 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi } return mCurrentChunkPollution; } - + public boolean hasRotor(ItemStack rotorStack){ if(rotorStack != null){ + if (rotorStack.getItem() instanceof ItemBasicScrubberTurbine) { + return true; + } if (rotorStack.getItem() instanceof GT_MetaGenerated_Tool && rotorStack.getItemDamage() >= 170 && rotorStack.getItemDamage() <= 179){ return true; } @@ -375,7 +381,7 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi public boolean damageTurbineRotor(){ try{ - + boolean creativeRotor = false; ItemStack rotorStack = this.mInventory[SLOT_ROTOR]; if (rotorStack == null) { @@ -390,15 +396,34 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi } } } - + + if (rotorStack.getItem() instanceof ItemBasicScrubberTurbine) { + long currentUse = ItemBasicScrubberTurbine.getFilterDamage(rotorStack); + //Remove broken Filter + if (rotorStack.getItemDamage() == 0 && currentUse >= 2500-10){ + this.mInventory[this.SLOT_FILTER] = null; + return false; + } + else if (rotorStack.getItemDamage() == 1 && currentUse >= 5000-10){ + this.mInventory[this.SLOT_FILTER] = null; + return false; + } + else { + //Do Damage + ItemAirFilter.setFilterDamage(rotorStack, currentUse+10); + Logger.WARNING("Rotor Damage: "+currentUse); + return true; + } + } + if(mInventory[SLOT_ROTOR].getItem() instanceof GT_MetaGenerated_Tool_01 && ((GT_MetaGenerated_Tool) mInventory[SLOT_ROTOR].getItem()).getToolStats(mInventory[SLOT_ROTOR]).getSpeedMultiplier()>0 && GT_MetaGenerated_Tool.getPrimaryMaterial(mInventory[SLOT_ROTOR]).mToolSpeed>0 ) { - + long damageValue = (long) Math.floor(Math.abs(MathUtils.randFloat(1, 2) - MathUtils.randFloat(1, 3)) * (1 + 3 - 1) + 1); double fDam = Math.floor(Math.abs(MathUtils.randFloat(1f, 2f) - MathUtils.randFloat(1f, 2f)) * (1f + 2f - 1f) + 1f); damageValue -= fDam; - + //Logger.WARNING("Trying to do "+damageValue+" damage to the rotor. ["+fDam+"]"); /*Materials M1 = GT_MetaGenerated_Tool.getPrimaryMaterial(this.mInventory[this.SLOT_ROTOR]); Materials M2 = GT_MetaGenerated_Tool.getSecondaryMaterial(this.mInventory[this.SLOT_ROTOR]); @@ -412,14 +437,27 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi long rotorDurability = (rotorDurabilityMax - rotorDamage); Logger.WARNING("Rotor Damage: "+rotorDamage + " | Max Durability: "+rotorDurabilityMax+" | "+" Remaining Durability: "+rotorDurability); if (rotorDurability >= damageValue){ - - - if (!mSaveRotor){ - Logger.WARNING("Damaging Rotor."); - - if (!creativeRotor) + + + if (!mSaveRotor){ + Logger.WARNING("Damaging Rotor."); + + if (!creativeRotor) GT_ModHandler.damageOrDechargeItem(this.mInventory[this.SLOT_ROTOR], (int) damageValue, 0, null); + long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); + if (tempDur < rotorDurabilityMax){ + return true; + } + else { + rotorDurability = 0; + } + } + else { + Logger.WARNING("Damaging Rotor."); + if (rotorDurability > 1000){ + if (!creativeRotor) + GT_ModHandler.damageOrDechargeItem(this.mInventory[this.SLOT_ROTOR], (int) damageValue/2, 0, null); long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); if (tempDur < rotorDurabilityMax){ return true; @@ -427,23 +465,10 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi else { rotorDurability = 0; } - } - else { - Logger.WARNING("Damaging Rotor."); - if (rotorDurability > 1000){ - if (!creativeRotor) - GT_ModHandler.damageOrDechargeItem(this.mInventory[this.SLOT_ROTOR], (int) damageValue/2, 0, null); - long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); - if (tempDur < rotorDurabilityMax){ - return true; - } - else { - rotorDurability = 0; - } - } - } - - + } + } + + } if (rotorDurability <= 0 && !mSaveRotor && !creativeRotor) { @@ -494,11 +519,11 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi } public boolean removePollution(int toRemove){ - + if (this == null || this.getBaseMetaTileEntity() == null || this.getBaseMetaTileEntity().getWorld() == null) { return false; } - + if (this.mTier < 7) { int startPollution = getCurrentChunkPollution(); PollutionUtils.removePollution(this.getBaseMetaTileEntity(), toRemove); @@ -512,7 +537,7 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi Chunk aThisChunk = this.getBaseMetaTileEntity().getWorld().getChunkFromBlockCoords(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getZCoord()); int mainChunkX = aThisChunk.xPosition; int mainChunkZ = aThisChunk.zPosition; - + World aWorld = this.getBaseMetaTileEntity().getWorld(); int xPos = this.getBaseMetaTileEntity().getXCoord(); int zPos = this.getBaseMetaTileEntity().getZCoord(); @@ -536,21 +561,21 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi aSurrounding.put(c1); aSurrounding.put(c2); aSurrounding.put(c3); - + for (Chunk r : aSurrounding) { if (!r.isChunkLoaded) { continue; } - + int startPollution = getPollutionInChunk(r); if (startPollution == 0) { continue; } - + Logger.WARNING("Trying to remove pollution from chunk "+r.xPosition+", "+r.zPosition+" | "+startPollution); int after = 0; boolean isMainChunk = r.isAtLocation(mainChunkX, mainChunkZ); - + int removal = Math.max(0, !isMainChunk ? (toRemove/4) : toRemove); if (removePollution(r, removal)) { chunksWithRemoval++; @@ -567,7 +592,7 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi return totalRemoved > 0 && chunksWithRemoval > 0; } } - + public boolean removePollution(Chunk aChunk, int toRemove){ int before = getCurrentChunkPollution(); PollutionUtils.removePollution(aChunk, toRemove); @@ -591,7 +616,7 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi if (filter == null) { return false; } - + boolean creativeRotor = false; ItemStack rotorStack = this.mInventory[SLOT_ROTOR]; if (rotorStack != null) { @@ -603,11 +628,11 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi } } } - + if (creativeRotor) { return true; } - + if (filter.getItem() instanceof ItemAirFilter){ @@ -645,10 +670,25 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi @Override public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { - if (aIndex == 4){ - return false; + if (aIndex == 5) { + if (aStack.getItem() instanceof ItemAirFilter) { + Logger.INFO("Inserting Air Filter into "+aIndex); + return true; + } } - return super.canInsertItem(aIndex, aStack, aSide); + if (aIndex == 4) { + if (this.mInventory[6] != null) { + Logger.INFO("Found conveyor, can automate turbines. Inserting into "+aIndex); + if (aStack.getItem() instanceof ItemBasicScrubberTurbine) { + return true; + } + if (aStack.getItem() instanceof GT_MetaGenerated_Tool && aStack.getItemDamage() >= 170 && aStack.getItemDamage() <= 179){ + return true; + } + } + } + //return super.canInsertItem(aIndex, aStack, aSide); + return false; } @Override @@ -695,29 +735,29 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi } int mAirSides = getFreeSpaces(); int reduction = 0; - + try { - long tVoltage = maxEUInput(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - reduction += (((Math.max((tTier-2), 1)*2)*50)*mAirSides); - reduction = (MathUtils.safeInt((long)reduction*this.mBaseEff)/100000)*mAirSides*Math.max((tTier-2), 1); - reduction = MathUtils.safeInt(((long)reduction/100)*this.mOptimalAirFlow); - - aTooltipSuper.put("Maximum pollution removed per second: "+reduction); + long tVoltage = maxEUInput(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + reduction += (((Math.max((tTier-2), 1)*2)*50)*mAirSides); + reduction = (MathUtils.safeInt((long)reduction*this.mBaseEff)/100000)*mAirSides*Math.max((tTier-2), 1); + reduction = MathUtils.safeInt(((long)reduction/100)*this.mOptimalAirFlow); + + aTooltipSuper.put("Maximum pollution removed per second: "+reduction); } catch (Throwable t) { aTooltipSuper.put("Maximum pollution removed per second: "+mPollutionReduction); } aTooltipSuper.put("Air Sides: "+mAirSides); - + String[] mBuiltOutput = new String[aTooltipSuper.size()]; int aIndex = 0; for (String i : aTooltipSuper) { mBuiltOutput[aIndex++] = i; } - - - + + + return mBuiltOutput; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java index 2f9bbcc9fb..78f60f13c9 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java @@ -350,15 +350,16 @@ public class GregtechMetaPollutionDetector extends GregtechMetaTileEntity { } //Emit Redstone if (this.getCurrentChunkPollution() >= this.mRedstoneLevel){ - this.markDirty(); for (int i=0;i<6;i++){ this.getBaseMetaTileEntity().setStrongOutputRedstoneSignal((byte) i, (byte) 16); } + this.markDirty(); } else { for (int i=0;i<6;i++){ this.getBaseMetaTileEntity().setStrongOutputRedstoneSignal((byte) i, (byte) 0); } + this.markDirty(); } //Do Math for stats diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java index eca02d290e..10286411a7 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java @@ -2,9 +2,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.misc; import java.util.ArrayList; -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; - import gregtech.api.enums.*; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -15,13 +12,13 @@ import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; - import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.minecraft.ItemStackData; import gtPlusPlus.core.block.ModBlocks; -import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java index 31c9636cac..2d249feaff 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java @@ -221,6 +221,11 @@ extends GregtechMeta_MultiBlockBase { @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); - mCuttingMode = aNBT.getBoolean("mCuttingMode"); + if (aNBT.hasKey("mCuttingMode")) { + mCuttingMode = aNBT.getBoolean("mCuttingMode"); + } + else { + mCuttingMode = true; + } } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java index 4cf8c55005..8f54d21906 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java @@ -1,8 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; -import static gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map.sAdvFreezerRecipes; -import static gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map.sAdvFreezerRecipes_GT; - import gregtech.api.GregTech_API; import gregtech.api.enums.TAE; import gregtech.api.enums.Textures; @@ -11,8 +8,8 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_Recipe; import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GT_Recipe; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.util.minecraft.FluidUtils; @@ -106,12 +103,7 @@ public class GregtechMetaTileEntity_IndustrialVacuumFreezer extends GregtechMeta return "VacuumFreezer"; } - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - if (sAdvFreezerRecipes_GT.mRecipeList.size() < 1) { - for (GT_Recipe a : sAdvFreezerRecipes.mRecipeList) { - sAdvFreezerRecipes_GT.add(a); - } - } + public GT_Recipe.GT_Recipe_Map getRecipeMap() { return GTPP_Recipe.GTPP_Recipe_Map.sAdvFreezerRecipes_GT; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java new file mode 100644 index 0000000000..06d63867da --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java @@ -0,0 +1,135 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.steam; + +import static gregtech.api.GregTech_API.sBlockCasings1; + +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_SteamMultiBase; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +public class GregtechMetaTileEntity_SteamMacerator extends GregtechMeta_SteamMultiBase { + + private String mCasingName = "Bronze Plated Bricks"; + + public GregtechMetaTileEntity_SteamMacerator(String aName) { + super(aName); + } + + public GregtechMetaTileEntity_SteamMacerator(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity arg0) { + return new GregtechMetaTileEntity_SteamMacerator(this.mName); + } + + public boolean isFacingValid(byte aFacing) { + return aFacing > 1; + } + + @Override + protected GT_RenderedTexture getFrontOverlay() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_STEAM_MACERATOR); + } + + @Override + protected GT_RenderedTexture getFrontOverlayActive() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_STEAM_MACERATOR_ACTIVE); + } + + @Override + public String getMachineType() { + return "Macerator"; + } + + @Override + public String[] getTooltip() { + if (mCasingName.contains("gt.blockcasings")) { + mCasingName = ItemList.Casing_BronzePlatedBricks.get(1).getDisplayName(); + } + return new String[]{ + "Controller Block for the Steam Macerator", + "Macerates "+getMaxParallelRecipes()+" ores at a time", + "Size(WxHxD): 3x3x3 (Hollow), Controller (Front centered)", + "1x Input Bus (Any casing)", + "1x Output Bus (Any casing)", + "1x Steam Hatch (Any casing)", + mCasingName+" for the rest (14 at least!)", + TAG_HIDE_MAINT + }; + } + + @Override + public int getMaxParallelRecipes() { + return 8; + } + + + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sMaceratorRecipes; + } + + @Override + public boolean checkMultiblock(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; + int tAmount = 0; + if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { + return false; + } else { + for (int i = -1; i < 2; ++i) { + for (int j = -1; j < 2; ++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); + Block aBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + int aMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + + if (!isValidBlockForStructure(tTileEntity, 10, true, aBlock, aMeta, + sBlockCasings1, 10)) { + Logger.INFO("Bad macerator casing"); + return false; + } + ++tAmount; + + } + } + } + } + if (tAmount >= 14) { + fixAllMaintenanceIssue(); + } + return tAmount >= 14; + } + } + + @Override + public ItemStack[] getOutputItems(GT_Recipe aRecipe) { + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[1]; + for (int h = 0; h < 1; h++) { + if (aRecipe.getOutput(h) != null) { + tOutputItems[h] = aRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + return tOutputItems; + } + + @Override + public int getOutputCount(ItemStack[] aOutputs) { + return 1; + } + + + +} diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java new file mode 100644 index 0000000000..05b6b19d5c --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java @@ -0,0 +1,989 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +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.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.GTPP_Recipe; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.data.Triplet; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_ElementalDataOrbHolder; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers.GT_MetaTileEntity_Hatch_Catalysts; +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.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_ElementalDuplicator extends GregtechMeta_MultiBlockBase { + + private int mSolidCasingTier = 0; + private int mMachineCasingTier = 0; + private int mPipeCasingTier = 0; + private int mCoilTier = 0; + + private ArrayList<GT_MetaTileEntity_Hatch_ElementalDataOrbHolder> mDataHolders = new ArrayList<GT_MetaTileEntity_Hatch_ElementalDataOrbHolder>(); + + private static final HashMap<Integer, Triplet<Block, Integer, Integer>> mTieredBlockRegistry = new HashMap<Integer, Triplet<Block, Integer, Integer>>(); + + public GregtechMTE_ElementalDuplicator(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_ElementalDuplicator(final String aName) { + super(aName); + } + + public static boolean registerMachineCasingForTier(int aTier, Block aBlock, int aMeta, int aCasingTextureID) { + int aSize = mTieredBlockRegistry.size(); + int aSize2 = aSize; + Triplet<Block, Integer, Integer> aCasingData = new Triplet<Block, Integer, Integer>(aBlock, aMeta, aCasingTextureID); + if (mTieredBlockRegistry.containsKey(aTier)) { + CORE.crash("Tried to register a Machine casing for tier "+aTier+" to the Chemical Plant, however this tier already contains one."); + } + mTieredBlockRegistry.put(aTier, aCasingData); + aSize = mTieredBlockRegistry.size(); + return aSize > aSize2; + } + + private static Block getBlockForTier(int aTier) { + if (!mTieredBlockRegistry.containsKey(aTier)) { + return Blocks.bedrock; + } + return mTieredBlockRegistry.get(aTier).getValue_1(); + } + private static int getMetaForTier(int aTier) { + if (!mTieredBlockRegistry.containsKey(aTier)) { + return 32; + } + return mTieredBlockRegistry.get(aTier).getValue_2(); + } + private static int getCasingTextureIdForTier(int aTier) { + return 67; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_ElementalDuplicator(this.mName); + } + + @Override + public String getMachineType() { + return "Chemical Plant"; + } + + @Override + public String[] getTooltip() { + return new String[] { + "Controller Block for the Industrial Replication Machine", + "Now replication is less painful", + "Please read to user manual for more information on construction & usage", + TAG_HIDE_MAINT + }; + } + + @Override + public String getSound() { + return GregTech_API.sSoundList.get(Integer.valueOf(207)); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + + ITexture aOriginalTexture; + + // Check things exist client side (The worst code ever) + if (aBaseMetaTileEntity.getWorld() != null) { + + } + int aCasingID = getCasingTextureID(); + aOriginalTexture = Textures.BlockIcons.CASING_BLOCKS[aCasingID]; + + if (aSide == aFacing) { + return new ITexture[]{aOriginalTexture, new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; + } + return new ITexture[]{aOriginalTexture}; + } + + @Override + public boolean hasSlotInGUI() { + return true; + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT; + } + + public static void generateRecipes() { + for (GTPP_Recipe i : GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlantRecipes.mRecipeList) { + GTPP_Recipe.GTPP_Recipe_Map.sChemicalPlant_GT.add(i); + } + } + + @Override + public boolean isFacingValid(final byte aFacing) { + return aFacing > 1; + } + + @Override + public int getMaxParallelRecipes() { + return 2 * getPipeCasingTier(); + } + + @Override + public int getEuDiscountForParallelism() { + return 100; + } + + private int getSolidCasingTier() { + return this.mSolidCasingTier; + } + + 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; + int aCasingID = getCasingTextureIdForTier(aTier); + return aCasingID; + } + + 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; + } + } + + @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); + } + + @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"); + } + + private static boolean isBlockSolidCasing(int aCurrentTier, Block aBlock, int aMeta) { + if (aBlock == null || (aMeta < 0 || aMeta > 16)) { + return false; + } + Block aTieredCasing = ModBlocks.blockCasings5Misc; + int aTieredMeta = 3; + if (aBlock == aTieredCasing && aMeta == aTieredMeta) { + 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; + } + } + + private static AutoMap<Integer> mValidCoilMetaCache; + + private static boolean isBlockCoil(Block aBlock, int aMeta) { + Block aCasingBlock; + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + aCasingBlock = StaticFields59.getBlockCasings5(); + } + else { + 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; + + Logger.INFO("Checking ChemPlant Structure"); + + // Require Air above controller + boolean aAirCheck = aBaseMetaTileEntity.getAirOffset(0, 1, 0); + + 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 (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + this.mCoilTier = (aCurrentCoilMeta+1); + } + 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 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++; + } + } + } + } + } + } + + 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; + } + + return tAmount; + } + + + public int checkSolidCasings(final IGregTechTileEntity aBaseMetaTileEntity, final ItemStack aStack, int aOffsetX, int aOffsetZ) { + + int tAmount = 0; + + // Only check a 7x7 + for (int i = -3; i < 4; i++) { + for (int j = -3; j < 4; j++) { + // If we are on the 7x7 ring, proceed + 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 { + if (aTileEntity != null) { + Logger.INFO("Adding "+aTileEntity.getInventoryName()); + } + 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_ElementalDuplicator) { + continue; + } + else { + Logger.INFO("Error counting Bottom Layer Casing Ring. Bad Tile Entity. Found "+aMetaTileEntity.getInventoryName()); + return tAmount; + } + } + } + else { + if (isBlockSolidCasing(mSolidCasingTier, aBlock, aMeta)) { + tAmount++; + } + else { + Logger.INFO("Error counting Bottom Layer Casing Ring. Found "+aBlock.getLocalizedName()+":"+aMeta); + return tAmount; + } + } + + } + } + + 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; + } + } + } + + return tAmount; + } + + public int getSolidCasingTierCheck(IGregTechTileEntity aBaseMetaTileEntity, int xDir, int zDir) { + Block aInitStructureCheck; + int aInitStructureCheckMeta; + if (xDir == 0) { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(zDir, 1, 0); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(zDir, 1, 0); + } + else { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 1, xDir); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, 1, xDir); + } + for (int aTier : mTieredBlockRegistry.keySet()) { + Triplet<Block, Integer, Integer> aData = mTieredBlockRegistry.get(aTier); + if (aData.getValue_1() == aInitStructureCheck && aData.getValue_2() == aInitStructureCheckMeta) { + return aTier; + } + } + return 0; + } + + @Override + public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_ElementalDataOrbHolder) { + log("Found GT_MetaTileEntity_Hatch_ElementalDataOrbHolder"); + return addToMachineListInternal(mDataHolders, aMetaTileEntity, aBaseCasingIndex); + } + return super.addToMachineList(aTileEntity, aBaseCasingIndex); + } + + public int getMachineCasingTierCheck(IGregTechTileEntity aBaseMetaTileEntity, int xDir, int zDir) { + return 10; + } + + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public int getAmountOfOutputs() { + return 1; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + 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) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mDataHolders.clear(); + } + } + // Silly Client Syncing + if (aBaseMetaTileEntity.isClientSide()) { + if (this != null && this.getBaseMetaTileEntity() != null && this.getBaseMetaTileEntity().getWorld() != null) { + this.mSolidCasingTier = getCasingTierOnClientSide(); + markDirty(); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + } + + @Override + 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)"); + + // checks if it has a catalyst with enough durability + ItemStack tCatalystRecipe = findCatalyst(aItemInputs); + if (tCatalystRecipe == null) { + log("does not have catalyst"); + 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"); + return false; + } + + // checks if it has enough catalyst durabilety + ArrayList<ItemStack>tCatalysts = null; + int tMaxParrallelCatalyst = aMaxParallelRecipes; + if (tCatalystRecipe != null) { + tCatalysts = new ArrayList<ItemStack>(); + tMaxParrallelCatalyst = getCatalysts(aItemInputs, tCatalystRecipe, aMaxParallelRecipes, tCatalysts); + log("Can process "+tMaxParrallelCatalyst+" recipes. If less than "+aMaxParallelRecipes+", catalyst does not have enough durability."); + } + + if (tMaxParrallelCatalyst == 0) { + log("found not enough catalysts"); + 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; + } + + // -- 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); + + this.mEUt = (int)Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 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 *= parallelRecipes; + } + } + + // 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; + } + } + + // 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 < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + + 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); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + + // 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()]); + + // Damage catalyst once all is said and done. + if (tCatalystRecipe != null) { + log("damaging catalyst"); + damageCatalyst(tCatalystRecipe, parallelRecipes); + } + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + } + + private int getCatalysts(ItemStack[] aItemInputs, ItemStack aRecipeCatalyst, int aMaxParrallel, ArrayList<ItemStack> aOutPut) { + int allowedParrallel = 0; + for (final ItemStack aInput : aItemInputs) { + if (aRecipeCatalyst.isItemEqual(aInput)) { + int aDurabilityRemaining = getMaxCatalystDurability() - getDamage(aInput); + return Math.min(aMaxParrallel, aDurabilityRemaining); + } + } + return allowedParrallel; + } + + private ItemStack findCatalyst(ItemStack[] aItemInputs) { + if (aItemInputs != null) { + for (final ItemStack aInput : aItemInputs) { + if (aInput != null) { + if (ItemUtils.isCatalyst(aInput)) { + return aInput; + } + } + } + } + return null; + } + + + private void damageCatalyst(ItemStack aStack, int parallelRecipes) { + for (int i=0; i<parallelRecipes; i++){ + 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"); + addOutput(CI.getEmptyCatalyst(1)); + aStack = null; + } + else { + log("damaging catalyst"); + setDamage(aStack, damage); + } + } + else { + log("not consuming catalyst"); + } + } + + + + } + + private int getDamage(ItemStack aStack) { + return ItemGenericChemBase.getCatalystDamage(aStack); + } + + private void setDamage(ItemStack aStack,int aAmount) { + ItemGenericChemBase.setCatalystDamage(aStack, aAmount); + } + + + + @SideOnly(Side.CLIENT) + private final int getCasingTierOnClientSide() { + + if (this == null || this.getBaseMetaTileEntity().getWorld() == null) { + return 0; + } + 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, 1, 0); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(zDir, 1, 0); + } + else { + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 1, xDir); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, 1, xDir); + } + for (int aTier : mTieredBlockRegistry.keySet()) { + Triplet<Block, Integer, Integer> aData = mTieredBlockRegistry.get(aTier); + if (aData.getValue_1() == aInitStructureCheck && aData.getValue_2() == aInitStructureCheckMeta) { + return aTier; + } + } + return 0; + } + catch (Throwable t) { + t.printStackTrace(); + return 0; + } + + } + + + + /* + * Catalyst Handling + */ + + + + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> tItems = super.getStoredInputs(); + for (GT_MetaTileEntity_Hatch_ElementalDataOrbHolder tHatch : mDataHolders) { + tHatch.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tHatch)) { + ArrayList<ItemStack> aTempList = new ArrayList(); + for (ItemStack s : tHatch.mInventory) { + aTempList.add(s); + } + tItems.addAll(aTempList); + } + } + return tItems; + } + + + + + +} diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java index 4a508f2f0f..d60e248ac1 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java @@ -1,10 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import static gregtech.api.enums.GT_Values.E; -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; - -import java.util.HashSet; - import gregtech.api.enums.TAE; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; @@ -12,8 +7,7 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.CustomRecipeMap; -import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GTPP_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.ModBlocks; @@ -72,16 +66,9 @@ public class GregtechMetaTileEntity_Refinery extends GregtechMeta_MultiBlockBase return "MatterFabricator"; } - private static final GT_Recipe_Map mGregTypeRecipeMap = new GT_Recipe_Map(new HashSet<GT_Recipe>(), "internal.recipe.fissionfuel", "Nuclear Fuel Processing", null, RES_PATH_GUI + "basicmachines/FissionFuel", 0, 0, 0, 4, 1, E, 1, E, true, false); - @Override public GT_Recipe_Map getRecipeMap() { - if (mGregTypeRecipeMap.mRecipeList.size() <= 0) { - for (GT_Recipe g : CustomRecipeMap.sFissionFuelProcessing.mRecipeList) { - mGregTypeRecipeMap.mRecipeList.add(g); - } - } - return mGregTypeRecipeMap; + return GTPP_Recipe.GTPP_Recipe_Map.sFissionFuelProcessing; } @Override @@ -255,7 +242,7 @@ public class GregtechMetaTileEntity_Refinery extends GregtechMeta_MultiBlockBase Logger.INFO("Your Muffler must be AT LEAST ZPM tier or higher."); } } - Logger.INFO("Fission Fuel Production Plant Formed. "+mGregTypeRecipeMap.mRecipeList.size()); + Logger.INFO("Fission Fuel Production Plant Formed. "+this.getRecipeMap().mRecipeList.size()); this.resetRecipeMapForAllInputHatches(this.getRecipeMap()); return true; } 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 823edbedcc..093075f395 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 @@ -3,6 +3,7 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.c 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; @@ -16,11 +17,12 @@ 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.GTPP_Recipe; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import gregtech.api.util.GTPP_Recipe; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.data.Triplet; import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.recipe.common.CI; @@ -32,6 +34,7 @@ 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.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; @@ -45,7 +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); } @@ -54,6 +59,39 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { super(aName); } + public static boolean registerMachineCasingForTier(int aTier, Block aBlock, int aMeta, int aCasingTextureID) { + int aSize = mTieredBlockRegistry.size(); + int aSize2 = aSize; + Triplet<Block, Integer, Integer> aCasingData = new Triplet<Block, Integer, Integer>(aBlock, aMeta, aCasingTextureID); + if (mTieredBlockRegistry.containsKey(aTier)) { + CORE.crash("Tried to register a Machine casing for tier "+aTier+" to the Chemical Plant, however this tier already contains one."); + } + mTieredBlockRegistry.put(aTier, aCasingData); + aSize = mTieredBlockRegistry.size(); + return aSize > aSize2; + } + + private static Block getBlockForTier(int aTier) { + if (!mTieredBlockRegistry.containsKey(aTier)) { + return Blocks.bedrock; + } + return mTieredBlockRegistry.get(aTier).getValue_1(); + } + private static int getMetaForTier(int aTier) { + if (!mTieredBlockRegistry.containsKey(aTier)) { + return 32; + } + return mTieredBlockRegistry.get(aTier).getValue_2(); + } + private static int getCasingTextureIdForTier(int aTier) { + if (!mTieredBlockRegistry.containsKey(aTier)) { + return 10; + } + int aCasingID = mTieredBlockRegistry.get(aTier).getValue_3(); + //Logger.INFO("Found casing texture ID "+aCasingID+" for tier "+aTier); + return aCasingID; + } + @Override public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { return new GregtechMTE_ChemicalPlant(this.mName); @@ -69,28 +107,8 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { return new String[] { "Controller Block for the Chemical Plant", "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", - "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", + "Please read to user manual for more information on construction & usage", + TAG_HIDE_MAINT }; } @@ -108,24 +126,8 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { 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]; - } + int aCasingID = getCasingTextureID(); + aOriginalTexture = Textures.BlockIcons.CASING_BLOCKS[aCasingID]; if (aSide == aFacing) { return new ITexture[]{aOriginalTexture, new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)}; @@ -135,11 +137,14 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { @Override public boolean hasSlotInGUI() { - return false; + return true; } @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; } @@ -165,7 +170,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { } private int getSolidCasingTier() { - return mSolidCasingTier; + return this.mSolidCasingTier; } private int getMachineCasingTier() { @@ -180,23 +185,9 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { private int getCasingTextureID() { // Check the Tier Client Side - int aTier = mSolidCasingTier; - - 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 aTier = mSolidCasingTier; + int aCasingID = getCasingTextureIdForTier(aTier); + return aCasingID; } public boolean addToMachineList(IGregTechTileEntity aTileEntity) { @@ -206,7 +197,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { GT_MetaTileEntity_TieredMachineBlock aMachineBlock = (GT_MetaTileEntity_TieredMachineBlock) aMetaTileEntity; int aTileTier = aMachineBlock.mTier; if (aTileTier > aMaxTier) { - Logger.INFO("Hatch tier too high."); + log("Hatch tier too high."); return false; } else { @@ -214,7 +205,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { } } else { - Logger.INFO("Bad Tile Entity being added to hatch map."); // Shouldn't ever happen, but.. ya know.. + log("Bad Tile Entity being added to hatch map."); // Shouldn't ever happen, but.. ya know.. return false; } } @@ -237,21 +228,15 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { mCoilTier = aNBT.getInteger("mCoilTier"); } - private static boolean isBlockSolidCasing(Block aBlock, int aMeta) { - if (aBlock == null) { + private static boolean isBlockSolidCasing(int aCurrentTier, Block aBlock, int aMeta) { + if (aBlock == null || (aMeta < 0 || aMeta > 16)) { return false; } - if (aBlock == GregTech_API.sBlockCasings2 && aMeta == 0) { + Block aTieredCasing = getBlockForTier(aCurrentTier); + int aTieredMeta = getMetaForTier(aCurrentTier); + if (aBlock == aTieredCasing && aMeta == aTieredMeta) { 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) { @@ -272,8 +257,8 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { Block aCasingBlock2 = GregTech_API.sBlockCasings2; if (aBlock == aCasingBlock2) { int aMetaBronzePipeCasing = 12; - int aMetaSteelPipeCasing = 13; - int aMetaTitaniumPipeCasing = 14; + //int aMetaSteelPipeCasing = 13; + //int aMetaTitaniumPipeCasing = 14; int aMetaTungstenPipeCasing = 15; if (aMeta > aMetaTungstenPipeCasing || aMeta < aMetaBronzePipeCasing) { return false; @@ -328,14 +313,13 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 3; int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 3; - int tAmount = 0; - Logger.INFO("Checking ChemPlant Structure"); + log("Checking ChemPlant Structure"); // Require Air above controller boolean aAirCheck = aBaseMetaTileEntity.getAirOffset(0, 1, 0); if (!aAirCheck) { - Logger.INFO("No Air Above Controller"); + log("No Air Above Controller"); return false; } else { @@ -344,7 +328,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { mSolidCasingTier = getSolidCasingTierCheck(aBaseMetaTileEntity, xDir, zDir); mMachineCasingTier = getMachineCasingTierCheck(aBaseMetaTileEntity, xDir, zDir); - Logger.INFO("Initial Casing Check Complete, Solid Casing Tier: "+mSolidCasingTier+", Machine Casing Tier: "+mMachineCasingTier); + log("Initial Casing Check Complete, Solid Casing Tier: "+mSolidCasingTier+", Machine Casing Tier: "+mMachineCasingTier); int aSolidCasingCount = 0; int aMachineCasingCount = 0; @@ -356,14 +340,14 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { 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); + log("Casing Counts: "); + log("Solid: "+aSolidCasingCount+", Machine: "+aMachineCasingCount); + log("Pipe: "+aPipeCount+", Coil: "+aCoilCount); - Logger.INFO("Casing Tiers: "); - Logger.INFO("Solid: "+getSolidCasingTier()+", Machine: "+getMachineCasingTier()); - Logger.INFO("Pipe: "+getPipeCasingTier()+", Coil: "+getCoilTier()); + log("Casing Tiers: "); + log("Solid: "+getSolidCasingTier()+", Machine: "+getMachineCasingTier()); + log("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()); @@ -372,23 +356,27 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { // Minimum 80/93 Solid Casings if (aSolidCasingCount < 80) { - Logger.INFO("Not enough solid casings. Found "+aSolidCasingCount+", require: 80."); + log("Not enough solid casings. Found "+aSolidCasingCount+", require: 80."); return false; } if (aMachineCasingCount != 57) { - Logger.INFO("Not enough machine casings. Found "+aMachineCasingCount+", require: 57."); + log("Not enough machine casings. Found "+aMachineCasingCount+", require: 57."); return false; } if (aPipeCount != 18) { - Logger.INFO("Not enough pipe casings. Found "+aPipeCount+", require: 18."); + log("Not enough pipe casings. Found "+aPipeCount+", require: 18."); return false; } if (aCoilCount != 27) { - Logger.INFO("Not enough coils. Found "+aCoilCount+", require: 27."); + log("Not enough coils. Found "+aCoilCount+", require: 27."); return false; } + /*if (mCatalystBuses.size() != 1) { + log("A Catalyst Bus is Required."); + return false; + }*/ - Logger.INFO("Structure Check Complete!"); + log("Structure Check Complete!"); return true; } @@ -508,7 +496,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { else { final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); if (aMetaTileEntity == null) { - Logger.INFO("Error counting Bottom Layer Casing Ring. Bad Tile Entity. Found "+aTileEntity.getInventoryName()); + log("Error counting Bottom Layer Casing Ring. Bad Tile Entity. Found "+aTileEntity.getInventoryName()); return tAmount; } //Handle controller @@ -516,17 +504,17 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { continue; } else { - Logger.INFO("Error counting Bottom Layer Casing Ring. Bad Tile Entity. Found "+aMetaTileEntity.getInventoryName()); + log("Error counting Bottom Layer Casing Ring. Bad Tile Entity. Found "+aMetaTileEntity.getInventoryName()); return tAmount; } } } else { - if (isBlockSolidCasing(aBlock, aMeta)) { + if (isBlockSolidCasing(mSolidCasingTier, aBlock, aMeta)) { tAmount++; } else { - Logger.INFO("Error counting Bottom Layer Casing Ring. Found "+aBlock.getLocalizedName()+":"+aMeta); + log("Error counting Bottom Layer Casing Ring. Found "+aBlock.getLocalizedName()+":"+aMeta); return tAmount; } } @@ -558,11 +546,11 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { } Block aBlock = aBaseMetaTileEntity.getBlockOffset(aOffsetX + i, r, aOffsetZ + j); int aMeta = aBaseMetaTileEntity.getMetaIDOffset(aOffsetX + i, r, aOffsetZ + j); - if (isBlockSolidCasing(aBlock, aMeta)) { + if (isBlockSolidCasing(mSolidCasingTier, aBlock, aMeta)) { tAmount++; } else { - Logger.INFO("Error counting Pillars. Found "+ItemUtils.getLocalizedNameOfBlock(aBlock, aMeta)); + log("Error counting Pillars. Found "+ItemUtils.getLocalizedNameOfBlock(aBlock, aMeta)); return tAmount; } } @@ -574,11 +562,11 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { 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)) { + if (isBlockSolidCasing(mSolidCasingTier, aBlock, aMeta)) { tAmount++; } else { - Logger.INFO("Error counting Top Layer casings. Found "+ItemUtils.getLocalizedNameOfBlock(aBlock, aMeta)); + log("Error counting Top Layer casings. Found "+ItemUtils.getLocalizedNameOfBlock(aBlock, aMeta)); return tAmount; } } @@ -644,26 +632,12 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { else { aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 1, xDir); aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, 1, 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; - } + } + for (int aTier : mTieredBlockRegistry.keySet()) { + Triplet<Block, Integer, Integer> aData = mTieredBlockRegistry.get(aTier); + if (aData.getValue_1() == aInitStructureCheck && aData.getValue_2() == aInitStructureCheckMeta) { + return aTier; + } } return 0; } @@ -684,7 +658,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { public int getMachineCasingTierCheck(IGregTechTileEntity aBaseMetaTileEntity, int xDir, int zDir) { Block aInitStructureCheck; int aInitStructureCheckMeta; - Logger.INFO(""+xDir+", "+zDir); + log(""+xDir+", "+zDir); if (xDir == 0) { if (zDir > 0) { aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 0, 1); @@ -694,7 +668,6 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 0, -1); aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, 0, -1); } - } else { if (xDir > 0) { @@ -706,9 +679,8 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(-1, 0, 0); } } - if (isBlockMachineCasing(aInitStructureCheck, aInitStructureCheckMeta)) { - Logger.INFO("Using Meta "+aInitStructureCheckMeta); + log("Using Meta "+aInitStructureCheckMeta); return aInitStructureCheckMeta; } return 0; @@ -758,7 +730,10 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { } // Silly Client Syncing if (aBaseMetaTileEntity.isClientSide()) { - this.mSolidCasingTier = getCasingTierOnClientSide(); + if (this != null && this.getBaseMetaTileEntity() != null && this.getBaseMetaTileEntity().getWorld() != null) { + this.mSolidCasingTier = getCasingTierOnClientSide(); + markDirty(); + } } super.onPostTick(aBaseMetaTileEntity, aTick); } @@ -793,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"); @@ -961,7 +949,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { log("damaging catalyst"); damageCatalyst(tCatalystRecipe, parallelRecipes); } - + // Commit outputs this.mOutputItems = tOutputItems; this.mOutputFluids = tOutputFluids; @@ -974,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) { @@ -1018,8 +1159,8 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { log("not consuming catalyst"); } } - - + + } @@ -1053,25 +1194,11 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase { aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(0, 1, xDir); aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(0, 1, 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; - } + for (int aTier : mTieredBlockRegistry.keySet()) { + Triplet<Block, Integer, Integer> aData = mTieredBlockRegistry.get(aTier); + if (aData.getValue_1() == aInitStructureCheck && aData.getValue_2() == aInitStructureCheckMeta) { + return aTier; + } } return 0; } @@ -1087,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/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java index 3eabcf517e..6619bc1253 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -19,6 +19,7 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.NBTUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.preloader.asm.AsmConfig; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_PowerSubStation; @@ -36,7 +37,7 @@ import net.minecraftforge.common.util.ForgeDirection; public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMeta_MultiBlockBase { - protected int mAverageEuUsage = 0; + protected long mAverageEuUsage = 0; protected long mTotalEnergyAdded = 0; protected long mTotalEnergyConsumed = 0; protected long mTotalEnergyLost = 0; @@ -366,7 +367,7 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe //mTotalEnergyAdded @Override public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mAverageEuUsage", this.mAverageEuUsage); + aNBT.setLong("mAverageEuUsage", this.mAverageEuUsage); //Usage Stats aNBT.setLong("mTotalEnergyAdded", this.mTotalEnergyAdded); @@ -380,7 +381,17 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe @Override public void loadNBTData(NBTTagCompound aNBT) { - this.mAverageEuUsage = aNBT.getInteger("mAverageEuUsage"); + + // Best not to get a long if the Tag Map is holding an int + if (aNBT.hasKey("mAverageEuUsage")) { + if (NBTUtils.isTagInteger(aNBT, "mAverageEuUsage")) { + int aAverageTag = aNBT.getInteger("mAverageEuUsage"); + this.mAverageEuUsage = aAverageTag; + } + else { + this.mAverageEuUsage = aNBT.getLong("mAverageEuUsage"); + } + } //Usage Stats this.mTotalEnergyAdded = aNBT.getLong("mTotalEnergyAdded"); @@ -421,7 +432,9 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe long stored = aHatch.getEUVar(); long voltage = aHatch.maxEUInput() * aHatch.maxAmperesIn(); - if (voltage > stored) return; + if (voltage > stored) { + return; + } if (this.getBaseMetaTileEntity().increaseStoredEnergyUnits(voltage, false)) { aHatch.setEUVar((stored - voltage)); @@ -449,7 +462,7 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe // Increase tax up to 2x if machine is not fully repaired mTax = mTax * (1f + (10000f - mEfficiency) / 10000f); - return MathUtils.roundToClosestInt(mTax); + return MathUtils.roundToClosestLong(mTax); } |