mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
--------- Co-authored-by: violetc <58360096+s-yh-china@users.noreply.github.com> Co-authored-by: Fortern <blueten.ki@gmail.com> Co-authored-by: MC_XiaoHei <xor7xiaohei@gmail.com> Co-authored-by: Helvetica Volubi <88063803+Suisuroru@users.noreply.github.com> Co-authored-by: MC_XiaoHei <xiaohei.xor7@outlook.com>
541 lines
36 KiB
Diff
541 lines
36 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
Date: Wed, 14 Dec 2022 14:47:06 +0800
|
|
Subject: [PATCH] Stackable ShulkerBoxes
|
|
|
|
This patch is Powered by fabric-carpet(https://github.com/gnembon/fabric-carpet) and plusls-carpet-addition(https://github.com/plusls/plusls-carpet-addition)
|
|
|
|
diff --git a/net/minecraft/commands/arguments/item/ItemInput.java b/net/minecraft/commands/arguments/item/ItemInput.java
|
|
index 643797124fe5a4489d0b7419b7e600c04f283ef2..51971a4ef18ab048dc576c26652982d57e440dc0 100644
|
|
--- a/net/minecraft/commands/arguments/item/ItemInput.java
|
|
+++ b/net/minecraft/commands/arguments/item/ItemInput.java
|
|
@@ -39,11 +39,13 @@ 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());
|
|
+ // Leaves start - stackable shulker boxes
|
|
+ if (allowOversizedStacks && count > org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemStack)) {
|
|
+ throw ERROR_STACK_TOO_BIG.create(this.getItemName(), org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemStack));
|
|
} else {
|
|
return itemStack;
|
|
}
|
|
+ // Leaves end - stackable shulker boxes
|
|
}
|
|
|
|
public String serialize(HolderLookup.Provider levelRegistry) {
|
|
diff --git a/net/minecraft/server/commands/GiveCommand.java b/net/minecraft/server/commands/GiveCommand.java
|
|
index b81f98738ef166336e4cc3092b6ba63f385b68e3..e800abc1149db77bc9b7ee1aabd17526ebda377c 100644
|
|
--- a/net/minecraft/server/commands/GiveCommand.java
|
|
+++ b/net/minecraft/server/commands/GiveCommand.java
|
|
@@ -52,7 +52,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 = org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemStack); // Leaves - stackable shulker boxes
|
|
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 9041830c19e2899479e1519488faba5c416ccd88..ca814ebdb05ca3af138bf087f26d2cf50baf3b9c 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -2974,7 +2974,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, org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(clickedItem) - clickedItem.getCount()); // Leaves - stackable shulker boxes
|
|
toPlace = Math.min(toPlace, slot.container.getMaxStackSize() - clickedItem.getCount());
|
|
if (toPlace == 1) {
|
|
action = InventoryAction.PLACE_ONE;
|
|
@@ -3010,7 +3010,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() <= org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(cursor)) { // Leaves - stackable shulker boxes
|
|
// As of 1.5, this is result slots only
|
|
action = InventoryAction.PICKUP_ALL;
|
|
}
|
|
@@ -3269,6 +3269,7 @@ public class ServerGamePacketListenerImpl
|
|
this.player.containerMenu.broadcastFullState();
|
|
} else {
|
|
this.player.containerMenu.broadcastChanges();
|
|
+ if (org.leavesmc.leaves.LeavesConfig.modify.shulkerBoxStackSize > 1) this.player.containerMenu.broadcastCarriedItem(); // Leaves - stackable shulker boxes - force send carried item
|
|
}
|
|
if (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.updateEquipmentOnPlayerActions) this.player.detectEquipmentUpdates(); // Paper - Force update attributes.
|
|
}
|
|
@@ -3381,7 +3382,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() <= org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemStack); // Leaves - stackable shulker boxes
|
|
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();
|
|
@@ -3423,6 +3424,7 @@ public class ServerGamePacketListenerImpl
|
|
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemStack);
|
|
this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemStack);
|
|
this.player.inventoryMenu.broadcastChanges();
|
|
+ if (org.leavesmc.leaves.LeavesConfig.modify.shulkerBoxStackSize > 1) this.player.containerMenu.sendSingleSlot(packet.slotNum(), itemStack); // Leaves - stackable shulker boxes - force send carried item
|
|
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..f575b464a8ce430646cb872ae6206a9a0677736b 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(), org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(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 133e042371bcf84f1935903ec57d204e3b7abd84..201599988e20219b6a99bf1594ad6c0c19e09038 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 6c0ebfb2be4e8b884456a2aa3d5fdc87e45a0e3c..b0e60d1d2a44bb35c87c35e82a172a38406b6c54 100644
|
|
--- a/net/minecraft/world/entity/item/ItemEntity.java
|
|
+++ b/net/minecraft/world/entity/item/ItemEntity.java
|
|
@@ -281,10 +281,52 @@ 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() < org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(item); // Paper - Alternative item-despawn-rate // Leaves - stackable shulker boxes
|
|
}
|
|
|
|
+ // Leaves end - stackable shulker boxes
|
|
+ private boolean tryStackShulkerBoxes(ItemEntity other) {
|
|
+ ItemStack selfStack = this.getItem();
|
|
+ if (org.leavesmc.leaves.LeavesConfig.modify.shulkerBoxStackSize == 1 ||
|
|
+ !(selfStack.getItem() instanceof net.minecraft.world.item.BlockItem blockItem) ||
|
|
+ !(blockItem.getBlock() instanceof net.minecraft.world.level.block.ShulkerBoxBlock)
|
|
+ ) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ ItemStack otherStack = other.getItem();
|
|
+ if (selfStack.getItem() == otherStack.getItem()
|
|
+ && org.leavesmc.leaves.util.ShulkerBoxUtils.shulkerBoxNoItem(selfStack)
|
|
+ && org.leavesmc.leaves.util.ShulkerBoxUtils.shulkerBoxNoItem(otherStack)
|
|
+ && Objects.equals(selfStack.getComponents(), otherStack.getComponents()) // empty block entity tags are cleaned up when spawning
|
|
+ && selfStack.getCount() != org.leavesmc.leaves.LeavesConfig.modify.shulkerBoxStackSize) {
|
|
+ int amount = Math.min(otherStack.getCount(), org.leavesmc.leaves.LeavesConfig.modify.shulkerBoxStackSize - selfStack.getCount());
|
|
+
|
|
+ selfStack.grow(amount);
|
|
+ this.setItem(selfStack);
|
|
+
|
|
+ this.pickupDelay = Math.max(other.pickupDelay, this.pickupDelay);
|
|
+ this.age = Math.min(other.getAge(), this.age);
|
|
+
|
|
+ otherStack.shrink(amount);
|
|
+ if (otherStack.isEmpty()) {
|
|
+ other.discard();
|
|
+ }
|
|
+ else {
|
|
+ other.setItem(otherStack);
|
|
+ }
|
|
+ return true;
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+ // Leaves end - stackable shulker boxes
|
|
+
|
|
private void tryToMerge(ItemEntity itemEntity) {
|
|
+ // Leaves start - stackable shulker boxes
|
|
+ if (tryStackShulkerBoxes(itemEntity)) {
|
|
+ return;
|
|
+ }
|
|
+ // Leaves end - stackable shulker boxes
|
|
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 d9cb4f0ed0c4f63362c837aeef3c4194911455c9..57bf2819271b3293a065b58d31b609f8463811b4 100644
|
|
--- a/net/minecraft/world/entity/player/Inventory.java
|
|
+++ b/net/minecraft/world/entity/player/Inventory.java
|
|
@@ -148,10 +148,12 @@ public class Inventory implements Container, Nameable {
|
|
}
|
|
|
|
private boolean hasRemainingSpaceForItem(ItemStack destination, ItemStack origin) {
|
|
+ // Leaves start - stackable shulker boxes
|
|
return !destination.isEmpty()
|
|
- && destination.isStackable()
|
|
- && destination.getCount() < this.getMaxStackSize(destination)
|
|
+ && org.leavesmc.leaves.util.ShulkerBoxUtils.isStackable(destination)
|
|
+ && destination.getCount() < org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(destination)
|
|
&& ItemStack.isSameItemSameComponents(destination, origin); // Paper - check if itemstack is stackable first
|
|
+ // Leaves end - stackable shulker boxes
|
|
}
|
|
|
|
// CraftBukkit start - Watch method above! :D
|
|
@@ -164,7 +166,7 @@ public class Inventory implements Container, Nameable {
|
|
}
|
|
|
|
if (this.hasRemainingSpaceForItem(itemInSlot, itemStack)) {
|
|
- remains -= (itemInSlot.getMaxStackSize() < this.getMaxStackSize() ? itemInSlot.getMaxStackSize() : this.getMaxStackSize()) - itemInSlot.getCount();
|
|
+ remains -= (org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemInSlot) < this.getMaxStackSize() ? org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemInSlot) : this.getMaxStackSize()) - itemInSlot.getCount(); // Leaves - stackable shulker boxes
|
|
}
|
|
if (remains <= 0) {
|
|
return itemStack.getCount();
|
|
@@ -173,7 +175,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 -= (org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemInOffhand) < this.getMaxStackSize() ? org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemInOffhand) : this.getMaxStackSize()) - itemInOffhand.getCount(); // Leaves - stackable shulker boxes
|
|
}
|
|
if (remains <= 0) {
|
|
return itemStack.getCount();
|
|
@@ -297,7 +299,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(); // Leaves - stackable shulker boxes
|
|
int min = Math.min(count, i);
|
|
if (min == 0) {
|
|
return count;
|
|
@@ -403,7 +405,7 @@ public class Inventory implements Container, Nameable {
|
|
break;
|
|
}
|
|
|
|
- int i = stack.getMaxStackSize() - this.getItem(slotWithRemainingSpace).getCount();
|
|
+ int i = org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(stack) - this.getItem(slotWithRemainingSpace).getCount(); // Leaves - stackable shulker boxes
|
|
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..1b92676459468d42931b84e5ceb19e8d30302f06 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, org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(stack)); // Leaves - 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 feebd1610ebd3c26a337259c14f5c774dc72b937..7df6ff842e41763aec2d88d1f8a5f7503932d905 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 2a4763c951ddc78c9d8a39e661e59bbffc5cf109..8aa689129334f75986fb7a18895e2c3fb3c365c8 100644
|
|
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
@@ -271,6 +271,13 @@ public abstract class AbstractContainerMenu {
|
|
this.sendAllDataToRemote();
|
|
}
|
|
|
|
+ // Leaves start - stackable shulker boxes
|
|
+ public void sendSingleSlot(int slotIndex, ItemStack item) {
|
|
+ if (this.synchronizer != null) {
|
|
+ this.synchronizer.sendSlotChange(this, slotIndex, item);
|
|
+ }
|
|
+ }
|
|
+ // Leaves end - stackable shulker boxes
|
|
private void updateDataSlotListeners(int slotIndex, int value) {
|
|
for (ContainerListener containerListener : this.containerListeners) {
|
|
containerListener.dataChanged(this, slotIndex, value);
|
|
@@ -428,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(org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemStack), slot1.getMaxStackSize(itemStack)); // Leaves - stackable shulker boxes
|
|
int min1 = Math.min(getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemStack) + i2, min);
|
|
count -= min1 - i2;
|
|
// slot1.setByPlayer(itemStack.copyWithCount(min1));
|
|
@@ -542,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(), org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(carried2) - carried2.getCount(), player); // Leaves - stackable shulker boxes
|
|
optional1.ifPresent(itemStack2 -> {
|
|
carried2.grow(itemStack2.getCount());
|
|
slot.onTake(player, itemStack2);
|
|
@@ -604,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(org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemStack))); // Leaves - stackable shulker boxes
|
|
}
|
|
} else if (clickType == ClickType.THROW && this.getCarried().isEmpty() && slotId >= 0) {
|
|
Slot slot2 = this.slots.get(slotId);
|
|
@@ -635,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() < org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemStack); i4 += maxStackSize) { // Leaves - stackable shulker boxes
|
|
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() != org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(item1)) { // Leaves - stackable shulker boxes
|
|
+ ItemStack itemStack1 = slot3.safeTake(item1.getCount(), org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(itemStack) - itemStack.getCount(), player); // Leaves - stackable shulker boxes
|
|
itemStack.grow(itemStack1.getCount());
|
|
}
|
|
}
|
|
@@ -761,7 +768,7 @@ public abstract class AbstractContainerMenu {
|
|
i = endIndex - 1;
|
|
}
|
|
|
|
- if (stack.isStackable()) {
|
|
+ if (org.leavesmc.leaves.util.ShulkerBoxUtils.isStackable(stack)) { // Leaves - stackable shulker boxes
|
|
while (!stack.isEmpty() && (reverseDirection ? i >= startIndex : i < endIndex)) {
|
|
Slot slot = this.slots.get(i);
|
|
ItemStack item = slot.getItem();
|
|
@@ -862,7 +869,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()) <= org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(stack) // Leaves - stackable shulker boxes
|
|
: flag;
|
|
}
|
|
|
|
@@ -870,7 +877,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 -> org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(stack); // Leaves - stackable shulker boxes
|
|
default -> stack.getCount();
|
|
};
|
|
}
|
|
@@ -892,7 +899,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..371bad86218971d6e031c6d74307b2ab0d460997 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(), org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(stack)); // Leaves - stackable shulker boxes
|
|
}
|
|
|
|
@Nullable
|
|
diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java
|
|
index 24ecca78dc1140b6fc47d59f2acefca6bc2b0220..649d17dcd7856e3b1344192d8ea4b2e9f73fc03b 100644
|
|
--- a/net/minecraft/world/item/ItemStack.java
|
|
+++ b/net/minecraft/world/item/ItemStack.java
|
|
@@ -165,7 +165,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;
|
|
|
|
@@ -192,7 +192,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 org.leavesmc.leaves.util.ShulkerBoxUtils.decodeMaxStackSize(itemStack);
|
|
}
|
|
}
|
|
|
|
@@ -201,13 +202,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 = org.leavesmc.leaves.util.ShulkerBoxUtils.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);
|
|
}
|
|
@@ -302,7 +305,7 @@ public final class ItemStack implements DataComponentHolder {
|
|
|
|
for (ItemStack itemStack : itemContainerContents.nonEmptyItems()) {
|
|
int count = itemStack.getCount();
|
|
- int maxStackSize = itemStack.getMaxStackSize();
|
|
+ int maxStackSize = org.leavesmc.leaves.util.ShulkerBoxUtils.getItemStackMaxCount(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 ad3f32888afd8b5f0038445a1b0fcc8cacec9fe2..18b7b7fe68c54a400f269f5ff1d09fe9e3d519b8 100644
|
|
--- a/net/minecraft/world/level/block/AbstractCauldronBlock.java
|
|
+++ b/net/minecraft/world/level/block/AbstractCauldronBlock.java
|
|
@@ -62,9 +62,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 (org.leavesmc.leaves.LeavesConfig.modify.shulkerBoxStackSize > 1 && 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 7729c33cad94cf2b4162324be75713650fc9d378..78b3bdb668320e9cf2fb09b59929fac43cf56aca 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 c63370fd458fb4f7190b79b1a8174fcc92d88f9c..4cca3fbbb93bb76d5d501dfad6997d909211809e 100644
|
|
--- a/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
|
@@ -148,7 +148,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 2d979850378c05ce569782d8e04a452f986612a7..a2fe5fdf50ae731e423821a0d1c52141b478e0be 100644
|
|
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
@@ -113,7 +113,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
|
|
@@ -692,9 +692,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())) { // Leaves - stackable shulker boxes
|
|
leftover = stack; // Paper - Make hoppers respect inventory max stack size
|
|
- stack = stack.split(destination.getMaxStackSize());
|
|
+ stack = stack.split(Math.min(destination.getMaxStackSize(), stack.getMaxStackSize())); // Leaves - stackable shulker boxes
|
|
}
|
|
// Spigot end
|
|
ignoreBlockEntityUpdates = true; // Paper - Perf: Optimize Hoppers
|