diff --git a/src/main/java/aztech/modern_industrialization/inventory/ConfigurableItemStack.java b/src/main/java/aztech/modern_industrialization/inventory/ConfigurableItemStack.java index 335743cd5..03ddb46c5 100644 --- a/src/main/java/aztech/modern_industrialization/inventory/ConfigurableItemStack.java +++ b/src/main/java/aztech/modern_industrialization/inventory/ConfigurableItemStack.java @@ -36,6 +36,7 @@ import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -145,15 +146,10 @@ public long getCapacity() { @Override public long getRemainingCapacityFor(ItemVariant key) { - return Math.min(key.getMaxStackSize(), adjustedCapacity) - amount; - } - - @Override - public void setAmount(long amount) { - super.setAmount(amount); if (adjustedCapacity < amount) { - adjustedCapacity = (int) amount; + return 0; // Make sure we don't get negative counts if this happens! } + return Math.min(key.getMaxStackSize(), adjustedCapacity) - amount; } /** @@ -176,7 +172,8 @@ public void adjustCapacity(boolean isIncrease, boolean isShiftDown) { if (!isIncrease) { delta = -delta; } - adjustedCapacity = Math.min(64, Math.max((int) amount, adjustedCapacity + delta)); + adjustedCapacity = Mth.clamp(adjustedCapacity + delta, 0, 64); + notifyListeners(); } public int getAdjustedCapacity() {