From f67d4c573913327408b7dee1d995e343010b1907 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Sat, 13 Feb 2021 17:08:51 +0800 Subject: [PATCH] Port teleport fix from 1.15 --- .../common/mixin/core/entity/EntityMixin.java | 18 ++++++++----- .../player/ServerPlayerEntityMixin.java | 27 ++++++++----------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/EntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/EntityMixin.java index fee7c3f3..e3bef12b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/EntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/EntityMixin.java @@ -458,7 +458,8 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, @Inject(method = "setPositionAndRotation", at = @At("RETURN")) private void arclight$loadChunk(double x, double y, double z, float yaw, float pitch, CallbackInfo ci) { - if (this.valid) this.world.getChunk((int) Math.floor(this.getPosX()) >> 4, (int) Math.floor(this.getPosZ()) >> 4); + if (this.valid) + this.world.getChunk((int) Math.floor(this.getPosX()) >> 4, (int) Math.floor(this.getPosZ()) >> 4); } public boolean canCollideWith(Entity entity) { @@ -828,12 +829,6 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, ArclightCaptures.captureEndPortalEntity((Entity) (Object) this, spawnPortal); ServerWorld.func_241121_a_(world); } - - this.getBukkitEntity().setHandle(entity); - ((EntityBridge) entity).bridge$setBukkitEntity(this.bridge$getBukkitEntity()); - if ((Object) this instanceof MobEntity) { - ((MobEntity) (Object) this).clearLeashed(true, false); - } } return entity; }); //Forge: End vanilla logic @@ -850,6 +845,15 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } } + @Inject(method = "copyDataFromOld", at = @At("HEAD")) + private void arclight$forwardHandle(Entity entityIn, CallbackInfo ci) { + ((InternalEntityBridge) entityIn).internal$getBukkitEntity().setHandle((Entity) (Object) this); + ((EntityBridge) this).bridge$setBukkitEntity(((InternalEntityBridge) entityIn).internal$getBukkitEntity()); + if (entityIn instanceof MobEntity) { + ((MobEntity) entityIn).clearLeashed(true, false); + } + } + /** * @author IzzelAliz * @reason diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java index f28c7099..1287559b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java @@ -75,7 +75,6 @@ import net.minecraft.util.text.event.HoverEvent; import net.minecraft.world.DimensionType; import net.minecraft.world.GameRules; import net.minecraft.world.GameType; -import net.minecraft.world.Teleporter; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeManager; import net.minecraft.world.server.ServerWorld; @@ -475,7 +474,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen // this.invulnerableDimensionChange = true; ServerWorld serverworld = this.getServerWorld(); RegistryKey registrykey = ((WorldBridge) serverworld).bridge$getTypeKey(); - if (registrykey == DimensionType.THE_END && ((WorldBridge) server).bridge$getTypeKey() == DimensionType.OVERWORLD && teleporter instanceof Teleporter) { //Forge: Fix non-vanilla teleporters triggering end credits + if (registrykey == DimensionType.THE_END && ((WorldBridge) server).bridge$getTypeKey() == DimensionType.OVERWORLD && teleporter.isVanilla()) { //Forge: Fix non-vanilla teleporters triggering end credits this.invulnerableDimensionChange = true; this.detach(); this.getServerWorld().removePlayer((ServerPlayerEntity) (Object) this, true); //Forge: The player entity is cloned so keep the data until after cloning calls copyFrom @@ -487,8 +486,6 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen return (ServerPlayerEntity) (Object) this; } else { - PlayerList playerlist = this.server.getPlayerList(); - /* IWorldInfo iworldinfo = server.getWorldInfo(); this.connection.sendPacket(new SRespawnPacket(server.getDimensionType(), server.getDimensionKey(), BiomeManager.getHashedSeed(server.getSeed()), this.interactionManager.getGameType(), this.interactionManager.func_241815_c_(), server.isDebug(), server.func_241109_A_(), true)); this.connection.sendPacket(new SServerDifficultyPacket(iworldinfo.getDifficulty(), iworldinfo.isDifficultyLocked())); @@ -496,7 +493,6 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen playerlist.updatePermissionLevel((ServerPlayerEntity) (Object) this); serverworld.removeEntity((ServerPlayerEntity) (Object) this, true); //Forge: the player entity is moved to the new world, NOT cloned. So keep the data alive with no matching invalidate call. this.revive(); - */ PortalInfo portalinfo = teleporter.getPortalInfo((ServerPlayerEntity) (Object) this, server, this::func_241829_a); ServerWorld[] exitWorld = new ServerWorld[]{server}; if (portalinfo != null) { @@ -520,18 +516,18 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen return null; } exit = tpEvent.getTo(); - exitWorld[0] = ((CraftWorld) exit.getWorld()).getHandle(); serverworld.getProfiler().endSection(); serverworld.getProfiler().startSection("placing"); this.invulnerableDimensionChange = true; - IWorldInfo iworldinfo = exitWorld[0].getWorldInfo(); - this.connection.sendPacket(new SRespawnPacket(exitWorld[0].getDimensionType(), exitWorld[0].getDimensionKey(), BiomeManager.getHashedSeed(exitWorld[0].getSeed()), this.interactionManager.getGameType(), this.interactionManager.func_241815_c_(), exitWorld[0].isDebug(), exitWorld[0].func_241109_A_(), true)); - this.connection.sendPacket(new SServerDifficultyPacket(iworldinfo.getDifficulty(), iworldinfo.isDifficultyLocked())); - playerlist.updatePermissionLevel((ServerPlayerEntity) (Object) this); - serverworld.removeEntity((ServerPlayerEntity) (Object) this, true); //Forge: the player entity is moved to the new world, NOT cloned. So keep the data alive with no matching invalidate call. - this.revive(); + ServerWorld newWorld = ((CraftWorld) exit.getWorld()).getHandle(); + if (newWorld != exitWorld[0]) { + exitWorld[0] = newWorld; + IWorldInfo newWorldInfo = exitWorld[0].getWorldInfo(); + this.connection.sendPacket(new SRespawnPacket(exitWorld[0].getDimensionType(), exitWorld[0].getDimensionKey(), BiomeManager.getHashedSeed(exitWorld[0].getSeed()), this.interactionManager.getGameType(), this.interactionManager.func_241815_c_(), exitWorld[0].isDebug(), exitWorld[0].func_241109_A_(), true)); + this.connection.sendPacket(new SServerDifficultyPacket(newWorldInfo.getDifficulty(), newWorldInfo.isDifficultyLocked())); + } this.setWorld(exitWorld[0]); exitWorld[0].addDuringPortalTeleport((ServerPlayerEntity) (Object) this); @@ -544,7 +540,8 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen return (ServerPlayerEntity) (Object) this;//forge: this is part of the ITeleporter patch });//Forge: End vanilla logic if (e == null) { - return null; + serverworld.addDuringPortalTeleport((ServerPlayerEntity) (Object) this); + return (ServerPlayerEntity) (Object) this; } else if (e != (Object) this) { throw new IllegalArgumentException(String.format("Teleporter %s returned not the player entity but instead %s, expected PlayerEntity %s", teleporter, e, this)); } @@ -565,8 +562,6 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen BasicEventHooks.firePlayerChangedDimensionEvent((ServerPlayerEntity) (Object) this, serverworld.getDimensionKey(), exitWorld[0].getDimensionKey()); PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.getBukkitEntity(), ((WorldBridge) serverworld).bridge$getWorld()); Bukkit.getPluginManager().callEvent(changeEvent); - } else { - return null; } return (ServerPlayerEntity) (Object) this; @@ -667,7 +662,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen if (container != null) { ((ContainerBridge) container).bridge$setTitle(itileinventory.getDisplayName()); boolean cancelled = false; - ArclightCaptures.captureContainerOwner((ServerPlayerEntity)(Object)this); + ArclightCaptures.captureContainerOwner((ServerPlayerEntity) (Object) this); container = CraftEventFactory.callInventoryOpenEvent((ServerPlayerEntity) (Object) this, container, cancelled); ArclightCaptures.resetContainerOwner(); if (container == null && !cancelled) {