mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
152 lines
8.3 KiB
Diff
152 lines
8.3 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
|
|
|
|
Removed since Leaf 1.21.4, useless
|
|
|
|
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 8eed7d70d5716f6d58c46b31a526b5de2a891f16..baf50c2f50325c64951dc37b1d57076b4a9c5b99 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
|
@@ -351,7 +351,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) {
|
|
@@ -369,11 +375,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);
|
|
@@ -381,7 +400,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 0c4074ed8b4fd9d6fcb838e8843d66f6f286ed5d..4728dd8bcbfc514eb5beeee716d849e578d5a53e 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;
|
|
+ }
|
|
+}
|