From 90a1460e864b11093ff93db48a766da7179ead8c Mon Sep 17 00:00:00 2001 From: FallingKey Date: Sun, 11 Aug 2024 16:15:31 +0800 Subject: [PATCH 1/3] Add configurable items --- .../server/0099-Change-max-stack-count.patch | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 patches/server/0099-Change-max-stack-count.patch diff --git a/patches/server/0099-Change-max-stack-count.patch b/patches/server/0099-Change-max-stack-count.patch new file mode 100644 index 000000000..afbaf3c18 --- /dev/null +++ b/patches/server/0099-Change-max-stack-count.patch @@ -0,0 +1,172 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: FallingKey +Date: Sun, 11 Aug 2024 14:20:37 +0800 +Subject: [PATCH] Change max stack count + + +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 3a27ef6da3d189f4f2211c9929dc1334790ab281..14eea6498e04f34a518988c978f27600715fe098 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.MaxStackCount.count < 1) { ++ return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && itemstack.getCount() < itemstack.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier; // 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.MaxStackCount.count; // 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.MaxStackCount.count == 0) { ++ return stack2.getCount() + stack1.getCount() > stack2.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier ? false : ItemStack.isSameItemSameComponents(stack1, stack2); ++ } else { ++ return stack2.getCount() + stack1.getCount() > org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count ? 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.MaxStackCount.count == 0) { ++ j = Math.min(Math.min(stack1.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier, maxCount) - stack1.getCount(), stack2.getCount()); ++ } else { ++ j = Math.min(Math.min(org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count, 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.MaxStackCount.count < 1) { ++ itemstack2 = ItemEntity.merge(stack1, stack2, 64); ++ } else { ++ itemstack2 = ItemEntity.merge(stack1, stack2, org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count); ++ } ++ // Leaf end - Change max stack count + + targetEntity.setItem(itemstack2); + } +diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java +index 7572c289758001c7417a192f0e6e994ffa8408b3..0e5fd0ba84bb139f23fc02482d54e5be582ced3c 100644 +--- a/src/main/java/net/minecraft/world/item/BlockItem.java ++++ b/src/main/java/net/minecraft/world/item/BlockItem.java +@@ -34,6 +34,7 @@ import net.minecraft.world.phys.shapes.CollisionContext; + import org.bukkit.craftbukkit.block.CraftBlock; + import org.bukkit.craftbukkit.block.data.CraftBlockData; + import org.bukkit.event.block.BlockCanBuildEvent; ++import org.dreeam.leaf.config.modules.gameplay.MaxStackCount; + // CraftBukkit end + + public class BlockItem extends Item { +@@ -269,8 +270,20 @@ public class BlockItem extends Item { + ItemContainerContents itemcontainercontents = (ItemContainerContents) entity.getItem().set(DataComponents.CONTAINER, ItemContainerContents.EMPTY); + + if (itemcontainercontents != null) { +- if (entity.level().purpurConfig.shulkerBoxItemDropContentsWhenDestroyed && entity.getItem().is(Items.SHULKER_BOX)) // Purpur +- ItemUtils.onContainerDestroyed(entity, itemcontainercontents.nonEmptyItemsCopy()); ++ // Leaf start - Change max stack count ++ if (entity.level().purpurConfig.shulkerBoxItemDropContentsWhenDestroyed) { // Purpur ++ if (MaxStackCount.count < 1) { ++ ItemUtils.onContainerDestroyed(entity, itemcontainercontents.nonEmptyItemsCopy()); ++ } else { ++ Level level = entity.level(); ++ if (!level.isClientSide) { ++ for (int Count = Math.min(entity.getItem().getCount(), org.dreeam.leaf.config.modules.gameplay.MaxContainerDestroy.count); Count > 0; Count = Count - 1) { ++ itemcontainercontents.nonEmptyItemsCopy().forEach(stack -> level.addFreshEntity(new ItemEntity(level, entity.getX(), entity.getY(), entity.getZ(), stack))); ++ } ++ } ++ } ++ } ++ // Leaf end - Change max stack count + } + + } +diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java +new file mode 100644 +index 0000000000000000000000000000000000000000..503f80ed917302abdf0ab14c13ce61d14c4b4adc +--- /dev/null ++++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java +@@ -0,0 +1,17 @@ ++package org.dreeam.leaf.config.modules.gameplay; ++ ++import org.dreeam.leaf.config.ConfigModules; ++import org.dreeam.leaf.config.EnumConfigCategory; ++ ++public class ItemStackMultiplier extends ConfigModules { ++ public String getBasePath() { ++ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".item-stack-multiplier"; ++ } ++ ++ public static int multiplier = 1; ++ ++ @Override ++ public void onLoaded() { ++ multiplier = config.getInt(getBasePath(), multiplier); ++ } ++} +diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxContainerDestroy.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxContainerDestroy.java +new file mode 100644 +index 0000000000000000000000000000000000000000..254ce472cb872323fdd86ded689268e439b46d0d +--- /dev/null ++++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxContainerDestroy.java +@@ -0,0 +1,17 @@ ++package org.dreeam.leaf.config.modules.gameplay; ++ ++import org.dreeam.leaf.config.ConfigModules; ++import org.dreeam.leaf.config.EnumConfigCategory; ++ ++public class MaxContainerDestroy extends ConfigModules { ++ public String getBasePath() { ++ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".max-container-destroy"; ++ } ++ ++ public static int count = 32767; ++ ++ @Override ++ public void onLoaded() { ++ count = config.getInt(getBasePath(), count); ++ } ++} +diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java +new file mode 100644 +index 0000000000000000000000000000000000000000..01208acaac7ef34a4f6dff51a208ed66d2d28079 +--- /dev/null ++++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java +@@ -0,0 +1,17 @@ ++package org.dreeam.leaf.config.modules.gameplay; ++ ++import org.dreeam.leaf.config.ConfigModules; ++import org.dreeam.leaf.config.EnumConfigCategory; ++ ++public class MaxStackCount extends ConfigModules { ++ public String getBasePath() { ++ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".change-max-stack-count"; ++ } ++ ++ public static int count = 0; ++ ++ @Override ++ public void onLoaded() { ++ count = config.getInt(getBasePath(), count); ++ } ++} From 230adfb6cba8c3c0d6f104624d59d8d092a55f5a Mon Sep 17 00:00:00 2001 From: FallingKey Date: Wed, 14 Aug 2024 00:36:23 +0800 Subject: [PATCH 2/3] del --- .../server/0099-Change-max-stack-count.patch | 172 ------------------ 1 file changed, 172 deletions(-) delete mode 100644 patches/server/0099-Change-max-stack-count.patch diff --git a/patches/server/0099-Change-max-stack-count.patch b/patches/server/0099-Change-max-stack-count.patch deleted file mode 100644 index afbaf3c18..000000000 --- a/patches/server/0099-Change-max-stack-count.patch +++ /dev/null @@ -1,172 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: FallingKey -Date: Sun, 11 Aug 2024 14:20:37 +0800 -Subject: [PATCH] Change max stack count - - -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 3a27ef6da3d189f4f2211c9929dc1334790ab281..14eea6498e04f34a518988c978f27600715fe098 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.MaxStackCount.count < 1) { -+ return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && itemstack.getCount() < itemstack.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier; // 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.MaxStackCount.count; // 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.MaxStackCount.count == 0) { -+ return stack2.getCount() + stack1.getCount() > stack2.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier ? false : ItemStack.isSameItemSameComponents(stack1, stack2); -+ } else { -+ return stack2.getCount() + stack1.getCount() > org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count ? 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.MaxStackCount.count == 0) { -+ j = Math.min(Math.min(stack1.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier, maxCount) - stack1.getCount(), stack2.getCount()); -+ } else { -+ j = Math.min(Math.min(org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count, 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.MaxStackCount.count < 1) { -+ itemstack2 = ItemEntity.merge(stack1, stack2, 64); -+ } else { -+ itemstack2 = ItemEntity.merge(stack1, stack2, org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count); -+ } -+ // Leaf end - Change max stack count - - targetEntity.setItem(itemstack2); - } -diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java -index 7572c289758001c7417a192f0e6e994ffa8408b3..0e5fd0ba84bb139f23fc02482d54e5be582ced3c 100644 ---- a/src/main/java/net/minecraft/world/item/BlockItem.java -+++ b/src/main/java/net/minecraft/world/item/BlockItem.java -@@ -34,6 +34,7 @@ import net.minecraft.world.phys.shapes.CollisionContext; - import org.bukkit.craftbukkit.block.CraftBlock; - import org.bukkit.craftbukkit.block.data.CraftBlockData; - import org.bukkit.event.block.BlockCanBuildEvent; -+import org.dreeam.leaf.config.modules.gameplay.MaxStackCount; - // CraftBukkit end - - public class BlockItem extends Item { -@@ -269,8 +270,20 @@ public class BlockItem extends Item { - ItemContainerContents itemcontainercontents = (ItemContainerContents) entity.getItem().set(DataComponents.CONTAINER, ItemContainerContents.EMPTY); - - if (itemcontainercontents != null) { -- if (entity.level().purpurConfig.shulkerBoxItemDropContentsWhenDestroyed && entity.getItem().is(Items.SHULKER_BOX)) // Purpur -- ItemUtils.onContainerDestroyed(entity, itemcontainercontents.nonEmptyItemsCopy()); -+ // Leaf start - Change max stack count -+ if (entity.level().purpurConfig.shulkerBoxItemDropContentsWhenDestroyed) { // Purpur -+ if (MaxStackCount.count < 1) { -+ ItemUtils.onContainerDestroyed(entity, itemcontainercontents.nonEmptyItemsCopy()); -+ } else { -+ Level level = entity.level(); -+ if (!level.isClientSide) { -+ for (int Count = Math.min(entity.getItem().getCount(), org.dreeam.leaf.config.modules.gameplay.MaxContainerDestroy.count); Count > 0; Count = Count - 1) { -+ itemcontainercontents.nonEmptyItemsCopy().forEach(stack -> level.addFreshEntity(new ItemEntity(level, entity.getX(), entity.getY(), entity.getZ(), stack))); -+ } -+ } -+ } -+ } -+ // Leaf end - Change max stack count - } - - } -diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java -new file mode 100644 -index 0000000000000000000000000000000000000000..503f80ed917302abdf0ab14c13ce61d14c4b4adc ---- /dev/null -+++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java -@@ -0,0 +1,17 @@ -+package org.dreeam.leaf.config.modules.gameplay; -+ -+import org.dreeam.leaf.config.ConfigModules; -+import org.dreeam.leaf.config.EnumConfigCategory; -+ -+public class ItemStackMultiplier extends ConfigModules { -+ public String getBasePath() { -+ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".item-stack-multiplier"; -+ } -+ -+ public static int multiplier = 1; -+ -+ @Override -+ public void onLoaded() { -+ multiplier = config.getInt(getBasePath(), multiplier); -+ } -+} -diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxContainerDestroy.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxContainerDestroy.java -new file mode 100644 -index 0000000000000000000000000000000000000000..254ce472cb872323fdd86ded689268e439b46d0d ---- /dev/null -+++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxContainerDestroy.java -@@ -0,0 +1,17 @@ -+package org.dreeam.leaf.config.modules.gameplay; -+ -+import org.dreeam.leaf.config.ConfigModules; -+import org.dreeam.leaf.config.EnumConfigCategory; -+ -+public class MaxContainerDestroy extends ConfigModules { -+ public String getBasePath() { -+ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".max-container-destroy"; -+ } -+ -+ public static int count = 32767; -+ -+ @Override -+ public void onLoaded() { -+ count = config.getInt(getBasePath(), count); -+ } -+} -diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java -new file mode 100644 -index 0000000000000000000000000000000000000000..01208acaac7ef34a4f6dff51a208ed66d2d28079 ---- /dev/null -+++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java -@@ -0,0 +1,17 @@ -+package org.dreeam.leaf.config.modules.gameplay; -+ -+import org.dreeam.leaf.config.ConfigModules; -+import org.dreeam.leaf.config.EnumConfigCategory; -+ -+public class MaxStackCount extends ConfigModules { -+ public String getBasePath() { -+ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".change-max-stack-count"; -+ } -+ -+ public static int count = 0; -+ -+ @Override -+ public void onLoaded() { -+ count = config.getInt(getBasePath(), count); -+ } -+} From dd6be4e559650edc0dd8fe0f447090d07e5d4077 Mon Sep 17 00:00:00 2001 From: FallingKey Date: Wed, 14 Aug 2024 00:50:12 +0800 Subject: [PATCH 3/3] Fix the configuration name and logic of the previous patch --- .../server/0099-Change-max-stack-count.patch | 172 ++++++++++++++++++ .../server/0100-Add-configurable-items.patch | 141 ++++++++++++++ 2 files changed, 313 insertions(+) create mode 100644 patches/server/0099-Change-max-stack-count.patch create mode 100644 patches/server/0100-Add-configurable-items.patch diff --git a/patches/server/0099-Change-max-stack-count.patch b/patches/server/0099-Change-max-stack-count.patch new file mode 100644 index 000000000..afbaf3c18 --- /dev/null +++ b/patches/server/0099-Change-max-stack-count.patch @@ -0,0 +1,172 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: FallingKey +Date: Sun, 11 Aug 2024 14:20:37 +0800 +Subject: [PATCH] Change max stack count + + +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 3a27ef6da3d189f4f2211c9929dc1334790ab281..14eea6498e04f34a518988c978f27600715fe098 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.MaxStackCount.count < 1) { ++ return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && itemstack.getCount() < itemstack.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier; // 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.MaxStackCount.count; // 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.MaxStackCount.count == 0) { ++ return stack2.getCount() + stack1.getCount() > stack2.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier ? false : ItemStack.isSameItemSameComponents(stack1, stack2); ++ } else { ++ return stack2.getCount() + stack1.getCount() > org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count ? 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.MaxStackCount.count == 0) { ++ j = Math.min(Math.min(stack1.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier, maxCount) - stack1.getCount(), stack2.getCount()); ++ } else { ++ j = Math.min(Math.min(org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count, 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.MaxStackCount.count < 1) { ++ itemstack2 = ItemEntity.merge(stack1, stack2, 64); ++ } else { ++ itemstack2 = ItemEntity.merge(stack1, stack2, org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count); ++ } ++ // Leaf end - Change max stack count + + targetEntity.setItem(itemstack2); + } +diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java +index 7572c289758001c7417a192f0e6e994ffa8408b3..0e5fd0ba84bb139f23fc02482d54e5be582ced3c 100644 +--- a/src/main/java/net/minecraft/world/item/BlockItem.java ++++ b/src/main/java/net/minecraft/world/item/BlockItem.java +@@ -34,6 +34,7 @@ import net.minecraft.world.phys.shapes.CollisionContext; + import org.bukkit.craftbukkit.block.CraftBlock; + import org.bukkit.craftbukkit.block.data.CraftBlockData; + import org.bukkit.event.block.BlockCanBuildEvent; ++import org.dreeam.leaf.config.modules.gameplay.MaxStackCount; + // CraftBukkit end + + public class BlockItem extends Item { +@@ -269,8 +270,20 @@ public class BlockItem extends Item { + ItemContainerContents itemcontainercontents = (ItemContainerContents) entity.getItem().set(DataComponents.CONTAINER, ItemContainerContents.EMPTY); + + if (itemcontainercontents != null) { +- if (entity.level().purpurConfig.shulkerBoxItemDropContentsWhenDestroyed && entity.getItem().is(Items.SHULKER_BOX)) // Purpur +- ItemUtils.onContainerDestroyed(entity, itemcontainercontents.nonEmptyItemsCopy()); ++ // Leaf start - Change max stack count ++ if (entity.level().purpurConfig.shulkerBoxItemDropContentsWhenDestroyed) { // Purpur ++ if (MaxStackCount.count < 1) { ++ ItemUtils.onContainerDestroyed(entity, itemcontainercontents.nonEmptyItemsCopy()); ++ } else { ++ Level level = entity.level(); ++ if (!level.isClientSide) { ++ for (int Count = Math.min(entity.getItem().getCount(), org.dreeam.leaf.config.modules.gameplay.MaxContainerDestroy.count); Count > 0; Count = Count - 1) { ++ itemcontainercontents.nonEmptyItemsCopy().forEach(stack -> level.addFreshEntity(new ItemEntity(level, entity.getX(), entity.getY(), entity.getZ(), stack))); ++ } ++ } ++ } ++ } ++ // Leaf end - Change max stack count + } + + } +diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java +new file mode 100644 +index 0000000000000000000000000000000000000000..503f80ed917302abdf0ab14c13ce61d14c4b4adc +--- /dev/null ++++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java +@@ -0,0 +1,17 @@ ++package org.dreeam.leaf.config.modules.gameplay; ++ ++import org.dreeam.leaf.config.ConfigModules; ++import org.dreeam.leaf.config.EnumConfigCategory; ++ ++public class ItemStackMultiplier extends ConfigModules { ++ public String getBasePath() { ++ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".item-stack-multiplier"; ++ } ++ ++ public static int multiplier = 1; ++ ++ @Override ++ public void onLoaded() { ++ multiplier = config.getInt(getBasePath(), multiplier); ++ } ++} +diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxContainerDestroy.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxContainerDestroy.java +new file mode 100644 +index 0000000000000000000000000000000000000000..254ce472cb872323fdd86ded689268e439b46d0d +--- /dev/null ++++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxContainerDestroy.java +@@ -0,0 +1,17 @@ ++package org.dreeam.leaf.config.modules.gameplay; ++ ++import org.dreeam.leaf.config.ConfigModules; ++import org.dreeam.leaf.config.EnumConfigCategory; ++ ++public class MaxContainerDestroy extends ConfigModules { ++ public String getBasePath() { ++ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".max-container-destroy"; ++ } ++ ++ public static int count = 32767; ++ ++ @Override ++ public void onLoaded() { ++ count = config.getInt(getBasePath(), count); ++ } ++} +diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java +new file mode 100644 +index 0000000000000000000000000000000000000000..01208acaac7ef34a4f6dff51a208ed66d2d28079 +--- /dev/null ++++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java +@@ -0,0 +1,17 @@ ++package org.dreeam.leaf.config.modules.gameplay; ++ ++import org.dreeam.leaf.config.ConfigModules; ++import org.dreeam.leaf.config.EnumConfigCategory; ++ ++public class MaxStackCount extends ConfigModules { ++ public String getBasePath() { ++ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".change-max-stack-count"; ++ } ++ ++ public static int count = 0; ++ ++ @Override ++ public void onLoaded() { ++ count = config.getInt(getBasePath(), count); ++ } ++} diff --git a/patches/server/0100-Add-configurable-items.patch b/patches/server/0100-Add-configurable-items.patch new file mode 100644 index 000000000..5a3843687 --- /dev/null +++ b/patches/server/0100-Add-configurable-items.patch @@ -0,0 +1,141 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: FallingKey +Date: Wed, 14 Aug 2024 00:28:48 +0800 +Subject: [PATCH] Add configurable items + + +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 14eea6498e04f34a518988c978f27600715fe098..023f4133c802ff0b0cdaf7b2730e09a786be8872 100644 +--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java ++++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +@@ -352,10 +352,10 @@ public class ItemEntity extends Entity implements TraceableEntity { + ItemStack itemstack = this.getItem(); + + // Leaf start - Change max stack count +- if (org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count < 1) { +- return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && itemstack.getCount() < itemstack.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier; // Paper - Alternative item-despawn-rate ++ if (org.dreeam.leaf.config.modules.gameplay.MaxEntityItemsStackCount.count < 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.MaxStackCount.count; // Paper - Alternative item-despawn-rate ++ return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && itemstack.getCount() < org.dreeam.leaf.config.modules.gameplay.MaxEntityItemsStackCount.count; // Paper - Alternative item-despawn-rate + } + // Leaf end - Change max stack count + } +@@ -376,10 +376,10 @@ public class ItemEntity extends Entity implements TraceableEntity { + + public static boolean areMergable(ItemStack stack1, ItemStack stack2) { + // Leaf start - Change max stack count +- if (org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count == 0) { +- return stack2.getCount() + stack1.getCount() > stack2.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier ? false : ItemStack.isSameItemSameComponents(stack1, stack2); ++ if (org.dreeam.leaf.config.modules.gameplay.MaxEntityItemsStackCount.count == 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.MaxStackCount.count ? false : ItemStack.isSameItemSameComponents(stack1, stack2); ++ return stack2.getCount() + stack1.getCount() > org.dreeam.leaf.config.modules.gameplay.MaxEntityItemsStackCount.count ? false : ItemStack.isSameItemSameComponents(stack1, stack2); + } + // Leaf end - Change max stack count + } +@@ -387,10 +387,10 @@ public class ItemEntity extends Entity implements TraceableEntity { + public static ItemStack merge(ItemStack stack1, ItemStack stack2, int maxCount) { + // Leaf start - Change max stack count + int j; +- if (org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count == 0) { +- j = Math.min(Math.min(stack1.getMaxStackSize() * org.dreeam.leaf.config.modules.gameplay.ItemStackMultiplier.multiplier, maxCount) - stack1.getCount(), stack2.getCount()); ++ if (org.dreeam.leaf.config.modules.gameplay.MaxEntityItemsStackCount.count == 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.MaxStackCount.count, maxCount) - stack1.getCount(), stack2.getCount()); ++ j = Math.min(Math.min(org.dreeam.leaf.config.modules.gameplay.MaxEntityItemsStackCount.count, maxCount) - stack1.getCount(), stack2.getCount()); + } + // Leaf end - Change max stack count + ItemStack itemstack2 = stack1.copyWithCount(stack1.getCount() + j); +@@ -402,10 +402,10 @@ public class ItemEntity extends Entity implements TraceableEntity { + private static void merge(ItemEntity targetEntity, ItemStack stack1, ItemStack stack2) { + // Leaf start - Change max stack count + ItemStack itemstack2; +- if (org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count < 1) { ++ if (org.dreeam.leaf.config.modules.gameplay.MaxEntityItemsStackCount.count < 1) { + itemstack2 = ItemEntity.merge(stack1, stack2, 64); + } else { +- itemstack2 = ItemEntity.merge(stack1, stack2, org.dreeam.leaf.config.modules.gameplay.MaxStackCount.count); ++ itemstack2 = ItemEntity.merge(stack1, stack2, org.dreeam.leaf.config.modules.gameplay.MaxEntityItemsStackCount.count); + } + // Leaf end - Change max stack count + +diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java +index 0e5fd0ba84bb139f23fc02482d54e5be582ced3c..0b6c6e3ed65552ee8b1feb9bb1c6669fbf130df9 100644 +--- a/src/main/java/net/minecraft/world/item/BlockItem.java ++++ b/src/main/java/net/minecraft/world/item/BlockItem.java +@@ -34,7 +34,6 @@ import net.minecraft.world.phys.shapes.CollisionContext; + import org.bukkit.craftbukkit.block.CraftBlock; + import org.bukkit.craftbukkit.block.data.CraftBlockData; + import org.bukkit.event.block.BlockCanBuildEvent; +-import org.dreeam.leaf.config.modules.gameplay.MaxStackCount; + // CraftBukkit end + + public class BlockItem extends Item { +@@ -272,16 +271,13 @@ public class BlockItem extends Item { + if (itemcontainercontents != null) { + // Leaf start - Change max stack count + if (entity.level().purpurConfig.shulkerBoxItemDropContentsWhenDestroyed) { // Purpur +- if (MaxStackCount.count < 1) { +- ItemUtils.onContainerDestroyed(entity, itemcontainercontents.nonEmptyItemsCopy()); +- } else { +- Level level = entity.level(); +- if (!level.isClientSide) { +- for (int Count = Math.min(entity.getItem().getCount(), org.dreeam.leaf.config.modules.gameplay.MaxContainerDestroy.count); Count > 0; Count = Count - 1) { +- itemcontainercontents.nonEmptyItemsCopy().forEach(stack -> level.addFreshEntity(new ItemEntity(level, entity.getX(), entity.getY(), entity.getZ(), stack))); +- } ++ Level level = entity.level(); ++ if (!level.isClientSide) { ++ for (int Count = Math.min(entity.getItem().getCount(), org.dreeam.leaf.config.modules.gameplay.MaxContainerDestroy.count); Count > 0; Count = Count - 1) { ++ itemcontainercontents.nonEmptyItemsCopy().forEach(stack -> level.addFreshEntity(new ItemEntity(level, entity.getX(), entity.getY(), entity.getZ(), stack))); + } + } ++ + } + // Leaf end - Change max stack count + } +diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java +deleted file mode 100644 +index 503f80ed917302abdf0ab14c13ce61d14c4b4adc..0000000000000000000000000000000000000000 +--- a/src/main/java/org/dreeam/leaf/config/modules/gameplay/ItemStackMultiplier.java ++++ /dev/null +@@ -1,17 +0,0 @@ +-package org.dreeam.leaf.config.modules.gameplay; +- +-import org.dreeam.leaf.config.ConfigModules; +-import org.dreeam.leaf.config.EnumConfigCategory; +- +-public class ItemStackMultiplier extends ConfigModules { +- public String getBasePath() { +- return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".item-stack-multiplier"; +- } +- +- public static int multiplier = 1; +- +- @Override +- public void onLoaded() { +- multiplier = config.getInt(getBasePath(), multiplier); +- } +-} +diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxEntityItemsStackCount.java +similarity index 80% +rename from src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java +rename to src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxEntityItemsStackCount.java +index 01208acaac7ef34a4f6dff51a208ed66d2d28079..858a41df2c29d1f87652dc3a49c739da453294ec 100644 +--- a/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxStackCount.java ++++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/MaxEntityItemsStackCount.java +@@ -3,9 +3,9 @@ package org.dreeam.leaf.config.modules.gameplay; + import org.dreeam.leaf.config.ConfigModules; + import org.dreeam.leaf.config.EnumConfigCategory; + +-public class MaxStackCount extends ConfigModules { ++public class MaxEntityItemsStackCount extends ConfigModules { + public String getBasePath() { +- return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".change-max-stack-count"; ++ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".max-entity-items-stack-count"; + } + + public static int count = 0;