Skip to content

Commit

Permalink
Fix EndPortal teleport entity's delta movement (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jan 2, 2025
1 parent b723a7f commit 41476d8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
44 changes: 44 additions & 0 deletions patches/server/0129-Fix-EntityPortalExitEvent-logic.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Thu, 2 Jan 2025 22:01:17 +0800
Subject: [PATCH] Fix EntityPortalExitEvent logic


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 58906cda0432dc8d5988f83f19a5f2deac094566..bfbb894f73251ec241451bee831ebf7973cb4293 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3962,19 +3962,29 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
if (this.portalProcess != null) { // if in a portal
CraftEntity bukkitEntity = this.getBukkitEntity();
+ org.bukkit.util.Vector after = org.bukkit.craftbukkit.util.CraftVector.toBukkit(velocity); // Leaves - fix
org.bukkit.event.entity.EntityPortalExitEvent event = new org.bukkit.event.entity.EntityPortalExitEvent(
bukkitEntity,
bukkitEntity.getLocation(), to.clone(),
- bukkitEntity.getVelocity(), org.bukkit.craftbukkit.util.CraftVector.toBukkit(velocity)
+ bukkitEntity.getVelocity(), after // Leaves - fix
);
event.callEvent();

+ // Leaves start - fix
// 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()))) {
- to = event.getTo().clone();
- velocity = org.bukkit.craftbukkit.util.CraftVector.toNMS(event.getAfter());
+ if (event.isCancelled() || (!to.equals(event.getTo()) || !after.equals(event.getAfter()))) {
+ if (!event.isCancelled()) {
+ if (event.getTo() != null) {
+ to = event.getTo().clone();
+ }
+ velocity = org.bukkit.craftbukkit.util.CraftVector.toNMS(event.getAfter());
+ } else {
+ to = event.getFrom().clone();
+ velocity = Vec3.ZERO;
+ }
teleportTarget = new TeleportTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), velocity, to.getYaw(), to.getPitch(), teleportTarget.missingRespawnBlock(), teleportTarget.asPassenger(), Set.of(), teleportTarget.postTeleportTransition(), teleportTarget.cause());
}
+ // Leaves end - fix
}
if (this.isRemoved()) {
return null;
26 changes: 26 additions & 0 deletions patches/server/0130-Fix-CraftPortalEvent-logic.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Thu, 2 Jan 2025 22:01:36 +0800
Subject: [PATCH] Fix CraftPortalEvent logic


diff --git a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
index 4aa14f975e1ceedf3d4a427e0daefb58b12fcafe..90ef0c5f53741516f9d9d0c2fead3bbbb930f72a 100644
--- a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
@@ -124,13 +124,13 @@ public class EndPortalBlock extends BaseEntityBlock implements Portal {
}

// CraftBukkit start
- CraftPortalEvent event = entity.callPortalEvent(entity, CraftLocation.toBukkit(vec3d, worldserver1.getWorld(), f, entity.getXRot()), PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0);
+ CraftPortalEvent event = entity.callPortalEvent(entity, CraftLocation.toBukkit(vec3d, worldserver1.getWorld(), f, 0.0F), PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0); // Leaves - fix
if (event == null) {
return null;
}
Location to = event.getTo();

- return new TeleportTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), entity.getDeltaMovement(), to.getYaw(), to.getPitch(), set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET), PlayerTeleportEvent.TeleportCause.END_PORTAL);
+ return new TeleportTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), Vec3.ZERO, to.getYaw(), to.getPitch(), set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET), PlayerTeleportEvent.TeleportCause.END_PORTAL); // Leaves - fix
// CraftBukkit end
}
}

0 comments on commit 41476d8

Please sign in to comment.