diff --git a/src/main/java/carpettisaddition/commands/lifetime/LifeTimeTracker.java b/src/main/java/carpettisaddition/commands/lifetime/LifeTimeTracker.java index bc1b0771b..d2e88aaab 100644 --- a/src/main/java/carpettisaddition/commands/lifetime/LifeTimeTracker.java +++ b/src/main/java/carpettisaddition/commands/lifetime/LifeTimeTracker.java @@ -2,11 +2,13 @@ import carpet.utils.Messenger; import carpettisaddition.commands.AbstractTracker; +import carpettisaddition.commands.lifetime.interfaces.IEntity; import carpettisaddition.commands.lifetime.interfaces.IServerWorld; import carpettisaddition.commands.lifetime.utils.LifeTimeTrackerUtil; import carpettisaddition.commands.lifetime.utils.SpecificDetailMode; import carpettisaddition.utils.TextUtil; import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; @@ -23,6 +25,8 @@ public class LifeTimeTracker extends AbstractTracker private static boolean attachedServer = false; private static final LifeTimeTracker INSTANCE = new LifeTimeTracker(); + private int currentTrackId = 0; + private final Map trackers = new Reference2ObjectArrayMap<>(); public LifeTimeTracker() @@ -56,6 +60,11 @@ public static boolean isActivated() return attachedServer && INSTANCE.isTracking(); } + public static boolean willTrackEntity(Entity entity) + { + return isActivated() && ((IEntity)entity).getTrackId() == INSTANCE.getCurrentTrackId() && LifeTimeTrackerUtil.isTrackedEntity(entity); + } + public Stream getAvailableEntityType() { if (!isActivated()) @@ -70,9 +79,15 @@ public Stream getAvailableEntityType() distinct(); } + public int getCurrentTrackId() + { + return this.currentTrackId; + } + @Override protected void initTracker() { + this.currentTrackId++; this.trackers.values().forEach(LifeTimeWorldTracker::initTracker); } diff --git a/src/main/java/carpettisaddition/commands/lifetime/LifeTimeWorldTracker.java b/src/main/java/carpettisaddition/commands/lifetime/LifeTimeWorldTracker.java index 91a144f6a..7a29f096d 100644 --- a/src/main/java/carpettisaddition/commands/lifetime/LifeTimeWorldTracker.java +++ b/src/main/java/carpettisaddition/commands/lifetime/LifeTimeWorldTracker.java @@ -46,7 +46,7 @@ public void initTracker() private Optional getTrackedData(Entity entity) { - if (LifeTimeTracker.isActivated() && LifeTimeTrackerUtil.isTrackedEntity(entity)) + if (LifeTimeTracker.willTrackEntity(entity)) { return Optional.of(this.dataMap.computeIfAbsent(entity.getType(), (e -> new TrackedData()))); } diff --git a/src/main/java/carpettisaddition/commands/lifetime/interfaces/IEntity.java b/src/main/java/carpettisaddition/commands/lifetime/interfaces/IEntity.java index 22ca5a734..f033eb74e 100644 --- a/src/main/java/carpettisaddition/commands/lifetime/interfaces/IEntity.java +++ b/src/main/java/carpettisaddition/commands/lifetime/interfaces/IEntity.java @@ -6,6 +6,8 @@ public interface IEntity { + int getTrackId(); + long getLifeTime(); Vec3d getSpawningPosition(); diff --git a/src/main/java/carpettisaddition/mixins/command/lifetime/EntityMixin.java b/src/main/java/carpettisaddition/mixins/command/lifetime/EntityMixin.java index 5dcbd72fc..4a23287c8 100644 --- a/src/main/java/carpettisaddition/mixins/command/lifetime/EntityMixin.java +++ b/src/main/java/carpettisaddition/mixins/command/lifetime/EntityMixin.java @@ -5,7 +5,6 @@ import carpettisaddition.commands.lifetime.interfaces.IServerWorld; import carpettisaddition.commands.lifetime.removal.RemovalReason; import carpettisaddition.commands.lifetime.spawning.SpawningReason; -import carpettisaddition.commands.lifetime.utils.LifeTimeTrackerUtil; import carpettisaddition.utils.GameUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -34,18 +33,30 @@ public abstract class EntityMixin implements IEntity private boolean recordedRemoval; private Vec3d spawningPos; private Vec3d removalPos; + private int trackId; @Inject(method = "", at = @At("TAIL")) private void onConstructLifeTimeTracker(CallbackInfo ci) { - this.doLifeTimeTracking = false; this.recordedSpawning = false; this.recordedRemoval = false; if (this.world instanceof ServerWorld) { this.spawnTime = ((IServerWorld)this.world).getLifeTimeWorldTracker().getSpawnStageCounter(); - this.doLifeTimeTracking = LifeTimeTracker.isActivated() && LifeTimeTrackerUtil.isTrackedEntity((Entity) (Object) this); + this.trackId = LifeTimeTracker.getInstance().getCurrentTrackId(); + this.doLifeTimeTracking = LifeTimeTracker.willTrackEntity((Entity)(Object)this); } + else + { + this.trackId = -1; + this.doLifeTimeTracking = false; + } + } + + @Override + public int getTrackId() + { + return this.trackId; } @Override