diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Creature.java b/src/main/java/com/minelittlepony/unicopia/entity/Creature.java index 82039a7f..77d0c083 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Creature.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Creature.java @@ -70,13 +70,17 @@ public class Creature extends Living implements WeaklyOwned.Mutabl public Creature(LivingEntity entity) { super(entity, EFFECT); physics = new EntityPhysics<>(entity, GRAVITY); + addTicker(physics); + addTicker(this::updateConsumption); + } + + @Override + public void initDataTracker() { + super.initDataTracker(); entity.getDataTracker().startTracking(MASTER, owner.toNBT()); entity.getDataTracker().startTracking(EATING, 0); entity.getDataTracker().startTracking(DISCORDED, false); entity.getDataTracker().startTracking(SMITTEN, false); - - addTicker(physics); - addTicker(this::updateConsumption); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java index 3b912b76..1529989b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java @@ -28,16 +28,8 @@ public class EntityPhysics implements Physics, Copyable gravity) { - this(entity, gravity, true); - } - - public EntityPhysics(T entity, TrackedData gravity, boolean register) { this.entity = entity; this.gravity = gravity; - - if (register) { - this.entity.getDataTracker().startTracking(gravity, 1F); - } } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Equine.java b/src/main/java/com/minelittlepony/unicopia/entity/Equine.java index a9cf3707..691bbfcf 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Equine.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Equine.java @@ -19,6 +19,8 @@ public interface Equine extends NbtSerialisable, Tickable, Pro void setSpecies(Race race); + void initDataTracker(); + /** * Called at the beginning of an update cycle. */ diff --git a/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java b/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java index 50680348..3d594ea7 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java @@ -41,8 +41,12 @@ public class ItemImpl implements Equine { public ItemImpl(ItemEntity owner) { this.entity = owner; this.physics = new ItemPhysics(owner); - owner.getDataTracker().startTracking(ITEM_GRAVITY, 1F); - owner.getDataTracker().startTracking(ITEM_RACE, Race.REGISTRY.getId(Race.HUMAN).toString()); + } + + @Override + public void initDataTracker() { + entity.getDataTracker().startTracking(ITEM_GRAVITY, 1F); + entity.getDataTracker().startTracking(ITEM_RACE, Race.REGISTRY.getId(Race.HUMAN).toString()); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/ItemPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/ItemPhysics.java index f1675f0d..b747dd0a 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/ItemPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/ItemPhysics.java @@ -4,7 +4,7 @@ import net.minecraft.entity.ItemEntity; class ItemPhysics extends EntityPhysics { public ItemPhysics(ItemEntity entity) { - super(entity, ItemImpl.ITEM_GRAVITY, false); + super(entity, ItemImpl.ITEM_GRAVITY); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Living.java b/src/main/java/com/minelittlepony/unicopia/entity/Living.java index 40d6ee7f..40e9fc21 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Living.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Living.java @@ -111,12 +111,15 @@ public abstract class Living implements Equine, Caste protected Living(T entity, TrackedData effect) { this.entity = entity; this.effectDelegate = new EffectSync(this, effect); - this.sneakingHeuristic = addTicker(new Interactable(entity::isSneaking)); this.landedHeuristic = addTicker(new Interactable(entity::isOnGround)); this.jumpingHeuristic = addTicker(new Interactable(((LivingEntityDuck)entity)::isJumping)); + } - entity.getDataTracker().startTracking(effect, new NbtCompound()); + @Override + public void initDataTracker() { + effectDelegate.initDataTracker(); + entity.getDataTracker().startTracking(Creature.GRAVITY, 1F); entity.getDataTracker().startTracking(CARRIER_ID, Optional.empty()); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java index eb9c98eb..37009bb5 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java @@ -41,12 +41,13 @@ public class Acrobatics implements Tickable, NbtSerialisable { public Acrobatics(Pony pony) { this.pony = pony; this.entity = pony.asEntity(); - - entity.getDataTracker().startTracking(HANGING_POSITION, Optional.empty()); - pony.addTicker(this::checkDislodge); } + public void initDataTracker() { + entity.getDataTracker().startTracking(HANGING_POSITION, Optional.empty()); + } + public boolean isImmobile() { return isFloppy() && entity.isOnGround(); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java index 4ab1ddf4..c527430d 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java @@ -38,6 +38,10 @@ class ManaContainer implements MagicReserves, Tickable, NbtSerialisable, Copyabl }); } + public void initDataTracker() { + bars.values().forEach(BarInst::initDataTracker); + } + protected BarInst addBar(String name, BarInst bar) { bars.put(name, bar); return bar; @@ -164,7 +168,12 @@ class ManaContainer implements MagicReserves, Tickable, NbtSerialisable, Copyabl this.marker = marker; this.max = max; this.trailingValue = initial; - pony.asEntity().getDataTracker().startTracking(marker, getMax() * initial); + this.prevTrailingValue = initial; + this.prevValue = initial; + } + + public void initDataTracker() { + pony.asEntity().getDataTracker().startTracking(marker, max * trailingValue); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerLevelStore.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerLevelStore.java index 006f20f8..f883529a 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerLevelStore.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerLevelStore.java @@ -21,7 +21,6 @@ class PlayerLevelStore implements Levelled.LevelStore { this.dataEntry = dataEntry; this.upgradeMana = upgradeMana; this.levelUpSound = levelUpSound; - pony.asEntity().getDataTracker().startTracking(dataEntry, 0); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index 67a93b73..02c1d532 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -125,15 +125,23 @@ public class Pony extends Living implements Copyable, Update this.corruption = new PlayerLevelStore(this, CORRUPTION, false, USounds.ENTITY_PLAYER_CORRUPTION); this.mana = addTicker(new ManaContainer(this)); - player.getDataTracker().startTracking(RACE, Race.DEFAULT_ID); - player.getDataTracker().startTracking(SUPPRESSED_RACE, Race.DEFAULT_ID); - addTicker(this::updateAnimations); addTicker(this::updateBatPonyAbilities); addTicker(this::updateCorruptionDecay); addTicker(new PlayerAttributes(this)); } + @Override + public void initDataTracker() { + super.initDataTracker(); + acrobatics.initDataTracker(); + mana.initDataTracker(); + entity.getDataTracker().startTracking(LEVEL, 0); + entity.getDataTracker().startTracking(CORRUPTION, 0); + entity.getDataTracker().startTracking(RACE, Race.DEFAULT_ID); + entity.getDataTracker().startTracking(SUPPRESSED_RACE, Race.DEFAULT_ID); + } + public static void registerAttributes(DefaultAttributeContainer.Builder builder) { builder.add(UEntityAttributes.EXTRA_MINING_SPEED); builder.add(UEntityAttributes.ENTITY_GRAVITY_MODIFIER); diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntity.java index 986e9bf5..6a9c29d3 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntity.java @@ -19,12 +19,14 @@ import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.duck.EntityDuck; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.Entity.PositionUpdater; import net.minecraft.entity.Entity.RemovalReason; import net.minecraft.fluid.Fluid; import net.minecraft.item.ItemStack; import net.minecraft.registry.tag.TagKey; +import net.minecraft.world.World; @Mixin(Entity.class) abstract class MixinEntity implements EntityDuck { @@ -64,6 +66,14 @@ abstract class MixinEntity implements EntityDuck { return self.hasVehicle() && self.getVehicle() instanceof LavaAffine affine && affine.isLavaAffine(); } + + @Inject(method = "", at = @At(value = "INVOKE", target = "net/minecraft/entity/Entity.initDataTracker()V")) + private void onInstanceInit(EntityType type, World world, CallbackInfo info) { + if (this instanceof Equine.Container c) { + c.get().initDataTracker(); + } + } + @Inject(method = "isFireImmune", at = @At("HEAD"), cancellable = true) private void onIsFireImmune(CallbackInfoReturnable info) { if (isLavaAffine() || (this instanceof Equine.Container c) && c.get().getCompositeRace().includes(Race.KIRIN)) { diff --git a/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java b/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java index 724c5660..c66cac4c 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java +++ b/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java @@ -43,6 +43,10 @@ public class EffectSync implements SpellContainer, NbtSerialisable { this.param = param; } + public void initDataTracker() { + owner.asEntity().getDataTracker().startTracking(param, new NbtCompound()); + } + public boolean tick(Situation situation) { return tick(spell -> { if (spell.isDying()) { diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java index 09fbff79..6ca4cb3c 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java @@ -67,7 +67,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster physics = new EntityPhysics<>(this, GRAVITY, false); + private final EntityPhysics physics = new EntityPhysics<>(this, GRAVITY); private final EntityReference homingTarget = new EntityReference<>(); private EntityReference owner;