2020-09-22 15:11:20 +02:00
|
|
|
package com.minelittlepony.unicopia.entity;
|
2020-04-15 14:22:03 +02:00
|
|
|
|
2020-09-23 17:19:28 +02:00
|
|
|
import com.minelittlepony.unicopia.Affinity;
|
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;
|
2020-10-02 09:39:00 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.Levelled;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.Spell;
|
2021-03-01 11:56:30 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.SpellType;
|
2021-02-18 21:30:43 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.ai.BreakHeartGoal;
|
2021-02-20 00:34:30 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.ai.DynamicTargetGoal;
|
2021-02-16 12:39:39 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.ai.WantItTakeItGoal;
|
2021-02-17 16:05:20 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.player.PlayerAttributes;
|
2021-02-16 12:39:39 +01:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
2021-02-18 21:30:43 +01:00
|
|
|
import net.minecraft.entity.SpawnGroup;
|
2021-02-16 12:39:39 +01:00
|
|
|
import net.minecraft.entity.ai.goal.GoalSelector;
|
|
|
|
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
|
|
|
import net.minecraft.entity.attribute.EntityAttributes;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.data.DataTracker;
|
|
|
|
import net.minecraft.entity.data.TrackedData;
|
|
|
|
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
2021-02-16 12:39:39 +01:00
|
|
|
import net.minecraft.entity.mob.MobEntity;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
|
|
|
2021-02-14 16:52:56 +01:00
|
|
|
public class Creature extends Living<LivingEntity> {
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
private static final TrackedData<CompoundTag> EFFECT = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND);
|
2021-02-22 14:54:24 +01:00
|
|
|
public static final TrackedData<Float> GRAVITY = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-10-02 09:39:00 +02:00
|
|
|
private static final LevelStore LEVELS = Levelled.fixed(0);
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
public static void boostrap() {}
|
|
|
|
|
2021-02-23 18:02:23 +01:00
|
|
|
private final EntityPhysics<Creature> physics = new EntityPhysics<>(this, GRAVITY);
|
2020-05-10 17:18:45 +02:00
|
|
|
|
|
|
|
public Creature(LivingEntity entity) {
|
2021-02-14 16:52:56 +01:00
|
|
|
super(entity, EFFECT);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 12:39:39 +01:00
|
|
|
public void initAi(GoalSelector goals, GoalSelector targets) {
|
2021-02-20 00:34:30 +01:00
|
|
|
DynamicTargetGoal targetter = new DynamicTargetGoal((MobEntity)entity);
|
|
|
|
targets.add(1, targetter);
|
|
|
|
goals.add(1, new WantItTakeItGoal((MobEntity)entity, targetter));
|
2021-02-18 21:30:43 +01:00
|
|
|
if (entity.getType().getSpawnGroup() == SpawnGroup.MONSTER) {
|
2021-02-20 00:34:30 +01:00
|
|
|
goals.add(3, new BreakHeartGoal((MobEntity)entity, targetter));
|
2021-02-18 21:30:43 +01:00
|
|
|
}
|
2021-02-16 12:39:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void registerAttributes(DefaultAttributeContainer.Builder builder) {
|
|
|
|
builder.add(EntityAttributes.GENERIC_ATTACK_DAMAGE);
|
|
|
|
builder.add(EntityAttributes.GENERIC_ATTACK_KNOCKBACK);
|
2021-02-17 16:05:20 +01:00
|
|
|
builder.add(PlayerAttributes.ENTITY_GRAVTY_MODIFIER);
|
2021-02-16 12:39:39 +01:00
|
|
|
}
|
|
|
|
|
2021-02-23 18:02:23 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void tick() {
|
|
|
|
super.tick();
|
|
|
|
physics.tick();
|
|
|
|
}
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
@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-10-02 09:39:00 +02:00
|
|
|
public LevelStore getLevel() {
|
|
|
|
return LEVELS;
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Affinity getAffinity() {
|
2020-10-08 19:22:20 +02:00
|
|
|
if (getMaster() instanceof Affine) {
|
|
|
|
return ((Affine)getMaster()).getAffinity();
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
return Affinity.NEUTRAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void toNBT(CompoundTag compound) {
|
2021-02-16 12:39:39 +01:00
|
|
|
super.toNBT(compound);
|
2020-09-24 14:49:02 +02:00
|
|
|
Spell effect = getSpell(true);
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
if (effect != null) {
|
2021-03-01 11:56:30 +01:00
|
|
|
compound.put("effect", SpellType.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) {
|
2021-02-16 12:39:39 +01:00
|
|
|
super.fromNBT(compound);
|
2020-04-22 16:28:20 +02:00
|
|
|
if (compound.contains("effect")) {
|
2021-03-01 11:56:30 +01:00
|
|
|
setSpell(SpellType.fromNBT(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
|
|
|
}
|
|
|
|
}
|