Implement PlatformHooks#addTicketForEnderPearls

Allows implementing Paper's legacy ender pearl behavior config
option.
This commit is contained in:
Spottedleaf
2025-06-20 20:24:15 -07:00
parent da21aeca85
commit a33ac1dc01
4 changed files with 13 additions and 3 deletions

View File

@@ -273,7 +273,7 @@ public final class FabricHooks extends BaseChunkSystemHooks implements PlatformH
} }
@Override @Override
public boolean addTicketForEnderPearls() { public boolean addTicketForEnderPearls(final ServerLevel world) {
return true; return true;
} }
} }

View File

@@ -288,7 +288,7 @@ public final class NeoForgeHooks extends BaseChunkSystemHooks implements Platfor
} }
@Override @Override
public boolean addTicketForEnderPearls() { public boolean addTicketForEnderPearls(final ServerLevel world) {
return true; return true;
} }
} }

View File

@@ -102,7 +102,7 @@ public interface PlatformHooks extends ChunkSystemHooks {
public int modifyEntityTrackingRange(final Entity entity, final int currentRange); public int modifyEntityTrackingRange(final Entity entity, final int currentRange);
public boolean addTicketForEnderPearls(); public boolean addTicketForEnderPearls(final ServerLevel world);
public static final class Holder { public static final class Holder {
private Holder() { private Holder() {

View File

@@ -30,10 +30,12 @@ public final class ServerEntityLookup extends EntityLookup {
// been implemented, but I don't think Vanilla has proper entity add/remove hooks like we do. Fixes MC-297591 // been implemented, but I don't think Vanilla has proper entity add/remove hooks like we do. Fixes MC-297591
private static final TicketType ENDER_PEARL_TICKER = ChunkSystemTicketType.create("chunk_system:ender_pearl_ticker", null); private static final TicketType ENDER_PEARL_TICKER = ChunkSystemTicketType.create("chunk_system:ender_pearl_ticker", null);
private final Long2IntOpenHashMap enderPearlChunkCount = new Long2IntOpenHashMap(); private final Long2IntOpenHashMap enderPearlChunkCount = new Long2IntOpenHashMap();
private final boolean keepEnderPearlsTicking;
public ServerEntityLookup(final ServerLevel world, final LevelCallback<Entity> worldCallback) { public ServerEntityLookup(final ServerLevel world, final LevelCallback<Entity> worldCallback) {
super(world, worldCallback); super(world, worldCallback);
this.serverWorld = world; this.serverWorld = world;
this.keepEnderPearlsTicking = PlatformHooks.get().addTicketForEnderPearls(world);
} }
@Override @Override
@@ -136,6 +138,10 @@ public final class ServerEntityLookup extends EntityLookup {
} }
private void addEnderPearl(final long coordinate) { private void addEnderPearl(final long coordinate) {
if (!this.keepEnderPearlsTicking) {
return;
}
final int oldCount = this.enderPearlChunkCount.addTo(coordinate, 1); final int oldCount = this.enderPearlChunkCount.addTo(coordinate, 1);
if (oldCount != 0) { if (oldCount != 0) {
return; return;
@@ -145,6 +151,10 @@ public final class ServerEntityLookup extends EntityLookup {
} }
private void removeEnderPearl(final long coordinate) { private void removeEnderPearl(final long coordinate) {
if (!this.keepEnderPearlsTicking) {
return;
}
final int oldCount = this.enderPearlChunkCount.addTo(coordinate, -1); final int oldCount = this.enderPearlChunkCount.addTo(coordinate, -1);
if (oldCount != 1) { if (oldCount != 1) {
return; return;