Fix up Leaves vanilla hopper patch
Shiroha CI / build (push) Canceled after 0s
Shiroha CI / Event File (push) Canceled after 0s

This commit is contained in:
2026-08-10 16:51:30 +08:00
parent 1bb895c165
commit fbe3db6fa8
2 changed files with 36 additions and 25 deletions
@@ -9,10 +9,10 @@ Origin patch link: https://github.com/LeavesMC/Leaves/blob/master/leaves-server/
Origin license: https://github.com/LeavesMC/Leaves/blob/master/LICENSE.md Origin license: https://github.com/LeavesMC/Leaves/blob/master/LICENSE.md
diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
index a858cb658af70f07614fa1f4d9e8a3435d5c161f..4c9d0bcd8820b250b51c06fff4531021ab57d408 100644 index a858cb658af70f07614fa1f4d9e8a3435d5c161f..95f0b3276137cb9d1fc296e97cc25a08a5200c95 100644
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java --- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java +++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
@@ -281,36 +281,55 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @@ -281,36 +281,67 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
ItemStack movedItem = origItemStack; ItemStack movedItem = origItemStack;
final int originalItemCount = origItemStack.getCount(); final int originalItemCount = origItemStack.getCount();
final int movedItemCount = Math.min(level.spigotConfig.hopperAmount, originalItemCount); final int movedItemCount = Math.min(level.spigotConfig.hopperAmount, originalItemCount);
@@ -32,21 +32,19 @@ index a858cb658af70f07614fa1f4d9e8a3435d5c161f..4c9d0bcd8820b250b51c06fff4531021
+ movedItem = callPullMoveEvent(hopper, container, movedItem); + movedItem = callPullMoveEvent(hopper, container, movedItem);
+ if (movedItem == null) { // cancelled + if (movedItem == null) { // cancelled
+ origItemStack.setCount(originalItemCount); + origItemStack.setCount(originalItemCount);
+ container.setChanged(); // keep parity with vanilla: source inv always marked changed
+ return true; + return true;
+ } + }
+ } + }
+ movedItem = origItemStack.copy(); + final int toRemove = Math.min(movedItem.getCount(), container.getItem(i).getCount());
+ final ItemStack remainingItem = addItem(container, hopper, container.removeItem(i, movedItemCount), null); + final ItemStack remainingItem = addItem(container, hopper, container.removeItem(i, toRemove), null);
+ final int remainingItemCount = remainingItem.getCount();
+ if (remainingItem.isEmpty()) { + if (remainingItem.isEmpty()) {
+ container.setChanged(); + container.setChanged();
return true; return true;
} }
- } - }
+ container.setItem(i, movedItem); -
+ } else {
+ container.setChanged(); // original logic always marks source inv as changed even if no move happens.
+ movedItem.setCount(movedItemCount);
- final ItemStack remainingItem = addItem(container, hopper, movedItem, null); - final ItemStack remainingItem = addItem(container, hopper, movedItem, null);
- final int remainingItemCount = remainingItem.getCount(); - final int remainingItemCount = remainingItem.getCount();
- if (remainingItemCount != movedItemCount) { - if (remainingItemCount != movedItemCount) {
@@ -54,6 +52,24 @@ index a858cb658af70f07614fa1f4d9e8a3435d5c161f..4c9d0bcd8820b250b51c06fff4531021
- origItemStack.setCount(originalItemCount); - origItemStack.setCount(originalItemCount);
- if (!origItemStack.isEmpty()) { - if (!origItemStack.isEmpty()) {
- origItemStack.setCount(originalItemCount - movedItemCount + remainingItemCount); - origItemStack.setCount(originalItemCount - movedItemCount + remainingItemCount);
+ if (remainingItemCount != toRemove) {
+ IGNORE_TILE_UPDATES.set(true); // Folia - region threading
+ container.setItem(i, remainingItem);
+ IGNORE_TILE_UPDATES.set(false); // Folia - region threading
+ container.setChanged();
+ return true;
}
-
IGNORE_TILE_UPDATES.set(true); // Folia - region threading
- container.setItem(i, origItemStack);
+ container.setItem(i, remainingItem);
IGNORE_TILE_UPDATES.set(false); // Folia - region threading
container.setChanged();
- return true;
+ } else {
+ container.setChanged(); // original logic always marks source inv as changed even if no move happens.
+ movedItem.setCount(movedItemCount);
+
+ if (!worldData.skipPullModeEventFire) { + if (!worldData.skipPullModeEventFire) {
+ movedItem = callPullMoveEvent(hopper, container, movedItem); + movedItem = callPullMoveEvent(hopper, container, movedItem);
+ if (movedItem == null) { // cancelled + if (movedItem == null) { // cancelled
@@ -63,13 +79,8 @@ index a858cb658af70f07614fa1f4d9e8a3435d5c161f..4c9d0bcd8820b250b51c06fff4531021
+ // site for IMIE did not exhibit the same behavior + // site for IMIE did not exhibit the same behavior
+ return true; + return true;
+ } + }
} + }
+
- IGNORE_TILE_UPDATES.set(true); // Folia - region threading
- container.setItem(i, origItemStack);
- IGNORE_TILE_UPDATES.set(false); // Folia - region threading
- container.setChanged();
- return true;
+ final ItemStack remainingItem = addItem(container, hopper, movedItem, null); + final ItemStack remainingItem = addItem(container, hopper, movedItem, null);
+ final int remainingItemCount = remainingItem.getCount(); + final int remainingItemCount = remainingItem.getCount();
+ if (remainingItemCount != movedItemCount) { + if (remainingItemCount != movedItemCount) {
@@ -1573,7 +1573,7 @@ index 6109d8da984b398bb1eb6cd6ab9a55f0511a615c..d3d6b3aeb24da7f3bf92c327095a9dc9
+ // Leaves end - Lithium Sleeping Block Entity + // Leaves end - Lithium Sleeping Block Entity
} }
diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fb0f4edfa0c6d08364db5a62b13e98a3d32f0d42 100644 index 95f0b3276137cb9d1fc296e97cc25a08a5200c95..26afe1f74b50b60d6c04e08967610a3d50183483 100644
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java --- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java +++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
@@ -27,8 +27,29 @@ import net.minecraft.world.level.storage.ValueInput; @@ -27,8 +27,29 @@ import net.minecraft.world.level.storage.ValueInput;
@@ -1660,7 +1660,7 @@ index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fb0f4edfa0c6d08364db5a62b13e98a3
return true; return true;
} }
} }
@@ -406,6 +447,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @@ -418,6 +459,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
private static void applyCooldown(final Hopper hopper) { private static void applyCooldown(final Hopper hopper) {
if (hopper instanceof HopperBlockEntity blockEntity && blockEntity.getLevel() != null) { if (hopper instanceof HopperBlockEntity blockEntity && blockEntity.getLevel() != null) {
blockEntity.setCooldown(blockEntity.getLevel().spigotConfig.hopperTransfer); blockEntity.setCooldown(blockEntity.getLevel().spigotConfig.hopperTransfer);
@@ -1668,7 +1668,7 @@ index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fb0f4edfa0c6d08364db5a62b13e98a3
} }
} }
@@ -449,12 +491,20 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @@ -461,12 +503,20 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
// Paper end - Perf: Optimize Hoppers // Paper end - Perf: Optimize Hoppers
private static boolean ejectItems(final Level level, final BlockPos blockPos, final HopperBlockEntity self) { private static boolean ejectItems(final Level level, final BlockPos blockPos, final HopperBlockEntity self) {
@@ -1690,7 +1690,7 @@ index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fb0f4edfa0c6d08364db5a62b13e98a3
if (isFullContainer(container, direction)) { if (isFullContainer(container, direction)) {
return false; return false;
} }
@@ -510,13 +560,21 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @@ -522,13 +572,21 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
io.papermc.paper.threadedregions.RegionizedWorldData worldData = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegionizedWorldData(); // Folia - region threading io.papermc.paper.threadedregions.RegionizedWorldData worldData = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegionizedWorldData(); // Folia - region threading
BlockPos blockPos = BlockPos.containing(hopper.getLevelX(), hopper.getLevelY() + 1.0, hopper.getLevelZ()); BlockPos blockPos = BlockPos.containing(hopper.getLevelX(), hopper.getLevelY() + 1.0, hopper.getLevelZ());
BlockState blockState = level.getBlockState(blockPos); BlockState blockState = level.getBlockState(blockPos);
@@ -1716,7 +1716,7 @@ index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fb0f4edfa0c6d08364db5a62b13e98a3
return true; return true;
} }
} }
@@ -527,7 +585,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @@ -539,7 +597,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
&& blockState.isCollisionShapeFullBlock(level, blockPos) && blockState.isCollisionShapeFullBlock(level, blockPos)
&& !blockState.is(BlockTags.DOES_NOT_BLOCK_HOPPERS); && !blockState.is(BlockTags.DOES_NOT_BLOCK_HOPPERS);
if (!isBlocked) { if (!isBlocked) {
@@ -1725,7 +1725,7 @@ index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fb0f4edfa0c6d08364db5a62b13e98a3
if (addItem(hopper, entity)) { if (addItem(hopper, entity)) {
return true; return true;
} }
@@ -649,7 +707,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @@ -661,7 +719,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
// CraftBukkit start // CraftBukkit start
private static @Nullable Container runHopperInventorySearchEvent( private static @Nullable Container runHopperInventorySearchEvent(
@@ -1734,7 +1734,7 @@ index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fb0f4edfa0c6d08364db5a62b13e98a3
org.bukkit.craftbukkit.block.CraftBlock hopper, org.bukkit.craftbukkit.block.CraftBlock hopper,
org.bukkit.craftbukkit.block.CraftBlock searchLocation, org.bukkit.craftbukkit.block.CraftBlock searchLocation,
org.bukkit.event.inventory.HopperInventorySearchEvent.ContainerType containerType org.bukkit.event.inventory.HopperInventorySearchEvent.ContainerType containerType
@@ -775,6 +833,19 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @@ -787,6 +845,19 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
} }
public void setCooldown(final int time) { public void setCooldown(final int time) {
@@ -1754,7 +1754,7 @@ index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fb0f4edfa0c6d08364db5a62b13e98a3
this.cooldownTime = time; this.cooldownTime = time;
} }
@@ -794,6 +865,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @@ -806,6 +877,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@Override @Override
protected void setItems(final NonNullList<ItemStack> items) { protected void setItems(final NonNullList<ItemStack> items) {
this.items = items; this.items = items;
@@ -1762,7 +1762,7 @@ index 4c9d0bcd8820b250b51c06fff4531021ab57d408..fb0f4edfa0c6d08364db5a62b13e98a3
} }
public static void entityInside(final Level level, final BlockPos pos, final BlockState blockState, final Entity entity, final HopperBlockEntity hopper) { public static void entityInside(final Level level, final BlockPos pos, final BlockState blockState, final Entity entity, final HopperBlockEntity hopper) {
@@ -808,4 +880,758 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @@ -820,4 +892,758 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
protected AbstractContainerMenu createMenu(final int containerId, final Inventory inventory) { protected AbstractContainerMenu createMenu(final int containerId, final Inventory inventory) {
return new HopperMenu(containerId, inventory, this); return new HopperMenu(containerId, inventory, this);
} }