Skip to content

Commit

Permalink
Properly handle unticked hopper tick adjustment
Browse files Browse the repository at this point in the history
For unticked hoppers, we should use MIN_VALUE as a marker
so that they compare equivalently regardless of whether they've
been through a region merge.
  • Loading branch information
Spottedleaf committed Mar 29, 2024
1 parent e50d09b commit ef2c697
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions patches/server/0003-Threaded-Regions.patch
Original file line number Diff line number Diff line change
Expand Up @@ -20394,25 +20394,36 @@ 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..c1d835555fe57745c3d9e416044bd049a537eecf 100644
index cdb739df2a285032d25d84f4464f202a7a3fa578..82e7e76fecceb55522b5828a56f036e42ef55201 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
@@ -82,6 +82,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -50,7 +50,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
public static final int HOPPER_CONTAINER_SIZE = 5;
private NonNullList<ItemStack> items;
public int cooldownTime;
- private long tickedGameTime;
+ private long tickedGameTime = Long.MIN_VALUE; // Folia - region threading

// CraftBukkit start - add fields and methods
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
@@ -82,6 +82,16 @@ 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;
+ if (this.tickedGameTime != Long.MIN_VALUE) {
+ 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
@@ -137,7 +147,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen

public static void pushItemsTick(Level world, BlockPos pos, BlockState state, HopperBlockEntity blockEntity) {
--blockEntity.cooldownTime;
Expand All @@ -20421,7 +20432,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..c1d835555fe57745c3d9e416044bd049
if (!blockEntity.isOnCooldown()) {
blockEntity.setCooldown(0);
// Spigot start
@@ -234,12 +242,11 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -234,12 +244,11 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
}

// Paper start - Perf: Optimize Hoppers
Expand All @@ -20437,7 +20448,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..c1d835555fe57745c3d9e416044bd049
boolean foundItem = false;
for (int i = 0; i < hopper.getContainerSize(); ++i) {
final ItemStack item = hopper.getItem(i);
@@ -254,7 +261,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -254,7 +263,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 @@ -20446,7 +20457,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..c1d835555fe57745c3d9e416044bd049
movedItem = callPushMoveEvent(destination, movedItem, hopper);
if (movedItem == null) { // cancelled
origItemStack.setCount(originalItemCount);
@@ -284,13 +291,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -284,13 +293,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 @@ -20462,7 +20473,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..c1d835555fe57745c3d9e416044bd049
movedItem = callPullMoveEvent(hopper, container, movedItem);
if (movedItem == null) { // cancelled
origItemStack.setCount(originalItemCount);
@@ -310,9 +318,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -310,9 +320,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
origItemStack.setCount(originalItemCount - movedItemCount + remainingItemCount);
}

Expand All @@ -20474,7 +20485,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..c1d835555fe57745c3d9e416044bd049
container.setChanged();
return true;
}
@@ -327,12 +335,13 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -327,12 +337,13 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen

@Nullable
private static ItemStack callPushMoveEvent(Container iinventory, ItemStack itemstack, HopperBlockEntity hopper) {
Expand All @@ -20489,15 +20500,15 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..c1d835555fe57745c3d9e416044bd049
}
if (!result) {
cooldownHopper(hopper);
@@ -348,6 +357,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -348,6 +359,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 +365,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -355,7 +367,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 @@ -20506,7 +20517,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..c1d835555fe57745c3d9e416044bd049
}
if (!result) {
cooldownHopper(hopper);
@@ -518,13 +528,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -518,13 +530,14 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
}

public static boolean suckInItems(Level world, Hopper hopper) {
Expand All @@ -20522,7 +20533,7 @@ index cdb739df2a285032d25d84f4464f202a7a3fa578..c1d835555fe57745c3d9e416044bd049
// merge container isEmpty check and move logic into one loop
if (iinventory instanceof WorldlyContainer worldlyContainer) {
for (final int slot : worldlyContainer.getSlotsForFace(enumdirection)) {
@@ -724,9 +735,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@@ -724,9 +737,9 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
stack = stack.split(to.getMaxStackSize());
}
// Spigot end
Expand Down

0 comments on commit ef2c697

Please sign in to comment.