Use redstone game time for hopper tickedGameTime

This should fix timing inconsistencies for hoppers
This commit is contained in:
Spottedleaf 2024-03-28 18:09:50 -07:00
parent 7bc84f49be
commit e73566fdc2

View File

@ -20274,10 +20274,34 @@ index 37e0b762b86e74f607a4541ecb7b24ad7a591d0e..4ddc3b3dc704610bf1fb7082e1c89a28
if (i % 40L == 0L) {
diff --git a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
index cdb739df2a285032d25d84f4464f202a7a3fa578..4fe1b822b4c280de9d5b46c1dc965045791c83d0 100644
index cdb739df2a285032d25d84f4464f202a7a3fa578..c1d835555fe57745c3d9e416044bd049a537eecf 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
@@ -234,12 +234,11 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -82,6 +82,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
}
// CraftBukkit end
+ // Folia start - region threading
+ @Override
+ public void updateTicks(final long fromTickOffset, final long fromRedstoneTimeOffset) {
+ super.updateTicks(fromTickOffset, fromRedstoneTimeOffset);
+ this.tickedGameTime += fromRedstoneTimeOffset;
+ }
+ // Folia end - region threading
+
public HopperBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityType.HOPPER, pos, state);
this.items = NonNullList.withSize(5, ItemStack.EMPTY);
@@ -137,7 +145,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
public static void pushItemsTick(Level world, BlockPos pos, BlockState state, HopperBlockEntity blockEntity) {
--blockEntity.cooldownTime;
- blockEntity.tickedGameTime = world.getGameTime();
+ blockEntity.tickedGameTime = world.getRedstoneGameTime(); // Folia - region threading
if (!blockEntity.isOnCooldown()) {
blockEntity.setCooldown(0);
// Spigot start
@@ -234,12 +242,11 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
}
// Paper start - Perf: Optimize Hoppers
@ -20293,7 +20317,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..4fe1b822b4c280de9d5b46c1dc965045
boolean foundItem = false;
for (int i = 0; i < hopper.getContainerSize(); ++i) {
final ItemStack item = hopper.getItem(i);
@@ -254,7 +253,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -254,7 +261,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
// We only need to fire the event once to give protection plugins a chance to cancel this event
// Because nothing uses getItem, every event call should end up the same result.
@ -20302,7 +20326,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..4fe1b822b4c280de9d5b46c1dc965045
movedItem = callPushMoveEvent(destination, movedItem, hopper);
if (movedItem == null) { // cancelled
origItemStack.setCount(originalItemCount);
@@ -284,13 +283,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -284,13 +291,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
}
private static boolean hopperPull(final Level level, final Hopper hopper, final Container container, ItemStack origItemStack, final int i) {
@ -20318,7 +20342,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..4fe1b822b4c280de9d5b46c1dc965045
movedItem = callPullMoveEvent(hopper, container, movedItem);
if (movedItem == null) { // cancelled
origItemStack.setCount(originalItemCount);
@@ -310,9 +310,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -310,9 +318,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
origItemStack.setCount(originalItemCount - movedItemCount + remainingItemCount);
}
@ -20330,7 +20354,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..4fe1b822b4c280de9d5b46c1dc965045
container.setChanged();
return true;
}
@@ -327,12 +327,13 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -327,12 +335,13 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@Nullable
private static ItemStack callPushMoveEvent(Container iinventory, ItemStack itemstack, HopperBlockEntity hopper) {
@ -20345,7 +20369,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..4fe1b822b4c280de9d5b46c1dc965045
}
if (!result) {
cooldownHopper(hopper);
@@ -348,6 +349,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -348,6 +357,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@Nullable
private static ItemStack callPullMoveEvent(final Hopper hopper, final Container container, final ItemStack itemstack) {
@ -20353,7 +20377,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..4fe1b822b4c280de9d5b46c1dc965045
final Inventory sourceInventory = getInventory(container);
final Inventory destination = getInventory(hopper);
@@ -355,7 +357,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -355,7 +365,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
final io.papermc.paper.event.inventory.PaperInventoryMoveItemEvent event = new io.papermc.paper.event.inventory.PaperInventoryMoveItemEvent(sourceInventory, CraftItemStack.asCraftMirror(itemstack), destination, false);
final boolean result = event.callEvent();
if (!event.calledGetItem && !event.calledSetItem) {
@ -20362,7 +20386,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..4fe1b822b4c280de9d5b46c1dc965045
}
if (!result) {
cooldownHopper(hopper);
@@ -518,13 +520,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -518,13 +528,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
}
public static boolean suckInItems(Level world, Hopper hopper) {
@ -20378,7 +20402,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..4fe1b822b4c280de9d5b46c1dc965045
// merge container isEmpty check and move logic into one loop
if (iinventory instanceof WorldlyContainer worldlyContainer) {
for (final int slot : worldlyContainer.getSlotsForFace(enumdirection)) {
@@ -724,9 +727,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -724,9 +735,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
stack = stack.split(to.getMaxStackSize());
}
// Spigot end