diff --git a/src/main/java/me/jellysquid/mods/lithium/mixin/ai/nearby_entity_tracking/EntityTrackingSectionMixin.java b/src/main/java/me/jellysquid/mods/lithium/mixin/ai/nearby_entity_tracking/EntityTrackingSectionMixin.java index a2e70f88d..862c6ee1a 100644 --- a/src/main/java/me/jellysquid/mods/lithium/mixin/ai/nearby_entity_tracking/EntityTrackingSectionMixin.java +++ b/src/main/java/me/jellysquid/mods/lithium/mixin/ai/nearby_entity_tracking/EntityTrackingSectionMixin.java @@ -1,5 +1,6 @@ package me.jellysquid.mods.lithium.mixin.ai.nearby_entity_tracking; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import me.jellysquid.mods.lithium.common.entity.PositionedEntityTrackingSection; import me.jellysquid.mods.lithium.common.entity.nearby_tracker.NearbyEntityListener; @@ -13,6 +14,7 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; @@ -30,6 +32,7 @@ public abstract class EntityTrackingSectionMixin implement @Shadow public abstract boolean isEmpty(); + @Unique private final ReferenceOpenHashSet nearbyEntityListeners = new ReferenceOpenHashSet<>(0); @Override @@ -51,11 +54,12 @@ public void removeListener(SectionedEntityCache sectionedEntityCache, NearbyE } } - @Inject(method = "isEmpty()Z", at = @At(value = "HEAD"), cancellable = true) - public void isEmpty(CallbackInfoReturnable cir) { - if (!this.nearbyEntityListeners.isEmpty()) { - cir.setReturnValue(false); - } + /** + * @author ishland, 2No2Name + */ + @ModifyReturnValue(method = "isEmpty()Z", at = @At(value = "RETURN")) + public boolean modifyIsEmpty(boolean previousIsEmpty) { + return previousIsEmpty && this.nearbyEntityListeners.isEmpty(); } @Inject(method = "add(Lnet/minecraft/world/entity/EntityLike;)V", at = @At("RETURN")) diff --git a/src/main/java/me/jellysquid/mods/lithium/mixin/util/entity_movement_tracking/EntityTrackingSectionMixin.java b/src/main/java/me/jellysquid/mods/lithium/mixin/util/entity_movement_tracking/EntityTrackingSectionMixin.java index 71210a1ed..e2a379c35 100644 --- a/src/main/java/me/jellysquid/mods/lithium/mixin/util/entity_movement_tracking/EntityTrackingSectionMixin.java +++ b/src/main/java/me/jellysquid/mods/lithium/mixin/util/entity_movement_tracking/EntityTrackingSectionMixin.java @@ -1,5 +1,7 @@ package me.jellysquid.mods.lithium.mixin.util.entity_movement_tracking; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.injector.WrapWithCondition; import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import me.jellysquid.mods.lithium.common.entity.PositionedEntityTrackingSection; import me.jellysquid.mods.lithium.common.entity.movement_tracker.EntityMovementTrackerSection; @@ -11,6 +13,7 @@ import net.minecraft.world.entity.SectionedEntityCache; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; @@ -19,16 +22,19 @@ import java.util.ArrayList; @Mixin(EntityTrackingSection.class) -public abstract class EntityTrackingSectionMixin implements EntityMovementTrackerSection, PositionedEntityTrackingSection { +public abstract class EntityTrackingSectionMixin implements EntityMovementTrackerSection, PositionedEntityTrackingSection { @Shadow private EntityTrackingStatus status; @Shadow public abstract boolean isEmpty(); + @Unique private final ReferenceOpenHashSet> sectionVisibilityListeners = new ReferenceOpenHashSet<>(0); + @Unique @SuppressWarnings("unchecked") private final ArrayList>[] entityMovementListenersByType = new ArrayList[MovementTrackerHelper.NUM_MOVEMENT_NOTIFYING_CLASSES]; + @Unique private final long[] lastEntityMovementByType = new long[MovementTrackerHelper.NUM_MOVEMENT_NOTIFYING_CLASSES]; @Override @@ -76,11 +82,9 @@ public long getChangeTime(int trackedClass) { return this.lastEntityMovementByType[trackedClass]; } - @Inject(method = "isEmpty()Z", at = @At(value = "HEAD"), cancellable = true) - public void isEmpty(CallbackInfoReturnable cir) { - if (!this.sectionVisibilityListeners.isEmpty()) { - cir.setReturnValue(false); - } + @ModifyReturnValue(method = "isEmpty()Z", at = @At(value = "RETURN")) + public boolean modifyIsEmpty(boolean previousIsEmpty) { + return previousIsEmpty && this.sectionVisibilityListeners.isEmpty(); }