mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-22 16:39:22 +00:00
[ci skip] Drop Optimize check nearby fire or lava on entity move
This commit is contained in:
147
patches/server/0110-Change-max-stack-count.patch
Normal file
147
patches/server/0110-Change-max-stack-count.patch
Normal file
@@ -0,0 +1,147 @@
|
||||
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 1fe41abcdc28013e2dae4b5c3ee727759fc3890c..18773f975b70f4d871808aa0eb1f7313baf26a91 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
||||
@@ -350,7 +350,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) {
|
||||
@@ -368,11 +374,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);
|
||||
@@ -380,7 +399,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..4a895897111454dc3558aa491b9d81cf610b5bbf
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxItemsStackCount.java
|
||||
@@ -0,0 +1,25 @@
|
||||
+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.addComment(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;
|
||||
+ }
|
||||
+}
|
||||
Reference in New Issue
Block a user