9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00

fix: fix grindstone curse book overstacking(#658) (#659)

* fix: fix grindstone curse book overstacking

* fix: remove unused import
This commit is contained in:
MC_XiaoHei
2025-08-06 10:59:44 +08:00
committed by GitHub
parent c29ff9a824
commit 3c09044e86
3 changed files with 18 additions and 8 deletions

View File

@@ -227,7 +227,7 @@ index 02d2efef2dc0f0e12eac0c71fa290af706f7694d..99f109e2653eff10c011f380694bd77a
default SlotAccess getChestVehicleSlot(final int index) {
diff --git a/net/minecraft/world/inventory/AbstractContainerMenu.java b/net/minecraft/world/inventory/AbstractContainerMenu.java
index e1783ad0adbb791b2ff7441243c9f0aeaf37c7f6..ffd723a424940a421e396a6ca07c952165705825 100644
index e1783ad0adbb791b2ff7441243c9f0aeaf37c7f6..47963968763cbee60016853d617f159c0761d282 100644
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java
@@ -295,6 +295,13 @@ public abstract class AbstractContainerMenu {
@@ -322,7 +322,7 @@ index e1783ad0adbb791b2ff7441243c9f0aeaf37c7f6..ffd723a424940a421e396a6ca07c9521
ItemStack item = container.getItem(i);
if (!item.isEmpty()) {
- f += (float)item.getCount() / container.getMaxStackSize(item);
+ f += Math.clamp((float) item.getCount() / container.getMaxStackSize(item), 0f, 1f); // Leaves - item over-stack util
+ f += org.leavesmc.leaves.util.ItemOverstackUtils.getItemStackSignalStrength(container.getMaxStackSize(), item); // Leaves - item over-stack util
}
}

View File

@@ -216,7 +216,7 @@ public class LithiumStackList extends NonNullList<ItemStack> implements LithiumD
for (int j = 0; j < inventorySize; ++j) {
ItemStack itemStack = this.get(j);
if (!itemStack.isEmpty()) {
f += (float) itemStack.getCount() / (float) Math.min(this.maxCountPerStack, itemStack.getMaxStackSize());
f += org.leavesmc.leaves.util.ItemOverstackUtils.getItemStackSignalStrength(this.maxCountPerStack, itemStack);
++i;
}
}

View File

@@ -1,5 +1,7 @@
package org.leavesmc.leaves.util;
import io.papermc.paper.datacomponent.DataComponentTypes;
import io.papermc.paper.datacomponent.item.ItemEnchantments;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.item.ItemEntity;
@@ -7,8 +9,8 @@ import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.ItemContainerContents;
import net.minecraft.world.item.enchantment.ItemEnchantments;
import net.minecraft.world.level.block.ShulkerBoxBlock;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
@@ -88,6 +90,14 @@ public class ItemOverstackUtils {
return itemStack;
}
public static float getItemStackSignalStrength(int maxStackSize, ItemStack itemStack) {
float result = (float) itemStack.getCount() / Math.min(maxStackSize, itemStack.getMaxStackSize());
if (LeavesConfig.modify.oldMC.allowGrindstoneOverstacking && CurseEnchantedBook.isCursedEnchantedBook(itemStack)) {
return result;
}
return Math.clamp(result, 0f, 1f);
}
public static boolean isStackable(ItemStack itemStack) {
return getItemStackMaxCount(itemStack) > 1 && (!itemStack.isDamageableItem() || !itemStack.isDamaged());
}
@@ -169,12 +179,12 @@ public class ItemOverstackUtils {
public static class CurseEnchantedBook implements ItemUtil {
public static boolean isCursedEnchantedBook(ItemStack stack) {
ItemEnchantments enchantments = stack.getOrDefault(DataComponents.STORED_ENCHANTMENTS, ItemEnchantments.EMPTY);
if (enchantments.size() != 1) {
ItemEnchantments enchantments = stack.getBukkitStack().getData(DataComponentTypes.STORED_ENCHANTMENTS);
if (enchantments == null || enchantments.enchantments().size() != 1) {
return false;
}
return stack.getBukkitStack().getEnchantmentLevel(org.bukkit.enchantments.Enchantment.BINDING_CURSE) == 1 ||
stack.getBukkitStack().getEnchantmentLevel(org.bukkit.enchantments.Enchantment.BINDING_CURSE) == 1;
return enchantments.enchantments().containsKey(Enchantment.BINDING_CURSE) ||
enchantments.enchantments().containsKey(Enchantment.VANISHING_CURSE);
}
@Override