Files
Shiroha/shiroha-server/minecraft-patches/features/0056-Leaves-Vanilla-hopper.patch
T

108 lines
5.8 KiB
Diff
Raw Normal View History

2026-07-09 00:03:09 +08:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2026-08-17 23:41:15 +08:00
From: NanaChiyo0721 <nanachiyo0721@163.com>
Date: Mon, 17 Aug 2026 23:38:00 +0800
Subject: [PATCH] Leaves: Vanilla hopper
2026-07-09 00:03:09 +08:00
2026-08-17 23:41:15 +08:00
Co-Authored-By: Creeam <102713261+HaHaWTH@users.noreply.github.com>
2026-07-09 00:03:09 +08:00
2026-08-17 23:41:15 +08:00
Original license: GPL-3.0-only
Original project: https://github.com/LeavesMC/Leaves
This is a temporary solution designed to attempt to restore the vanilla behavior of the funnel while preserving optimizations as much as possible. It should ultimately be replaced by the optimization solution provided by lithium.
2026-07-09 00:03:09 +08:00
diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
2026-08-17 23:41:15 +08:00
index a858cb658af70f07614fa1f4d9e8a3435d5c161f..9f7f8edaf3261cc0377dab33404ca1d30c548ff9 100644
2026-07-09 00:03:09 +08:00
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
2026-08-10 16:51:30 +08:00
@@ -281,36 +281,67 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
2026-07-09 00:03:09 +08:00
ItemStack movedItem = origItemStack;
final int originalItemCount = origItemStack.getCount();
final int movedItemCount = Math.min(level.spigotConfig.hopperAmount, originalItemCount);
- container.setChanged(); // original logic always marks source inv as changed even if no move happens.
- movedItem.setCount(movedItemCount);
2026-08-17 23:41:15 +08:00
+ // Leaves start - Vanilla hopper
+ if (org.dreeam.leaf.config.modules.gameplay.VanillaHopper.enabled && movedItemCount == 1) {
+ movedItem.setCount(movedItemCount);
+ container.setChanged();
+ if (!skipPullModeEventFire) {
+ movedItem = callPullMoveEvent(hopper, container, movedItem);
+ if (movedItem == null) { // cancelled
+ origItemStack.setCount(originalItemCount);
+ // Drastically improve performance by returning true.
+ // No plugin could have relied on the behavior of false as the other call
+ // site for IMIE did not exhibit the same behavior
+ return true;
+ }
+ }
+ final boolean removeOriginalItem = movedItem == origItemStack;
+ if (removeOriginalItem) {
+ movedItem = container.removeItem(i, movedItemCount);
+ }
2026-07-09 00:03:09 +08:00
- if (!worldData.skipPullModeEventFire) { // Folia - region threading
- movedItem = callPullMoveEvent(hopper, container, movedItem);
- if (movedItem == null) { // cancelled
- origItemStack.setCount(originalItemCount);
- // Drastically improve performance by returning true.
- // No plugin could have relied on the behavior of false as the other call
- // site for IMIE did not exhibit the same behavior
2026-08-17 23:41:15 +08:00
+ final int itemCountToMove = movedItem.getCount();
+ final ItemStack remainingItem = addItem(container, hopper, movedItem, null);
+ if (remainingItem.getCount() != itemCountToMove) {
+ origItemStack.setCount(removeOriginalItem ? originalItemCount - movedItemCount : originalItemCount);
+ container.setItem(i, origItemStack);
2026-07-09 00:03:09 +08:00
return true;
}
- }
2026-08-10 16:51:30 +08:00
-
2026-07-09 00:03:09 +08:00
- final ItemStack remainingItem = addItem(container, hopper, movedItem, null);
- final int remainingItemCount = remainingItem.getCount();
- if (remainingItemCount != movedItemCount) {
- origItemStack = origItemStack.copy(true);
2026-08-17 23:41:15 +08:00
origItemStack.setCount(originalItemCount);
2026-07-09 00:03:09 +08:00
- if (!origItemStack.isEmpty()) {
- origItemStack.setCount(originalItemCount - movedItemCount + remainingItemCount);
2026-08-17 23:41:15 +08:00
+ container.setItem(i, origItemStack);
2026-08-10 16:51:30 +08:00
+ } else {
+ container.setChanged(); // original logic always marks source inv as changed even if no move happens.
+ movedItem.setCount(movedItemCount);
+
2026-07-09 00:03:09 +08:00
+ if (!worldData.skipPullModeEventFire) {
+ movedItem = callPullMoveEvent(hopper, container, movedItem);
+ if (movedItem == null) { // cancelled
+ origItemStack.setCount(originalItemCount);
+ // Drastically improve performance by returning true.
+ // No plugin could have relied on the behavior of false as the other call
+ // site for IMIE did not exhibit the same behavior
+ return true;
+ }
2026-08-17 23:41:15 +08:00
}
- IGNORE_TILE_UPDATES.set(true); // Folia - region threading
- container.setItem(i, origItemStack);
- IGNORE_TILE_UPDATES.set(false); // Folia - region threading
- container.setChanged();
- return true;
2026-07-09 00:03:09 +08:00
+ final ItemStack remainingItem = addItem(container, hopper, movedItem, null);
+ final int remainingItemCount = remainingItem.getCount();
+ if (remainingItemCount != movedItemCount) {
+ origItemStack = origItemStack.copy(true);
+ origItemStack.setCount(originalItemCount);
+ if (!origItemStack.isEmpty()) {
+ origItemStack.setCount(originalItemCount - movedItemCount + remainingItemCount);
+ }
+
2026-08-17 23:41:15 +08:00
+ IGNORE_TILE_UPDATES.set(true); // Folia - region threading
2026-07-09 00:03:09 +08:00
+ container.setItem(i, origItemStack);
2026-08-17 23:41:15 +08:00
+ IGNORE_TILE_UPDATES.set(false); // Folia - region threading
2026-07-09 00:03:09 +08:00
+ container.setChanged();
+ return true;
+ }
+ origItemStack.setCount(originalItemCount);
}
- origItemStack.setCount(originalItemCount);
2026-08-17 23:41:15 +08:00
+ // Leaves end - Vanilla hopper
2026-07-09 00:03:09 +08:00
if (level.paperConfig().hopper.cooldownWhenFull) {
applyCooldown(hopper);