use of pneumaticCraft.common.ai.DroneAIImExBase in project PneumaticCraft by MineMaarten.
the class ProgWidgetDropItem method getWidgetAI.
@Override
public EntityAIBase getWidgetAI(IDroneBase drone, IProgWidget widget) {
return new DroneAIImExBase(drone, (ProgWidgetAreaItemBase) widget) {
private final Set<ChunkPosition> visitedPositions = new HashSet<ChunkPosition>();
@Override
public boolean shouldExecute() {
boolean shouldExecute = false;
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
ItemStack stack = drone.getInventory().getStackInSlot(i);
if (stack != null && widget.isItemValidForFilters(stack)) {
shouldExecute = super.shouldExecute();
break;
}
}
return shouldExecute;
}
@Override
protected boolean moveIntoBlock() {
return true;
}
@Override
protected boolean isValidPosition(ChunkPosition pos) {
//another requirement is that the drone can navigate to this exact block, but that's handled by the pathfinder.
return !visitedPositions.contains(pos);
}
@Override
protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock) {
visitedPositions.add(pos);
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
ItemStack stack = drone.getInventory().getStackInSlot(i);
if (stack != null && widget.isItemValidForFilters(stack)) {
if (useCount() && getRemainingCount() < stack.stackSize) {
stack = stack.splitStack(getRemainingCount());
decreaseCount(getRemainingCount());
} else {
decreaseCount(stack.stackSize);
drone.getInventory().setInventorySlotContents(i, null);
}
EntityItem item = new EntityItem(drone.getWorld(), pos.chunkPosX + 0.5, pos.chunkPosY + 0.5, pos.chunkPosZ + 0.5, stack);
if (((IItemDropper) widget).dropStraight()) {
item.motionX = 0;
item.motionY = 0;
item.motionZ = 0;
}
drone.getWorld().spawnEntityInWorld(item);
if (useCount() && getRemainingCount() == 0)
break;
}
}
return false;
}
};
}
Aggregations