Fixed item tracking not being synced to the client

This commit is contained in:
Sollace 2022-12-10 00:16:23 +00:00
parent a1268e8209
commit 7878f280e3
3 changed files with 28 additions and 17 deletions

View file

@ -4,6 +4,7 @@ import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Stream;
import com.minelittlepony.unicopia.util.Copieable;
import com.minelittlepony.unicopia.util.NbtSerialisable;
import net.minecraft.entity.LivingEntity;
@ -14,7 +15,7 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class ItemTracker implements NbtSerialisable {
public class ItemTracker implements NbtSerialisable, Copieable<ItemTracker> {
public static final long TICKS = 1;
public static final long SECONDS = 20 * TICKS;
public static final long HOURS = 1000 * TICKS;
@ -94,6 +95,12 @@ public class ItemTracker implements NbtSerialisable {
.forEach(item -> items.put((Trackable)item.getKey(), item.getValue()));
}
@Override
public void copyFrom(ItemTracker other) {
items.clear();
items.putAll(other.items);
}
public interface Trackable extends ItemConvertible {
void onUnequipped(Living<?> living, long timeWorn);

View file

@ -20,6 +20,7 @@ import com.minelittlepony.unicopia.entity.effect.UEffects;
import com.minelittlepony.unicopia.item.GlassesItem;
import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.network.datasync.EffectSync;
import com.minelittlepony.unicopia.network.datasync.Transmittable;
import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.projectile.ProjectileImpactListener;
import com.minelittlepony.unicopia.trinkets.TrinketsDelegate;
@ -41,7 +42,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
public abstract class Living<T extends LivingEntity> implements Equine<T>, Caster<T> {
public abstract class Living<T extends LivingEntity> implements Equine<T>, Caster<T>, Transmittable {
protected final T entity;
@ -255,17 +256,30 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
});
}
@Override
public void setDirty() {}
@Override
public void toNBT(NbtCompound compound) {
enchants.toNBT(compound);
effectDelegate.toNBT(compound);
compound.put("armour", armour.toNBT());
toSyncronisedNbt(compound);
}
@Override
public void fromNBT(NbtCompound compound) {
enchants.fromNBT(compound);
effectDelegate.fromNBT(compound);
fromSynchronizedNbt(compound);
}
@Override
public void toSyncronisedNbt(NbtCompound compound) {
compound.put("armour", armour.toNBT());
}
@Override
public void fromSynchronizedNbt(NbtCompound compound) {
armour.fromNBT(compound.getCompound("armour"));
}

View file

@ -29,7 +29,6 @@ import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.network.Channel;
import com.minelittlepony.unicopia.network.MsgOtherPlayerCapabilities;
import com.minelittlepony.unicopia.network.MsgPlayerAnimationChange;
import com.minelittlepony.unicopia.network.datasync.Transmittable;
import com.minelittlepony.unicopia.util.*;
import com.minelittlepony.unicopia.network.datasync.EffectSync.UpdateCallback;
import com.minelittlepony.common.util.animation.LinearInterpolator;
@ -60,7 +59,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.math.*;
import net.minecraft.world.GameMode;
public class Pony extends Living<PlayerEntity> implements Transmittable, Copieable<Pony>, UpdateCallback {
public class Pony extends Living<PlayerEntity> implements Copieable<Pony>, UpdateCallback {
private static final TrackedData<String> RACE = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.STRING);
@ -528,14 +527,9 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
return getArmour().contains(UItems.ALICORN_AMULET) || super.isEnemy(other);
}
@Override
public void toNBT(NbtCompound compound) {
super.toNBT(compound);
toSyncronisedNbt(compound);
}
@Override
public void toSyncronisedNbt(NbtCompound compound) {
super.toSyncronisedNbt(compound);
compound.putString("playerSpecies", Race.REGISTRY.getId(getActualSpecies()).toString());
compound.putFloat("magicExhaustion", magicExhaustion);
compound.putInt("ticksHanging", ticksHanging);
@ -557,14 +551,9 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
compound.put("advancementProgress", progress);
}
@Override
public void fromNBT(NbtCompound compound) {
super.fromNBT(compound);
fromSynchronizedNbt(compound);
}
@Override
public void fromSynchronizedNbt(NbtCompound compound) {
super.fromSynchronizedNbt(compound);
speciesPersisted = true;
setSpecies(Race.fromName(compound.getString("playerSpecies"), Race.HUMAN));
powers.fromNBT(compound.getCompound("powers"));
@ -597,6 +586,7 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
oldPlayer.getSpellSlot().stream(true).filter(SpellPredicate.IS_PLACED).forEach(getSpellSlot()::put);
}
oldPlayer.getSpellSlot().put(null);
getArmour().copyFrom(oldPlayer.getArmour());
setSpecies(oldPlayer.getActualSpecies());
getDiscoveries().copyFrom(oldPlayer.getDiscoveries());
getCharms().equipSpell(Hand.MAIN_HAND, oldPlayer.getCharms().getEquippedSpell(Hand.MAIN_HAND));