diff options
author | Yang Xizhi <60341015+GlodBlock@users.noreply.github.com> | 2022-10-18 03:07:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 21:07:37 +0200 |
commit | 8ceb4080ed410a59cf352f83fcc077e8a2bd93bd (patch) | |
tree | 28429d56ef7345e47041bd10d835631535040b40 /src | |
parent | 153f6ff61895729cc7441ee9d4c320ff35099bc0 (diff) | |
download | GT5-Unofficial-8ceb4080ed410a59cf352f83fcc077e8a2bd93bd.tar.gz GT5-Unofficial-8ceb4080ed410a59cf352f83fcc077e8a2bd93bd.tar.bz2 GT5-Unofficial-8ceb4080ed410a59cf352f83fcc077e8a2bd93bd.zip |
fix bunch of yottank issues (#94)
* yot tank/hatch fix
* dep
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/goodgenerator/blocks/tileEntity/GTMetaTileEntity/YOTTAHatch.java | 133 | ||||
-rw-r--r-- | src/main/java/goodgenerator/blocks/tileEntity/YottaFluidTank.java | 15 |
2 files changed, 110 insertions, 38 deletions
diff --git a/src/main/java/goodgenerator/blocks/tileEntity/GTMetaTileEntity/YOTTAHatch.java b/src/main/java/goodgenerator/blocks/tileEntity/GTMetaTileEntity/YOTTAHatch.java index 80571221e5..9d5f9feb40 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/GTMetaTileEntity/YOTTAHatch.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/GTMetaTileEntity/YOTTAHatch.java @@ -10,7 +10,10 @@ import appeng.api.networking.events.MENetworkStorageEvent; import appeng.api.networking.security.BaseActionSource; import appeng.api.networking.security.IActionHost; import appeng.api.networking.storage.IStorageGrid; -import appeng.api.storage.*; +import appeng.api.storage.ICellContainer; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IItemList; import appeng.api.util.AECableType; @@ -75,7 +78,9 @@ public class YOTTAHatch extends GT_MetaTileEntity_Hatch private YottaFluidTank host; private AENetworkProxy gridProxy = null; private int priority; - private byte ticksSinceUpdate; + private byte tickRate = 20; + private String lastFluid = ""; + private BigInteger lastAmt = BigInteger.ZERO; private AccessRestriction readMode = AccessRestriction.READ_WRITE; private final AccessRestriction[] AEModes = new AccessRestriction[] { AccessRestriction.NO_ACCESS, AccessRestriction.READ, AccessRestriction.WRITE, AccessRestriction.READ_WRITE @@ -181,10 +186,10 @@ public class YOTTAHatch extends GT_MetaTileEntity_Hatch if (host.mFluidName == null || host.mFluidName.equals("") || host.mStorageCurrent.compareTo(BigInteger.ZERO) <= 0) return out; - int ready; - if (host.mStorageCurrent.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { - ready = Integer.MAX_VALUE; - } else ready = host.mStorageCurrent.intValue(); + long ready; + if (host.mStorageCurrent.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) { + ready = Long.MAX_VALUE; + } else ready = host.mStorageCurrent.longValue(); out.add(FluidUtil.createAEFluidStack(FluidRegistry.getFluid(host.mFluidName), ready)); return out; } @@ -192,10 +197,9 @@ public class YOTTAHatch extends GT_MetaTileEntity_Hatch @Override @Optional.Method(modid = "appliedenergistics2") public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, BaseActionSource src) { - FluidStack rInput = input.getFluidStack(); - int amt = fill(null, rInput, false); - if (amt == rInput.amount) { - if (type.equals(Actionable.MODULATE)) fill(null, rInput, true); + long amt = fill(null, input, false); + if (amt == input.getStackSize()) { + if (type.equals(Actionable.MODULATE)) fill(null, input, true); return null; } return input; @@ -204,10 +208,10 @@ public class YOTTAHatch extends GT_MetaTileEntity_Hatch @Override @Optional.Method(modid = "appliedenergistics2") public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, BaseActionSource src) { - FluidStack ready = drain(null, request.getFluidStack(), false); + IAEFluidStack ready = drain(null, request, false); if (ready != null) { if (mode.equals(Actionable.MODULATE)) drain(null, request.getFluidStack(), true); - return FluidUtil.createAEFluidStack(ready.getFluid(), ready.amount); + return ready; } else return null; } @@ -225,25 +229,29 @@ public class YOTTAHatch extends GT_MetaTileEntity_Hatch @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - ticksSinceUpdate++; - if (ticksSinceUpdate > 20) { - IGridNode node = getGridNode(null); - if (node != null) { - IGrid grid = node.getGrid(); - if (grid != null) { - grid.postEvent(new MENetworkCellArrayUpdate()); - IStorageGrid storageGrid = grid.getCache(IStorageGrid.class); - if (storageGrid == null) { - node.getGrid().postEvent(new MENetworkStorageEvent(null, StorageChannel.FLUIDS)); - } else { - node.getGrid() - .postEvent(new MENetworkStorageEvent( - storageGrid.getFluidInventory(), StorageChannel.FLUIDS)); + if (shouldTick(aTick)) { + if (isChanged()) { + IGridNode node = getGridNode(null); + if (node != null) { + IGrid grid = node.getGrid(); + if (grid != null) { + grid.postEvent(new MENetworkCellArrayUpdate()); + IStorageGrid storageGrid = grid.getCache(IStorageGrid.class); + if (storageGrid == null) { + node.getGrid().postEvent(new MENetworkStorageEvent(null, StorageChannel.FLUIDS)); + } else { + node.getGrid() + .postEvent(new MENetworkStorageEvent( + storageGrid.getFluidInventory(), StorageChannel.FLUIDS)); + } + node.getGrid().postEvent(new MENetworkCellArrayUpdate()); } - node.getGrid().postEvent(new MENetworkCellArrayUpdate()); } + faster(); + update(); + } else { + slower(); } - ticksSinceUpdate = 0; } super.onPostTick(aBaseMetaTileEntity, aTick); } @@ -279,6 +287,27 @@ public class YOTTAHatch extends GT_MetaTileEntity_Hatch return 0; } + public long fill(ForgeDirection from, IAEFluidStack resource, boolean doFill) { + if (host == null + || host.getBaseMetaTileEntity() == null + || !host.getBaseMetaTileEntity().isActive()) return 0; + if (host.mFluidName == null + || host.mFluidName.equals("") + || host.mFluidName.equals(resource.getFluid().getName())) { + host.mFluidName = resource.getFluid().getName(); + if (host.mStorage.subtract(host.mStorageCurrent).compareTo(BigInteger.valueOf(resource.getStackSize())) + >= 0) { + if (doFill) host.addFluid(resource.getStackSize()); + return resource.getStackSize(); + } else { + long added = host.mStorage.subtract(host.mStorageCurrent).longValue(); + if (doFill) host.addFluid(added); + return added; + } + } + return 0; + } + @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { if (host == null @@ -298,6 +327,26 @@ public class YOTTAHatch extends GT_MetaTileEntity_Hatch return new FluidStack(resource.getFluid(), ready); } + public IAEFluidStack drain(ForgeDirection from, IAEFluidStack resource, boolean doDrain) { + if (host == null + || host.getBaseMetaTileEntity() == null + || !host.getBaseMetaTileEntity().isActive()) return null; + if (host.mFluidName == null + || host.mFluidName.equals("") + || !host.mFluidName.equals(resource.getFluid().getName())) return null; + long ready; + if (host.mStorageCurrent.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) { + ready = Long.MAX_VALUE; + } else ready = host.mStorageCurrent.longValue(); + ready = Math.min(ready, resource.getStackSize()); + if (doDrain) { + host.reduceFluid(ready); + } + IAEFluidStack copy = resource.copy(); + copy.setStackSize(ready); + return copy; + } + @Override public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { if (host == null @@ -416,4 +465,32 @@ public class YOTTAHatch extends GT_MetaTileEntity_Hatch public void saveChanges(IMEInventory cellInventory) { // This is handled by host itself. } + + private boolean isChanged() { + if (this.host == null) return false; + return !this.lastAmt.equals(this.host.mStorageCurrent) || !this.lastFluid.equals(this.host.mFluidName); + } + + private void update() { + if (this.host == null) return; + this.lastAmt = this.host.mStorageCurrent; + this.lastFluid = this.host.mFluidName; + } + + private void faster() { + if (this.tickRate > 15) { + this.tickRate -= 5; + } + } + + private void slower() { + if (this.tickRate < 100) { + this.tickRate += 5; + } + } + + private boolean shouldTick(long tick) { + if (this.host == null) return false; + return tick % this.tickRate == 0; + } } diff --git a/src/main/java/goodgenerator/blocks/tileEntity/YottaFluidTank.java b/src/main/java/goodgenerator/blocks/tileEntity/YottaFluidTank.java index a7395636df..bf15d4a097 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/YottaFluidTank.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/YottaFluidTank.java @@ -118,7 +118,7 @@ public class YottaFluidTank extends GT_MetaTileEntity_TooltipMultiBlockBase_EM return true; } - public boolean reduceFluid(int amount) { + public boolean reduceFluid(long amount) { BigInteger tmp = new BigInteger(amount + ""); if (mStorageCurrent.compareTo(tmp) < 0) { return false; @@ -128,7 +128,7 @@ public class YottaFluidTank extends GT_MetaTileEntity_TooltipMultiBlockBase_EM } } - public boolean addFluid(int amount) { + public boolean addFluid(long amount) { BigInteger tmp = new BigInteger(amount + ""); if (mStorage.subtract(mStorageCurrent).compareTo(tmp) < 0) { return false; @@ -138,16 +138,11 @@ public class YottaFluidTank extends GT_MetaTileEntity_TooltipMultiBlockBase_EM } } - private int calGlassTier(int meta) { - if (meta >= 1 && meta <= 6) return meta; // returns correct meta for Tiers 1-6, 7-12 is colour variations of HV - if (meta >= 7 && meta <= 12) return 1; // For all the HV Glass colour variations - return meta; // returns the rest - } - @Override public boolean checkMachine_EM(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { mStorage = BigInteger.ZERO; glassMeta = 0; + maxCell = 0; mYottaHatch.clear(); if (!structureCheck_EM(YOTTANK_BOTTOM, 2, 0, 0)) return false; int cnt = 0; @@ -156,8 +151,8 @@ public class YottaFluidTank extends GT_MetaTileEntity_TooltipMultiBlockBase_EM } if (cnt > 15 || cnt < 1) return false; if (!structureCheck_EM(YOTTANK_TOP, 2, cnt + 2, 0)) return false; - // maxCell+1 = Tier of highest Cell. maxCell itself just return Tier-1 - if (mMaintenanceHatches.size() == 1 && maxCell + 1 <= calGlassTier(glassMeta)) { + // maxCell+1 = Tier of highest Cell. glassMeta is the glass voltage tier + if (mMaintenanceHatches.size() == 1 && maxCell + 3 <= glassMeta) { if (mStorage.compareTo(mStorageCurrent) < 0) mStorageCurrent = mStorage; if (FluidRegistry.getFluidStack(mFluidName, 1) == null) { mStorageCurrent = BigInteger.ZERO; |