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));
}
}
}
}
}
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;
}
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));
}
}
}
Aggregations