mirror of
https://github.com/LeavesMC/Leaves.git
synced 2026-01-04 15:41:31 +00:00
Better stackable shulker (#532)
This commit is contained in:
@@ -25,41 +25,6 @@ index 643797124fe5a4489d0b7419b7e600c04f283ef2..51971a4ef18ab048dc576c26652982d5
|
||||
}
|
||||
|
||||
public String serialize(HolderLookup.Provider levelRegistry) {
|
||||
diff --git a/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java b/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
||||
index f550a87a93b51704b48e9ea25f669bcd930e26e4..988e3bdb8cdb61f4a9d63a3de28dba997c1ee439 100644
|
||||
--- a/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
||||
+++ b/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
||||
@@ -19,9 +19,16 @@ public record ClientboundContainerSetContentPacket(int containerId, int stateId,
|
||||
ClientboundContainerSetContentPacket::items,
|
||||
ItemStack.OPTIONAL_STREAM_CODEC,
|
||||
ClientboundContainerSetContentPacket::carriedItem,
|
||||
- ClientboundContainerSetContentPacket::new
|
||||
+ ClientboundContainerSetContentPacket::create // Leaves - stackable shulker boxes
|
||||
);
|
||||
|
||||
+ // Leaves start - stackable shulker boxes
|
||||
+ private static ClientboundContainerSetContentPacket create(int containerId, int stateId, List<ItemStack> items, ItemStack carriedItem) {
|
||||
+ items.forEach(org.leavesmc.leaves.util.ShulkerBoxUtils::correctItemStackMaxStackSize);
|
||||
+ return new ClientboundContainerSetContentPacket(containerId, stateId, items, carriedItem);
|
||||
+ }
|
||||
+ // Leaves end - stackable shulker boxes
|
||||
+
|
||||
// Paper start - Handle large packets disconnecting client
|
||||
@Override
|
||||
public boolean hasLargePacketFallback() {
|
||||
diff --git a/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java b/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
index c1130f596cf3443eeb62eb1b12587172fe0859ee..ad51ad9f104f8f7238298b025e2d7485aa88a253 100644
|
||||
--- a/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
+++ b/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
@@ -19,7 +19,7 @@ public class ClientboundContainerSetSlotPacket implements Packet<ClientGamePacke
|
||||
this.containerId = containerId;
|
||||
this.stateId = stateId;
|
||||
this.slot = slot;
|
||||
- this.itemStack = itemStack.copy();
|
||||
+ this.itemStack = org.leavesmc.leaves.util.ShulkerBoxUtils.correctItemStackMaxStackSize(itemStack.copy()); // Leaves - stackable shulker boxes
|
||||
}
|
||||
|
||||
private ClientboundContainerSetSlotPacket(RegistryFriendlyByteBuf buffer) {
|
||||
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
|
||||
@@ -74,7 +39,7 @@ index b81f98738ef166336e4cc3092b6ba63f385b68e3..e800abc1149db77bc9b7ee1aabd17526
|
||||
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 064a9b6cf6792192fc1fa80095a48c2025cebf2a..72e1265509a00376515e963499099c0765104ea2 100644
|
||||
index 064a9b6cf6792192fc1fa80095a48c2025cebf2a..64e35d11a901ea77a1a22386fbbf4ff450ece1a8 100644
|
||||
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -2974,7 +2974,7 @@ public class ServerGamePacketListenerImpl
|
||||
@@ -99,7 +64,7 @@ index 064a9b6cf6792192fc1fa80095a48c2025cebf2a..72e1265509a00376515e963499099c07
|
||||
this.player.containerMenu.broadcastFullState();
|
||||
} else {
|
||||
this.player.containerMenu.broadcastChanges();
|
||||
+ this.player.containerMenu.broadcastCarriedItem(); // Leaves - stackable shulker boxes - force send carried item
|
||||
+ 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.
|
||||
}
|
||||
@@ -112,6 +77,14 @@ index 064a9b6cf6792192fc1fa80095a48c2025cebf2a..72e1265509a00376515e963499099c07
|
||||
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
|
||||
@@ -291,10 +264,24 @@ index feebd1610ebd3c26a337259c14f5c774dc72b937..7df6ff842e41763aec2d88d1f8a5f750
|
||||
|
||||
default SlotAccess getChestVehicleSlot(final int index) {
|
||||
diff --git a/net/minecraft/world/inventory/AbstractContainerMenu.java b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
index 2a4763c951ddc78c9d8a39e661e59bbffc5cf109..c6cdf1ffcf80de4872d59e1b628547f0d93e905e 100644
|
||||
index 2a4763c951ddc78c9d8a39e661e59bbffc5cf109..260ed8a599c4fc9ba0efe08a05448b02bcbb755c 100644
|
||||
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
@@ -428,7 +428,7 @@ public abstract class AbstractContainerMenu {
|
||||
@@ -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);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
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;
|
||||
@@ -303,7 +290,7 @@ index 2a4763c951ddc78c9d8a39e661e59bbffc5cf109..c6cdf1ffcf80de4872d59e1b628547f0
|
||||
int min1 = Math.min(getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemStack) + i2, min);
|
||||
count -= min1 - i2;
|
||||
// slot1.setByPlayer(itemStack.copyWithCount(min1));
|
||||
@@ -542,7 +542,7 @@ public abstract class AbstractContainerMenu {
|
||||
@@ -542,7 +549,7 @@ public abstract class AbstractContainerMenu {
|
||||
slot.setByPlayer(carried2);
|
||||
}
|
||||
} else if (ItemStack.isSameItemSameComponents(carried, carried2)) {
|
||||
@@ -312,7 +299,7 @@ index 2a4763c951ddc78c9d8a39e661e59bbffc5cf109..c6cdf1ffcf80de4872d59e1b628547f0
|
||||
optional1.ifPresent(itemStack2 -> {
|
||||
carried2.grow(itemStack2.getCount());
|
||||
slot.onTake(player, itemStack2);
|
||||
@@ -604,7 +604,7 @@ public abstract class AbstractContainerMenu {
|
||||
@@ -604,7 +611,7 @@ public abstract class AbstractContainerMenu {
|
||||
Slot slot2 = this.slots.get(slotId);
|
||||
if (slot2.hasItem()) {
|
||||
ItemStack itemStack = slot2.getItem();
|
||||
@@ -321,7 +308,7 @@ index 2a4763c951ddc78c9d8a39e661e59bbffc5cf109..c6cdf1ffcf80de4872d59e1b628547f0
|
||||
}
|
||||
} else if (clickType == ClickType.THROW && this.getCarried().isEmpty() && slotId >= 0) {
|
||||
Slot slot2 = this.slots.get(slotId);
|
||||
@@ -635,15 +635,15 @@ public abstract class AbstractContainerMenu {
|
||||
@@ -635,15 +642,15 @@ public abstract class AbstractContainerMenu {
|
||||
int maxStackSize = button == 0 ? 1 : -1;
|
||||
|
||||
for (int i3 = 0; i3 < 2; i3++) {
|
||||
@@ -340,7 +327,7 @@ index 2a4763c951ddc78c9d8a39e661e59bbffc5cf109..c6cdf1ffcf80de4872d59e1b628547f0
|
||||
itemStack.grow(itemStack1.getCount());
|
||||
}
|
||||
}
|
||||
@@ -761,7 +761,7 @@ public abstract class AbstractContainerMenu {
|
||||
@@ -761,7 +768,7 @@ public abstract class AbstractContainerMenu {
|
||||
i = endIndex - 1;
|
||||
}
|
||||
|
||||
@@ -349,7 +336,7 @@ index 2a4763c951ddc78c9d8a39e661e59bbffc5cf109..c6cdf1ffcf80de4872d59e1b628547f0
|
||||
while (!stack.isEmpty() && (reverseDirection ? i >= startIndex : i < endIndex)) {
|
||||
Slot slot = this.slots.get(i);
|
||||
ItemStack item = slot.getItem();
|
||||
@@ -862,7 +862,7 @@ public abstract class AbstractContainerMenu {
|
||||
@@ -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())
|
||||
@@ -358,7 +345,7 @@ index 2a4763c951ddc78c9d8a39e661e59bbffc5cf109..c6cdf1ffcf80de4872d59e1b628547f0
|
||||
: flag;
|
||||
}
|
||||
|
||||
@@ -870,7 +870,7 @@ public abstract class AbstractContainerMenu {
|
||||
@@ -870,7 +877,7 @@ public abstract class AbstractContainerMenu {
|
||||
return switch (type) {
|
||||
case 0 -> Mth.floor((float)stack.getCount() / slots.size());
|
||||
case 1 -> 1;
|
||||
@@ -367,7 +354,7 @@ index 2a4763c951ddc78c9d8a39e661e59bbffc5cf109..c6cdf1ffcf80de4872d59e1b628547f0
|
||||
default -> stack.getCount();
|
||||
};
|
||||
}
|
||||
@@ -892,7 +892,7 @@ public abstract class AbstractContainerMenu {
|
||||
@@ -892,7 +899,7 @@ public abstract class AbstractContainerMenu {
|
||||
for (int i = 0; i < container.getContainerSize(); i++) {
|
||||
ItemStack item = container.getItem(i);
|
||||
if (!item.isEmpty()) {
|
||||
@@ -403,7 +390,7 @@ index 5ceb8964476b40db4511bec91ff13c4f522a1357..371bad86218971d6e031c6d74307b2ab
|
||||
|
||||
@Nullable
|
||||
diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java
|
||||
index 24ecca78dc1140b6fc47d59f2acefca6bc2b0220..5671b5a727c13b4034ee71ab20dc1c8d1ad5e991 100644
|
||||
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 {
|
||||
@@ -415,14 +402,24 @@ index 24ecca78dc1140b6fc47d59f2acefca6bc2b0220..5671b5a727c13b4034ee71ab20dc1c8d
|
||||
@Nullable
|
||||
private Entity entityRepresentation;
|
||||
|
||||
@@ -201,13 +201,15 @@ public final class ItemStack implements DataComponentHolder {
|
||||
@@ -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.correctItemStackMaxStackSize(value.copy());
|
||||
+ 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
|
||||
@@ -435,7 +432,7 @@ index 24ecca78dc1140b6fc47d59f2acefca6bc2b0220..5671b5a727c13b4034ee71ab20dc1c8d
|
||||
} finally {
|
||||
net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(prev);
|
||||
}
|
||||
@@ -302,7 +304,7 @@ public final class ItemStack implements DataComponentHolder {
|
||||
@@ -302,7 +305,7 @@ public final class ItemStack implements DataComponentHolder {
|
||||
|
||||
for (ItemStack itemStack : itemContainerContents.nonEmptyItems()) {
|
||||
int count = itemStack.getCount();
|
||||
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] No block update command
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
||||
index 26a20dea38628c7acd88f172a09b12af02a82d09..e1962e123dc2d6a3cf97ba723532e30863bf400f 100644
|
||||
index 270ce4c452ed7efce45923e80b11a606c3f15dab..07f2af32c57cf002af0b25e4a9f2c75558663c86 100644
|
||||
--- a/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -1786,6 +1786,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||
@@ -17,10 +17,10 @@ index 26a20dea38628c7acd88f172a09b12af02a82d09..e1962e123dc2d6a3cf97ba723532e308
|
||||
this.neighborUpdater.updateNeighborsAtExceptFromFacing(pos, block, null, orientation);
|
||||
}
|
||||
diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java
|
||||
index e98be72cc4ec6c613835c514153b0615d839f8b9..8106a9532f8b41fdf423b3aee46a0a7dffd6867b 100644
|
||||
index 649d17dcd7856e3b1344192d8ea4b2e9f73fc03b..93b7c607e0f527a910fc15c88c9a0a9ede26f23d 100644
|
||||
--- a/net/minecraft/world/item/ItemStack.java
|
||||
+++ b/net/minecraft/world/item/ItemStack.java
|
||||
@@ -481,7 +481,7 @@ public final class ItemStack implements DataComponentHolder {
|
||||
@@ -482,7 +482,7 @@ public final class ItemStack implements DataComponentHolder {
|
||||
net.minecraft.world.level.block.state.BlockState block = serverLevel.getBlockState(newPos);
|
||||
|
||||
if (!(block.getBlock() instanceof net.minecraft.world.level.block.BaseEntityBlock)) { // Containers get placed automatically
|
||||
@@ -30,7 +30,7 @@ index e98be72cc4ec6c613835c514153b0615d839f8b9..8106a9532f8b41fdf423b3aee46a0a7d
|
||||
|
||||
serverLevel.notifyAndUpdatePhysics(newPos, null, oldBlock, block, serverLevel.getBlockState(newPos), updateFlags, net.minecraft.world.level.block.Block.UPDATE_LIMIT); // send null chunk as chunk.k() returns false by this point
|
||||
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
|
||||
index bf731da711ce629c0f9250a7bd4025d363623773..9714752bfe7019b2578b3b993801d797d642ff96 100644
|
||||
index 845319dd3e355f739cce70b7df3172dd146601b1..7fca1659bd85b1a737355fb9a8377dff64a7fe17 100644
|
||||
--- a/net/minecraft/world/level/chunk/LevelChunk.java
|
||||
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
|
||||
@@ -413,7 +413,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
|
||||
|
||||
@@ -5,10 +5,10 @@ Subject: [PATCH] Allow grindstone overstacking
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/inventory/AbstractContainerMenu.java b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
index ca02b10c0491e7f5b41157ce8613c299c91d13c0..b15dbce0bb39d7f736c9f05c942e0acb4e55de72 100644
|
||||
index 260ed8a599c4fc9ba0efe08a05448b02bcbb755c..842a5dfeb16ce5bd9af57e5af4cce90bd766c6b2 100644
|
||||
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
@@ -747,10 +747,15 @@ public abstract class AbstractContainerMenu {
|
||||
@@ -754,10 +754,15 @@ public abstract class AbstractContainerMenu {
|
||||
public abstract boolean stillValid(Player player);
|
||||
|
||||
protected boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection) {
|
||||
@@ -24,7 +24,7 @@ index ca02b10c0491e7f5b41157ce8613c299c91d13c0..b15dbce0bb39d7f736c9f05c942e0acb
|
||||
if (isCheck) {
|
||||
stack = stack.copy();
|
||||
}
|
||||
@@ -815,6 +820,14 @@ public abstract class AbstractContainerMenu {
|
||||
@@ -822,6 +827,14 @@ public abstract class AbstractContainerMenu {
|
||||
// Paper end - Add PlayerTradeEvent and PlayerPurchaseEvent
|
||||
if (itemx.isEmpty() && slotx.mayPlace(stack)) {
|
||||
int i1 = slotx.getMaxStackSize(stack);
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package org.leavesmc.leaves.util;
|
||||
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
import net.minecraft.world.item.component.ItemContainerContents;
|
||||
import net.minecraft.world.level.block.ShulkerBoxBlock;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.leavesmc.leaves.LeavesConfig;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ShulkerBoxUtils {
|
||||
|
||||
public static boolean shulkerBoxNoItem(@NotNull ItemStack stack) {
|
||||
@@ -23,10 +26,34 @@ public class ShulkerBoxUtils {
|
||||
return stack.getMaxStackSize();
|
||||
}
|
||||
|
||||
public static ItemStack correctItemStackMaxStackSize(ItemStack itemStack) {
|
||||
int trulyMaxStackSize = getItemStackMaxCount(itemStack);
|
||||
if (itemStack.getMaxStackSize() != trulyMaxStackSize) {
|
||||
itemStack.set(DataComponents.MAX_STACK_SIZE, trulyMaxStackSize);
|
||||
public static int getItemStackMaxCountReal(ItemStack stack) {
|
||||
CompoundTag nbt = Optional.ofNullable(stack.get(DataComponents.CUSTOM_DATA)).orElse(CustomData.EMPTY).copyTag();
|
||||
return nbt.getInt("Leaves.RealStackSize").orElse(stack.getMaxStackSize());
|
||||
}
|
||||
|
||||
public static ItemStack encodeMaxStackSize(ItemStack itemStack) {
|
||||
int realMaxStackSize = getItemStackMaxCountReal(itemStack);
|
||||
int modifiedMaxStackSize = getItemStackMaxCount(itemStack);
|
||||
if (itemStack.getMaxStackSize() != modifiedMaxStackSize) {
|
||||
itemStack.set(DataComponents.MAX_STACK_SIZE, modifiedMaxStackSize);
|
||||
CompoundTag nbt = itemStack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).copyTag();
|
||||
nbt.putInt("Leaves.RealStackSize", realMaxStackSize);
|
||||
itemStack.set(DataComponents.CUSTOM_DATA, CustomData.of(nbt));
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static ItemStack decodeMaxStackSize(ItemStack itemStack) {
|
||||
int realMaxStackSize = getItemStackMaxCountReal(itemStack);
|
||||
if (itemStack.getMaxStackSize() != realMaxStackSize) {
|
||||
itemStack.set(DataComponents.MAX_STACK_SIZE, realMaxStackSize);
|
||||
CompoundTag nbt = itemStack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).copyTag();
|
||||
nbt.remove("Leaves.RealStackSize");
|
||||
if (nbt.isEmpty()) {
|
||||
itemStack.remove(DataComponents.CUSTOM_DATA);
|
||||
} else {
|
||||
itemStack.set(DataComponents.CUSTOM_DATA, CustomData.of(nbt));
|
||||
}
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
@@ -34,4 +61,4 @@ public class ShulkerBoxUtils {
|
||||
public static boolean isStackable(ItemStack itemStack) {
|
||||
return getItemStackMaxCount(itemStack) > 1 && (!itemStack.isDamageableItem() || !itemStack.isDamaged());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user