From 60fb93349f4a451bb592fd46cccae934367a12a1 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 2 Jul 2022 12:26:55 +1000 Subject: [PATCH] SPIGOT-1729, SPIGOT-7090: Keep precision in teleportation between worlds By: Doc --- .../net/minecraft/world/entity/Entity.patch | 78 +++++++++---------- .../craftbukkit/entity/CraftEntity.java | 7 +- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch b/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch index 48c9b30281..1c27b5f201 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch @@ -1,10 +1,11 @@ --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java -@@ -122,8 +122,64 @@ +@@ -122,8 +122,65 @@ import net.minecraft.world.scores.ScoreboardTeamBase; import org.slf4j.Logger; +// CraftBukkit start ++import net.minecraft.core.Position; +import net.minecraft.world.level.dimension.WorldDimension; +import org.bukkit.Bukkit; +import org.bukkit.Location; @@ -65,7 +66,7 @@ private static final Logger LOGGER = LogUtils.getLogger(); public static final String ID_TAG = "id"; public static final String PASSENGERS_TAG = "Passengers"; -@@ -234,6 +290,24 @@ +@@ -234,6 +291,24 @@ public boolean hasVisualFire; @Nullable private IBlockData feetBlockState; @@ -90,7 +91,7 @@ public Entity(EntityTypes entitytypes, World world) { this.id = Entity.ENTITY_COUNTER.incrementAndGet(); -@@ -365,6 +439,12 @@ +@@ -365,6 +440,12 @@ public void onClientRemoval() {} public void setPose(EntityPose entitypose) { @@ -103,7 +104,7 @@ this.entityData.set(Entity.DATA_POSE, entitypose); } -@@ -389,6 +469,33 @@ +@@ -389,6 +470,33 @@ } protected void setRot(float f, float f1) { @@ -137,7 +138,7 @@ this.setYRot(f % 360.0F); this.setXRot(f1 % 360.0F); } -@@ -430,6 +537,15 @@ +@@ -430,6 +538,15 @@ this.baseTick(); } @@ -153,7 +154,7 @@ public void baseTick() { this.level.getProfiler().push("entityBaseTick"); this.feetBlockState = null; -@@ -444,7 +560,7 @@ +@@ -444,7 +561,7 @@ this.walkDistO = this.walkDist; this.xRotO = this.getXRot(); this.yRotO = this.getYRot(); @@ -162,7 +163,7 @@ if (this.canSpawnSprintParticle()) { this.spawnSprintParticle(); } -@@ -479,6 +595,10 @@ +@@ -479,6 +596,10 @@ if (this.isInLava()) { this.lavaHurt(); this.fallDistance *= 0.5F; @@ -173,7 +174,7 @@ } this.checkOutOfWorld(); -@@ -522,15 +642,48 @@ +@@ -522,15 +643,48 @@ public void lavaHurt() { if (!this.fireImmune()) { @@ -223,7 +224,7 @@ int j = i * 20; if (this instanceof EntityLiving) { -@@ -644,6 +797,28 @@ +@@ -644,6 +798,28 @@ block.updateEntityAfterFallOn(this.level, this); } @@ -252,7 +253,7 @@ if (this.onGround) { block.stepOn(this.level, blockposition, iblockdata, this); } -@@ -1295,6 +1470,7 @@ +@@ -1295,6 +1471,7 @@ this.yo = d1; this.zo = d4; this.setPos(d3, d1, d4); @@ -260,7 +261,7 @@ } public void moveTo(Vec3D vec3d) { -@@ -1485,6 +1661,12 @@ +@@ -1485,6 +1662,12 @@ return false; } @@ -273,7 +274,7 @@ public void awardKillScore(Entity entity, int i, DamageSource damagesource) { if (entity instanceof EntityPlayer) { CriterionTriggers.ENTITY_KILLED_PLAYER.trigger((EntityPlayer) entity, this, damagesource); -@@ -1518,7 +1700,7 @@ +@@ -1518,7 +1701,7 @@ } else { String s = this.getEncodeId(); @@ -282,7 +283,7 @@ return false; } else { nbttagcompound.putString("id", s); -@@ -1543,6 +1725,18 @@ +@@ -1543,6 +1726,18 @@ Vec3D vec3d = this.getDeltaMovement(); nbttagcompound.put("Motion", this.newDoubleList(vec3d.x, vec3d.y, vec3d.z)); @@ -301,7 +302,7 @@ nbttagcompound.put("Rotation", this.newFloatList(this.getYRot(), this.getXRot())); nbttagcompound.putFloat("FallDistance", this.fallDistance); nbttagcompound.putShort("Fire", (short) this.remainingFireTicks); -@@ -1551,6 +1745,22 @@ +@@ -1551,6 +1746,22 @@ nbttagcompound.putBoolean("Invulnerable", this.invulnerable); nbttagcompound.putInt("PortalCooldown", this.portalCooldown); nbttagcompound.putUUID("UUID", this.getUUID()); @@ -324,7 +325,7 @@ IChatBaseComponent ichatbasecomponent = this.getCustomName(); if (ichatbasecomponent != null) { -@@ -1618,6 +1828,11 @@ +@@ -1618,6 +1829,11 @@ } } @@ -336,7 +337,7 @@ return nbttagcompound; } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT"); -@@ -1699,6 +1914,44 @@ +@@ -1699,6 +1915,44 @@ } else { throw new IllegalStateException("Entity has invalid position"); } @@ -381,7 +382,7 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT"); CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Entity being loaded"); -@@ -1774,9 +2027,22 @@ +@@ -1774,9 +2028,22 @@ } else if (this.level.isClientSide) { return null; } else { @@ -404,7 +405,7 @@ this.level.addFreshEntity(entityitem); return entityitem; } -@@ -1870,7 +2136,7 @@ +@@ -1870,7 +2137,7 @@ this.setPose(EntityPose.STANDING); this.vehicle = entity; @@ -413,7 +414,7 @@ entity.getIndirectPassengersStream().filter((entity2) -> { return entity2 instanceof EntityPlayer; }).forEach((entity2) -> { -@@ -1901,7 +2167,7 @@ +@@ -1901,7 +2168,7 @@ Entity entity = this.vehicle; this.vehicle = null; @@ -422,7 +423,7 @@ } } -@@ -1910,10 +2176,31 @@ +@@ -1910,10 +2177,31 @@ this.removeVehicle(); } @@ -455,7 +456,7 @@ if (this.passengers.isEmpty()) { this.passengers = ImmutableList.of(entity); } else { -@@ -1929,12 +2216,32 @@ +@@ -1929,12 +2217,32 @@ } } @@ -489,7 +490,7 @@ if (this.passengers.size() == 1 && this.passengers.get(0) == entity) { this.passengers = ImmutableList.of(); } else { -@@ -1945,6 +2252,7 @@ +@@ -1945,6 +2253,7 @@ entity.boardingCooldown = 60; } @@ -497,7 +498,7 @@ } protected boolean canAddPassenger(Entity entity) { -@@ -2007,14 +2315,20 @@ +@@ -2007,14 +2316,20 @@ if (this.isInsidePortal) { MinecraftServer minecraftserver = worldserver.getServer(); @@ -521,7 +522,7 @@ this.level.getProfiler().pop(); } -@@ -2132,6 +2446,13 @@ +@@ -2132,6 +2447,13 @@ } public void setSwimming(boolean flag) { @@ -535,7 +536,7 @@ this.setSharedFlag(4, flag); } -@@ -2177,8 +2498,12 @@ +@@ -2177,8 +2499,12 @@ return this.getTeam() != null ? this.getTeam().isAlliedTo(scoreboardteambase) : false; } @@ -549,7 +550,7 @@ } public boolean getSharedFlag(int i) { -@@ -2197,7 +2522,7 @@ +@@ -2197,7 +2523,7 @@ } public int getMaxAirSupply() { @@ -558,7 +559,7 @@ } public int getAirSupply() { -@@ -2205,7 +2530,18 @@ +@@ -2205,7 +2531,18 @@ } public void setAirSupply(int i) { @@ -578,7 +579,7 @@ } public int getTicksFrozen() { -@@ -2232,11 +2568,41 @@ +@@ -2232,11 +2569,41 @@ public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) { this.setRemainingFireTicks(this.remainingFireTicks + 1); @@ -622,7 +623,7 @@ } public void onAboveBubbleCol(boolean flag) { -@@ -2394,15 +2760,38 @@ +@@ -2394,15 +2761,38 @@ @Nullable public Entity changeDimension(WorldServer worldserver) { @@ -631,7 +632,7 @@ + } + + @Nullable -+ public Entity teleportTo(WorldServer worldserver, BlockPosition location) { ++ public Entity teleportTo(WorldServer worldserver, Position location) { + // CraftBukkit end if (this.level instanceof WorldServer && !this.isRemoved()) { this.level.getProfiler().push("changeDimension"); @@ -644,7 +645,7 @@ + // CraftBukkit end this.level.getProfiler().push("reposition"); - ShapeDetectorShape shapedetectorshape = this.findDimensionEntryPoint(worldserver); -+ ShapeDetectorShape shapedetectorshape = (location == null) ? this.findDimensionEntryPoint(worldserver) : new ShapeDetectorShape(new Vec3D(location.getX(), location.getY(), location.getZ()), Vec3D.ZERO, this.yRot, this.xRot, worldserver, null); // CraftBukkit ++ ShapeDetectorShape shapedetectorshape = (location == null) ? this.findDimensionEntryPoint(worldserver) : new ShapeDetectorShape(new Vec3D(location.x(), location.y(), location.z()), Vec3D.ZERO, this.yRot, this.xRot, worldserver, null); // CraftBukkit if (shapedetectorshape == null) { return null; @@ -663,7 +664,7 @@ this.level.getProfiler().popPush("reloading"); Entity entity = this.getType().create(worldserver); -@@ -2411,9 +2800,17 @@ +@@ -2411,9 +2801,17 @@ entity.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, entity.getXRot()); entity.setDeltaMovement(shapedetectorshape.speed); worldserver.addDuringTeleport(entity); @@ -683,7 +684,7 @@ } this.removeAfterChangingDimensions(); -@@ -2434,20 +2831,34 @@ +@@ -2434,20 +2832,34 @@ @Nullable protected ShapeDetectorShape findDimensionEntryPoint(WorldServer worldserver) { @@ -723,30 +724,29 @@ IBlockData iblockdata = this.level.getBlockState(this.portalEntrancePos); EnumDirection.EnumAxis enumdirection_enumaxis; Vec3D vec3d; -@@ -2464,8 +2875,8 @@ +@@ -2464,8 +2876,8 @@ vec3d = new Vec3D(0.5D, 0.0D, 0.0D); } - return BlockPortalShape.createPortalInfo(worldserver, blockutil_rectangle, enumdirection_enumaxis, vec3d, this.getDimensions(this.getPose()), this.getDeltaMovement(), this.getYRot(), this.getXRot()); - }).orElse((Object) null); + return BlockPortalShape.createPortalInfo(worldserverFinal, blockutil_rectangle, enumdirection_enumaxis, vec3d, this.getDimensions(this.getPose()), this.getDeltaMovement(), this.getYRot(), this.getXRot(), event); // CraftBukkit -+ }).orElse(null); // CraftBuukkit - decompile error ++ }).orElse(null); // CraftBukkit - decompile error } } else { BlockPosition blockposition1; -@@ -2475,8 +2886,15 @@ +@@ -2475,8 +2887,14 @@ } else { blockposition1 = worldserver.getHeightmapPos(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver.getSharedSpawnPos()); } + // CraftBukkit start -+ CraftPortalEvent event = callPortalEvent(this, worldserver, blockposition1, PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0); ++ CraftPortalEvent event = callPortalEvent(this, worldserver, blockposition1.offset(0.5D, 0, 0.5D), PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0); + if (event == null) { + return null; + } -+ blockposition1 = new BlockPosition(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()); - return new ShapeDetectorShape(new Vec3D((double) blockposition1.getX() + 0.5D, (double) blockposition1.getY(), (double) blockposition1.getZ() + 0.5D), this.getDeltaMovement(), this.getYRot(), this.getXRot()); -+ return new ShapeDetectorShape(new Vec3D((double) blockposition1.getX() + 0.5D, (double) blockposition1.getY(), (double) blockposition1.getZ() + 0.5D), this.getDeltaMovement(), this.getYRot(), this.getXRot(), ((CraftWorld) event.getTo().getWorld()).getHandle(), event); ++ return new ShapeDetectorShape(new Vec3D(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()), this.getDeltaMovement(), this.getYRot(), this.getXRot(), ((CraftWorld) event.getTo().getWorld()).getHandle(), event); + // CraftBukkit end } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 6589e7b62c..4606c8d439 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Set; import java.util.UUID; import net.minecraft.core.BlockPosition; +import net.minecraft.core.Position; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.chat.IChatBaseComponent; @@ -508,7 +509,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { @Override public boolean teleport(Location location, TeleportCause cause) { - Preconditions.checkArgument(location != null, "location"); + Preconditions.checkArgument(location != null, "location cannot be null"); location.checkFinite(); if (entity.isVehicle() || entity.isRemoved()) { @@ -519,10 +520,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { entity.stopRiding(); // Let the server handle cross world teleports - if (!location.getWorld().equals(getWorld())) { + if (location.getWorld() != null && !location.getWorld().equals(getWorld())) { // Prevent teleportation to an other world during world generation Preconditions.checkState(!entity.generation, "Cannot teleport entity to an other world during world generation"); - entity.teleportTo(((CraftWorld) location.getWorld()).getHandle(), new BlockPosition(location.getX(), location.getY(), location.getZ())); + entity.teleportTo(((CraftWorld) location.getWorld()).getHandle(), new Position(location.getX(), location.getY(), location.getZ())); return true; }