Search in sources :

Example 1 with Agent

use of org.spongepowered.api.entity.living.Agent in project SpongeCommon by SpongePowered.

the class MixinEntityAITasks method removeTask.

/**
 * @author Zidane - November 30th, 2015
 * @reason Integrate Sponge events into the AI task removal.
 *
 * @param aiBase
 */
@SuppressWarnings({ "rawtypes" })
@Overwrite
public void removeTask(EntityAIBase aiBase) {
    final Iterator iterator = this.taskEntries.iterator();
    while (iterator.hasNext()) {
        final EntityAITasks.EntityAITaskEntry entityaitaskentry = (EntityAITasks.EntityAITaskEntry) iterator.next();
        final EntityAIBase otherAiBase = entityaitaskentry.action;
        // Sponge start
        if (otherAiBase.equals(aiBase)) {
            AITaskEvent.Remove event = null;
            if (ShouldFire.AI_TASK_EVENT_REMOVE && this.owner != null && !((IMixinEntity) this.owner).isInConstructPhase()) {
                event = SpongeEventFactory.createAITaskEventRemove(Sponge.getCauseStackManager().getCurrentCause(), (Goal) this, (Agent) this.owner, (AITask) otherAiBase, entityaitaskentry.priority);
                SpongeImpl.postEvent(event);
            }
            if (event == null || !event.isCancelled()) {
                if (entityaitaskentry.using) {
                    entityaitaskentry.using = false;
                    otherAiBase.resetTask();
                    this.executingTaskEntries.remove(entityaitaskentry);
                }
                iterator.remove();
                return;
            }
        }
    // Sponge end
    }
}
Also used : Agent(org.spongepowered.api.entity.living.Agent) AITaskEvent(org.spongepowered.api.event.entity.ai.AITaskEvent) Goal(org.spongepowered.api.entity.ai.Goal) IMixinEntityAIBase(org.spongepowered.common.interfaces.ai.IMixinEntityAIBase) EntityAIBase(net.minecraft.entity.ai.EntityAIBase) Iterator(java.util.Iterator) EntityAITasks(net.minecraft.entity.ai.EntityAITasks) IMixinEntityAITasks(org.spongepowered.common.interfaces.ai.IMixinEntityAITasks) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) AITask(org.spongepowered.api.entity.ai.task.AITask) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with Agent

use of org.spongepowered.api.entity.living.Agent in project AdamantineShield by Karanum.

the class EntityBlockChangeListener method onBlockPlace.

// @Listener(order = Order.POST)
// public void onTileEntityBlockPlace(ChangeBlockEvent.Place e, @Root TileEntity te) {
// System.out.println("PLACE EVENT:");
// long time = new Date().getTime();
// for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
// BlockType orig = transaction.getOriginal().getState().getType();
// BlockType result = transaction.getFinal().getState().getType();
// if (orig != BlockTypes.AIR && !technicalBlocks.contains(orig)) {
// System.out.println(transaction);
// //db.addToQueue(new BlockQueueEntry(transaction.getOriginal(), ActionType.MOB_DESTROY, te.getType().getName(), time));
// }
// if (!technicalBlocks.contains(result))
// System.out.println(transaction);
// //db.addToQueue(new BlockQueueEntry(transaction.getFinal(), ActionType.MOB_PLACE, te.getType().getName(), time));
// }
// }
// 
// @Listener(order = Order.POST)
// public void onTileEntityBlockBreak(ChangeBlockEvent.Break e, @Root TileEntity te) {
// System.out.println("BREAK EVENT:");
// long time = new Date().getTime();
// for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
// if (technicalBlocks.contains(transaction.getOriginal().getState().getType()))
// return;
// System.out.println(transaction);
// //db.addToQueue(new BlockQueueEntry(transaction.getOriginal(), ActionType.MOB_PLACE, te.getType().getName(), time));
// }
// }
@Listener(order = Order.POST)
public void onBlockPlace(ChangeBlockEvent.Place e, @Root Entity ent) {
    if (ent instanceof Player || ent instanceof Agent)
        return;
    long time = new Date().getTime();
    for (Transaction<BlockSnapshot> transaction : e.getTransactions()) {
        String name = ent.getType().getName();
        if (transaction.getOriginal().getState().getType() != BlockTypes.AIR) {
            db.addToQueue(new BlockQueueEntry(transaction.getOriginal(), ActionType.MOB_DESTROY, name, time));
        }
        db.addToQueue(new BlockQueueEntry(transaction.getFinal(), ActionType.MOB_PLACE, name, time));
    }
}
Also used : Agent(org.spongepowered.api.entity.living.Agent) Player(org.spongepowered.api.entity.living.player.Player) BlockQueueEntry(com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Date(java.util.Date) Listener(org.spongepowered.api.event.Listener)

Example 3 with Agent

use of org.spongepowered.api.entity.living.Agent in project SpongeAPI by SpongePowered.

the class SpongeAITaskEventTest method testAITaskEventRemove_invalidTargetAgentAndGoalOwner.

@Test(expected = IllegalArgumentException.class)
public void testAITaskEventRemove_invalidTargetAgentAndGoalOwner() {
    Agent targetEntity = mock(Agent.class);
    Agent secondEntity = mock(Agent.class);
    Goal goal = mock(Goal.class);
    Mockito.when(goal.getOwner()).thenReturn(secondEntity);
    SpongeEventFactory.createAITaskEventRemove(Cause.of(EventContext.empty(), mock(Game.class)), goal, targetEntity, mock(AITask.class), 0);
}
Also used : Agent(org.spongepowered.api.entity.living.Agent) Goal(org.spongepowered.api.entity.ai.Goal) AITask(org.spongepowered.api.entity.ai.task.AITask) Test(org.junit.Test)

Example 4 with Agent

use of org.spongepowered.api.entity.living.Agent in project SpongeAPI by SpongePowered.

the class SpongeAITaskEventTest method testAITaskEventAdd_invalidTargetAgentAndGoalOwner.

@Test(expected = IllegalArgumentException.class)
public void testAITaskEventAdd_invalidTargetAgentAndGoalOwner() {
    Agent targetEntity = mock(Agent.class);
    Agent secondEntity = mock(Agent.class);
    Goal goal = mock(Goal.class);
    Mockito.when(goal.getOwner()).thenReturn(secondEntity);
    SpongeEventFactory.createAITaskEventAdd(Cause.of(EventContext.empty(), mock(Game.class)), 0, 0, goal, targetEntity, mock(AITask.class));
}
Also used : Agent(org.spongepowered.api.entity.living.Agent) Goal(org.spongepowered.api.entity.ai.Goal) AITask(org.spongepowered.api.entity.ai.task.AITask) Test(org.junit.Test)

Example 5 with Agent

use of org.spongepowered.api.entity.living.Agent in project SpongeAPI by SpongePowered.

the class SpongeAITaskEventTest method testValidTargetAgentAndGoalOwner.

@Test
public void testValidTargetAgentAndGoalOwner() {
    Agent targetEntity = mock(Agent.class);
    Goal goal = mock(Goal.class);
    Mockito.when(goal.getOwner()).thenReturn(targetEntity);
    SpongeEventFactory.createAITaskEventAdd(Cause.of(EventContext.empty(), mock(Game.class)), 0, 0, goal, targetEntity, mock(AITask.class));
    SpongeEventFactory.createAITaskEventRemove(Cause.of(EventContext.empty(), mock(Game.class)), goal, targetEntity, mock(AITask.class), 0);
}
Also used : Agent(org.spongepowered.api.entity.living.Agent) Goal(org.spongepowered.api.entity.ai.Goal) AITask(org.spongepowered.api.entity.ai.task.AITask) Test(org.junit.Test)

Aggregations

Agent (org.spongepowered.api.entity.living.Agent)6 AITask (org.spongepowered.api.entity.ai.task.AITask)5 Goal (org.spongepowered.api.entity.ai.Goal)4 Test (org.junit.Test)3 IMixinEntityAIBase (org.spongepowered.common.interfaces.ai.IMixinEntityAIBase)2 BlockQueueEntry (com.karanumcoding.adamantineshield.db.queue.BlockQueueEntry)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 EntityAIBase (net.minecraft.entity.ai.EntityAIBase)1 EntityAITasks (net.minecraft.entity.ai.EntityAITasks)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 AITaskType (org.spongepowered.api.entity.ai.task.AITaskType)1 AbstractAITask (org.spongepowered.api.entity.ai.task.AbstractAITask)1 Player (org.spongepowered.api.entity.living.player.Player)1 Listener (org.spongepowered.api.event.Listener)1 AITaskEvent (org.spongepowered.api.event.entity.ai.AITaskEvent)1 PluginContainer (org.spongepowered.api.plugin.PluginContainer)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 IMixinEntityAITasks (org.spongepowered.common.interfaces.ai.IMixinEntityAITasks)1