From 913088788f6a02300b3a2cdd80bbd8481806bbc2 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Mon, 20 Jan 2025 19:28:52 +0200 Subject: [PATCH] first commit --- .../common/storage/FluidCellInventory.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java b/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java index 8f69bc41..ab740dc9 100644 --- a/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java +++ b/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java @@ -50,6 +50,8 @@ public class FluidCellInventory implements IFluidCellInventory { public static final int singleByteAmount = 256 * 8; private boolean cardVoidOverflow = false; private boolean cardDistribution = false; + private byte restrictionTypes = 0; + private long restrictionLong = 0; public FluidCellInventory(final ItemStack o, final ISaveProvider container) throws AppEngException { if (o == null) { @@ -97,6 +99,8 @@ public class FluidCellInventory implements IFluidCellInventory { this.tagCompound = Platform.openNbtData(o); this.storedFluids = this.tagCompound.getShort(FLUID_TYPE_TAG); this.storedFluidCount = this.tagCompound.getLong(FLUID_COUNT_TAG); + this.restrictionTypes = this.tagCompound.getByte("cellRestrictionTypes"); + this.restrictionLong = this.tagCompound.getLong("cellRestrictionAmount"); this.cellFluids = null; } @@ -151,8 +155,8 @@ public class FluidCellInventory implements IFluidCellInventory { public boolean canHoldNewFluid() { final long bytesFree = this.getFreeBytes(); return (bytesFree > this.getBytesPerType() - || (bytesFree == this.getBytesPerType() && this.getUnusedFluidCount() > 0)) - && this.getRemainingFluidTypes() > 0; + || (bytesFree == this.getBytesPerType() && this.getUnusedFluidCount() > 0)) + && this.getRemainingFluidTypes() > 0; } @Override @@ -173,6 +177,7 @@ public class FluidCellInventory implements IFluidCellInventory { @Override public long getTotalFluidTypes() { + if (restrictionTypes > 0) return restrictionTypes; return this.cellType.getTotalTypes(this.cellItem); } @@ -195,6 +200,11 @@ public class FluidCellInventory implements IFluidCellInventory { @Override public long getRemainingFluidCount() { + if (restrictionLong > 0) { + return Math.min( + restrictionLong - this.getStoredFluidCount(), + this.getFreeBytes() * singleByteAmount + this.getUnusedFluidCount()); + } final long remaining = this.getFreeBytes() * singleByteAmount + this.getUnusedFluidCount(); return remaining > 0 ? remaining : 0; } @@ -210,10 +220,22 @@ public class FluidCellInventory implements IFluidCellInventory { } if (types == 0) types = this.getTotalFluidTypes(); if (l != null) { - remaining = (((this.getTotalBytes() / types) - (int) Math.ceil((double) l.getStackSize() / singleByteAmount) - - getBytesPerType()) * singleByteAmount) + (singleByteAmount - l.getStackSize() % singleByteAmount); + if (restrictionLong > 0) { + remaining = Math.min((restrictionLong / types) - l.getStackSize(), this.getUnusedFluidCount()); + } else { + remaining = (((this.getTotalBytes() / types) + - (int) Math.ceil((double) l.getStackSize() / singleByteAmount) + - getBytesPerType()) * singleByteAmount) + + (singleByteAmount - l.getStackSize() % singleByteAmount); + } } else { - remaining = ((this.getTotalBytes() / types) - this.getBytesPerType()) * singleByteAmount; + if (restrictionLong > 0) { + remaining = Math.min( + restrictionLong / types, + ((this.getTotalBytes() / types) - this.getBytesPerType()) * singleByteAmount); + } else { + remaining = ((this.getTotalBytes() / types) - this.getBytesPerType()) * singleByteAmount; + } } return remaining > 0 ? remaining : 0; } @@ -371,7 +393,7 @@ public class FluidCellInventory implements IFluidCellInventory { remainingFluidCount = this.getRemainingFluidCountDist(null); } else { remainingFluidCount = this.getRemainingFluidCount() - - ((long) this.getBytesPerType() * singleByteAmount); + - ((long) this.getBytesPerType() * singleByteAmount); } if (remainingFluidCount > 0) {