Search in sources :

Example 1 with GoalBridge

use of org.spongepowered.common.bridge.world.entity.ai.GoalBridge in project SpongeCommon by SpongePowered.

the class GoalSelectorMixin method onAddEntityTask.

/**
 * @author gabizou - February 1st, 2016
 *
 * Purpose: Rewrites the overwrite to use a redirect when an entry is being added
 * to the task entries. We throw an event for plugins to potentially cancel.
 */
@Redirect(method = "addGoal", at = @At(value = "INVOKE", target = "Ljava/util/Set;add(Ljava/lang/Object;)Z", remap = false))
private boolean onAddEntityTask(final Set<WrappedGoal> goals, final Object task, final int priority, final Goal base) {
    ((GoalBridge) base).bridge$setGoalExecutor((GoalExecutor<?>) this);
    if (!ShouldFire.GOAL_EVENT_ADD || this.owner == null || ((EntityBridge) this.owner).bridge$isConstructing()) {
        // Event is fired in bridge$fireConstructors
        return goals.add(new WrappedGoal(priority, base));
    }
    final GoalEvent.Add event = SpongeEventFactory.createGoalEventAdd(PhaseTracker.getCauseStackManager().currentCause(), priority, priority, (Agent) this.owner, (GoalExecutor<?>) this, (org.spongepowered.api.entity.ai.goal.Goal<?>) base);
    SpongeCommon.post(event);
    if (event.isCancelled()) {
        ((GoalBridge) base).bridge$setGoalExecutor(null);
        return false;
    }
    return goals.add(new WrappedGoal(event.priority(), base));
}
Also used : GoalBridge(org.spongepowered.common.bridge.world.entity.ai.GoalBridge) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal) GoalEvent(org.spongepowered.api.event.entity.ai.goal.GoalEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

WrappedGoal (net.minecraft.world.entity.ai.goal.WrappedGoal)1 GoalEvent (org.spongepowered.api.event.entity.ai.goal.GoalEvent)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 GoalBridge (org.spongepowered.common.bridge.world.entity.ai.GoalBridge)1