package com.minelittlepony.unicopia.equine; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.magic.Affinity; import com.minelittlepony.unicopia.magic.Affine; import com.minelittlepony.unicopia.magic.AttachableSpell; import com.minelittlepony.unicopia.magic.Caster; import com.minelittlepony.unicopia.magic.Spell; import com.minelittlepony.unicopia.magic.spell.SpellRegistry; import com.minelittlepony.unicopia.network.EffectSync; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.nbt.CompoundTag; public class Creature implements Ponylike, Caster { private static final TrackedData EFFECT = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND); public static void boostrap() {} private final EffectSync effectDelegate = new EffectSync(this, EFFECT); private final Physics physics = new EntityPhysics<>(this); private final LivingEntity entity; public Creature(LivingEntity entity) { this.entity = entity; entity.getDataTracker().startTracking(EFFECT, new CompoundTag()); } @Override public Race getSpecies() { return Race.HUMAN; } @Override public Physics getPhysics() { return physics; } @Override public void setSpecies(Race race) { } @Override public EffectSync getPrimarySpellSlot() { return effectDelegate; } @Override public void tick() { if (hasSpell()) { AttachableSpell effect = getSpell(AttachableSpell.class, true); if (effect != null) { if (entity.getEntityWorld().isClient()) { effect.renderOnPerson(this); } if (!effect.updateOnPerson(this)) { setSpell(null); } } } } @Override public void setOwner(LivingEntity owner) { } @Override public LivingEntity getOwner() { return entity; } @Override public int getCurrentLevel() { return 0; } @Override public void setCurrentLevel(int level) { } @Override public Affinity getAffinity() { if (getOwner() instanceof Affine) { return ((Affine)getOwner()).getAffinity(); } return Affinity.NEUTRAL; } @Override public void toNBT(CompoundTag compound) { Spell effect = getSpell(); if (effect != null) { compound.put("effect", SpellRegistry.toNBT(effect)); } physics.toNBT(compound); } @Override public void fromNBT(CompoundTag compound) { if (compound.contains("effect")) { setSpell(SpellRegistry.instance().createEffectFromNBT(compound.getCompound("effect"))); } physics.fromNBT(compound); } }