Fix custom teleporters NPE (#7296)

This commit is contained in:
mrp-v2 2020-09-08 16:29:07 -04:00 committed by GitHub
parent 178e3d244a
commit e421ea164c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 6 deletions

View file

@ -218,7 +218,7 @@
} }
public boolean func_70028_i(Entity p_70028_1_) { public boolean func_70028_i(Entity p_70028_1_) {
@@ -2087,6 +2117,10 @@ @@ -2087,14 +2117,19 @@
@Nullable @Nullable
public Entity func_241206_a_(ServerWorld p_241206_1_) { public Entity func_241206_a_(ServerWorld p_241206_1_) {
@ -229,8 +229,11 @@
if (this.field_70170_p instanceof ServerWorld && !this.field_70128_L) { if (this.field_70170_p instanceof ServerWorld && !this.field_70128_L) {
this.field_70170_p.func_217381_Z().func_76320_a("changeDimension"); this.field_70170_p.func_217381_Z().func_76320_a("changeDimension");
this.func_213319_R(); this.func_213319_R();
@@ -2095,6 +2129,7 @@ this.field_70170_p.func_217381_Z().func_76320_a("reposition");
if (portalinfo == null) { - 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; return null;
} else { } else {
+ Entity transportedEntity = teleporter.placeEntity(this, (ServerWorld) this.field_70170_p, p_241206_1_, this.field_70177_z, spawnPortal -> { //Forge: Start vanilla logic + Entity transportedEntity = teleporter.placeEntity(this, (ServerWorld) this.field_70170_p, p_241206_1_, this.field_70177_z, spawnPortal -> { //Forge: Start vanilla logic

View file

@ -19,7 +19,7 @@
ServerWorld serverworld = this.func_71121_q(); ServerWorld serverworld = this.func_71121_q();
RegistryKey<World> registrykey = serverworld.func_234923_W_(); RegistryKey<World> 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_) {
+ 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_213319_R();
- this.func_71121_q().func_217434_e(this); - 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 + 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); playerlist.func_187243_f(this);
- serverworld.func_217434_e(this); - serverworld.func_217434_e(this);
- this.field_70128_L = false; - 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. + 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(); + this.revive();
PortalInfo portalinfo = this.func_241829_a(p_241206_1_); + PortalInfo portalinfo = teleporter.isVanilla() ? this.func_241829_a(p_241206_1_) : null;
if (portalinfo != null) { + if (portalinfo != null || !teleporter.isVanilla()) {
+ Entity e = teleporter.placeEntity(this, serverworld, p_241206_1_, this.field_70177_z, spawnPortal -> {//Forge: Start vanilla logic + 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"); serverworld.func_217381_Z().func_76320_a("moving");
if (registrykey == World.field_234918_g_ && p_241206_1_.func_234923_W_() == World.field_234919_h_) { if (registrykey == World.field_234918_g_ && p_241206_1_.func_234923_W_() == World.field_234919_h_) {

View file

@ -24,6 +24,7 @@ import java.util.function.Function;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.world.Teleporter;
import net.minecraft.world.server.ServerWorld; 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<Boolean, Entity> repositionEntity) { default Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
return repositionEntity.apply(true); return repositionEntity.apply(true);
} }
//used internally to handle vanilla hardcoding
default boolean isVanilla()
{
return getClass() == Teleporter.class;
}
} }