|
|
|
|
@@ -0,0 +1,280 @@
|
|
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: MrHua269 <wangxyper@163.com>
|
|
|
|
|
Date: Thu, 6 Feb 2025 23:15:04 +0800
|
|
|
|
|
Subject: [PATCH] Removed paper hopper optimizations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/net/minecraft/world/level/block/entity/BlockEntity.java b/net/minecraft/world/level/block/entity/BlockEntity.java
|
|
|
|
|
index 003e9db957023486278679803b313ce89d573587..2ce2f94e53a8e9cb4240ab1102b30b4fa07c92dc 100644
|
|
|
|
|
--- a/net/minecraft/world/level/block/entity/BlockEntity.java
|
|
|
|
|
+++ b/net/minecraft/world/level/block/entity/BlockEntity.java
|
|
|
|
|
@@ -203,7 +203,7 @@ public abstract class BlockEntity {
|
|
|
|
|
|
|
|
|
|
public void setChanged() {
|
|
|
|
|
if (this.level != null) {
|
|
|
|
|
- if (IGNORE_TILE_UPDATES.get().booleanValue()) return; // Paper - Perf: Optimize Hoppers // Folia - region threading
|
|
|
|
|
+ //if (IGNORE_TILE_UPDATES.get().booleanValue()) return; // Paper - Perf: Optimize Hoppers // Folia - region threading // Luminol - Disable paper hooper optimizations
|
|
|
|
|
setChanged(this.level, this.worldPosition, this.blockState);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
|
|
|
index ae988c4910421fb720177178ef6136e595ae6946..17c1bf710e6cb2ac0a6f41b6ec85e98e253d25e5 100644
|
|
|
|
|
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
|
|
|
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
|
|
|
@@ -298,9 +298,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
|
|
|
origItemStack.setCount(originalItemCount - movedItemCount + remainingItemCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- IGNORE_TILE_UPDATES.set(true); // Folia - region threading
|
|
|
|
|
+ //IGNORE_TILE_UPDATES.set(true); // Folia - region threading // Luminol - Disable paper hooper optimizations
|
|
|
|
|
container.setItem(i, origItemStack);
|
|
|
|
|
- IGNORE_TILE_UPDATES.set(false); // Folia - region threading
|
|
|
|
|
+ //IGNORE_TILE_UPDATES.set(false); // Folia - region threading // Luminol - Disable paper hooper optimizations
|
|
|
|
|
container.setChanged();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@@ -433,58 +433,60 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
// Paper start - Perf: Optimize Hoppers
|
|
|
|
|
- return hopperPush(level, attachedContainer, opposite, blockEntity);
|
|
|
|
|
- //for (int i = 0; i < blockEntity.getContainerSize(); i++) {
|
|
|
|
|
- // ItemStack item = blockEntity.getItem(i);
|
|
|
|
|
- // if (!item.isEmpty()) {
|
|
|
|
|
- // int count = item.getCount();
|
|
|
|
|
- // // CraftBukkit start - Call event when pushing items into other inventories
|
|
|
|
|
- // ItemStack original = item.copy();
|
|
|
|
|
- // org.bukkit.craftbukkit.inventory.CraftItemStack oitemstack = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(
|
|
|
|
|
- // blockEntity.removeItem(i, level.spigotConfig.hopperAmount)
|
|
|
|
|
- // ); // Spigot
|
|
|
|
|
-
|
|
|
|
|
- // org.bukkit.inventory.Inventory destinationInventory;
|
|
|
|
|
- // // Have to special case large chests as they work oddly
|
|
|
|
|
- // if (attachedContainer instanceof final net.minecraft.world.CompoundContainer compoundContainer) {
|
|
|
|
|
- // destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest(compoundContainer);
|
|
|
|
|
- // } else if (attachedContainer.getOwner() != null) {
|
|
|
|
|
- // destinationInventory = attachedContainer.getOwner().getInventory();
|
|
|
|
|
- // } else {
|
|
|
|
|
- // destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventory(attachedContainer);
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- // org.bukkit.event.inventory.InventoryMoveItemEvent event = new org.bukkit.event.inventory.InventoryMoveItemEvent(
|
|
|
|
|
- // blockEntity.getOwner().getInventory(),
|
|
|
|
|
- // oitemstack,
|
|
|
|
|
- // destinationInventory,
|
|
|
|
|
- // true
|
|
|
|
|
- // );
|
|
|
|
|
- // if (!event.callEvent()) {
|
|
|
|
|
- // blockEntity.setItem(i, original);
|
|
|
|
|
- // blockEntity.setCooldown(level.spigotConfig.hopperTransfer); // Delay hopper checks // Spigot
|
|
|
|
|
- // return false;
|
|
|
|
|
- // }
|
|
|
|
|
- // int origCount = event.getItem().getAmount(); // Spigot
|
|
|
|
|
- // ItemStack itemStack = HopperBlockEntity.addItem(blockEntity, attachedContainer, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItem()), opposite);
|
|
|
|
|
- // // CraftBukkit end
|
|
|
|
|
-
|
|
|
|
|
- // if (itemStack.isEmpty()) {
|
|
|
|
|
- // attachedContainer.setChanged();
|
|
|
|
|
- // return true;
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- // item.setCount(count);
|
|
|
|
|
- // // Spigot start
|
|
|
|
|
- // item.shrink(origCount - itemStack.getCount());
|
|
|
|
|
- // if (count <= level.spigotConfig.hopperAmount) {
|
|
|
|
|
- // // Spigot end
|
|
|
|
|
- // blockEntity.setItem(i, item);
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- //}
|
|
|
|
|
-
|
|
|
|
|
- //return false;
|
|
|
|
|
+ //return hopperPush(level, attachedContainer, opposite, blockEntity); // Luminol - Disable paper hopper optimization
|
|
|
|
|
+ // Luminol start - Disable paper hopper optimization
|
|
|
|
|
+ for (int i = 0; i < blockEntity.getContainerSize(); i++) {
|
|
|
|
|
+ ItemStack item = blockEntity.getItem(i);
|
|
|
|
|
+ if (!item.isEmpty()) {
|
|
|
|
|
+ int count = item.getCount();
|
|
|
|
|
+ // CraftBukkit start - Call event when pushing items into other inventories
|
|
|
|
|
+ ItemStack original = item.copy();
|
|
|
|
|
+ org.bukkit.craftbukkit.inventory.CraftItemStack oitemstack = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(
|
|
|
|
|
+ blockEntity.removeItem(i, level.spigotConfig.hopperAmount)
|
|
|
|
|
+ ); // Spigot
|
|
|
|
|
+
|
|
|
|
|
+ org.bukkit.inventory.Inventory destinationInventory;
|
|
|
|
|
+ // Have to special case large chests as they work oddly
|
|
|
|
|
+ if (attachedContainer instanceof final net.minecraft.world.CompoundContainer compoundContainer) {
|
|
|
|
|
+ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest(compoundContainer);
|
|
|
|
|
+ } else if (attachedContainer.getOwner() != null) {
|
|
|
|
|
+ destinationInventory = attachedContainer.getOwner().getInventory();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventory(attachedContainer);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ org.bukkit.event.inventory.InventoryMoveItemEvent event = new org.bukkit.event.inventory.InventoryMoveItemEvent(
|
|
|
|
|
+ blockEntity.getOwner().getInventory(),
|
|
|
|
|
+ oitemstack,
|
|
|
|
|
+ destinationInventory,
|
|
|
|
|
+ true
|
|
|
|
|
+ );
|
|
|
|
|
+ if (!event.callEvent()) {
|
|
|
|
|
+ blockEntity.setItem(i, original);
|
|
|
|
|
+ blockEntity.setCooldown(level.spigotConfig.hopperTransfer); // Delay hopper checks // Spigot
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ int origCount = event.getItem().getAmount(); // Spigot
|
|
|
|
|
+ ItemStack itemStack = HopperBlockEntity.addItem(blockEntity, attachedContainer, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItem()), opposite);
|
|
|
|
|
+ // CraftBukkit end
|
|
|
|
|
+
|
|
|
|
|
+ if (itemStack.isEmpty()) {
|
|
|
|
|
+ attachedContainer.setChanged();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ item.setCount(count);
|
|
|
|
|
+ // Spigot start
|
|
|
|
|
+ item.shrink(origCount - itemStack.getCount());
|
|
|
|
|
+ if (count <= level.spigotConfig.hopperAmount) {
|
|
|
|
|
+ // Spigot end
|
|
|
|
|
+ blockEntity.setItem(i, item);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ // Luminol end
|
|
|
|
|
// Paper end - Perf: Optimize Hoppers
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -568,57 +570,59 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
|
|
|
ItemStack item = container.getItem(slot);
|
|
|
|
|
if (!item.isEmpty() && canTakeItemFromContainer(hopper, container, item, slot, direction)) {
|
|
|
|
|
// Paper start - Perf: Optimize Hoppers
|
|
|
|
|
- return hopperPull(level, hopper, container, item, slot);
|
|
|
|
|
- //int count = item.getCount();
|
|
|
|
|
- //// CraftBukkit start - Call event on collection of items from inventories into the hopper
|
|
|
|
|
- //ItemStack original = item.copy();
|
|
|
|
|
- //org.bukkit.craftbukkit.inventory.CraftItemStack oitemstack = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(
|
|
|
|
|
- // container.removeItem(slot, level.spigotConfig.hopperAmount) // Spigot
|
|
|
|
|
- //);
|
|
|
|
|
-
|
|
|
|
|
- //org.bukkit.inventory.Inventory sourceInventory;
|
|
|
|
|
- //// Have to special case large chests as they work oddly
|
|
|
|
|
- //if (container instanceof final net.minecraft.world.CompoundContainer compoundContainer) {
|
|
|
|
|
- // sourceInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest(compoundContainer);
|
|
|
|
|
- //} else if (container.getOwner() != null) {
|
|
|
|
|
- // sourceInventory = container.getOwner().getInventory();
|
|
|
|
|
- //} else {
|
|
|
|
|
- // sourceInventory = new org.bukkit.craftbukkit.inventory.CraftInventory(container);
|
|
|
|
|
- //}
|
|
|
|
|
-
|
|
|
|
|
- //org.bukkit.event.inventory.InventoryMoveItemEvent event = new org.bukkit.event.inventory.InventoryMoveItemEvent(
|
|
|
|
|
- // sourceInventory,
|
|
|
|
|
- // oitemstack,
|
|
|
|
|
- // hopper.getOwner().getInventory(),
|
|
|
|
|
- // false
|
|
|
|
|
- //);
|
|
|
|
|
-
|
|
|
|
|
- //if (!event.callEvent()) {
|
|
|
|
|
- // container.setItem(slot, original);
|
|
|
|
|
-
|
|
|
|
|
- // if (hopper instanceof final HopperBlockEntity hopperBlockEntity) {
|
|
|
|
|
- // hopperBlockEntity.setCooldown(level.spigotConfig.hopperTransfer); // Spigot
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- // return false;
|
|
|
|
|
- //}
|
|
|
|
|
- //int origCount = event.getItem().getAmount(); // Spigot
|
|
|
|
|
- //ItemStack itemStack = HopperBlockEntity.addItem(container, hopper, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItem()), null);
|
|
|
|
|
- //// CraftBukkit end
|
|
|
|
|
-
|
|
|
|
|
- //if (itemStack.isEmpty()) {
|
|
|
|
|
- // container.setChanged();
|
|
|
|
|
- // return true;
|
|
|
|
|
- //}
|
|
|
|
|
-
|
|
|
|
|
- //item.setCount(count);
|
|
|
|
|
- //// Spigot start
|
|
|
|
|
- //item.shrink(origCount - itemStack.getCount());
|
|
|
|
|
- //if (count <= level.spigotConfig.hopperAmount) {
|
|
|
|
|
- // // Spigot end
|
|
|
|
|
- // container.setItem(slot, item);
|
|
|
|
|
- //}
|
|
|
|
|
- // Paper end - Perf: Optimize Hoppers
|
|
|
|
|
+ //return hopperPull(level, hopper, container, item, slot); // Luminol - Disable paper hooper optimizations
|
|
|
|
|
+ // Luminol start - Disable paper hooper optimizations
|
|
|
|
|
+ int count = item.getCount();
|
|
|
|
|
+ // CraftBukkit start - Call event on collection of items from inventories into the hopper
|
|
|
|
|
+ ItemStack original = item.copy();
|
|
|
|
|
+ org.bukkit.craftbukkit.inventory.CraftItemStack oitemstack = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(
|
|
|
|
|
+ container.removeItem(slot, level.spigotConfig.hopperAmount) // Spigot
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ org.bukkit.inventory.Inventory sourceInventory;
|
|
|
|
|
+ // Have to special case large chests as they work oddly
|
|
|
|
|
+ if (container instanceof final net.minecraft.world.CompoundContainer compoundContainer) {
|
|
|
|
|
+ sourceInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest(compoundContainer);
|
|
|
|
|
+ } else if (container.getOwner() != null) {
|
|
|
|
|
+ sourceInventory = container.getOwner().getInventory();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sourceInventory = new org.bukkit.craftbukkit.inventory.CraftInventory(container);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ org.bukkit.event.inventory.InventoryMoveItemEvent event = new org.bukkit.event.inventory.InventoryMoveItemEvent(
|
|
|
|
|
+ sourceInventory,
|
|
|
|
|
+ oitemstack,
|
|
|
|
|
+ hopper.getOwner().getInventory(),
|
|
|
|
|
+ false
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ if (!event.callEvent()) {
|
|
|
|
|
+ container.setItem(slot, original);
|
|
|
|
|
+
|
|
|
|
|
+ if (hopper instanceof final HopperBlockEntity hopperBlockEntity) {
|
|
|
|
|
+ hopperBlockEntity.setCooldown(level.spigotConfig.hopperTransfer); // Spigot
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ int origCount = event.getItem().getAmount(); // Spigot
|
|
|
|
|
+ ItemStack itemStack = HopperBlockEntity.addItem(container, hopper, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItem()), null);
|
|
|
|
|
+ // CraftBukkit end
|
|
|
|
|
+
|
|
|
|
|
+ if (itemStack.isEmpty()) {
|
|
|
|
|
+ container.setChanged();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ item.setCount(count);
|
|
|
|
|
+ // Spigot start
|
|
|
|
|
+ item.shrink(origCount - itemStack.getCount());
|
|
|
|
|
+ if (count <= level.spigotConfig.hopperAmount) {
|
|
|
|
|
+ // Spigot end
|
|
|
|
|
+ container.setItem(slot, item);
|
|
|
|
|
+ }
|
|
|
|
|
+ // Luminol end
|
|
|
|
|
+ //Paper end - Perf: Optimize Hoppers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
@@ -690,9 +694,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
|
|
|
stack = stack.split(destination.getMaxStackSize());
|
|
|
|
|
}
|
|
|
|
|
// Spigot end
|
|
|
|
|
- IGNORE_TILE_UPDATES.set(Boolean.TRUE); // Paper - Perf: Optimize Hoppers // Folia - region threading
|
|
|
|
|
+ //IGNORE_TILE_UPDATES.set(Boolean.TRUE); // Paper - Perf: Optimize Hoppers // Folia - region threading // Luminol - Disable paper hooper optimizations
|
|
|
|
|
destination.setItem(slot, stack);
|
|
|
|
|
- IGNORE_TILE_UPDATES.set(Boolean.FALSE); // Paper - Perf: Optimize Hoppers // Folia - region threading
|
|
|
|
|
+ //IGNORE_TILE_UPDATES.set(Boolean.FALSE); // Paper - Perf: Optimize Hoppers // Folia - region threading // Luminol - Disable paper hooper optimizations
|
|
|
|
|
stack = leftover; // Paper - Make hoppers respect inventory max stack size
|
|
|
|
|
flag = true;
|
|
|
|
|
} else if (canMergeItems(item, stack)) {
|
|
|
|
|
@@ -780,7 +784,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
|
public static Container getContainerAt(Level level, BlockPos pos) {
|
|
|
|
|
- return getContainerAt(level, pos, level.getBlockState(pos), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, true); // Paper - Optimize hoppers
|
|
|
|
|
+ return getContainerAt(level, pos, level.getBlockState(pos), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, false); // Paper - Optimize hoppers // Luminol - Disable paper hooper optimizations
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Nullable
|