Skip to content

Commit

Permalink
Better smooth teleport api
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Nov 28, 2024
1 parent 77de601 commit b3844d0
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 26 deletions.
22 changes: 19 additions & 3 deletions patches/api/0008-Slice-Smooth-Teleports.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,41 @@ Subject: [PATCH] Slice: Smooth Teleports
Original license: MIT
Original project: https://github.com/Cryptite/Slice

Co-authored-by: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>

diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index d5df69a2e5b228545dfaaaa98ce88ec0da806315..a6d43ac0ee1b4bac6efc3283c7eea643a45e2d93 100644
index f96ca62d81db8362a9f74f00ff54b151f96c04fe..f1d9f17b3ef15e2db5dabe563f7c56fa9c1be651 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -3691,6 +3691,19 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -3691,6 +3691,33 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
String getClientBrandName();
// Paper end

+ /**
+ * This abuses some of how Minecraft works and allows teleporting a player to another world without
+ * This abuses some of how Minecraft works and attempts to teleport a player to another world without
+ * triggering typical respawn packets. All of natural state of chunk resends, entity adds/removes, etc still
+ * happen but the visual "refresh" of a world change is hidden. Depending on the destination location/world,
+ * this can act as a "smooth teleport" to a world if the new world is very similar looking to the old one.
+ *
+ * @param location New location to teleport this Player to
+ * @deprecated use {@link #teleportWithoutRespawnOptionally(Location)}
+ */
+ // Slice start
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ @Deprecated(since = "1.21.1", forRemoval = true)
+ void teleportWithoutRespawn(@NotNull Location location);
+
+ /**
+ * This abuses some of how Minecraft works and attempts to teleport a player to another world without
+ * triggering typical respawn packets. All of natural state of chunk resends, entity adds/removes, etc still
+ * happen but the visual "refresh" of a world change is hidden. Depending on the destination location/world,
+ * this can act as a "smooth teleport" to a world if the new world is very similar looking to the old one.
+ *
+ * @param location New location to teleport this Player to
+ * @return Whether the teleport was successful
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ boolean teleportWithoutRespawnOptionally(@NotNull Location location);
+ // Slice end
+
// Paper start - Teleport API
Expand Down
31 changes: 26 additions & 5 deletions patches/server/0027-Slice-Smooth-Teleports.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Subject: [PATCH] Slice: Smooth Teleports
Original license: MIT
Original project: https://github.com/Cryptite/Slice

Co-authored-by: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>

diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 1dc2af59bafa5a5dc6721da02cde19a3ca77af28..b2ae3fdf128e7d66e3f3430266321a6a09fa0be6 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
Expand All @@ -19,37 +21,56 @@ index 1dc2af59bafa5a5dc6721da02cde19a3ca77af28..b2ae3fdf128e7d66e3f3430266321a6a
// Paper start - rewrite chunk system
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index bf3561764bab8e1b237c2b9760181853f60c8fa7..26a92a77481c46969b68e454b906b3935ad02043 100644
index bf3561764bab8e1b237c2b9760181853f60c8fa7..fa658c59c61449e6499f5f0c334df180e532f883 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -901,10 +901,10 @@ public abstract class PlayerList {
ServerLevel worldserver1 = entityplayer1.serverLevel();
LevelData worlddata = worldserver1.getLevelData();

- entityplayer1.connection.send(new ClientboundRespawnPacket(entityplayer1.createCommonSpawnInfo(worldserver1), (byte) i));
+ if (!entityplayer.smoothWorldTeleport) entityplayer1.connection.send(new ClientboundRespawnPacket(entityplayer1.createCommonSpawnInfo(worldserver1), (byte) i)); // Slice
+ if (!entityplayer.smoothWorldTeleport || !isSameLogicalHeight((ServerLevel) fromWorld, worldserver)) entityplayer1.connection.send(new ClientboundRespawnPacket(entityplayer1.createCommonSpawnInfo(worldserver1), (byte) i)); // Slice // Leaf
entityplayer1.connection.send(new ClientboundSetChunkCacheRadiusPacket(worldserver1.spigotConfig.viewDistance)); // Spigot
entityplayer1.connection.send(new ClientboundSetSimulationDistancePacket(worldserver1.spigotConfig.simulationDistance)); // Spigot
- entityplayer1.connection.teleport(CraftLocation.toBukkit(entityplayer1.position(), worldserver1.getWorld(), entityplayer1.getYRot(), entityplayer1.getXRot())); // CraftBukkit
+ if (!entityplayer.smoothWorldTeleport) entityplayer1.connection.teleport(CraftLocation.toBukkit(entityplayer1.position(), worldserver1.getWorld(), entityplayer1.getYRot(), entityplayer1.getXRot())); // CraftBukkit // Slice
+ if (!entityplayer.smoothWorldTeleport || !isSameLogicalHeight((ServerLevel) fromWorld, worldserver)) entityplayer1.connection.teleport(CraftLocation.toBukkit(entityplayer1.position(), worldserver1.getWorld(), entityplayer1.getYRot(), entityplayer1.getXRot())); // CraftBukkit // Slice // Leaf
entityplayer1.connection.send(new ClientboundSetDefaultSpawnPositionPacket(worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle()));
entityplayer1.connection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
entityplayer1.connection.send(new ClientboundSetExperiencePacket(entityplayer1.experienceProgress, entityplayer1.totalExperience, entityplayer1.experienceLevel));
@@ -965,6 +965,8 @@ public abstract class PlayerList {
return entityplayer1;
}

+ private boolean isSameLogicalHeight(ServerLevel level1, ServerLevel level2) { return level1.getLogicalHeight() == level2.getLogicalHeight(); } // Leaf - Check world height before smooth teleport
+
public void sendActivePlayerEffects(ServerPlayer player) {
this.sendActiveEffects(player, player.connection);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 88668656c8586d758b636561066d96dd883e6201..95c6275ec833a0bfe4e7b8105db5abafd69079c3 100644
index 88668656c8586d758b636561066d96dd883e6201..75f1e56281014a8fc7e682478307d8f40ad4bdcc 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1365,6 +1365,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -1365,6 +1365,25 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// Paper end
}

+ // Slice start
+ @Override
+ public void teleportWithoutRespawn(Location location) {
+ ServerPlayer serverPlayer = getHandle();
+ serverPlayer.smoothWorldTeleport = true;
+ teleport(location);
+ serverPlayer.smoothWorldTeleport = false;
+ }
+
+ @Override
+ public boolean teleportWithoutRespawnOptionally(Location location) {
+ ServerPlayer serverPlayer = getHandle();
+ serverPlayer.smoothWorldTeleport = true;
+ boolean teleportResult = teleport(location);
+ serverPlayer.smoothWorldTeleport = false;
+ return teleportResult;
+ }
+ // Slice end
+
@Override
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0033-Leaves-Xaero-Map-Protocol.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Original project: https://github.com/LeavesMC/Leaves
This patch is Powered by Xaero Map

diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 73d67b3bebcf3dff210e25dda0b3df206e129173..a25a8268d148862312ebf93cf9d7828b4e051375 100644
index bbd64da6ffa78c7e2376f38456681aaf1823528a..135a53742607dfccff17aa86f80f106b4a31f6b0 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -1336,6 +1336,7 @@ public abstract class PlayerList {
@@ -1338,6 +1338,7 @@ public abstract class PlayerList {
player.connection.send(new ClientboundInitializeBorderPacket(worldborder));
player.connection.send(new ClientboundSetTimePacket(world.getGameTime(), world.getDayTime(), world.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
player.connection.send(new ClientboundSetDefaultSpawnPositionPacket(world.getSharedSpawnPos(), world.getSharedSpawnAngle()));
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0037-Leaves-Replay-Mod-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ index b2ae3fdf128e7d66e3f3430266321a6a09fa0be6..7c6bda95b8b08cc70182f19cf0b991f7
this.stats = server.getPlayerList().getPlayerStats(this);
this.advancements = server.getPlayerList().getPlayerAdvancements(this);
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index a25a8268d148862312ebf93cf9d7828b4e051375..b7228c495871d3222f184c1ede4d846d9c13a435 100644
index 135a53742607dfccff17aa86f80f106b4a31f6b0..94b43be23f1b6498a09e9c45d2ec02df8fbd6d17 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -155,6 +155,7 @@ public abstract class PlayerList {
Expand Down Expand Up @@ -462,10 +462,10 @@ index 770606c4462d85d116f6d0bf91192dc49f438d0f..4317420bd5d3fc8e20ffd7f3a3d48c5a
if (entity instanceof EnderDragonPart complexPart) {
if (complexPart.parentMob instanceof EnderDragon) {
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 95c6275ec833a0bfe4e7b8105db5abafd69079c3..7294c6cc2cf65e3c142d174025d24d854bbe68ae 100644
index 75f1e56281014a8fc7e682478307d8f40ad4bdcc..8addddffe97751524f265241ac644a9291405c42 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2263,7 +2263,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -2273,7 +2273,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {

@Override
public boolean canSee(Player player) {
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0057-SparklyPaper-Optimize-canSee-checks.patch
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ index 4d91b50e527320647f6c9aa20fc5da071c3fdee0..dde015810f6e914ad99dcb8ab66c7aa3
}
// CraftBukkit end
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index c6964b6027e0ac57e3e01deae0da22665f2afc40..801a237b666fe8f26e477d848b1f9e31a4025fd0 100644
index 0021f9bf8d6870bd9275ef59567c51ffce7615d0..a2f329e958fe72d262da9a4cee050efb69294df4 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -200,7 +200,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
Expand All @@ -41,7 +41,7 @@ index c6964b6027e0ac57e3e01deae0da22665f2afc40..801a237b666fe8f26e477d848b1f9e31
private final Set<UUID> unlistedEntities = new HashSet<>(); // Paper - Add Listing API for Player
private static final WeakHashMap<Plugin, WeakReference<Plugin>> pluginWeakReferences = new WeakHashMap<>();
private int hash = 0;
@@ -2269,9 +2269,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -2279,9 +2279,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {

@Override
public boolean canSee(org.bukkit.entity.Entity entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ index a608f57ebca98eda88ad749d0aad021678be54f9..1f301caa36212c85b06a33c714cb1050
this.player.connection.send(this.updateClientChunkRadius(sendViewDistance));
this.player.connection.send(this.updateClientSimulationDistance(tickViewDistance));
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index b7228c495871d3222f184c1ede4d846d9c13a435..505d7376681071e67c460d5a88eaa95f3d6ab820 100644
index 94b43be23f1b6498a09e9c45d2ec02df8fbd6d17..0d41cd4fe9b423a8644475494bcfb73f98e8b70b 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -1718,7 +1718,7 @@ public abstract class PlayerList {
@@ -1720,7 +1720,7 @@ public abstract class PlayerList {

public void setViewDistance(int viewDistance) {
this.viewDistance = viewDistance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Remove useless creating stats json bases on player name logic


diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 505d7376681071e67c460d5a88eaa95f3d6ab820..bc7dd0ceea8bb304fb4370084bf19f29c1df0828 100644
index 0d41cd4fe9b423a8644475494bcfb73f98e8b70b..8d8f552acd4d2e846e1fd0bc19574d93c372fc2b 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -1685,6 +1685,8 @@ public abstract class PlayerList {
@@ -1687,6 +1687,8 @@ public abstract class PlayerList {
File file = this.server.getWorldPath(LevelResource.PLAYER_STATS_DIR).toFile();
File file1 = new File(file, String.valueOf(uuid) + ".json");

Expand All @@ -17,7 +17,7 @@ index 505d7376681071e67c460d5a88eaa95f3d6ab820..bc7dd0ceea8bb304fb4370084bf19f29
if (!file1.exists()) {
File file2 = new File(file, displayName + ".json"); // CraftBukkit
Path path = file2.toPath();
@@ -1693,6 +1695,8 @@ public abstract class PlayerList {
@@ -1695,6 +1697,8 @@ public abstract class PlayerList {
file2.renameTo(file1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ index 50dc68a005490415b88780397ef6c26859596dd5..162115048cffc824376e54b7f60ae071
public static record Favicon(byte[] iconBytes) {
private static final String PREFIX = "data:image/png;base64,";
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index 2e78a464ae2f85722786e9da668f42851d8d65c4..86462d3eff74f373820ccdbb162978d1d4a6d9d6 100644
index eecc459c7e16dfcda57f0682e90ed1b38d71da44..5a88fd8997d2703a1318df441a2789a7b1ab229c 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -707,6 +707,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
Expand Down Expand Up @@ -151,10 +151,10 @@ index 8a3736dbf6ee0b2c6fbb514b2841154d2ad9f0f5..22eb98d51e0cbc996195f7f1ba07c0e4
if (packet == null || this.processedDisconnect) { // Spigot
return;
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 3ac1446ed791e06e2bbf226b925890ac4d1a16de..2cdfd22baf31df99e2c2b1d114c47cb88569538f 100644
index dad180fa1bab9cd9ed08891d42836020f6e709b2..0d791d0e0cbbc77dd1e5b376f82c26e3618c236e 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -1639,7 +1639,7 @@ public abstract class PlayerList {
@@ -1641,7 +1641,7 @@ public abstract class PlayerList {
// Paper end
boolean flag = this.verifyChatTrusted(message);

Expand All @@ -163,7 +163,7 @@ index 3ac1446ed791e06e2bbf226b925890ac4d1a16de..2cdfd22baf31df99e2c2b1d114c47cb8
OutgoingChatMessage outgoingchatmessage = OutgoingChatMessage.create(message);
boolean flag1 = false;

@@ -1668,6 +1668,7 @@ public abstract class PlayerList {
@@ -1670,6 +1670,7 @@ public abstract class PlayerList {
}

public boolean verifyChatTrusted(PlayerChatMessage message) { // Paper - private -> public
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0089-Configurable-connection-message.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Configurable connection message


diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 2cdfd22baf31df99e2c2b1d114c47cb88569538f..8e3bbc7a0cf2a3e5999738c0f764544f5e64ef4a 100644
index 0d791d0e0cbbc77dd1e5b376f82c26e3618c236e..6da4b4d3f00527aabf398ab614140bc6f8c7442c 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -452,7 +452,7 @@ public abstract class PlayerList {
Expand Down Expand Up @@ -35,7 +35,7 @@ index 2cdfd22baf31df99e2c2b1d114c47cb88569538f..8e3bbc7a0cf2a3e5999738c0f764544f
this.cserver.getPluginManager().callEvent(playerQuitEvent);
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());

@@ -1812,4 +1812,29 @@ public abstract class PlayerList {
@@ -1814,4 +1814,29 @@ public abstract class PlayerList {
public boolean isAllowCommandsForAllPlayers() {
return this.allowCommandsForAllPlayers;
}
Expand Down

0 comments on commit b3844d0

Please sign in to comment.