mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-30 08:18:00 +01:00
Only interact with the datatracker after it's safe to do so
This commit is contained in:
parent
ba2e673de7
commit
9c71272def
13 changed files with 61 additions and 25 deletions
|
@ -70,13 +70,17 @@ public class Creature extends Living<LivingEntity> 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
|
||||
|
|
|
@ -28,16 +28,8 @@ public class EntityPhysics<T extends Entity> implements Physics, Copyable<Entity
|
|||
private float lastGravity = 1;
|
||||
|
||||
public EntityPhysics(T entity, TrackedData<Float> gravity) {
|
||||
this(entity, gravity, true);
|
||||
}
|
||||
|
||||
public EntityPhysics(T entity, TrackedData<Float> gravity, boolean register) {
|
||||
this.entity = entity;
|
||||
this.gravity = gravity;
|
||||
|
||||
if (register) {
|
||||
this.entity.getDataTracker().startTracking(gravity, 1F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,8 @@ public interface Equine<T extends Entity> extends NbtSerialisable, Tickable, Pro
|
|||
|
||||
void setSpecies(Race race);
|
||||
|
||||
void initDataTracker();
|
||||
|
||||
/**
|
||||
* Called at the beginning of an update cycle.
|
||||
*/
|
||||
|
|
|
@ -41,8 +41,12 @@ public class ItemImpl implements Equine<ItemEntity> {
|
|||
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
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.entity.ItemEntity;
|
|||
|
||||
class ItemPhysics extends EntityPhysics<ItemEntity> {
|
||||
public ItemPhysics(ItemEntity entity) {
|
||||
super(entity, ItemImpl.ITEM_GRAVITY, false);
|
||||
super(entity, ItemImpl.ITEM_GRAVITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -111,12 +111,15 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
protected Living(T entity, TrackedData<NbtCompound> 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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -125,15 +125,23 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, 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);
|
||||
|
|
|
@ -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 = "<init>", 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<Boolean> info) {
|
||||
if (isLavaAffine() || (this instanceof Equine.Container c) && c.get().getCompositeRace().includes(Race.KIRIN)) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -67,7 +67,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster<Ma
|
|||
|
||||
private final EffectSync effectDelegate = new EffectSync(this, EFFECT);
|
||||
|
||||
private final EntityPhysics<MagicProjectileEntity> physics = new EntityPhysics<>(this, GRAVITY, false);
|
||||
private final EntityPhysics<MagicProjectileEntity> physics = new EntityPhysics<>(this, GRAVITY);
|
||||
|
||||
private final EntityReference<Entity> homingTarget = new EntityReference<>();
|
||||
private EntityReference<LivingEntity> owner;
|
||||
|
|
Loading…
Reference in a new issue