mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-21 18:15:54 +01:00
8c5b837e05
Firstly, the old methods all routed to the CompletableFuture method. However, the CF method could not guarantee that if the caller was off-main that the future would be "completed" on-main. Since the callback methods used the CF one, this meant that the callback methods did not guarantee that the callbacks were to be called on the main thread. Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb) so that the methods with the callback are guaranteed to invoke the callback on the main thread. The CF behavior remains unchanged; it may still appear to complete on main if invoked off-main. Secondly, remove the scheduleOnMain invocation in the async chunk completion. This unnecessarily delays the callback by 1 tick. Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which will load chunks within an area. This method is provided as a helper as keeping all chunks loaded within an area can be complicated to implement for plugins (due to the lacking ticket API), and is already implemented internally anyways. Fourthly, remove the ticket addition that occured with getChunkAt and getChunkAtAsync. The ticket addition may delay the unloading of the chunk unnecessarily. It also fixes a very rare timing bug where the future/callback would be completed after the chunk unloads.
63 lines
3.8 KiB
Diff
63 lines
3.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
|
|
Date: Sun, 27 Oct 2024 12:36:53 -0700
|
|
Subject: [PATCH] Allow using old ender pearl behavior
|
|
|
|
When enabled, ender pearls will not load chunks and will save to the world instead of the player.
|
|
|
|
== AT ==
|
|
public net.minecraft.world.entity.projectile.Projectile cachedOwner
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index b525369fb6f3bb80c1553ae41b1e3bddeda29936..2e8ecf3bbb9f9ceba6f896738fa1ab8e2bd0fed6 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -836,6 +836,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
|
|
while (iterator.hasNext()) {
|
|
ThrownEnderpearl entityenderpearl = (ThrownEnderpearl) iterator.next();
|
|
+ if (entityenderpearl.level().paperConfig().misc.legacyEnderPearlBehavior) continue; // Paper - Allow using old ender pearl behavior
|
|
|
|
if (entityenderpearl.isRemoved()) {
|
|
ServerPlayer.LOGGER.warn("Trying to save removed ender pearl, skipping");
|
|
@@ -3146,7 +3147,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
}
|
|
|
|
public static long placeEnderPearlTicket(ServerLevel world, ChunkPos chunkPos) {
|
|
- world.getChunkSource().addRegionTicket(TicketType.ENDER_PEARL, chunkPos, 2, chunkPos);
|
|
+ if (!world.paperConfig().misc.legacyEnderPearlBehavior) world.getChunkSource().addRegionTicket(TicketType.ENDER_PEARL, chunkPos, 2, chunkPos); // Paper - Allow using old ender pearl behavior
|
|
return TicketType.ENDER_PEARL.timeout();
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index a03ff473a683611670ee274b0eec5a395ee6981a..30de3d1a7792c38ae946f19cb0e14637919b5001 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -602,7 +602,13 @@ public abstract class PlayerList {
|
|
while (iterator.hasNext()) {
|
|
ThrownEnderpearl entityenderpearl = (ThrownEnderpearl) iterator.next();
|
|
|
|
+ // Paper start - Allow using old ender pearl behavior
|
|
+ if (!entityenderpearl.level().paperConfig().misc.legacyEnderPearlBehavior) {
|
|
entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER, EntityRemoveEvent.Cause.PLAYER_QUIT); // CraftBukkit - add Bukkit remove cause
|
|
+ } else {
|
|
+ entityenderpearl.cachedOwner = null;
|
|
+ }
|
|
+ // Paper end - Allow using old ender pearl behavior
|
|
}
|
|
|
|
worldserver.removePlayerImmediately(entityplayer, Entity.RemovalReason.UNLOADED_WITH_PLAYER);
|
|
diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java b/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java
|
|
index 5f790dd24f2bdae827c6dc597064b9b265089751..bd2684528157f928460f2143dd71a48e11983123 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java
|
|
@@ -252,7 +252,7 @@ public class ThrownEnderpearl extends ThrowableItemProjectile {
|
|
Entity entity = super.teleport(teleportTarget);
|
|
|
|
if (entity != null) {
|
|
- entity.placePortalTicket(BlockPos.containing(entity.position()));
|
|
+ if (!this.level().paperConfig().misc.legacyEnderPearlBehavior) entity.placePortalTicket(BlockPos.containing(entity.position())); // Paper - Allow using old ender pearl behavior
|
|
}
|
|
|
|
return entity;
|