From fafdf0f8a7ff8cf74f53b85e448d571e303a40ed Mon Sep 17 00:00:00 2001 From: William Blake Galbreath Date: Fri, 10 Jan 2025 12:39:08 -0800 Subject: [PATCH] Fix stuck in portals --- .../server/0121-Fix-stuck-in-portals.patch | 60 ------------------- .../features/0001-Ridables.patch | 8 +-- .../server/level/ServerPlayer.java.patch | 8 +++ .../minecraft/world/entity/Entity.java.patch | 13 +++- .../purpurmc/purpur/PurpurWorldConfig.java | 2 + 5 files changed, 26 insertions(+), 65 deletions(-) delete mode 100644 patches/server/0121-Fix-stuck-in-portals.patch diff --git a/patches/server/0121-Fix-stuck-in-portals.patch b/patches/server/0121-Fix-stuck-in-portals.patch deleted file mode 100644 index b82ae6777..000000000 --- a/patches/server/0121-Fix-stuck-in-portals.patch +++ /dev/null @@ -1,60 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Blake Galbreath -Date: Thu, 14 Jan 2021 16:48:10 -0600 -Subject: [PATCH] Fix stuck in portals - - -diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java -index 303c9b2c6f1a62e40c5657248b727c14bb9c613a..92c0a7609e45a8cdb809ad7579f1713fc15675cf 100644 ---- a/net/minecraft/server/level/ServerPlayer.java -+++ b/net/minecraft/server/level/ServerPlayer.java -@@ -1678,6 +1678,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple - worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION); - this.unsetRemoved(); - // CraftBukkit end -+ this.portalPos = io.papermc.paper.util.MCUtil.toBlockPosition(exit); // Purpur - Fix stuck in portals - this.setServerLevel(worldserver); - this.connection.internalTeleport(PositionMoveRotation.of(teleportTarget), teleportTarget.relatives()); // CraftBukkit - use internal teleport without event - this.connection.resetPosition(); -diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index cfe26c762b2affa5050c175f6ab0306af6cfbe71..f15a8c14417b83b237dc7b9a11490116314cd4c6 100644 ---- a/net/minecraft/world/entity/Entity.java -+++ b/net/minecraft/world/entity/Entity.java -@@ -3465,14 +3465,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess - return Vec3.directionFromRotation(this.getRotationVector()); - } - -+ public BlockPos portalPos = BlockPos.ZERO; // Purpur - public void setAsInsidePortal(Portal portal, BlockPos pos) { - if (this.isOnPortalCooldown()) { -+ if (!(level().purpurConfig.playerFixStuckPortal && this instanceof Player && !pos.equals(this.portalPos))) // Purpur - Fix stuck in portals - this.setPortalCooldown(); - } else if (this.level.purpurConfig.entitiesCanUsePortals || this instanceof ServerPlayer) { // Purpur - Entities can use portals - if (this.portalProcess != null && this.portalProcess.isSamePortal(portal)) { - if (!this.portalProcess.isInsidePortalThisTick()) { - this.portalProcess.updateEntryPosition(pos.immutable()); - this.portalProcess.setAsInsidePortalThisTick(true); -+ this.portalPos = BlockPos.ZERO; // Purpur - Fix stuck in portals - } - } else { - this.portalProcess = new PortalProcessor(portal, pos.immutable()); -diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -index 86b27b11f178be0cc05842ccb3ffe4ef14196855..126d2689166579785735cf250ddf0838512ce81b 100644 ---- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -@@ -327,6 +327,7 @@ public class PurpurWorldConfig { - public int playerDeathExpDropMax = 100; - public boolean teleportIfOutsideBorder = false; - public boolean totemOfUndyingWorksInInventory = false; -+ public boolean playerFixStuckPortal = false; - private void playerSettings() { - if (PurpurConfig.version < 19) { - boolean oldVal = getBoolean("gameplay-mechanics.player.idle-timeout.mods-target", idleTimeoutTargetPlayer); -@@ -342,6 +343,7 @@ public class PurpurWorldConfig { - playerDeathExpDropMax = getInt("gameplay-mechanics.player.exp-dropped-on-death.maximum", playerDeathExpDropMax); - teleportIfOutsideBorder = getBoolean("gameplay-mechanics.player.teleport-if-outside-border", teleportIfOutsideBorder); - totemOfUndyingWorksInInventory = getBoolean("gameplay-mechanics.player.totem-of-undying-works-in-inventory", totemOfUndyingWorksInInventory); -+ playerFixStuckPortal = getBoolean("gameplay-mechanics.player.fix-stuck-in-portal", playerFixStuckPortal); - } - - public boolean silkTouchEnabled = false; diff --git a/purpur-server/minecraft-patches/features/0001-Ridables.patch b/purpur-server/minecraft-patches/features/0001-Ridables.patch index 4dbd0a3ef..847c7b0b3 100644 --- a/purpur-server/minecraft-patches/features/0001-Ridables.patch +++ b/purpur-server/minecraft-patches/features/0001-Ridables.patch @@ -42,7 +42,7 @@ index 7f136e044a243814372beef1400d3b6a148d2cbf..5e730cdde960603d5fa0fa7d1b70ec56 public LevelChunk getChunkIfLoaded(int x, int z) { return this.chunkSource.getChunkAtIfLoadedImmediately(x, z); // Paper - Use getChunkIfLoadedImmediately diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java -index 5b50bc97ccab73dcafa29e3a8c5d04b3c4e8c1d4..c03639557e498f44a53fbf223928f68e515638eb 100644 +index 78daeb23bb520774697c8d3d68aa4abe28a40cac..03d0df75dedd414aa54d88ed204cf82c3a4dfc88 100644 --- a/net/minecraft/server/level/ServerPlayer.java +++ b/net/minecraft/server/level/ServerPlayer.java @@ -842,6 +842,15 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc @@ -75,7 +75,7 @@ index 0c184da09628c0f2fd21e4cacd3ab6ae74f11e64..e569a1e0c282e43410ad321790114acc if ((target instanceof Bucketable && target instanceof LivingEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET) && (event.isCancelled() || ServerGamePacketListenerImpl.this.player.getInventory().getSelected() == null || ServerGamePacketListenerImpl.this.player.getInventory().getSelected().getItem() != origItem)) { target.resendPossiblyDesyncedEntityData(ServerGamePacketListenerImpl.this.player); // Paper - The entire mob gets deleted, so resend it diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index f7e17ca9f5011503827f7141d62e556c1cc72fcf..25adb04858ad55dc80a2967e49b3dc0dafe44307 100644 +index 0c88c51f870030812fabbe4239bca2bb815fea92..cf3b9cbe7658d85fee387ede1c27fbd71d940631 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -3136,6 +3136,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -107,7 +107,7 @@ index f7e17ca9f5011503827f7141d62e556c1cc72fcf..25adb04858ad55dc80a2967e49b3dc0d if (this.passengers.size() == 1 && this.passengers.get(0) == passenger) { this.passengers = ImmutableList.of(); } else { -@@ -5097,4 +5112,44 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess +@@ -5100,4 +5115,44 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess return ((ServerLevel) this.level).isPositionEntityTicking(this.blockPosition()); } // Paper end - Expose entity id counter @@ -5040,7 +5040,7 @@ index 47c1ad2ef30d464abb3c804260f0fd7cde193ba5..c6b3894fe085c2b565651ab3ae2f1acb this.openTradingScreen(player, this.getDisplayName(), 1); } diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java -index 7305ef5af0b13cb40b9a881a0364895395ff2072..27a0cb04dd50974a96ed420ef811d9c9f3182e52 100644 +index 6e84f57c90c0747403c4679bc920f9a9aa83594f..fa258b6a1795d18a053843e93349dbf9aadf7e77 100644 --- a/net/minecraft/world/entity/player/Player.java +++ b/net/minecraft/world/entity/player/Player.java @@ -218,6 +218,19 @@ public abstract class Player extends LivingEntity { diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/server/level/ServerPlayer.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/server/level/ServerPlayer.java.patch index a95dac4ca..f95931c25 100644 --- a/purpur-server/minecraft-patches/sources/net/minecraft/server/level/ServerPlayer.java.patch +++ b/purpur-server/minecraft-patches/sources/net/minecraft/server/level/ServerPlayer.java.patch @@ -40,6 +40,14 @@ Entity entity = damageSource.getEntity(); if (!( // Paper - split the if statement. If below statement is false, hurtServer would not have been evaluated. Return false. !(entity instanceof Player player && !this.canHarmPlayer(player)) +@@ -1446,6 +_,7 @@ + serverLevel.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION); + this.unsetRemoved(); + // CraftBukkit end ++ this.portalPos = io.papermc.paper.util.MCUtil.toBlockPosition(exit); // Purpur - Fix stuck in portals + this.setServerLevel(level); + this.connection.internalTeleport(PositionMoveRotation.of(teleportTransition), teleportTransition.relatives()); // CraftBukkit - use internal teleport without event + this.connection.resetPosition(); @@ -2014,6 +_,26 @@ this.lastSentExp = -1; // CraftBukkit - Added to reset } diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/entity/Entity.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/entity/Entity.java.patch index 82987a93b..8bcfd1adb 100644 --- a/purpur-server/minecraft-patches/sources/net/minecraft/world/entity/Entity.java.patch +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/entity/Entity.java.patch @@ -47,15 +47,26 @@ // CraftBukkit start - fire PlayerUnleashEntityEvent // Paper start - Expand EntityUnleashEvent org.bukkit.event.player.PlayerUnleashEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerUnleashEntityEvent(this, player, hand, !player.hasInfiniteMaterials()); -@@ -3250,7 +_,7 @@ +@@ -3247,15 +_,18 @@ + return Vec3.directionFromRotation(this.getRotationVector()); + } + ++ public BlockPos portalPos = BlockPos.ZERO; // Purpur - Fix stuck in portals public void setAsInsidePortal(Portal portal, BlockPos pos) { if (this.isOnPortalCooldown()) { ++ if (!(level().purpurConfig.playerFixStuckPortal && this instanceof Player && !pos.equals(this.portalPos))) // Purpur - Fix stuck in portals this.setPortalCooldown(); - } else { + } else if (this.level.purpurConfig.entitiesCanUsePortals || this instanceof ServerPlayer) { // Purpur - Entities can use portals if (this.portalProcess == null || !this.portalProcess.isSamePortal(portal)) { this.portalProcess = new PortalProcessor(portal, pos.immutable()); } else if (!this.portalProcess.isInsidePortalThisTick()) { + this.portalProcess.updateEntryPosition(pos.immutable()); + this.portalProcess.setAsInsidePortalThisTick(true); ++ this.portalPos = BlockPos.ZERO; // Purpur - Fix stuck in portals + } + } + } @@ -3955,7 +_,7 @@ // CraftBukkit end diff --git a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java index d14a86d55..ac087a070 100644 --- a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java +++ b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java @@ -319,6 +319,7 @@ public class PurpurWorldConfig { public int playerDeathExpDropMax = 100; public boolean teleportIfOutsideBorder = false; public boolean totemOfUndyingWorksInInventory = false; + public boolean playerFixStuckPortal = false; private void playerSettings() { if (PurpurConfig.version < 19) { boolean oldVal = getBoolean("gameplay-mechanics.player.idle-timeout.mods-target", idleTimeoutTargetPlayer); @@ -334,6 +335,7 @@ public class PurpurWorldConfig { playerDeathExpDropMax = getInt("gameplay-mechanics.player.exp-dropped-on-death.maximum", playerDeathExpDropMax); teleportIfOutsideBorder = getBoolean("gameplay-mechanics.player.teleport-if-outside-border", teleportIfOutsideBorder); totemOfUndyingWorksInInventory = getBoolean("gameplay-mechanics.player.totem-of-undying-works-in-inventory", totemOfUndyingWorksInInventory); + playerFixStuckPortal = getBoolean("gameplay-mechanics.player.fix-stuck-in-portal", playerFixStuckPortal); } public boolean silkTouchEnabled = false;