fix cell restriction types being greater than cell type limits (#1727)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kogepan229 <73163994+Kogepan229@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-06 18:53:11 +01:00
1 parent f469e63dee
commit 67077d9d4b
3 files changed
+35 -4

No files matched your search

+12 -2
View File
@@ -445,8 +445,18 @@ public abstract class AEBaseCell extends AEBaseItem implements IStorageCell, IIt
ItemStackNBT.removeTag(is, "cellRestrictionTypes");
ItemStackNBT.removeTag(is, "cellRestrictionAmount");
} else {
ItemStackNBT.setByte(is, "cellRestrictionTypes", newRestriction.restrictionTypes);
ItemStackNBT.setLong(is, "cellRestrictionAmount", newRestriction.restrictionAmount);
long effectiveTypes = newRestriction.restrictionTypes == 0 ? this.totalTypes
: Math.min(newRestriction.restrictionTypes, this.totalTypes);
long maxAmount = (this.totalBytes - (long) this.perType * effectiveTypes)
* this.getStackType().getAmountPerByte();
long amount = Math.min(newRestriction.restrictionAmount, maxAmount);
ItemStackNBT.setByte(
is,
"cellRestrictionTypes",
(byte) Math.min(newRestriction.restrictionTypes, this.totalTypes));
ItemStackNBT.setLong(is, "cellRestrictionAmount", amount);
}
}
@@ -98,6 +98,10 @@ public abstract class CellInventory<StackType extends IAEStack<StackType>> imple
this.restrictionTypes = this.tagCompound.getByte("cellRestrictionTypes");
this.restrictionLong = this.tagCompound.getLong("cellRestrictionAmount");
if (this.restrictionTypes > this.maxTypes) {
this.restrictionTypes = (byte) (this.maxTypes & 0x7F);
}
this.cellStacks = (IItemList<StackType>) this.getStackType().createPrimitiveList();
this.loadCellStacks();
@@ -23,6 +23,7 @@ import appeng.api.AEApi;
import appeng.api.config.CopyMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IStorageCell;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.implementations.tiles.ICellWorkbench;
import appeng.api.storage.ICellWorkbenchItem;
@@ -152,8 +153,24 @@ public class TileCellWorkbench extends AEBaseTile implements ICellWorkbench, IPr
ItemStack is = this.cell.getStackInSlot(0);
if (this.manager.getSetting(Settings.COPY_MODE) == CopyMode.KEEP_ON_REMOVE) {
if (is != null && is.getItem() instanceof ICellRestriction icr)
icr.setCellRestriction(is, new CellRestrictionData(cellRestrictTypes, cellRestrictAmount));
if (is != null && is.getItem() instanceof ICellRestriction icr) {
CellRestrictionData newRestriction = new CellRestrictionData(cellRestrictTypes, cellRestrictAmount);
if (is.getItem() instanceof IStorageCell asCell) {
var totalTypes = asCell.getTotalTypes(is);
// we need to avoid 0 before the max amount calc
long effectiveTypes = newRestriction.restrictionTypes == 0 ? totalTypes
: Math.min(newRestriction.restrictionTypes, totalTypes);
long maxAmount = (asCell.getBytesLong(is) - (long) asCell.getBytesPerType(is) * effectiveTypes)
* asCell.getStackType().getAmountPerByte();
long amount = Math.min(newRestriction.restrictionAmount, maxAmount);
// we need to allow 0 here again, so Restriction#isReset() works
// otherwise restrictions might be (MaxType, 0 Items) instead of (0, 0)
// for clearing them in copy mode
effectiveTypes = Math.min(newRestriction.restrictionTypes, totalTypes);
newRestriction = new CellRestrictionData((byte) effectiveTypes, amount);
}
icr.setCellRestriction(is, newRestriction);
}
}
if (this.updateStackTypeFromCell()) {