fix EntityPortalExitEvent handling

This commit is contained in:
Lulu13022002
2025-06-14 17:22:24 +02:00
parent 6fbb3846d7
commit dac59acac9
3 changed files with 23 additions and 14 deletions

View File

@@ -28633,7 +28633,7 @@ index 8cc5c0716392ba06501542ff5cbe71ee43979e5d..09fd99c9cbd23b5f3c899bfb00c9b896
+ // Paper end - block counting + // Paper end - block counting
} }
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 01f7ceeb2966e0801f8e18572733d46f9dbdbc18..1b21bf733f7fc1b626844c488d4b93a792438762 100644 index bd962b2a0f381ddc1c7251162531bdecf3c2706b..9344cdbad8415f6ff4d592d3f13390e85477a10d 100644
--- a/net/minecraft/world/entity/Entity.java --- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java
@@ -147,7 +147,7 @@ import net.minecraft.world.waypoints.WaypointTransmitter; @@ -147,7 +147,7 @@ import net.minecraft.world.waypoints.WaypointTransmitter;
@@ -29108,7 +29108,7 @@ index 01f7ceeb2966e0801f8e18572733d46f9dbdbc18..1b21bf733f7fc1b626844c488d4b93a7
} }
public InteractionResult interact(Player player, InteractionHand hand) { public InteractionResult interact(Player player, InteractionHand hand) {
@@ -4282,15 +4519,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -4291,15 +4528,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
} }
public Iterable<Entity> getIndirectPassengers() { public Iterable<Entity> getIndirectPassengers() {
@@ -29134,7 +29134,7 @@ index 01f7ceeb2966e0801f8e18572733d46f9dbdbc18..1b21bf733f7fc1b626844c488d4b93a7
} }
public int countPlayerPassengers() { public int countPlayerPassengers() {
@@ -4433,77 +4672,136 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -4442,77 +4681,136 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return Mth.lerp(partialTick, this.yRotO, this.yRot); return Mth.lerp(partialTick, this.yRotO, this.yRot);
} }
@@ -29325,7 +29325,7 @@ index 01f7ceeb2966e0801f8e18572733d46f9dbdbc18..1b21bf733f7fc1b626844c488d4b93a7
public boolean touchingUnloadedChunk() { public boolean touchingUnloadedChunk() {
AABB aabb = this.getBoundingBox().inflate(1.0); AABB aabb = this.getBoundingBox().inflate(1.0);
@@ -4658,6 +4956,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -4667,6 +4965,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
} }
public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) { public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
@@ -29341,7 +29341,7 @@ index 01f7ceeb2966e0801f8e18572733d46f9dbdbc18..1b21bf733f7fc1b626844c488d4b93a7
if (!checkPosition(this, x, y, z)) { if (!checkPosition(this, x, y, z)) {
return; return;
} }
@@ -4814,6 +5121,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -4823,6 +5130,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@Override @Override
public final void setRemoved(Entity.RemovalReason removalReason, @Nullable org.bukkit.event.entity.EntityRemoveEvent.Cause cause) { // CraftBukkit - add Bukkit remove cause public final void setRemoved(Entity.RemovalReason removalReason, @Nullable org.bukkit.event.entity.EntityRemoveEvent.Cause cause) { // CraftBukkit - add Bukkit remove cause
@@ -29354,7 +29354,7 @@ index 01f7ceeb2966e0801f8e18572733d46f9dbdbc18..1b21bf733f7fc1b626844c488d4b93a7
org.bukkit.craftbukkit.event.CraftEventFactory.callEntityRemoveEvent(this, cause); // CraftBukkit org.bukkit.craftbukkit.event.CraftEventFactory.callEntityRemoveEvent(this, cause); // CraftBukkit
final boolean alreadyRemoved = this.removalReason != null; // Paper - Folia schedulers final boolean alreadyRemoved = this.removalReason != null; // Paper - Folia schedulers
if (this.removalReason == null) { if (this.removalReason == null) {
@@ -4824,7 +5137,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -4833,7 +5146,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.stopRiding(); this.stopRiding();
} }
@@ -29363,7 +29363,7 @@ index 01f7ceeb2966e0801f8e18572733d46f9dbdbc18..1b21bf733f7fc1b626844c488d4b93a7
this.levelCallback.onRemove(removalReason); this.levelCallback.onRemove(removalReason);
this.onRemoval(removalReason); this.onRemoval(removalReason);
// Paper start - Folia schedulers // Paper start - Folia schedulers
@@ -4858,7 +5171,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -4867,7 +5180,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public boolean shouldBeSaved() { public boolean shouldBeSaved() {
return (this.removalReason == null || this.removalReason.shouldSave()) return (this.removalReason == null || this.removalReason.shouldSave())
&& !this.isPassenger() && !this.isPassenger()

View File

@@ -1473,7 +1473,7 @@
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(this.problemPath(), LOGGER)) { try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(this.problemPath(), LOGGER)) {
TagValueOutput tagValueOutput = TagValueOutput.createWithContext(scopedCollector, entity.registryAccess()); TagValueOutput tagValueOutput = TagValueOutput.createWithContext(scopedCollector, entity.registryAccess());
entity.saveWithoutId(tagValueOutput); entity.saveWithoutId(tagValueOutput);
@@ -2864,7 +_,56 @@ @@ -2864,7 +_,65 @@
@Nullable @Nullable
public Entity teleport(TeleportTransition teleportTransition) { public Entity teleport(TeleportTransition teleportTransition) {
@@ -1507,18 +1507,27 @@
+ velocity = Vec3.ZERO; + velocity = Vec3.ZERO;
+ } + }
+ if (this.portalProcess != null) { // if in a portal + if (this.portalProcess != null) { // if in a portal
+ org.bukkit.craftbukkit.entity.CraftEntity bukkitEntity = this.getBukkitEntity(); + org.bukkit.entity.Entity bukkitEntity = this.getBukkitEntity();
+ org.bukkit.util.Vector before = bukkitEntity.getVelocity();
+ org.bukkit.util.Vector after = org.bukkit.craftbukkit.util.CraftVector.toBukkit(velocity);
+ org.bukkit.event.entity.EntityPortalExitEvent event = new org.bukkit.event.entity.EntityPortalExitEvent( + org.bukkit.event.entity.EntityPortalExitEvent event = new org.bukkit.event.entity.EntityPortalExitEvent(
+ bukkitEntity, + bukkitEntity,
+ bukkitEntity.getLocation(), to.clone(), + bukkitEntity.getLocation(), to.clone(),
+ bukkitEntity.getVelocity(), org.bukkit.craftbukkit.util.CraftVector.toBukkit(velocity) + before, after
+ ); + );
+ event.callEvent(); + event.callEvent();
+ +
+ // Only change the target if actually needed, since we reset relative flags + // Only change the target if actually needed, since we reset relative flags
+ if (!event.isCancelled() && event.getTo() != null && (!event.getTo().equals(event.getFrom()) || !event.getAfter().equals(event.getBefore()))) { // todo this looks broken + if (event.isCancelled() || !to.equals(event.getTo()) || !after.equals(event.getAfter())) {
+ to = event.getTo().clone(); + if (event.isCancelled() || event.getTo() == null) {
+ velocity = org.bukkit.craftbukkit.util.CraftVector.toVec3(event.getAfter()); + org.bukkit.World toWorld = to.getWorld();
+ to = event.getFrom().clone();
+ to.setWorld(toWorld); // cancelling doesn't cancel the teleport just the position/velocity (old quirk)
+ velocity = org.bukkit.craftbukkit.util.CraftVector.toVec3(event.getBefore());
+ } else {
+ to = event.getTo().clone();
+ velocity = org.bukkit.craftbukkit.util.CraftVector.toVec3(event.getAfter());
+ }
+ teleportTransition = new TeleportTransition(((org.bukkit.craftbukkit.CraftWorld) to.getWorld()).getHandle(), org.bukkit.craftbukkit.util.CraftLocation.toVec3(to), velocity, to.getYaw(), to.getPitch(), teleportTransition.missingRespawnBlock(), teleportTransition.asPassenger(), Set.of(), teleportTransition.postTeleportTransition(), teleportTransition.cause()); + teleportTransition = new TeleportTransition(((org.bukkit.craftbukkit.CraftWorld) to.getWorld()).getHandle(), org.bukkit.craftbukkit.util.CraftLocation.toVec3(to), velocity, to.getYaw(), to.getPitch(), teleportTransition.missingRespawnBlock(), teleportTransition.asPassenger(), Set.of(), teleportTransition.postTeleportTransition(), teleportTransition.cause());
+ } + }
+ } + }

View File

@@ -81,7 +81,7 @@ public class BlockStateListPopulator extends DummyGeneratorAccess {
return false; return false;
} }
this.setBlock(pos, blockState.getFluidState().createLegacyBlock(), 3, recursionLeft); // capture the block without the event during the capture this.setBlock(pos, blockState.getFluidState().createLegacyBlock(), 3, recursionLeft); // capture block without the event
return true; return true;
} }