2020-09-22 15:11:20 +02:00
|
|
|
package com.minelittlepony.unicopia.entity;
|
2020-04-15 14:22:03 +02:00
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.Affine;
|
|
|
|
import com.minelittlepony.unicopia.ability.magic.Affinity;
|
|
|
|
import com.minelittlepony.unicopia.ability.magic.AttachableSpell;
|
|
|
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
|
|
|
import com.minelittlepony.unicopia.ability.magic.Spell;
|
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.SpellRegistry;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.network.EffectSync;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-09-22 15:11:20 +02:00
|
|
|
public class Creature implements Equine<LivingEntity>, Caster<LivingEntity> {
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
private static final TrackedData<CompoundTag> EFFECT = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND);
|
|
|
|
|
|
|
|
public static void boostrap() {}
|
|
|
|
|
|
|
|
private final EffectSync effectDelegate = new EffectSync(this, EFFECT);
|
|
|
|
|
2020-05-10 17:18:45 +02:00
|
|
|
private final Physics physics = new EntityPhysics<>(this);
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
private final LivingEntity entity;
|
|
|
|
|
2020-05-10 17:18:45 +02:00
|
|
|
public Creature(LivingEntity entity) {
|
2020-01-16 12:35:46 +01:00
|
|
|
this.entity = entity;
|
|
|
|
|
|
|
|
entity.getDataTracker().startTracking(EFFECT, new CompoundTag());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Race getSpecies() {
|
|
|
|
return Race.HUMAN;
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:18:45 +02:00
|
|
|
@Override
|
|
|
|
public Physics getPhysics() {
|
|
|
|
return physics;
|
|
|
|
}
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
@Override
|
|
|
|
public void setSpecies(Race race) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-28 18:27:30 +02:00
|
|
|
public EffectSync getPrimarySpellSlot() {
|
|
|
|
return effectDelegate;
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 17:18:45 +02:00
|
|
|
public void tick() {
|
2020-05-28 18:27:30 +02:00
|
|
|
if (hasSpell()) {
|
|
|
|
AttachableSpell effect = getSpell(AttachableSpell.class, true);
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
if (effect != null) {
|
|
|
|
if (entity.getEntityWorld().isClient()) {
|
|
|
|
effect.renderOnPerson(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!effect.updateOnPerson(this)) {
|
2020-05-28 18:27:30 +02:00
|
|
|
setSpell(null);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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() {
|
2020-04-15 18:12:00 +02:00
|
|
|
if (getOwner() instanceof Affine) {
|
|
|
|
return ((Affine)getOwner()).getAffinity();
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
return Affinity.NEUTRAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void toNBT(CompoundTag compound) {
|
2020-05-28 18:27:30 +02:00
|
|
|
Spell effect = getSpell();
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
if (effect != null) {
|
2020-05-28 18:27:30 +02:00
|
|
|
compound.put("effect", SpellRegistry.toNBT(effect));
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
2020-05-10 17:18:45 +02:00
|
|
|
physics.toNBT(compound);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fromNBT(CompoundTag compound) {
|
2020-04-22 16:28:20 +02:00
|
|
|
if (compound.contains("effect")) {
|
2020-05-28 18:27:30 +02:00
|
|
|
setSpell(SpellRegistry.instance().createEffectFromNBT(compound.getCompound("effect")));
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
2020-05-10 17:18:45 +02:00
|
|
|
physics.fromNBT(compound);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
}
|