Try and prevent cloned players from polluting the environment

This commit is contained in:
Sollace 2023-09-02 16:39:43 +01:00
parent 3a18054752
commit 806538858e
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB

View file

@ -1,6 +1,7 @@
package com.minelittlepony.unicopia.ability.magic.spell.effect; package com.minelittlepony.unicopia.ability.magic.spell.effect;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
@ -15,6 +16,7 @@ import com.minelittlepony.unicopia.entity.behaviour.Inventory;
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
import com.minelittlepony.unicopia.projectile.ProjectileDelegate; import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
import net.fabricmc.fabric.api.entity.FakePlayer;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
@ -180,6 +182,9 @@ public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.Enti
final GameMode aMode = a.interactionManager.getGameMode(); final GameMode aMode = a.interactionManager.getGameMode();
final GameMode bMode = b.interactionManager.getGameMode(); final GameMode bMode = b.interactionManager.getGameMode();
final UUID aUUid = a.getUuid();
final UUID bUUid = b.getUuid();
final ServerPlayerEntity aClone = clonePlayer(a); final ServerPlayerEntity aClone = clonePlayer(a);
final ServerPlayerEntity bClone = clonePlayer(b); final ServerPlayerEntity bClone = clonePlayer(b);
@ -189,6 +194,9 @@ public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.Enti
a.copyFrom(bClone, true); a.copyFrom(bClone, true);
b.copyFrom(aClone, true); b.copyFrom(aClone, true);
a.setUuid(aUUid);
b.setUuid(bUUid);
a.interactionManager.changeGameMode(aMode); a.interactionManager.changeGameMode(aMode);
b.interactionManager.changeGameMode(bMode); b.interactionManager.changeGameMode(bMode);
@ -208,11 +216,16 @@ public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.Enti
} }
private static ServerPlayerEntity clonePlayer(ServerPlayerEntity player) { private static ServerPlayerEntity clonePlayer(ServerPlayerEntity player) {
ServerPlayerEntity clone = new ServerPlayerEntity(player.getServer(), player.getServerWorld(), player.getGameProfile()) { ServerPlayerEntity clone = new FakePlayer(player.getServerWorld(), player.getGameProfile()) {
@Override @Override
public void tick() { public void tick() {
discard(); discard();
} }
@Override
public void setUuid(UUID uuid) {
super.setUuid(UUID.randomUUID());
}
}; };
NbtCompound compound = player.writeNbt(new NbtCompound()); NbtCompound compound = player.writeNbt(new NbtCompound());