diff options
author | Yang Xizhi <60341015+GlodBlock@users.noreply.github.com> | 2022-11-20 21:02:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-20 14:02:03 +0100 |
commit | 35ef004e284c7413c34e7d473dfd8a6e924fcab4 (patch) | |
tree | 2d44b22cba8552760a9b72745c4670485bc69d55 /src/main/java | |
parent | 721566601dbaf990c1a3d7cabf59d056e8a5b157 (diff) | |
download | GT5-Unofficial-35ef004e284c7413c34e7d473dfd8a6e924fcab4.tar.gz GT5-Unofficial-35ef004e284c7413c34e7d473dfd8a6e924fcab4.tar.bz2 GT5-Unofficial-35ef004e284c7413c34e7d473dfd8a6e924fcab4.zip |
add the multiblock base that supports power usage as long value (#1521)
* add multiblock base supports long power usage
* e
* fix type
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ExtendedPowerMultiBlockBase.java | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ExtendedPowerMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ExtendedPowerMultiBlockBase.java new file mode 100644 index 0000000000..6d22622797 --- /dev/null +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ExtendedPowerMultiBlockBase.java @@ -0,0 +1,89 @@ +package gregtech.api.metatileentity.implementations; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +/** + * Multiblock base class that allows machine to use power over int. + */ +public abstract class GT_MetaTileEntity_ExtendedPowerMultiBlockBase< + T extends GT_MetaTileEntity_EnhancedMultiBlockBase<T>> + extends GT_MetaTileEntity_EnhancedMultiBlockBase<T> { + + public long lEUt; + + protected GT_MetaTileEntity_ExtendedPowerMultiBlockBase(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + protected GT_MetaTileEntity_ExtendedPowerMultiBlockBase(String aName) { + super(aName); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + // NBT can be loaded as any primitive type, so we can load it as long. + this.lEUt = aNBT.getLong("mEUt"); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setLong("mEUt", this.lEUt); + } + + @Override + protected void calculateOverclockedNessMultiInternal( + int aEUt, int aDuration, int mAmperage, long maxInputVoltage, boolean perfectOC) { + // 5% space for cable loss + long zMaxInputVoltage = maxInputVoltage / 100L * 95L; + long zTime = aDuration; + long zEUt = aEUt; + while (zEUt < zMaxInputVoltage) { + zEUt = zEUt << 2; + zTime = zTime >> (perfectOC ? 2 : 1); + if (zTime <= 0) { + break; + } + } + if (zTime <= 0) { + zTime = 1; + } + if (zEUt > zMaxInputVoltage) { + zEUt = zEUt >> 2; + zTime = zTime << (perfectOC ? 2 : 1); + } + if (zTime > Integer.MAX_VALUE - 1) { + zTime = Integer.MAX_VALUE - 1; + } + this.lEUt = zEUt; + this.mMaxProgresstime = (int) zTime; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.lEUt > 0) { + addEnergyOutput((this.lEUt * mEfficiency) / 10000); + return true; + } + if (this.lEUt < 0) { + if (!drainEnergyInput(getActualEnergyUsage())) { + criticalStopMachine(); + return false; + } + } + return true; + } + + @Override + public void stopMachine() { + this.lEUt = 0; + super.stopMachine(); + } + + @Override + protected long getActualEnergyUsage() { + return (-this.lEUt * 10000) / Math.max(1000, mEfficiency); + } +} |