Fixed crash when players have disguised as other players

This commit is contained in:
Sollace 2022-10-13 18:16:23 +02:00
parent 9f6826ee7d
commit 67a894958c
5 changed files with 13 additions and 55 deletions

View file

@ -8,7 +8,6 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.ability.magic.CasterView;
import com.minelittlepony.unicopia.block.data.Ether;
import com.minelittlepony.unicopia.entity.player.dummy.DummyPlayerEntity;
import com.minelittlepony.unicopia.entity.player.dummy.DummyServerPlayerEntity;
import com.minelittlepony.unicopia.network.handler.ClientNetworkHandler;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftSessionService;
@ -99,9 +98,6 @@ public class InteractionManager {
*/
@NotNull
public PlayerEntity createPlayer(World world, GameProfile profile) {
if (world instanceof ServerWorld) {
return new DummyServerPlayerEntity((ServerWorld)world, profile);
}
return new DummyPlayerEntity(world, profile);
}
}

View file

@ -78,6 +78,8 @@ public class MindSwapSpell extends MimicSpell {
if (counterpart.getId().isPresent() && counterpart.get(caster.getReferenceWorld()) == null) {
caster.getMaster().damage(DamageSource.MAGIC, Float.MAX_VALUE);
setDead();
return false;
}
}

View file

@ -194,8 +194,6 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi
return;
}
Caster.of(entity).ifPresent(c -> c.getSpellSlot().clear());
if (entity instanceof LivingEntity) {
((LivingEntity) entity).getAttributeInstance(UEntityAttributes.ENTITY_GRAVTY_MODIFIER).clearModifiers();
}
@ -343,9 +341,13 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi
}
entityNbt.putString("playerName", profile.getName());
entityNbt.putByte("playerVisibleParts", player.getDataTracker().get(Disguise.PlayerAccess.getModelBitFlag()));
entityNbt.put("playerNbt", player.writeNbt(new NbtCompound()));
NbtCompound playerNbt = player.writeNbt(new NbtCompound());
playerNbt.remove("unicopia_caster");
entityNbt.put("playerNbt", playerNbt);
} else {
entity.saveSelfNbt(entityNbt);
entityNbt.remove("unicopia_caster");
}
return entityNbt;

View file

@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.Owned;
import com.mojang.authlib.GameProfile;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
@ -24,6 +25,11 @@ public class DummyPlayerEntity extends PlayerEntity implements Owned<PlayerEntit
/*noop*/
}
@Override
protected void onBlockCollision(BlockState state) {
/*noop*/
}
@Override
@Nullable
public PlayerEntity getMaster() {

View file

@ -1,48 +0,0 @@
package com.minelittlepony.unicopia.entity.player.dummy;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.Owned;
import com.mojang.authlib.GameProfile;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
public class DummyServerPlayerEntity extends ServerPlayerEntity implements Owned<PlayerEntity> {
private PlayerEntity owner;
public DummyServerPlayerEntity(ServerWorld world, GameProfile profile) {
super(world.getServer(), world, profile, null);
}
@Override
protected void playEquipSound(ItemStack stack) {
/*noop*/
}
@Override
protected void onBlockCollision(BlockState state) {
/*noop*/
}
@Override
@Nullable
public PlayerEntity getMaster() {
return owner;
}
@Override
public void setMaster(PlayerEntity owner) {
this.owner = owner;
}
@Override
public boolean shouldRenderName() {
return !InteractionManager.instance().isClientPlayer(getMaster());
}
}