Fixed players data being lost when you respawn

This commit is contained in:
Sollace 2020-05-29 20:13:10 +02:00
parent 22c430750c
commit 848f6ef66d
6 changed files with 50 additions and 4 deletions

View file

@ -1,5 +1,7 @@
package com.minelittlepony.unicopia.entity;
import com.minelittlepony.unicopia.util.Copieable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
@ -13,7 +15,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
public class EntityPhysics<T extends Ponylike<?> & Owned<? extends Entity>> implements Physics {
public class EntityPhysics<T extends Ponylike<?> & Owned<? extends Entity>> implements Physics, Copieable<EntityPhysics<T>> {
private float gravity = 1;
@ -84,6 +86,11 @@ public class EntityPhysics<T extends Ponylike<?> & Owned<? extends Entity>> impl
return gravity;
}
@Override
public void copyFrom(EntityPhysics<T> other) {
gravity = other.gravity;
}
@Override
public void toNBT(CompoundTag compound) {
if (gravity != 0) {

View file

@ -5,12 +5,13 @@ import java.util.Map;
import com.minelittlepony.unicopia.enchanting.PageOwner;
import com.minelittlepony.unicopia.enchanting.PageState;
import com.minelittlepony.unicopia.util.Copieable;
import com.minelittlepony.unicopia.util.NbtSerialisable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
public class PlayerPageStats implements NbtSerialisable, PageOwner {
public class PlayerPageStats implements NbtSerialisable, Copieable<PlayerPageStats>, PageOwner {
private final Map<Identifier, PageState> pageStates = new HashMap<>();
private final Pony pony;
@ -29,6 +30,12 @@ public class PlayerPageStats implements NbtSerialisable, PageOwner {
pony.sendCapabilities(full);
}
@Override
public void copyFrom(PlayerPageStats other) {
pageStates.clear();
pageStates.putAll(other.pageStates);
}
@Override
public void toNBT(CompoundTag compound) {
if (!pageStates.isEmpty()) {
@ -63,5 +70,4 @@ public class PlayerPageStats implements NbtSerialisable, PageOwner {
});
}
}
}

View file

@ -24,6 +24,7 @@ import com.minelittlepony.unicopia.network.MsgPlayerCapabilities;
import com.minelittlepony.unicopia.network.Transmittable;
import com.minelittlepony.unicopia.toxin.Toxicity;
import com.minelittlepony.unicopia.toxin.Toxin;
import com.minelittlepony.unicopia.util.Copieable;
import com.minelittlepony.util.BasicEasingInterpolator;
import com.minelittlepony.util.IInterpolator;
import com.mojang.authlib.GameProfile;
@ -47,7 +48,7 @@ import net.minecraft.util.Unit;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
public class Pony implements Caster<PlayerEntity>, Ponylike<PlayerEntity>, Transmittable {
public class Pony implements Caster<PlayerEntity>, Ponylike<PlayerEntity>, Transmittable, Copieable<Pony> {
private static final TrackedData<Integer> RACE = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER);
static final TrackedData<Float> ENERGY = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
@ -363,9 +364,11 @@ public class Pony implements Caster<PlayerEntity>, Ponylike<PlayerEntity>, Trans
pageStates.fromNBT(compound);
}
@Override
public void copyFrom(Pony oldPlayer) {
setSpell(oldPlayer.getSpell());
setSpecies(oldPlayer.getSpecies());
pageStates.copyFrom(oldPlayer.pageStates);
setDirty();
}

View file

@ -0,0 +1,24 @@
package com.minelittlepony.unicopia.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.minelittlepony.unicopia.ducks.PonyContainer;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.container.ContainerListener;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
@Mixin(ServerPlayerEntity.class)
abstract class MixinServerPlayerEntity extends PlayerEntity implements ContainerListener, PonyContainer<Pony> {
MixinServerPlayerEntity() {super(null, null);}
@SuppressWarnings("unchecked")
@Inject(method = "copyFrom(Lnet/minecraft/server/network/ServerPlayerEntity;Z)V", at = @At("HEAD"))
private void onCopyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
get().copyFrom(((PonyContainer<Pony>)oldPlayer).get());
}
}

View file

@ -0,0 +1,5 @@
package com.minelittlepony.unicopia.util;
public interface Copieable<T extends Copieable<T>> {
void copyFrom(T other);
}

View file

@ -17,6 +17,7 @@
"MixinLivingEntity",
"MixinPlayerEntity",
"MixinProjectileEntity",
"MixinServerPlayerEntity",
"Walker"
],
"client": [