Skip to content

Commit

Permalink
Static helper instead of instance
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxplay committed Jan 4, 2025
1 parent 48031ef commit c65e09c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@
+ }
+ } else if (cursor.getCount() <= slot.getMaxStackSize()) {
+ if (cursor.is(Items.BUNDLE) && packet.getButtonNum() == 0) {
+ int toPickup = new net.minecraft.world.item.component.BundleContents.Mutable(cursor.get(DataComponents.BUNDLE_CONTENTS)).getMaxAmountToAdd(slot.getItem());
+ int toPickup = cursor.get(DataComponents.BUNDLE_CONTENTS).getMaxAmountToAdd(slot.getItem());
+ if (toPickup >= slot.getItem().getCount()) {
+ action = InventoryAction.PICKUP_ALL_INTO_BUNDLE;
+ } else if (toPickup == 0) {
Expand All @@ -2094,7 +2094,7 @@
+ action = InventoryAction.PICKUP_SOME_INTO_BUNDLE;
+ }
+ } else if (slot.getItem().is(Items.BUNDLE) && packet.getButtonNum() == 0) {
+ int toPickup = new net.minecraft.world.item.component.BundleContents.Mutable(slot.getItem().get(DataComponents.BUNDLE_CONTENTS)).getMaxAmountToAdd(cursor);
+ int toPickup = slot.getItem().get(DataComponents.BUNDLE_CONTENTS).getMaxAmountToAdd(cursor);
+ if (toPickup >= cursor.getCount()) {
+ action = InventoryAction.PLACE_ALL_INTO_BUNDLE;
+ } else if (toPickup == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--- a/net/minecraft/world/item/component/BundleContents.java
+++ b/net/minecraft/world/item/component/BundleContents.java
@@ -76,6 +_,12 @@
return !stack.isEmpty() && stack.getItem().canFitInsideContainerItems();
}

+ // Paper start - correct bundle inventory action
+ public int getMaxAmountToAdd(final ItemStack stack) {
+ return Mutable.getMaxAmountToAdd(stack, this.weight);
+ }
+ // Paper end - correct bundle inventory action
+
public int getNumberOfItemsToShow() {
int size = this.size();
int i = size > 12 ? 11 : 12;
@@ -171,7 +_,13 @@
}

public int getMaxAmountToAdd(ItemStack stack) {
- Fraction fraction = Fraction.ONE.subtract(this.weight);
+ // Paper start - correct bundle inventory action
+ // Static overload to easily compute this value without the need for an instance of mutable.
+ return getMaxAmountToAdd(stack, this.weight);
+ }
+ static int getMaxAmountToAdd(final ItemStack stack, final Fraction weight) {
+ Fraction fraction = Fraction.ONE.subtract(weight);
+ // Paper end - correct bundle inventory action
return Math.max(fraction.divideBy(BundleContents.getWeight(stack)).intValue(), 0);
}

0 comments on commit c65e09c

Please sign in to comment.