-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore vanilla teleportation logic for non-players
- Loading branch information
1 parent
f175193
commit 5a6ff9b
Showing
4 changed files
with
376 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Jake Potrebic <jake.m.potrebic@gmail.com> | ||
Date: Thu, 16 May 2024 11:14:16 -0700 | ||
Subject: [PATCH] fixup! More Teleport API | ||
|
||
|
||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java | ||
index a2d336ceb52b63db5c03432ee7bc94dc6a742b82..0f64e3e3ce1e932a8df6b27ab9bbfc2156f58f04 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java | ||
@@ -239,20 +239,21 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { | ||
location.checkFinite(); | ||
// Paper start - Teleport passenger API | ||
Set<io.papermc.paper.entity.TeleportFlag> flagSet = Set.of(flags); | ||
- boolean dismount = !flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_VEHICLE); | ||
- boolean ignorePassengers = flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS); | ||
- // Don't allow teleporting between worlds while keeping passengers | ||
- if (flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS) && this.entity.isVehicle() && location.getWorld() != this.getWorld()) { | ||
+ final boolean retainVehicle = flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_VEHICLE); | ||
+ final boolean retainPassengers = flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS); | ||
+ final boolean sameWorld = location.getWorld() == this.getWorld(); | ||
+ | ||
+ if (this.entity.isVehicle() && retainPassengers && !sameWorld) { | ||
+ // if target is a vehicle (has passengers) and RETAIN_PASSENGERS is specified and the tp is inter-world | ||
return false; | ||
} | ||
|
||
- // Don't allow to teleport between worlds if remaining on vehicle | ||
- if (!dismount && this.entity.isPassenger() && location.getWorld() != this.getWorld()) { | ||
- return false; | ||
+ if (this.entity.isPassenger() && retainVehicle) { | ||
+ return false; // You can't teleport a passenger and keep the vehicle | ||
} | ||
// Paper end | ||
|
||
- if ((!ignorePassengers && this.entity.isVehicle()) || this.entity.isRemoved()) { // Paper - Teleport passenger API | ||
+ if (this.entity.isRemoved()) { // Paper - Teleport passenger API (move vehicle check up a bit) | ||
return false; | ||
} | ||
|
||
@@ -268,7 +269,8 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { | ||
// Paper end | ||
|
||
// If this entity is riding another entity, we must dismount before teleporting. | ||
- if (dismount) this.entity.stopRiding(); // Paper - Teleport passenger API | ||
+ this.entity.stopRiding(); // Paper - Teleport passenger API - always stop riding; if RETAIN_VEHICLE was specified, it returned early above | ||
+ if (!retainPassengers) this.entity.ejectPassengers(); // Paper - Teleport passenger API | ||
|
||
// Let the server handle cross world teleports | ||
if (location.getWorld() != null && !location.getWorld().equals(this.getWorld())) { |
23 changes: 23 additions & 0 deletions
23
patches/server/1047-fixup-Add-EntityPortalReadyEvent.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Jake Potrebic <jake.m.potrebic@gmail.com> | ||
Date: Thu, 16 May 2024 11:35:16 -0700 | ||
Subject: [PATCH] fixup! Add EntityPortalReadyEvent | ||
|
||
|
||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java | ||
index 2bc85351e6e52f90da5fdb29d8d042a06132d742..e7e9c5995b854dfbeb2dfe788bf86ba3457c3086 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/Entity.java | ||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java | ||
@@ -3224,10 +3224,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess | ||
this.portalTime = i; | ||
// Paper start - Add EntityPortalReadyEvent | ||
io.papermc.paper.event.entity.EntityPortalReadyEvent event = new io.papermc.paper.event.entity.EntityPortalReadyEvent(this.getBukkitEntity(), worldserver1 == null ? null : worldserver1.getWorld(), org.bukkit.PortalType.NETHER); | ||
- if (!event.callEvent()) { | ||
+ if (!event.callEvent() || event.getTargetWorld() == null) { | ||
this.portalTime = 0; | ||
} else { | ||
- worldserver1 = event.getTargetWorld() == null ? null : ((CraftWorld) event.getTargetWorld()).getHandle(); | ||
+ worldserver1 = ((CraftWorld) event.getTargetWorld()).getHandle(); | ||
// Paper end - Add EntityPortalReadyEvent | ||
this.setPortalCooldown(); | ||
// CraftBukkit start |
Oops, something went wrong.