Skip to content

Commit

Permalink
Make machine capacity settable independently of the current inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Sep 16, 2024
1 parent 0e003ff commit 396c456
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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() {
Expand Down

0 comments on commit 396c456

Please sign in to comment.