Search in sources :

Example 1 with SetAITargetEvent

use of org.spongepowered.api.event.entity.ai.SetAITargetEvent in project SpongeCommon by SpongePowered.

the class MixinEntityLiving method onSetAttackTarget.

/**
 * @author gabizou - January 4th, 2016
 *
 * This is to instill the check that if the entity is vanish, check whether they're untargetable
 * as well.
 *
 * @param entitylivingbaseIn The entity living base coming in
 */
@Inject(method = "setAttackTarget", at = @At("HEAD"), cancellable = true)
private void onSetAttackTarget(@Nullable EntityLivingBase entitylivingbaseIn, CallbackInfo ci) {
    if (!this.world.isRemote && ShouldFire.SET_A_I_TARGET_EVENT) {
        if (entitylivingbaseIn != null) {
            if (((IMixinEntity) entitylivingbaseIn).isVanished() && ((IMixinEntity) entitylivingbaseIn).isUntargetable()) {
                this.attackTarget = null;
                ci.cancel();
            } else {
                SetAITargetEvent event = SpongeCommonEventFactory.callSetAttackTargetEvent((Entity) entitylivingbaseIn, this);
                if (event.isCancelled()) {
                    ci.cancel();
                } else {
                    this.attackTarget = ((EntityLivingBase) event.getTarget().orElse(null));
                }
            }
        }
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) SetAITargetEvent(org.spongepowered.api.event.entity.ai.SetAITargetEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with SetAITargetEvent

use of org.spongepowered.api.event.entity.ai.SetAITargetEvent in project SpongeCommon by SpongePowered.

the class SpongeCommonEventFactory method callSetAttackTargetEvent.

public static SetAITargetEvent callSetAttackTargetEvent(@Nullable final Entity target, final Agent agent) {
    final SetAITargetEvent event = SpongeEventFactory.createSetAITargetEvent(PhaseTracker.getCauseStackManager().currentCause(), agent, Optional.ofNullable(target));
    SpongeCommon.post(event);
    return event;
}
Also used : SetAITargetEvent(org.spongepowered.api.event.entity.ai.SetAITargetEvent)

Example 3 with SetAITargetEvent

use of org.spongepowered.api.event.entity.ai.SetAITargetEvent in project SpongeCommon by SpongePowered.

the class MobMixin method onSetAttackTarget.

/**
 * @author gabizou - January 4th, 2016
 *
 * This is to instill the check that if the entity is vanish, check whether they're untargetable
 * as well.
 *
 * @param entitylivingbaseIn The entity living base coming in
 */
@Inject(method = "setTarget", at = @At("HEAD"), cancellable = true)
private void onSetAttackTarget(@Nullable final LivingEntity entitylivingbaseIn, final CallbackInfo ci) {
    if (this.level.isClientSide || entitylivingbaseIn == null) {
        return;
    }
    // noinspection ConstantConditions
    if (EntityUtil.isUntargetable((net.minecraft.world.entity.Entity) (Object) this, entitylivingbaseIn)) {
        this.target = null;
        ci.cancel();
        return;
    }
    if (ShouldFire.SET_A_I_TARGET_EVENT) {
        final SetAITargetEvent event = SpongeCommonEventFactory.callSetAttackTargetEvent((Entity) entitylivingbaseIn, (Agent) this);
        if (event.isCancelled()) {
            ci.cancel();
        } else {
            this.target = ((LivingEntity) event.target().orElse(null));
        }
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) SetAITargetEvent(org.spongepowered.api.event.entity.ai.SetAITargetEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

SetAITargetEvent (org.spongepowered.api.event.entity.ai.SetAITargetEvent)3 Inject (org.spongepowered.asm.mixin.injection.Inject)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1