Skip to content

Commit

Permalink
Use redstone game time for hopper tickedGameTime
Browse files Browse the repository at this point in the history
This should fix timing inconsistencies for hoppers
  • Loading branch information
Spottedleaf committed Mar 29, 2024
1 parent 7bc84f4 commit e73566f
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions patches/server/0003-Threaded-Regions.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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) {
Expand All @@ -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);
}

Expand All @@ -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) {
Expand All @@ -20345,15 +20369,15 @@ 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) {
+ io.papermc.paper.threadedregions.RegionizedWorldData worldData = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegionizedWorldData(); // Folia - region threading
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) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit e73566f

Please sign in to comment.