Skip to content

Commit 396c456

Browse files
committed
Make machine capacity settable independently of the current inventory
1 parent 0e003ff commit 396c456

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/main/java/aztech/modern_industrialization/inventory/ConfigurableItemStack.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import net.minecraft.core.Registry;
3737
import net.minecraft.core.registries.BuiltInRegistries;
3838
import net.minecraft.nbt.CompoundTag;
39+
import net.minecraft.util.Mth;
3940
import net.minecraft.world.entity.player.Player;
4041
import net.minecraft.world.item.Item;
4142
import net.minecraft.world.item.ItemStack;
@@ -145,15 +146,10 @@ public long getCapacity() {
145146

146147
@Override
147148
public long getRemainingCapacityFor(ItemVariant key) {
148-
return Math.min(key.getMaxStackSize(), adjustedCapacity) - amount;
149-
}
150-
151-
@Override
152-
public void setAmount(long amount) {
153-
super.setAmount(amount);
154149
if (adjustedCapacity < amount) {
155-
adjustedCapacity = (int) amount;
150+
return 0; // Make sure we don't get negative counts if this happens!
156151
}
152+
return Math.min(key.getMaxStackSize(), adjustedCapacity) - amount;
157153
}
158154

159155
/**
@@ -176,7 +172,8 @@ public void adjustCapacity(boolean isIncrease, boolean isShiftDown) {
176172
if (!isIncrease) {
177173
delta = -delta;
178174
}
179-
adjustedCapacity = Math.min(64, Math.max((int) amount, adjustedCapacity + delta));
175+
adjustedCapacity = Mth.clamp(adjustedCapacity + delta, 0, 64);
176+
notifyListeners();
180177
}
181178

182179
public int getAdjustedCapacity() {

0 commit comments

Comments
 (0)