mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-29 20:09:23 +00:00
Fix grindstone overstaking
This commit is contained in:
@@ -5,9 +5,27 @@ Subject: [PATCH] Allow grindstone overstacking
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/inventory/AbstractContainerMenu.java b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
index f151ec990241d091daedcb2af8f3f36fae5f277b..2dae8f5bdb32e0bd6bba3c522fb9e1c0b9e82bd8 100644
|
||||
index 49abae7db7d7a9ee967ea24b7503e1e9489d4005..0136f1286e81b4ef1efd8ed83bffc3a936619eee 100644
|
||||
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
@@ -585,7 +585,7 @@ public abstract class AbstractContainerMenu {
|
||||
} else if (carried.isEmpty()) {
|
||||
if (slot.mayPlace(item)) {
|
||||
int maxStackSize = slot.getMaxStackSize(item);
|
||||
- if (item.getCount() > maxStackSize) {
|
||||
+ if (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.allowGrindstoneOverstacking && item.getCount() > maxStackSize) { // Leaves - grindstone overstacking
|
||||
slot.setByPlayer(item.split(maxStackSize));
|
||||
} else {
|
||||
inventory.setItem(button, ItemStack.EMPTY);
|
||||
@@ -594,7 +594,7 @@ public abstract class AbstractContainerMenu {
|
||||
}
|
||||
} else if (slot.mayPickup(player) && slot.mayPlace(item)) {
|
||||
int maxStackSize = slot.getMaxStackSize(item);
|
||||
- if (item.getCount() > maxStackSize) {
|
||||
+ if (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.allowGrindstoneOverstacking && item.getCount() > maxStackSize) { // Leaves - grindstone overstacking
|
||||
slot.setByPlayer(item.split(maxStackSize));
|
||||
slot.onTake(player, carried);
|
||||
if (!inventory.add(carried)) {
|
||||
@@ -754,10 +754,15 @@ public abstract class AbstractContainerMenu {
|
||||
public abstract boolean stillValid(Player player);
|
||||
|
||||
@@ -61,3 +79,20 @@ index 18c15a7657e6fd994a8f17d0812c822d6adc8eab..00a0ce28632a7f515a94087c2752e878
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
diff --git a/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java b/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
||||
index 63d6a43dab067aa4c8fb67095c455130196eef9f..4d3608c0f463c0fb8634c4b9ce5fb597e3eb2509 100644
|
||||
--- a/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
||||
+++ b/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
||||
@@ -145,6 +145,12 @@ public abstract class BaseContainerBlockEntity extends BlockEntity implements Co
|
||||
@Override
|
||||
public void setItem(int slot, ItemStack stack) {
|
||||
this.getItems().set(slot, stack);
|
||||
+ // Leaves end - grindstone overstacking
|
||||
+ if (org.leavesmc.leaves.LeavesConfig.modify.oldMC.allowGrindstoneOverstacking) {
|
||||
+ this.setChanged();
|
||||
+ return;
|
||||
+ }
|
||||
+ // Leaves end - grindstone overstacking
|
||||
stack.limitSize(this.getMaxStackLeaves(stack)); // Leaves - item over-stack util
|
||||
this.setChanged();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,17 @@ public class ItemOverstackUtils {
|
||||
public static int getItemStackMaxCount(ItemStack stack) {
|
||||
int size;
|
||||
for (ItemUtil util : overstackUtils) {
|
||||
if ((size = util.getMaxStackCount(stack)) != -1) {
|
||||
if ((size = util.getMaxServerStackCount(stack)) != -1) {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
return stack.getMaxStackSize();
|
||||
}
|
||||
|
||||
public static int getNetworkMaxCount(ItemStack stack) {
|
||||
int size;
|
||||
for (ItemUtil util : overstackUtils) {
|
||||
if ((size = util.getMaxClientStackCount(stack)) != -1) {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
@@ -58,7 +68,7 @@ public class ItemOverstackUtils {
|
||||
|
||||
public static ItemStack encodeMaxStackSize(ItemStack itemStack) {
|
||||
int realMaxStackSize = getItemStackMaxCountReal(itemStack);
|
||||
int modifiedMaxStackSize = getItemStackMaxCount(itemStack);
|
||||
int modifiedMaxStackSize = getNetworkMaxCount(itemStack);
|
||||
if (itemStack.getMaxStackSize() != modifiedMaxStackSize) {
|
||||
itemStack.set(DataComponents.MAX_STACK_SIZE, modifiedMaxStackSize);
|
||||
CompoundTag nbt = itemStack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).copyTag();
|
||||
@@ -94,7 +104,12 @@ public class ItemOverstackUtils {
|
||||
boolean tryStackItems(ItemEntity self, ItemEntity other);
|
||||
|
||||
// number -> modified count, -1 -> I don't care
|
||||
int getMaxStackCount(ItemStack stack);
|
||||
int getMaxServerStackCount(ItemStack stack);
|
||||
|
||||
// number -> modified count, -1 -> I don't care
|
||||
default int getMaxClientStackCount(ItemStack stack) {
|
||||
return getMaxServerStackCount(stack);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ShulkerBox implements ItemUtil {
|
||||
@@ -137,7 +152,7 @@ public class ItemOverstackUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackCount(ItemStack stack) {
|
||||
public int getMaxServerStackCount(ItemStack stack) {
|
||||
if (isEnabled() && stack.getItem() instanceof BlockItem bi &&
|
||||
bi.getBlock() instanceof ShulkerBoxBlock && (LeavesConfig.modify.shulkerBox.sameNbtStackable || shulkerBoxNoItem(stack))) {
|
||||
return LeavesConfig.modify.shulkerBox.shulkerBoxStackSize;
|
||||
@@ -167,34 +182,16 @@ public class ItemOverstackUtils {
|
||||
|
||||
@Override
|
||||
public boolean tryStackItems(ItemEntity self, ItemEntity other) {
|
||||
ItemStack selfStack = self.getItem();
|
||||
ItemStack otherStack = other.getItem();
|
||||
if (!isEnabled() ||
|
||||
selfStack.getItem() != otherStack.getItem() ||
|
||||
!(isCursedEnchantedBook(selfStack)) ||
|
||||
selfStack.getCount() >= 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int amount = Math.min(otherStack.getCount(), 2 - selfStack.getCount());
|
||||
|
||||
selfStack.grow(amount);
|
||||
self.setItem(selfStack);
|
||||
|
||||
self.pickupDelay = Math.max(other.pickupDelay, self.pickupDelay);
|
||||
self.age = Math.min(other.getAge(), self.age);
|
||||
|
||||
otherStack.shrink(amount);
|
||||
if (otherStack.isEmpty()) {
|
||||
other.discard();
|
||||
} else {
|
||||
other.setItem(otherStack);
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackCount(ItemStack stack) {
|
||||
public int getMaxServerStackCount(ItemStack stack) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxClientStackCount(ItemStack stack) {
|
||||
if (isEnabled() && isCursedEnchantedBook(stack)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user