9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/patches/server/0134-Change-max-stack-count.patch
2024-11-29 17:55:29 -05:00

150 lines
8.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: FallingKey <FallingKey@Outlook.com>
Date: Sun, 11 Aug 2024 14:20:37 +0800
Subject: [PATCH] Change max stack count
TODO - Dreeam:
- Check shulkerbox unpack whether correct
- stacked dropped shulkerbox unpack issue, need to base on box's item count
- dropped itemstack -> hopper behavior, need to transfer into hopper with correct count
- ...still testing lol
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
index af0f7ce6efa799e6f5ea6d34250d462f51b1c4e3..7db0f22a22f6752380d62d4e53bc9481464e2233 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -348,7 +348,13 @@ public class ItemEntity extends Entity implements TraceableEntity {
private boolean isMergable() {
ItemStack itemstack = this.getItem();
- return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && itemstack.getCount() < itemstack.getMaxStackSize(); // Paper - Alternative item-despawn-rate
+ // Leaf start - Change max stack count
+ if (org.dreeam.leaf.config.modules.gameplay.MaxItemsStackCount.maxItemStackCount < 1) {
+ return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && itemstack.getCount() < itemstack.getMaxStackSize(); // Paper - Alternative item-despawn-rate
+ } else {
+ return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && itemstack.getCount() < org.dreeam.leaf.config.modules.gameplay.MaxItemsStackCount.maxItemStackCount; // Paper - Alternative item-despawn-rate
+ }
+ // Leaf end - Change max stack count
}
private void tryToMerge(ItemEntity other) {
@@ -366,11 +372,24 @@ public class ItemEntity extends Entity implements TraceableEntity {
}
public static boolean areMergable(ItemStack stack1, ItemStack stack2) {
- return stack2.getCount() + stack1.getCount() > stack2.getMaxStackSize() ? false : ItemStack.isSameItemSameComponents(stack1, stack2);
+ // Leaf start - Change max stack count
+ if (org.dreeam.leaf.config.modules.gameplay.MaxItemsStackCount.maxItemStackCount == 0) {
+ return stack2.getCount() + stack1.getCount() > stack2.getMaxStackSize() ? false : ItemStack.isSameItemSameComponents(stack1, stack2);
+ } else {
+ return stack2.getCount() + stack1.getCount() > org.dreeam.leaf.config.modules.gameplay.MaxItemsStackCount.maxItemStackCount ? false : ItemStack.isSameItemSameComponents(stack1, stack2);
+ }
+ // Leaf end - Change max stack count
}
public static ItemStack merge(ItemStack stack1, ItemStack stack2, int maxCount) {
- int j = Math.min(Math.min(stack1.getMaxStackSize(), maxCount) - stack1.getCount(), stack2.getCount());
+ // Leaf start - Change max stack count
+ int j;
+ if (org.dreeam.leaf.config.modules.gameplay.MaxItemsStackCount.maxItemStackCount == 0) {
+ j = Math.min(Math.min(stack1.getMaxStackSize(), maxCount) - stack1.getCount(), stack2.getCount());
+ } else {
+ j = Math.min(Math.min(org.dreeam.leaf.config.modules.gameplay.MaxItemsStackCount.maxItemStackCount, maxCount) - stack1.getCount(), stack2.getCount());
+ }
+ // Leaf end - Change max stack count
ItemStack itemstack2 = stack1.copyWithCount(stack1.getCount() + j);
stack2.shrink(j);
@@ -378,7 +397,14 @@ public class ItemEntity extends Entity implements TraceableEntity {
}
private static void merge(ItemEntity targetEntity, ItemStack stack1, ItemStack stack2) {
- ItemStack itemstack2 = ItemEntity.merge(stack1, stack2, 64);
+ // Leaf start - Change max stack count
+ ItemStack itemstack2;
+ if (org.dreeam.leaf.config.modules.gameplay.MaxItemsStackCount.maxItemStackCount < 1) {
+ itemstack2 = ItemEntity.merge(stack1, stack2, 64);
+ } else {
+ itemstack2 = ItemEntity.merge(stack1, stack2, org.dreeam.leaf.config.modules.gameplay.MaxItemsStackCount.maxItemStackCount);
+ }
+ // Leaf end - Change max stack count
targetEntity.setItem(itemstack2);
}
diff --git a/src/main/java/net/minecraft/world/item/ItemUtils.java b/src/main/java/net/minecraft/world/item/ItemUtils.java
index 4901f0d89ae2472bce7f242d9529236674f5d134..127f41511cdcaacc00e0f128c20339f38c7ce733 100644
--- a/src/main/java/net/minecraft/world/item/ItemUtils.java
+++ b/src/main/java/net/minecraft/world/item/ItemUtils.java
@@ -42,14 +42,32 @@ public class ItemUtils {
Level level = itemEntity.level();
if (!level.isClientSide) {
// Paper start - call EntityDropItemEvent
- contents.forEach(stack -> {
- ItemEntity droppedItem = new ItemEntity(level, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), stack);
- org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(itemEntity.getBukkitEntity(), (org.bukkit.entity.Item) droppedItem.getBukkitEntity());
- if (event.callEvent()) {
- level.addFreshEntity(droppedItem);
+ // Leaf start - Change max stack count
+ if (org.dreeam.leaf.config.modules.gameplay.MaxItemsStackCount.maxContainerDestroyCount == 0) {
+ contents.forEach(stack -> {
+ addFreshEntityWithCallEvent(itemEntity, level, stack);
+ });
+ } else {
+ java.util.Iterator<ItemStack> iterator = contents.iterator();
+ for (int count = Math.min(itemEntity.getItem().getCount(), org.dreeam.leaf.config.modules.gameplay.MaxItemsStackCount.maxContainerDestroyCount); count > 0; count--) {
+ if (!iterator.hasNext()) break;
+
+ ItemStack stack = iterator.next();
+ addFreshEntityWithCallEvent(itemEntity, level, stack);
}
- });
+ }
+ // Leaf end - Change max stack count
// Paper end - call EntityDropItemEvent
}
}
+
+ // Leaf start - Change max stack count
+ private static void addFreshEntityWithCallEvent(ItemEntity itemEntity, Level level, ItemStack stack) {
+ ItemEntity droppedItem = new ItemEntity(level, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), stack);
+ org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(itemEntity.getBukkitEntity(), (org.bukkit.entity.Item) droppedItem.getBukkitEntity());
+ if (event.callEvent()) {
+ level.addFreshEntity(droppedItem);
+ }
+ }
+ // Leaf end - Change max stack count
}
diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxItemsStackCount.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxItemsStackCount.java
new file mode 100644
index 0000000000000000000000000000000000000000..434a938cb1e2ac906783be2507fa7846f2f013a2
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxItemsStackCount.java
@@ -0,0 +1,27 @@
+package org.dreeam.leaf.config.modules.gameplay;
+
+import org.dreeam.leaf.config.ConfigModules;
+import org.dreeam.leaf.config.EnumConfigCategory;
+
+public class MaxItemsStackCount extends ConfigModules {
+
+ public String getBasePath() {
+ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".max-item-stack-count";
+ }
+
+ public static int maxItemStackCount = 0;
+ public static int maxContainerDestroyCount = 0;
+
+ @Override
+ public void onLoaded() {
+ config.addCommentRegionBased(getBasePath(),
+ "Don't touch this unless you know what you are doing!",
+ "不要动该项, 除非你知道自己在做什么!");
+
+ maxItemStackCount = config.getInt(getBasePath() + ".max-dropped-items-stack-count", maxItemStackCount);
+ maxContainerDestroyCount = config.getInt(getBasePath() + ".max-container-destroy-count", maxContainerDestroyCount);
+
+ if (maxItemStackCount < 0) maxItemStackCount = 0;
+ if (maxContainerDestroyCount < 0) maxContainerDestroyCount = 0;
+ }
+}