529 lines
36 KiB
Diff
529 lines
36 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Helvetica Volubi <suisuroru@blue-millennium.fun>
|
|
Date: Mon, 9 Jun 2025 19:23:10 +0800
|
|
Subject: [PATCH] Stackable ShulkerBoxes
|
|
|
|
Co-authored by: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
Some of changes is a part of : Leaves (https://github.com/LeavesMC/Leaves/blob/9d32c5bd3df7c76055aff886ed9efda02e45a45a/leaves-server/minecraft-patches/features/0034-Stackable-ShulkerBoxes.patch)
|
|
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
|
|
diff --git a/net/minecraft/commands/arguments/item/ItemInput.java b/net/minecraft/commands/arguments/item/ItemInput.java
|
|
index 643797124fe5a4489d0b7419b7e600c04f283ef2..3b4d97c76db9c742072c92dd7c8b39553c62a1f1 100644
|
|
--- a/net/minecraft/commands/arguments/item/ItemInput.java
|
|
+++ b/net/minecraft/commands/arguments/item/ItemInput.java
|
|
@@ -39,8 +39,9 @@ public class ItemInput {
|
|
public ItemStack createItemStack(int count, boolean allowOversizedStacks) throws CommandSyntaxException {
|
|
ItemStack itemStack = new ItemStack(this.item, count);
|
|
itemStack.applyComponents(this.components);
|
|
- if (allowOversizedStacks && count > itemStack.getMaxStackSize()) {
|
|
- throw ERROR_STACK_TOO_BIG.create(this.getItemName(), itemStack.getMaxStackSize());
|
|
+ int maxCount = fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemStack); // Lophine - Stackable ShulkerBoxes
|
|
+ if (allowOversizedStacks && count > maxCount) { // Lophine - Stackable ShulkerBoxes
|
|
+ throw ERROR_STACK_TOO_BIG.create(this.getItemName(), maxCount); // Lophine - Stackable ShulkerBoxes
|
|
} else {
|
|
return itemStack;
|
|
}
|
|
diff --git a/net/minecraft/server/commands/GiveCommand.java b/net/minecraft/server/commands/GiveCommand.java
|
|
index 5a1c21b05545a03fbb00cf734605049870d3eecb..2ade5ce23cdab08b1746e2cbe99bfe1d3da42f02 100644
|
|
--- a/net/minecraft/server/commands/GiveCommand.java
|
|
+++ b/net/minecraft/server/commands/GiveCommand.java
|
|
@@ -55,7 +55,7 @@ public class GiveCommand {
|
|
private static int giveItem(CommandSourceStack source, ItemInput item, Collection<ServerPlayer> targets, int count) throws CommandSyntaxException {
|
|
ItemStack itemStack = item.createItemStack(1, false);
|
|
final Component displayName = itemStack.getDisplayName(); // Paper - get display name early
|
|
- int maxStackSize = itemStack.getMaxStackSize();
|
|
+ int maxStackSize = fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemStack); // Lophine - Stackable ShulkerBoxes
|
|
int i = maxStackSize * 100;
|
|
if (count > i) {
|
|
source.sendFailure(Component.translatable("commands.give.failed.toomanyitems", i, itemStack.getDisplayName()));
|
|
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 513cbbf227c5037ee77055473e8815eb05496679..5af3293a532124c2a0e8797efb729de750f33628 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -3064,7 +3064,7 @@ public class ServerGamePacketListenerImpl
|
|
} else if (slot.mayPlace(cursor)) {
|
|
if (ItemStack.isSameItemSameComponents(clickedItem, cursor)) {
|
|
int toPlace = packet.buttonNum() == 0 ? cursor.getCount() : 1;
|
|
- toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.getCount());
|
|
+ toPlace = Math.min(toPlace, fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(clickedItem) - clickedItem.getCount()); // Lophine - Stackable ShulkerBoxes
|
|
toPlace = Math.min(toPlace, slot.container.getMaxStackSize() - clickedItem.getCount());
|
|
if (toPlace == 1) {
|
|
action = InventoryAction.PLACE_ONE;
|
|
@@ -3100,7 +3100,7 @@ public class ServerGamePacketListenerImpl
|
|
}
|
|
} else if (ItemStack.isSameItemSameComponents(cursor, clickedItem)) {
|
|
if (clickedItem.getCount() >= 0) {
|
|
- if (clickedItem.getCount() + cursor.getCount() <= cursor.getMaxStackSize()) {
|
|
+ if (clickedItem.getCount() + cursor.getCount() <= fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(cursor)) { // Lophine - Stackable ShulkerBoxes
|
|
// As of 1.5, this is result slots only
|
|
action = InventoryAction.PICKUP_ALL;
|
|
}
|
|
@@ -3359,6 +3359,7 @@ public class ServerGamePacketListenerImpl
|
|
this.player.containerMenu.broadcastFullState();
|
|
} else {
|
|
this.player.containerMenu.broadcastChanges();
|
|
+ if (fun.bm.lophine.utils.ShulkerBoxesUtil.shouldCheck()) this.player.containerMenu.broadcastCarriedItem(); // Lophine - Stackable ShulkerBoxes
|
|
}
|
|
if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdates(); // Paper - Force update attributes.
|
|
}
|
|
@@ -3469,7 +3470,7 @@ public class ServerGamePacketListenerImpl
|
|
}
|
|
|
|
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
|
|
- boolean flag2 = itemStack.isEmpty() || itemStack.getCount() <= itemStack.getMaxStackSize();
|
|
+ boolean flag2 = itemStack.isEmpty() || itemStack.getCount() <= fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemStack); // Lophine - Stackable ShulkerBoxes
|
|
if (flag || (flag1 && !ItemStack.matches(this.player.inventoryMenu.getSlot(packet.slotNum()).getItem(), packet.itemStack()))) { // Insist on valid slot
|
|
// CraftBukkit start - Call click event
|
|
org.bukkit.inventory.InventoryView inventory = this.player.inventoryMenu.getBukkitView();
|
|
@@ -3511,6 +3512,7 @@ public class ServerGamePacketListenerImpl
|
|
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemStack);
|
|
this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemStack);
|
|
this.player.inventoryMenu.broadcastChanges();
|
|
+ if (fun.bm.lophine.utils.ShulkerBoxesUtil.shouldCheck()) this.player.containerMenu.broadcastCarriedItem(); // Lophine - Stackable ShulkerBoxes
|
|
if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdates(); // Paper - Force update attributes.
|
|
} else if (flag && flag2) {
|
|
if (this.dropSpamThrottler.isUnderThreshold()) {
|
|
diff --git a/net/minecraft/world/Container.java b/net/minecraft/world/Container.java
|
|
index b382665cc125b8b5c0938e5e55984e4bf91d37ff..5d8bd05f966cf9befe8b8f3359b2fa4ce2428e98 100644
|
|
--- a/net/minecraft/world/Container.java
|
|
+++ b/net/minecraft/world/Container.java
|
|
@@ -32,6 +32,12 @@ public interface Container extends Clearable, Iterable<ItemStack> {
|
|
return Math.min(this.getMaxStackSize(), stack.getMaxStackSize());
|
|
}
|
|
|
|
+ // Leaves start - stackable shulker boxes
|
|
+ default int getMaxStackLeaves(ItemStack stack) {
|
|
+ return Math.min(this.getMaxStackSize(), fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(stack));
|
|
+ }
|
|
+ // Leaves end - stackable shulker boxes
|
|
+
|
|
void setChanged();
|
|
|
|
boolean stillValid(Player player);
|
|
diff --git a/net/minecraft/world/SimpleContainer.java b/net/minecraft/world/SimpleContainer.java
|
|
index d907e24d563e27acab2f2bf9711b1755ea9afd19..6189cb7c1745a242b610e89c859cc849f16cc9e3 100644
|
|
--- a/net/minecraft/world/SimpleContainer.java
|
|
+++ b/net/minecraft/world/SimpleContainer.java
|
|
@@ -211,7 +211,7 @@ public class SimpleContainer implements Container, StackedContentsCompatible {
|
|
@Override
|
|
public void setItem(int index, ItemStack stack) {
|
|
this.items.set(index, stack);
|
|
- stack.limitSize(this.getMaxStackSize(stack));
|
|
+ stack.limitSize(this.getMaxStackLeaves(stack)); // Leaves - stackable shulker boxes
|
|
this.setChanged();
|
|
}
|
|
|
|
@@ -286,7 +286,7 @@ public class SimpleContainer implements Container, StackedContentsCompatible {
|
|
}
|
|
|
|
private void moveItemsBetweenStacks(ItemStack stack, ItemStack other) {
|
|
- int maxStackSize = this.getMaxStackSize(other);
|
|
+ int maxStackSize = this.getMaxStackLeaves(other); // Leaves - stackable shulker boxes
|
|
int min = Math.min(stack.getCount(), maxStackSize - other.getCount());
|
|
if (min > 0) {
|
|
other.grow(min);
|
|
diff --git a/net/minecraft/world/entity/item/ItemEntity.java b/net/minecraft/world/entity/item/ItemEntity.java
|
|
index 8b318426d3aff4be920181bb8b882c43119e1571..8d67df8732f3b71eee044e535c4536930fd6e405 100644
|
|
--- a/net/minecraft/world/entity/item/ItemEntity.java
|
|
+++ b/net/minecraft/world/entity/item/ItemEntity.java
|
|
@@ -279,10 +279,45 @@ public class ItemEntity extends Entity implements TraceableEntity {
|
|
|
|
private boolean isMergable() {
|
|
ItemStack item = this.getItem();
|
|
- return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && item.getCount() < item.getMaxStackSize(); // Paper - Alternative item-despawn-rate
|
|
+ return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && item.getCount() < fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(item); // Paper - Alternative item-despawn-rate // Lophine - Stackable ShulkerBoxes
|
|
+ }
|
|
+
|
|
+ // Lophine start - Stackable ShulkerBoxes
|
|
+ private boolean tryMergeShulkerBox(ItemEntity ote) {
|
|
+ ItemStack sf = this.getItem();
|
|
+ ItemStack ot = ote.getItem();
|
|
+ if (!fun.bm.lophine.utils.ShulkerBoxesUtil.checkShulkerBox(sf)) return false;
|
|
+ if (sf.getItem().equals(ot.getItem())
|
|
+ && fun.bm.lophine.utils.ShulkerBoxesUtil.emptyShulkerBoxCheck(sf)
|
|
+ && fun.bm.lophine.utils.ShulkerBoxesUtil.emptyShulkerBoxCheck(ot)
|
|
+ && Objects.equals(sf.getComponents(), ot.getComponents()) // empty block entity tags are cleaned up when spawning
|
|
+ && sf.getCount() != fun.bm.lophine.utils.ShulkerBoxesUtil.getShulkerBoxesMaxCountUnsafe()) {
|
|
+ int count = Math.min(ot.getCount(), fun.bm.lophine.utils.ShulkerBoxesUtil.getShulkerBoxesMaxCountUnsafe() - sf.getCount());
|
|
+ sf.grow(count);
|
|
+ this.setItem(sf);
|
|
+
|
|
+ this.pickupDelay = Math.max(ote.pickupDelay, this.pickupDelay);
|
|
+ this.age = Math.min(ote.getAge(), this.age);
|
|
+ ot.shrink(count);
|
|
+ if (ot.isEmpty()) {
|
|
+ ote.discard();
|
|
+ }
|
|
+ else {
|
|
+ ote.setItem(ot);
|
|
+ }
|
|
+ return true;
|
|
+ }
|
|
+ return false;
|
|
}
|
|
+ // Lophine end - Stackable ShulkerBoxes
|
|
|
|
private void tryToMerge(ItemEntity itemEntity) {
|
|
+ // Lophine start - Stackable ShulkerBoxes
|
|
+ if (fun.bm.lophine.utils.ShulkerBoxesUtil.shouldCheck()
|
|
+ && this.tryMergeShulkerBox(itemEntity)) {
|
|
+ return;
|
|
+ }
|
|
+ // Lophine end - Stackable ShulkerBoxes
|
|
ItemStack item = this.getItem();
|
|
ItemStack item1 = itemEntity.getItem();
|
|
if (Objects.equals(this.target, itemEntity.target) && areMergable(item, item1)) {
|
|
diff --git a/net/minecraft/world/entity/player/Inventory.java b/net/minecraft/world/entity/player/Inventory.java
|
|
index a6bb436dc80daf6901dc027a6011ead4b3ed27e2..53210a7d32241c47c2b1cd698b515726f0a1fd0d 100644
|
|
--- a/net/minecraft/world/entity/player/Inventory.java
|
|
+++ b/net/minecraft/world/entity/player/Inventory.java
|
|
@@ -166,8 +166,8 @@ public class Inventory implements Container, Nameable {
|
|
|
|
private boolean hasRemainingSpaceForItem(ItemStack destination, ItemStack origin) {
|
|
return !destination.isEmpty()
|
|
- && destination.isStackable()
|
|
- && destination.getCount() < this.getMaxStackSize(destination)
|
|
+ && fun.bm.lophine.utils.ShulkerBoxesUtil.isStackable(destination) // Lophine - Stackable ShulkerBoxes
|
|
+ && destination.getCount() < fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(destination) // Lophine - Stackable ShulkerBoxes
|
|
&& ItemStack.isSameItemSameComponents(destination, origin); // Paper - check if itemstack is stackable first
|
|
}
|
|
|
|
@@ -181,7 +181,7 @@ public class Inventory implements Container, Nameable {
|
|
}
|
|
|
|
if (this.hasRemainingSpaceForItem(itemInSlot, itemStack)) {
|
|
- remains -= (itemInSlot.getMaxStackSize() < this.getMaxStackSize() ? itemInSlot.getMaxStackSize() : this.getMaxStackSize()) - itemInSlot.getCount();
|
|
+ remains -= (fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemInSlot) < this.getMaxStackSize() ? fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemInSlot) : this.getMaxStackSize()) - itemInSlot.getCount(); // Lophine - Stackable ShulkerBoxes
|
|
}
|
|
if (remains <= 0) {
|
|
return itemStack.getCount();
|
|
@@ -190,7 +190,7 @@ public class Inventory implements Container, Nameable {
|
|
|
|
ItemStack itemInOffhand = this.equipment.get(EquipmentSlot.OFFHAND);
|
|
if (this.hasRemainingSpaceForItem(itemInOffhand, itemStack)) {
|
|
- remains -= (itemInOffhand.getMaxStackSize() < this.getMaxStackSize() ? itemInOffhand.getMaxStackSize() : this.getMaxStackSize()) - itemInOffhand.getCount();
|
|
+ remains -= (fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemInOffhand) < this.getMaxStackSize() ? fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemInOffhand) : this.getMaxStackSize()) - itemInOffhand.getCount(); // Lophine - Stackable ShulkerBoxes
|
|
}
|
|
if (remains <= 0) {
|
|
return itemStack.getCount();
|
|
@@ -314,7 +314,7 @@ public class Inventory implements Container, Nameable {
|
|
this.setItem(slot, item);
|
|
}
|
|
|
|
- int i = this.getMaxStackSize(item) - item.getCount();
|
|
+ int i = this.getMaxStackLeaves(item) - item.getCount();
|
|
int min = Math.min(count, i);
|
|
if (min == 0) {
|
|
return count;
|
|
@@ -420,7 +420,7 @@ public class Inventory implements Container, Nameable {
|
|
break;
|
|
}
|
|
|
|
- int i = stack.getMaxStackSize() - this.getItem(slotWithRemainingSpace).getCount();
|
|
+ int i = fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(stack) - this.getItem(slotWithRemainingSpace).getCount(); // Lophine - Stackable ShulkerBoxes
|
|
if (this.add(slotWithRemainingSpace, stack.split(i)) && sendPacket && this.player instanceof ServerPlayer serverPlayer) {
|
|
serverPlayer.connection.send(this.createInventoryUpdatePacket(slotWithRemainingSpace));
|
|
}
|
|
diff --git a/net/minecraft/world/entity/player/StackedItemContents.java b/net/minecraft/world/entity/player/StackedItemContents.java
|
|
index 83ccde54c625d40dc595e000c533f60aa929bd5a..3206b599481eeab29c58bc1ca9cac6935da9963a 100644
|
|
--- a/net/minecraft/world/entity/player/StackedItemContents.java
|
|
+++ b/net/minecraft/world/entity/player/StackedItemContents.java
|
|
@@ -23,7 +23,7 @@ public class StackedItemContents {
|
|
}
|
|
|
|
public void accountStack(ItemStack stack) {
|
|
- this.accountStack(stack, stack.getMaxStackSize());
|
|
+ this.accountStack(stack, fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(stack)); // Lophine - Stackable Shulker Boxes
|
|
}
|
|
|
|
public void accountStack(ItemStack stack, int maxStackSize) {
|
|
diff --git a/net/minecraft/world/entity/vehicle/ContainerEntity.java b/net/minecraft/world/entity/vehicle/ContainerEntity.java
|
|
index 02d2efef2dc0f0e12eac0c71fa290af706f7694d..d042b3729a615bdabeb08f559ac895a731856545 100644
|
|
--- a/net/minecraft/world/entity/vehicle/ContainerEntity.java
|
|
+++ b/net/minecraft/world/entity/vehicle/ContainerEntity.java
|
|
@@ -163,7 +163,7 @@ public interface ContainerEntity extends Container, MenuProvider {
|
|
default void setChestVehicleItem(int slot, ItemStack stack) {
|
|
this.unpackChestVehicleLootTable(null);
|
|
this.getItemStacks().set(slot, stack);
|
|
- stack.limitSize(this.getMaxStackSize(stack));
|
|
+ stack.limitSize(this.getMaxStackLeaves(stack)); // Leaves - stackable shulker boxes
|
|
}
|
|
|
|
default SlotAccess getChestVehicleSlot(final int index) {
|
|
diff --git a/net/minecraft/world/inventory/AbstractContainerMenu.java b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
index 852b4381985ed167b05881f068e9542c31cdaf23..379ccae078370b4e8fc909e642f1a70066f70ebf 100644
|
|
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
@@ -234,6 +234,14 @@ public abstract class AbstractContainerMenu {
|
|
return list;
|
|
}
|
|
|
|
+ // Lophine start - Stackable ShulkerBoxes
|
|
+ public void boardcastChangesSigleSlot(int slot, ItemStack item) {
|
|
+ if (this.synchronizer != null) {
|
|
+ this.synchronizer.sendSlotChange(this, slot, item);
|
|
+ }
|
|
+ }
|
|
+ // Lophine end - Stackable ShulkerBoxes
|
|
+
|
|
public void broadcastChanges() {
|
|
for (int i = 0; i < this.slots.size(); i++) {
|
|
ItemStack item = this.slots.get(i).getItem();
|
|
@@ -427,7 +435,7 @@ public abstract class AbstractContainerMenu {
|
|
&& (this.quickcraftType == 2 || carried1.getCount() >= this.quickcraftSlots.size())
|
|
&& this.canDragTo(slot1)) {
|
|
int i2 = slot1.hasItem() ? slot1.getItem().getCount() : 0;
|
|
- int min = Math.min(itemStack.getMaxStackSize(), slot1.getMaxStackSize(itemStack));
|
|
+ int min = Math.min(fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemStack), slot1.getMaxStackSize(itemStack)); // Lophine - Stackable ShulkerBoxes
|
|
int min1 = Math.min(getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemStack) + i2, min);
|
|
count -= min1 - i2;
|
|
// slot1.setByPlayer(itemStack.copyWithCount(min1));
|
|
@@ -541,7 +549,7 @@ public abstract class AbstractContainerMenu {
|
|
slot.setByPlayer(carried2);
|
|
}
|
|
} else if (ItemStack.isSameItemSameComponents(carried, carried2)) {
|
|
- Optional<ItemStack> optional1 = slot.tryRemove(carried.getCount(), carried2.getMaxStackSize() - carried2.getCount(), player);
|
|
+ Optional<ItemStack> optional1 = slot.tryRemove(carried.getCount(), fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(carried2) - carried2.getCount(), player); // Lophine - Stackable ShulkerBoxes
|
|
optional1.ifPresent(itemStack2 -> {
|
|
carried2.grow(itemStack2.getCount());
|
|
slot.onTake(player, itemStack2);
|
|
@@ -603,7 +611,7 @@ public abstract class AbstractContainerMenu {
|
|
Slot slot2 = this.slots.get(slotId);
|
|
if (slot2.hasItem()) {
|
|
ItemStack itemStack = slot2.getItem();
|
|
- this.setCarried(itemStack.copyWithCount(itemStack.getMaxStackSize()));
|
|
+ this.setCarried(itemStack.copyWithCount(fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemStack))); // Lophine - Stackable ShulkerBoxes
|
|
}
|
|
} else if (clickType == ClickType.THROW && this.getCarried().isEmpty() && slotId >= 0) {
|
|
Slot slot2 = this.slots.get(slotId);
|
|
@@ -634,15 +642,15 @@ public abstract class AbstractContainerMenu {
|
|
int maxStackSize = button == 0 ? 1 : -1;
|
|
|
|
for (int i3 = 0; i3 < 2; i3++) {
|
|
- for (int i4 = count; i4 >= 0 && i4 < this.slots.size() && itemStack.getCount() < itemStack.getMaxStackSize(); i4 += maxStackSize) {
|
|
+ for (int i4 = count; i4 >= 0 && i4 < this.slots.size() && itemStack.getCount() < fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemStack); i4 += maxStackSize) { // Lophine - Stackable ShulkerBoxes
|
|
Slot slot3 = this.slots.get(i4);
|
|
if (slot3.hasItem()
|
|
&& canItemQuickReplace(slot3, itemStack, true)
|
|
&& slot3.mayPickup(player)
|
|
&& this.canTakeItemForPickAll(itemStack, slot3)) {
|
|
ItemStack item1 = slot3.getItem();
|
|
- if (i3 != 0 || item1.getCount() != item1.getMaxStackSize()) {
|
|
- ItemStack itemStack1 = slot3.safeTake(item1.getCount(), itemStack.getMaxStackSize() - itemStack.getCount(), player);
|
|
+ if (i3 != 0 || item1.getCount() != fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(item1)) { // Lophine - stackable shulker boxes
|
|
+ ItemStack itemStack1 = slot3.safeTake(item1.getCount(), fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemStack) - itemStack.getCount(), player); // Lophine - stackable shulker boxes
|
|
itemStack.grow(itemStack1.getCount());
|
|
}
|
|
}
|
|
@@ -744,7 +752,7 @@ public abstract class AbstractContainerMenu {
|
|
i = endIndex - 1;
|
|
}
|
|
|
|
- if (stack.isStackable()) {
|
|
+ if (fun.bm.lophine.utils.ShulkerBoxesUtil.isStackable(stack)) { // Lophine - Stackable ShulkerBoxes
|
|
while (!stack.isEmpty() && (reverseDirection ? i >= startIndex : i < endIndex)) {
|
|
Slot slot = this.slots.get(i);
|
|
ItemStack item = slot.getItem();
|
|
@@ -845,7 +853,7 @@ public abstract class AbstractContainerMenu {
|
|
public static boolean canItemQuickReplace(@Nullable Slot slot, ItemStack stack, boolean stackSizeMatters) {
|
|
boolean flag = slot == null || !slot.hasItem();
|
|
return !flag && ItemStack.isSameItemSameComponents(stack, slot.getItem())
|
|
- ? slot.getItem().getCount() + (stackSizeMatters ? 0 : stack.getCount()) <= stack.getMaxStackSize()
|
|
+ ? slot.getItem().getCount() + (stackSizeMatters ? 0 : stack.getCount()) <= fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(stack) // Lophine - Stackable ShulkerBoxes
|
|
: flag;
|
|
}
|
|
|
|
@@ -853,7 +861,7 @@ public abstract class AbstractContainerMenu {
|
|
return switch (type) {
|
|
case 0 -> Mth.floor((float)stack.getCount() / slots.size());
|
|
case 1 -> 1;
|
|
- case 2 -> stack.getMaxStackSize();
|
|
+ case 2 -> fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(stack); // Lophine - Stackable ShulkerBoxes
|
|
default -> stack.getCount();
|
|
};
|
|
}
|
|
@@ -875,7 +883,7 @@ public abstract class AbstractContainerMenu {
|
|
for (int i = 0; i < container.getContainerSize(); i++) {
|
|
ItemStack item = container.getItem(i);
|
|
if (!item.isEmpty()) {
|
|
- f += (float)item.getCount() / container.getMaxStackSize(item);
|
|
+ f += (float)item.getCount() / container.getMaxStackLeaves(item); // Leaves - stackable shulker boxes
|
|
}
|
|
}
|
|
|
|
diff --git a/net/minecraft/world/inventory/MerchantContainer.java b/net/minecraft/world/inventory/MerchantContainer.java
|
|
index 1e5dfb1f9e371fa23cdfa9280797aa0e183d4cd2..cf87267130c0aebd38206556261929d6f6383bc9 100644
|
|
--- a/net/minecraft/world/inventory/MerchantContainer.java
|
|
+++ b/net/minecraft/world/inventory/MerchantContainer.java
|
|
@@ -109,7 +109,7 @@ public class MerchantContainer implements Container {
|
|
@Override
|
|
public void setItem(int index, ItemStack stack) {
|
|
this.itemStacks.set(index, stack);
|
|
- stack.limitSize(this.getMaxStackSize(stack));
|
|
+ stack.limitSize(this.getMaxStackLeaves(stack)); // Leaves - stackable shulker boxes
|
|
if (this.isPaymentSlot(index)) {
|
|
this.updateSellItem();
|
|
}
|
|
diff --git a/net/minecraft/world/inventory/Slot.java b/net/minecraft/world/inventory/Slot.java
|
|
index 5ceb8964476b40db4511bec91ff13c4f522a1357..dd978d1590fb896775a240ed87e38d85744017d3 100644
|
|
--- a/net/minecraft/world/inventory/Slot.java
|
|
+++ b/net/minecraft/world/inventory/Slot.java
|
|
@@ -75,7 +75,7 @@ public class Slot {
|
|
}
|
|
|
|
public int getMaxStackSize(ItemStack stack) {
|
|
- return Math.min(this.getMaxStackSize(), stack.getMaxStackSize());
|
|
+ return Math.min(this.getMaxStackSize(), fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(stack)); // Lophine - Stackable ShulkerBoxes
|
|
}
|
|
|
|
@Nullable
|
|
diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java
|
|
index 2c15a382dcbd1087dc06b562149239c8bf4e035e..25b0f7ee2d80bcfa10e850fa59001d0da7b5fd9c 100644
|
|
--- a/net/minecraft/world/item/ItemStack.java
|
|
+++ b/net/minecraft/world/item/ItemStack.java
|
|
@@ -162,7 +162,7 @@ public final class ItemStack implements DataComponentHolder {
|
|
@Deprecated
|
|
@Nullable
|
|
private Item item;
|
|
- PatchedDataComponentMap components;
|
|
+ public PatchedDataComponentMap components; // Leaves - stackable shulker boxes
|
|
@Nullable
|
|
private Entity entityRepresentation;
|
|
|
|
@@ -189,7 +189,8 @@ public final class ItemStack implements DataComponentHolder {
|
|
} else {
|
|
Holder<Item> holder = Item.STREAM_CODEC.decode(buffer);
|
|
DataComponentPatch dataComponentPatch = codec.decode(buffer);
|
|
- return new ItemStack(holder, varInt, dataComponentPatch);
|
|
+ ItemStack itemStack = new ItemStack(holder, varInt, dataComponentPatch);
|
|
+ return fun.bm.lophine.utils.ShulkerBoxesUtil.decodeMaxStackSize(itemStack);
|
|
}
|
|
}
|
|
|
|
@@ -198,13 +199,15 @@ public final class ItemStack implements DataComponentHolder {
|
|
if (value.isEmpty() || value.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem()
|
|
buffer.writeVarInt(0);
|
|
} else {
|
|
- buffer.writeVarInt(io.papermc.paper.util.sanitizer.ItemComponentSanitizer.sanitizeCount(io.papermc.paper.util.sanitizer.ItemObfuscationSession.currentSession(), value, value.getCount())); // Paper - potentially sanitize count
|
|
- Item.STREAM_CODEC.encode(buffer, value.getItemHolder());
|
|
+ // Leaves start - stackable shulker boxes
|
|
+ final ItemStack itemStack = fun.bm.lophine.utils.ShulkerBoxesUtil.encodeMaxStackSize(value.copy());
|
|
+ buffer.writeVarInt(io.papermc.paper.util.sanitizer.ItemComponentSanitizer.sanitizeCount(io.papermc.paper.util.sanitizer.ItemObfuscationSession.currentSession(), itemStack, itemStack.getCount())); // Paper - potentially sanitize count
|
|
+ Item.STREAM_CODEC.encode(buffer, itemStack.getItemHolder());
|
|
// Paper start - adventure; conditionally render translatable components
|
|
boolean prev = net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.get();
|
|
- try (final io.papermc.paper.util.SafeAutoClosable ignored = io.papermc.paper.util.sanitizer.ItemObfuscationSession.withContext(c -> c.itemStack(value))) { // pass the itemstack as context to the obfuscation session
|
|
+ try (final io.papermc.paper.util.SafeAutoClosable ignored = io.papermc.paper.util.sanitizer.ItemObfuscationSession.withContext(c -> c.itemStack(itemStack))) { // pass the itemstack as context to the obfuscation session
|
|
net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(true);
|
|
- codec.encode(buffer, value.components.asPatch());
|
|
+ codec.encode(buffer, itemStack.components.asPatch());
|
|
} finally {
|
|
net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(prev);
|
|
}
|
|
@@ -299,7 +302,7 @@ public final class ItemStack implements DataComponentHolder {
|
|
|
|
for (ItemStack itemStack : itemContainerContents.nonEmptyItems()) {
|
|
int count = itemStack.getCount();
|
|
- int maxStackSize = itemStack.getMaxStackSize();
|
|
+ int maxStackSize = fun.bm.lophine.utils.ShulkerBoxesUtil.getItemMaxCount(itemStack); // Leaves - stackable shulker boxes
|
|
if (count > maxStackSize) {
|
|
return DataResult.error(() -> "Item stack with count of " + count + " was larger than maximum: " + maxStackSize);
|
|
}
|
|
diff --git a/net/minecraft/world/level/block/AbstractCauldronBlock.java b/net/minecraft/world/level/block/AbstractCauldronBlock.java
|
|
index 1a927b08f86c0585e62d8c4207954ab36d3316ee..e9899a03b15a2ca3dbd941775f14b041bbcfc85e 100644
|
|
--- a/net/minecraft/world/level/block/AbstractCauldronBlock.java
|
|
+++ b/net/minecraft/world/level/block/AbstractCauldronBlock.java
|
|
@@ -57,9 +57,27 @@ public abstract class AbstractCauldronBlock extends Block {
|
|
ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult
|
|
) {
|
|
CauldronInteraction cauldronInteraction = this.interactions.map().get(stack.getItem());
|
|
- return cauldronInteraction.interact(state, level, pos, player, hand, stack, hitResult.getDirection()); // Paper - pass hit direction
|
|
+ return wrapInteractor(cauldronInteraction, state, level, pos, player, hand, stack, hitResult.getDirection()); // Paper - pass hit direction // Leaves - stackable shulker boxes
|
|
}
|
|
|
|
+ // Leaves start - stackable shulker boxes
|
|
+ private InteractionResult wrapInteractor(CauldronInteraction cauldronBehavior, BlockState blockState, Level world, BlockPos blockPos, Player playerEntity, InteractionHand hand, ItemStack itemStack, net.minecraft.core.Direction hitDirection) {
|
|
+ int count = -1;
|
|
+ if (fun.bm.lophine.utils.ShulkerBoxesUtil.shouldCheck() && itemStack.getItem() instanceof net.minecraft.world.item.BlockItem bi &&
|
|
+ bi.getBlock() instanceof ShulkerBoxBlock) {
|
|
+ count = itemStack.getCount();
|
|
+ }
|
|
+ InteractionResult result = cauldronBehavior.interact(blockState, world, blockPos, playerEntity, hand, itemStack, hitDirection);
|
|
+ if (count > 0 && result.consumesAction()) {
|
|
+ ItemStack current = playerEntity.getItemInHand(hand);
|
|
+ if (current.getItem() instanceof net.minecraft.world.item.BlockItem bi && bi.getBlock() instanceof ShulkerBoxBlock) {
|
|
+ current.setCount(count);
|
|
+ }
|
|
+ }
|
|
+ return result;
|
|
+ }
|
|
+ // Leaves end - stackable shulker boxes
|
|
+
|
|
@Override
|
|
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
|
|
return SHAPE;
|
|
diff --git a/net/minecraft/world/level/block/CrafterBlock.java b/net/minecraft/world/level/block/CrafterBlock.java
|
|
index 38b03c7b02bdfc579e5e126c12de3d878e26d188..33e24f2c3b63b2d3b55dfae2f2e55869abeed055 100644
|
|
--- a/net/minecraft/world/level/block/CrafterBlock.java
|
|
+++ b/net/minecraft/world/level/block/CrafterBlock.java
|
|
@@ -192,7 +192,7 @@ public class CrafterBlock extends BaseEntityBlock {
|
|
Direction direction = state.getValue(ORIENTATION).front();
|
|
Container containerAt = HopperBlockEntity.getContainerAt(level, pos.relative(direction));
|
|
ItemStack itemStack = stack.copy();
|
|
- if (containerAt != null && (containerAt instanceof CrafterBlockEntity || stack.getCount() > containerAt.getMaxStackSize(stack))) {
|
|
+ if (containerAt != null && (containerAt instanceof CrafterBlockEntity || stack.getCount() > containerAt.getMaxStackLeaves(stack))) { // Leaves - stackable shulker boxes
|
|
// CraftBukkit start - InventoryMoveItemEvent
|
|
org.bukkit.craftbukkit.inventory.CraftItemStack oitemstack = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack);
|
|
|
|
diff --git a/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
index 36a72a11d28f99bfe85868461925b778cc01478e..831900a4ed6ca335707289391a095af7717a01a4 100644
|
|
--- a/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
@@ -409,7 +409,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
|
|
ItemStack itemStack = this.items.get(index);
|
|
boolean flag = !stack.isEmpty() && ItemStack.isSameItemSameComponents(itemStack, stack);
|
|
this.items.set(index, stack);
|
|
- stack.limitSize(this.getMaxStackSize(stack));
|
|
+ stack.limitSize(this.getMaxStackLeaves(stack)); // Leaves - stackable shulker boxes
|
|
if (index == 0 && !flag && this.level instanceof ServerLevel serverLevel) {
|
|
this.cookingTotalTime = getTotalCookTime(serverLevel, this, this.recipeType, this.cookSpeedMultiplier); // Paper - cook speed multiplier API
|
|
this.cookingTimer = 0;
|
|
diff --git a/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java b/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
|
index 5a094257a31f0500278a706a418e1697f8810ffb..1f132848ae284668c05d6ca17d5890fa341e14cd 100644
|
|
--- a/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
|
@@ -145,7 +145,7 @@ public abstract class BaseContainerBlockEntity extends BlockEntity implements Co
|
|
@Override
|
|
public void setItem(int slot, ItemStack stack) {
|
|
this.getItems().set(slot, stack);
|
|
- stack.limitSize(this.getMaxStackSize(stack));
|
|
+ stack.limitSize(this.getMaxStackLeaves(stack)); // Leaves - stackable shulker boxes
|
|
this.setChanged();
|
|
}
|
|
|
|
diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
index 5de769e7bd56bb3355c3c711d46ce5e103ea4409..061501979195cf43c6da4d4b6cf6359251978bd3 100644
|
|
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
@@ -123,7 +123,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
public void setItem(int index, ItemStack stack) {
|
|
this.unpackLootTable(null);
|
|
this.getItems().set(index, stack);
|
|
- stack.limitSize(this.getMaxStackSize(stack));
|
|
+ stack.limitSize(this.getMaxStackLeaves(stack)); // Leaves - stackable shulker boxes
|
|
}
|
|
|
|
@Override
|
|
@@ -690,9 +690,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
if (item.isEmpty()) {
|
|
// Spigot start - SPIGOT-6693, SimpleContainer#setItem
|
|
ItemStack leftover = ItemStack.EMPTY; // Paper - Make hoppers respect inventory max stack size
|
|
- if (!stack.isEmpty() && stack.getCount() > destination.getMaxStackSize()) {
|
|
+ if (!stack.isEmpty() && (stack.getCount() > destination.getMaxStackSize() || stack.getCount() > stack.getMaxStackSize())) {
|
|
leftover = stack; // Paper - Make hoppers respect inventory max stack size
|
|
- stack = stack.split(destination.getMaxStackSize());
|
|
+ stack = stack.split(Math.min(destination.getMaxStackSize(), stack.getMaxStackSize()));
|
|
}
|
|
// Spigot end
|
|
IGNORE_TILE_UPDATES.set(Boolean.TRUE); // Paper - Perf: Optimize Hoppers // Folia - region threading
|