9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-03 22:26:19 +00:00

[ci skip] Add configurable max item stack count (#101)

* Add configurable items

* del

* Fix the configuration name and logic of the previous patch
This commit is contained in:
FallingKey
2024-09-16 13:27:39 +08:00
committed by Dreeam
parent 3fc6616283
commit 215089937e
2 changed files with 313 additions and 0 deletions

View File

@@ -0,0 +1,172 @@
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
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);
+ }
+}