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