Search in sources :

Example 1 with NearbyEntityListenerProvider

use of me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider in project lithium-fabric by CaffeineMC.

the class ServerEntityManagerListenerMixin method onAddEntity.

@Inject(method = "updateEntityPosition()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/EntityTrackingSection;add(Lnet/minecraft/world/entity/EntityLike;)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void onAddEntity(CallbackInfo ci, BlockPos blockPos, long newPos, EntityTrackingStatus entityTrackingStatus, EntityTrackingSection<T> entityTrackingSection) {
    NearbyEntityListenerMulti listener = ((NearbyEntityListenerProvider) this.entity).getListener();
    if (listener != null) {
        // noinspection unchecked
        listener.forEachChunkInRangeChange(((ServerEntityManagerAccessor<T>) this.manager).getCache(), ChunkSectionPos.from(this.sectionPos), ChunkSectionPos.from(newPos));
    }
    this.notifyMovementListeners();
}
Also used : NearbyEntityListenerMulti(me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerMulti) NearbyEntityListenerProvider(me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with NearbyEntityListenerProvider

use of me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider in project lithium-fabric by CaffeineMC.

the class ServerEntityManagerListenerMixin method onRemoveEntity.

@Inject(method = "remove(Lnet/minecraft/entity/Entity$RemovalReason;)V", at = @At(value = "HEAD"))
private void onRemoveEntity(Entity.RemovalReason reason, CallbackInfo ci) {
    NearbyEntityListenerMulti listener = ((NearbyEntityListenerProvider) this.entity).getListener();
    if (listener != null) {
        // noinspection unchecked
        listener.forEachChunkInRangeChange(((ServerEntityManagerAccessor<T>) this.manager).getCache(), ChunkSectionPos.from(this.sectionPos), null);
    }
    this.notifyMovementListeners();
}
Also used : NearbyEntityListenerMulti(me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerMulti) NearbyEntityListenerProvider(me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with NearbyEntityListenerProvider

use of me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider in project roadrunner by MaxNeedsSnacks.

the class EntityTrackerEngine method onEntityAdded.

/**
 * Called when an entity is added to the world.
 */
public void onEntityAdded(int x, int y, int z, LivingEntity entity) {
    if (this.addEntity(x, y, z, entity)) {
        if (entity instanceof NearbyEntityListenerProvider) {
            NearbyEntityListenerMulti listener = ((NearbyEntityListenerProvider) entity).getListener();
            this.addListener(x, y, z, listener);
            listener.setTrackingEngine(this);
        }
    }
}
Also used : NearbyEntityListenerMulti(me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerMulti) NearbyEntityListenerProvider(me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider)

Example 4 with NearbyEntityListenerProvider

use of me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider in project roadrunner by MaxNeedsSnacks.

the class EntityTrackerEngine method onEntityRemoved.

/**
 * Called when an entity is removed from the world.
 */
public void onEntityRemoved(int x, int y, int z, LivingEntity entity) {
    if (this.removeEntity(x, y, z, entity)) {
        if (entity instanceof NearbyEntityListenerProvider) {
            NearbyEntityListenerMulti listener = ((NearbyEntityListenerProvider) entity).getListener();
            this.removeListener(listener);
            listener.clearTrackingEngine();
        }
    }
}
Also used : NearbyEntityListenerMulti(me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerMulti) NearbyEntityListenerProvider(me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider)

Example 5 with NearbyEntityListenerProvider

use of me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider in project lithium-fabric by CaffeineMC.

the class FleeEntityGoalMixin method init.

@Inject(method = "<init>(Lnet/minecraft/entity/mob/PathAwareEntity;Ljava/lang/Class;Ljava/util/function/Predicate;FDDLjava/util/function/Predicate;)V", at = @At("RETURN"))
private void init(PathAwareEntity mob, Class<T> fleeFromType, Predicate<LivingEntity> predicate, float distance, double slowSpeed, double fastSpeed, Predicate<LivingEntity> predicate2, CallbackInfo ci) {
    EntityDimensions dimensions = this.mob.getType().getDimensions();
    double adjustedRange = dimensions.width * 0.5D + this.fleeDistance + 2D;
    int horizontalRange = MathHelper.ceil(adjustedRange);
    this.tracker = new NearbyEntityTracker<>(fleeFromType, mob, new Vec3i(horizontalRange, MathHelper.ceil(dimensions.height + 3 + 2), horizontalRange));
    ((NearbyEntityListenerProvider) mob).addListener(this.tracker);
}
Also used : EntityDimensions(net.minecraft.entity.EntityDimensions) Vec3i(net.minecraft.util.math.Vec3i) NearbyEntityListenerProvider(me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

NearbyEntityListenerProvider (me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerProvider)6 NearbyEntityListenerMulti (me.jellysquid.mods.lithium.common.entity.tracker.nearby.NearbyEntityListenerMulti)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 EntityDimensions (net.minecraft.entity.EntityDimensions)2 Vec3i (net.minecraft.util.math.Vec3i)2