From 741e8427a9f4e9bee4768e44fa88df832e825e95 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 13 Jan 2020 17:58:06 +0000 Subject: + Added support for TecTech Multi-Amp Energy Hatches. Closes #565. $ Fixed COMET behaving like a Fusion Reactor. No more weird power usage/output. --- .../api/helpers/GregtechPlusPlus_API.java | 6 +- .../base/GregtechMeta_MultiBlockBase.java | 82 ++++++++++++-- .../GregtechMetaTileEntity_Cyclotron.java | 123 +-------------------- ...chMetaTileEntity_PowerSubStationController.java | 52 ++++++--- 4 files changed, 114 insertions(+), 149 deletions(-) (limited to 'src/Java') diff --git a/src/Java/gtPlusPlus/api/helpers/GregtechPlusPlus_API.java b/src/Java/gtPlusPlus/api/helpers/GregtechPlusPlus_API.java index 3acca269d7..fb1258f6d2 100644 --- a/src/Java/gtPlusPlus/api/helpers/GregtechPlusPlus_API.java +++ b/src/Java/gtPlusPlus/api/helpers/GregtechPlusPlus_API.java @@ -14,11 +14,7 @@ public class GregtechPlusPlus_API { public static class Multiblock_API { - private static final HashMap mSpecialBehaviourItemMap; - - static { - mSpecialBehaviourItemMap = new HashMap(); - } + private static final HashMap mSpecialBehaviourItemMap = new HashMap(); /** * Register a special behaviour for GT++ Multis to listen use. diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java index f41efe602a..50c3c42600 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -99,9 +99,8 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult try { calculatePollutionReduction = GT_MetaTileEntity_Hatch_Muffler.class.getDeclaredMethod("calculatePollutionReduction", int.class); - } catch (NoSuchMethodException | SecurityException e) {} - - mCustomBehviours = new HashMap(); + } + catch (NoSuchMethodException | SecurityException e) {} } @@ -121,7 +120,7 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult public ArrayList mDischargeHatches = new ArrayList(); // Custom Behaviour Map - private static final HashMap mCustomBehviours; + private static final HashMap mCustomBehviours = new HashMap();; public GregtechMeta_MultiBlockBase(final int aID, final String aName, @@ -1034,7 +1033,7 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult */ // First populate the map if we need to. - if (mCustomBehviours == null || mCustomBehviours.isEmpty()) { + if (mCustomBehviours.isEmpty()) { mCustomBehviours.putAll(Multiblock_API.getSpecialBehaviourItemMap()); } @@ -1553,7 +1552,8 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult this.mDischargeHatches.clear(); this.mControlCoreBus.clear(); this.mAirIntakes.clear(); - this.mMultiDynamoHatches.clear(); + this.mTecTechEnergyHatches.clear(); + this.mTecTechDynamoHatches.clear(); } } @@ -1578,7 +1578,14 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult tTileEntity = localIterator.next(); } tTileEntity = null; - for (final Iterator localIterator = this.mMultiDynamoHatches + for (final Iterator localIterator = this.mTecTechDynamoHatches + .iterator(); localIterator.hasNext(); tTileEntity + .getBaseMetaTileEntity() + .doExplosion(gregtech.api.enums.GT_Values.V[8])) { + tTileEntity = localIterator.next(); + } + tTileEntity = null; + for (final Iterator localIterator = this.mTecTechEnergyHatches .iterator(); localIterator.hasNext(); tTileEntity .getBaseMetaTileEntity() .doExplosion(gregtech.api.enums.GT_Values.V[8])) { @@ -1873,7 +1880,7 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult //Handle TT Multi-A Dynamos else if (LoadedMods.TecTech && isThisHatchMultiDynamo(aMetaTileEntity)) { log("Found isThisHatchMultiDynamo"); - aDidAdd = addToMachineListInternal(mMultiDynamoHatches, aMetaTileEntity, aBaseCasingIndex); + aDidAdd = addToMachineListInternal(mTecTechDynamoHatches, aMetaTileEntity, aBaseCasingIndex); } //Handle Fluid Hatches using seperate logic @@ -2126,10 +2133,16 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult /** - * This is the array Used to Store the Tectech Multi-Amp hatches. + * This is the array Used to Store the Tectech Multi-Amp Dynamo hatches. + */ + + public ArrayList mTecTechDynamoHatches = new ArrayList(); + + /** + * This is the array Used to Store the Tectech Multi-Amp Energy hatches. */ - public ArrayList mMultiDynamoHatches = new ArrayList(); + public ArrayList mTecTechEnergyHatches = new ArrayList(); /** * TecTech Multi-Amp Dynamo Support @@ -2149,12 +2162,11 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult } if (isThisHatchMultiDynamo(aTileEntity)) { updateTexture(aTileEntity, aBaseCasingIndex); - return this.mMultiDynamoHatches.add((GT_MetaTileEntity_Hatch) aMetaTileEntity); + return this.mTecTechDynamoHatches.add((GT_MetaTileEntity_Hatch) aMetaTileEntity); } return false; } - @SuppressWarnings("rawtypes") public boolean isThisHatchMultiDynamo(Object aMetaTileEntity){ Class mDynamoClass; mDynamoClass = ReflectionUtils.getClass("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti"); @@ -2176,6 +2188,52 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult } return super.addDynamoToMachineList(aTileEntity, aBaseCasingIndex); } + + + /** + * TecTech Multi-Amp Energy Hatch Support + * @param aTileEntity - The Energy Hatch + * @param aBaseCasingIndex - Casing Texture + * @return + */ + + public boolean addMultiAmpEnergyToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex){ + //GT_MetaTileEntity_Hatch_DynamoMulti + if (aTileEntity == null) { + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (isThisHatchMultiEnergy(aTileEntity)) { + updateTexture(aTileEntity, aBaseCasingIndex); + return this.mTecTechEnergyHatches.add((GT_MetaTileEntity_Hatch) aMetaTileEntity); + } + return false; + } + + public boolean isThisHatchMultiEnergy(Object aMetaTileEntity){ + Class mDynamoClass; + mDynamoClass = ReflectionUtils.getClass("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti"); + if (mDynamoClass != null){ + if (mDynamoClass.isInstance(aMetaTileEntity)){ + return true; + } + } + return false; + } + + @Override + public boolean addEnergyInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (LoadedMods.TecTech){ + if (isThisHatchMultiDynamo(aTileEntity)) { + addMultiAmpDynamoToMachineList(aTileEntity, aBaseCasingIndex); + } + + } + return super.addEnergyInputToMachineList(aTileEntity, aBaseCasingIndex); + } /** diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java index ed6c913e6b..6070e3604a 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java @@ -2,7 +2,6 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; import java.util.ArrayList; -import gregtech.GT_Mod; import gregtech.api.enums.Dyes; import gregtech.api.enums.TAE; import gregtech.api.enums.Textures; @@ -10,7 +9,6 @@ import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; @@ -25,7 +23,6 @@ import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.item.chemistry.IonParticles; import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import net.minecraft.block.Block; @@ -37,8 +34,6 @@ import net.minecraftforge.fluids.FluidStack; public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBase { - public long mEUStore; - public GregtechMetaTileEntity_Cyclotron(int aID, String aName, String aNameRegional, int tier) { super(aID, aName, aNameRegional); } @@ -95,13 +90,11 @@ public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBas @Override public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setLong("mEUStore", mEUStore); super.saveNBTData(aNBT); } @Override public void loadNBTData(NBTTagCompound aNBT) { - mEUStore = aNBT.getLong("mEUStore"); super.loadNBTData(aNBT); } @@ -394,113 +387,6 @@ public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBas return 0; } - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (aBaseMetaTileEntity.isServerSide()) { - if (mEfficiency < 0) - mEfficiency = 0; - - //Time Counter - this.mTotalRunTime++; - this.fixAllMaintenanceIssue(); - - onRunningTick(null); - - boolean aFormCheck = (aTick % 100 == 0 ? checkMultiblock(aBaseMetaTileEntity, mInventory[1]) : true); - - - - if (mRunningOnLoad && aFormCheck) { - this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); - checkRecipe(mInventory[1]); - } - if (--mUpdate == 0 || --mStartUpCheck == 0) { - mInputHatches.clear(); - mInputBusses.clear(); - mOutputHatches.clear(); - mOutputBusses.clear(); - mDynamoHatches.clear(); - mEnergyHatches.clear(); - mMufflerHatches.clear(); - mMaintenanceHatches.clear(); - mChargeHatches.clear(); - mDischargeHatches.clear(); - mControlCoreBus.clear(); - mAirIntakes.clear(); - mMultiDynamoHatches.clear(); - mMachine = aFormCheck; - } - if (mStartUpCheck < 0) { - if (mMachine) { - if (this.mEnergyHatches != null) { - for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) - if (isValidMetaTileEntity(tHatch)) { - if (aBaseMetaTileEntity.getStoredEU() + (2048*4) < maxEUStore() - && tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits((2048*4), false)) { - aBaseMetaTileEntity.increaseStoredEnergyUnits((2048*4), true); - } - } - } - if (this.mEUStore <= 0 && mMaxProgresstime > 0) { - stopMachine(); - } - if (getRepairStatus() > 0) { - if (mMaxProgresstime > 0) { - this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(mEUt, true); - if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime) { - if (mOutputItems != null) - for (ItemStack tStack : mOutputItems) if (tStack != null) addOutput(tStack); - if (mOutputFluids != null) - for (FluidStack tStack : mOutputFluids) if (tStack != null) addOutput(tStack); - mEfficiency = Math.max(0, Math.min(mEfficiency + mEfficiencyIncrease, getMaxEfficiency(mInventory[1]) - ((getIdealStatus() - getRepairStatus()) * 1000))); - mOutputItems = null; - mProgresstime = 0; - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; - if (mOutputFluids != null && mOutputFluids.length > 0) { - try { - GT_Mod.instance.achievements.issueAchivementHatchFluid(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), mOutputFluids[0]); - } catch (Exception e) { - } - } - this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); - if (aBaseMetaTileEntity.isAllowedToWork()) - checkRecipe(mInventory[1]); - } - } else { - if (aTick % 100 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified()) { - turnCasingActive(mMaxProgresstime > 0); - if (aBaseMetaTileEntity.isAllowedToWork()) { - this.mEUStore = (int) aBaseMetaTileEntity.getStoredEU(); - if (checkRecipe(mInventory[1])) { - if (this.mEUStore < this.mLastRecipe.mSpecialValue) { - mMaxProgresstime = 0; - turnCasingActive(false); - } - aBaseMetaTileEntity.decreaseStoredEnergyUnits(this.mLastRecipe.mSpecialValue, true); - } - } - if (mMaxProgresstime <= 0) - mEfficiency = Math.max(0, mEfficiency - 1000); - } - } - } else { - this.mLastRecipe = null; - stopMachine(); - } - } else { - turnCasingActive(false); - this.mLastRecipe = null; - stopMachine(); - } - } - //doRandomMaintenanceDamage(); - aBaseMetaTileEntity.setErrorDisplayID((aBaseMetaTileEntity.getErrorDisplayID() & ~127) | (mWrench ? 0 : 1) | (mScrewdriver ? 0 : 2) | (mSoftHammer ? 0 : 4) | (mHardHammer ? 0 : 8) - | (mSolderingTool ? 0 : 16) | (mCrowbar ? 0 : 32) | (mMachine ? 0 : 64)); - aBaseMetaTileEntity.setActive(mMaxProgresstime > 0); - } - } - @Override public boolean onRunningTick(ItemStack aStack) { if (this.mOutputBusses.size() > 0) { @@ -529,10 +415,9 @@ public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBas } } } - } - PollutionUtils.addPollution(getBaseMetaTileEntity(), this.getPollutionPerTick(aStack)); - - return true; + } + this.fixAllMaintenanceIssue(); + return super.onRunningTick(aStack); } @@ -570,7 +455,7 @@ public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBas return new String[]{ "COMET - Compact Cyclotron MK "+tier, "EU Required: "+powerRequired+"EU/t", - "Stored EU: "+mEUStore+" / "+maxEUStore()}; + "Stored EU: "+this.getEUVar()+" / "+maxEUStore()}; } @Override 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 7300b3507b..666b7980ec 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 @@ -47,6 +47,7 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe private final int ENERGY_TAX = 2; //TecTech Support + public ArrayList mAllEnergyHatches = new ArrayList(); public ArrayList mAllDynamoHatches = new ArrayList(); public GregtechMetaTileEntity_PowerSubStationController(final int aID, final String aName, final String aNameRegional) { @@ -138,12 +139,26 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 7) { return 8; } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 8) { - return CORE.GTNH ? GT_Values.V.length : 9; + return 9; } else { return -1; } } + public static int getMaxHatchTier(int aCellTier) { + switch(aCellTier) { + case 9: + return CORE.GTNH ? 15 : 9; + default: + if (aCellTier < 4) { + return 0; + } + else { + return aCellTier; + } + } + } + public static final int CELL_HEIGHT_MAX = 16; public static final int CELL_HEIGHT_MIN = 2; @@ -153,8 +168,11 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 2; final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 2; - this.mMultiDynamoHatches.clear(); - this.mAllDynamoHatches.clear(); + this.mTecTechDynamoHatches.clear(); + this.mAllDynamoHatches.clear(); + + this.mTecTechEnergyHatches.clear(); + this.mAllEnergyHatches.clear(); boolean tFoundCeiling = false; int tCasingCount = 0; @@ -249,7 +267,7 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe mAllDynamoHatches.addAll(this.mDynamoHatches); if (LoadedMods.TecTech) { - mAllDynamoHatches.addAll(this.mMultiDynamoHatches); + mAllDynamoHatches.addAll(this.mTecTechDynamoHatches); } @@ -257,7 +275,7 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe checkMachineProblem("Needed 1 maintenance hatch, found " + this.mMaintenanceHatches.size()); return false; } - if (this.mEnergyHatches.size() < 1) { + if (this.mAllEnergyHatches.size() < 1) { checkMachineProblem("Needed at least 1 energy hatch, found 0"); return false; } @@ -269,15 +287,17 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe // Find average EU throughput int totalEuThroughput = 0; int hatchCount = 0; + + int aMaxHatchTier = getMaxHatchTier(tOverallCellTier); - for (GT_MetaTileEntity_Hatch_Energy re : this.mEnergyHatches) { + for (GT_MetaTileEntity_Hatch re : this.mAllEnergyHatches) { long tier = re.getOutputTier(); - if(tier > tOverallCellTier) { - checkMachineProblem("Energy hatch (tier " + tier + ") is too strong for cells (tier " + tOverallCellTier + ")"); + if(tier > aMaxHatchTier) { + checkMachineProblem("Energy hatch (tier " + tier + ") is too strong for cells (tier " + aMaxHatchTier + ")"); return false; } if(tier < 3) { - checkMachineProblem("Energy hatch (tier " + tier + ") is too weak for cells (tier " + tOverallCellTier + ")"); + checkMachineProblem("Energy hatch (tier " + tier + ") is too weak for cells (tier " + aMaxHatchTier + ")"); return false; } totalEuThroughput += re.maxEUInput(); @@ -286,12 +306,12 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe for (GT_MetaTileEntity_Hatch re : this.mAllDynamoHatches) { long tier = re.getInputTier(); - if(tier > tOverallCellTier) { - checkMachineProblem("Dynamo hatch (tier " + tier + ") is too strong for cells (tier " + tOverallCellTier + ")"); + if(tier > aMaxHatchTier) { + checkMachineProblem("Dynamo hatch (tier " + tier + ") is too strong for cells (tier " + aMaxHatchTier + ")"); return false; } if(tier < 3) { - checkMachineProblem("Energy hatch (tier " + tier + ") is too weak for cells (tier " + tOverallCellTier + ")"); + checkMachineProblem("Energy hatch (tier " + tier + ") is too weak for cells (tier " + aMaxHatchTier + ")"); return false; } totalEuThroughput += re.maxEUOutput(); @@ -431,6 +451,12 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe return MathUtils.roundToClosestInt(mTax); } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + this.fixAllMaintenanceIssue(); + } + @Override public boolean onRunningTick(ItemStack aStack) { // First, decay overcharge (0.1% of stored energy plus 1000 EU per tick) @@ -448,7 +474,7 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe for (GT_MetaTileEntity_Hatch_OutputBattery tHatch : this.mDischargeHatches) { drawEnergyFromHatch(tHatch); } - for (GT_MetaTileEntity_Hatch_Energy tHatch : this.mEnergyHatches) { + for (GT_MetaTileEntity_Hatch tHatch : this.mAllEnergyHatches) { drawEnergyFromHatch(tHatch); } -- cgit