From e421ea164c28ea509218414062c1bba5637ee565 Mon Sep 17 00:00:00 2001 From: mrp-v2 Date: Tue, 8 Sep 2020 16:29:07 -0400 Subject: [PATCH] Fix custom teleporters NPE (#7296) --- patches/minecraft/net/minecraft/entity/Entity.java.patch | 9 ++++++--- .../entity/player/ServerPlayerEntity.java.patch | 8 +++++--- .../java/net/minecraftforge/common/util/ITeleporter.java | 7 +++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/patches/minecraft/net/minecraft/entity/Entity.java.patch b/patches/minecraft/net/minecraft/entity/Entity.java.patch index e276212b1..e25026ffc 100644 --- a/patches/minecraft/net/minecraft/entity/Entity.java.patch +++ b/patches/minecraft/net/minecraft/entity/Entity.java.patch @@ -218,7 +218,7 @@ } public boolean func_70028_i(Entity p_70028_1_) { -@@ -2087,6 +2117,10 @@ +@@ -2087,14 +2117,19 @@ @Nullable public Entity func_241206_a_(ServerWorld p_241206_1_) { @@ -229,8 +229,11 @@ if (this.field_70170_p instanceof ServerWorld && !this.field_70128_L) { this.field_70170_p.func_217381_Z().func_76320_a("changeDimension"); this.func_213319_R(); -@@ -2095,6 +2129,7 @@ - if (portalinfo == null) { + this.field_70170_p.func_217381_Z().func_76320_a("reposition"); +- PortalInfo portalinfo = this.func_241829_a(p_241206_1_); +- if (portalinfo == null) { ++ PortalInfo portalinfo = teleporter.isVanilla() ? this.func_241829_a(p_241206_1_) : null; ++ if (portalinfo == null && teleporter.isVanilla()) { return null; } else { + Entity transportedEntity = teleporter.placeEntity(this, (ServerWorld) this.field_70170_p, p_241206_1_, this.field_70177_z, spawnPortal -> { //Forge: Start vanilla logic diff --git a/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch b/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch index fd9b254cf..f34d1abf2 100644 --- a/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch +++ b/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch @@ -19,7 +19,7 @@ ServerWorld serverworld = this.func_71121_q(); RegistryKey registrykey = serverworld.func_234923_W_(); - if (registrykey == World.field_234920_i_ && p_241206_1_.func_234923_W_() == World.field_234918_g_) { -+ if (registrykey == World.field_234920_i_ && p_241206_1_.func_234923_W_() == World.field_234918_g_ && teleporter instanceof net.minecraft.world.Teleporter) { //Forge: Fix non-vanilla teleporters triggering end credits ++ if (registrykey == World.field_234920_i_ && p_241206_1_.func_234923_W_() == World.field_234918_g_ && teleporter.isVanilla()) { //Forge: Fix non-vanilla teleporters triggering end credits this.func_213319_R(); - this.func_71121_q().func_217434_e(this); + this.func_71121_q().removePlayer(this, true); //Forge: The player entity is cloned so keep the data until after cloning calls copyFrom @@ -32,10 +32,12 @@ playerlist.func_187243_f(this); - serverworld.func_217434_e(this); - this.field_70128_L = false; +- PortalInfo portalinfo = this.func_241829_a(p_241206_1_); +- if (portalinfo != null) { + serverworld.removeEntity(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 = this.func_241829_a(p_241206_1_); - if (portalinfo != null) { ++ PortalInfo portalinfo = teleporter.isVanilla() ? this.func_241829_a(p_241206_1_) : null; ++ if (portalinfo != null || !teleporter.isVanilla()) { + Entity e = teleporter.placeEntity(this, serverworld, p_241206_1_, this.field_70177_z, spawnPortal -> {//Forge: Start vanilla logic serverworld.func_217381_Z().func_76320_a("moving"); if (registrykey == World.field_234918_g_ && p_241206_1_.func_234923_W_() == World.field_234919_h_) { diff --git a/src/main/java/net/minecraftforge/common/util/ITeleporter.java b/src/main/java/net/minecraftforge/common/util/ITeleporter.java index a4b7be108..63096ada4 100644 --- a/src/main/java/net/minecraftforge/common/util/ITeleporter.java +++ b/src/main/java/net/minecraftforge/common/util/ITeleporter.java @@ -24,6 +24,7 @@ import java.util.function.Function; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.world.Teleporter; import net.minecraft.world.server.ServerWorld; /** @@ -57,4 +58,10 @@ public interface ITeleporter { default Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function repositionEntity) { return repositionEntity.apply(true); } + + //used internally to handle vanilla hardcoding + default boolean isVanilla() + { + return getClass() == Teleporter.class; + } }