use of com.minecolonies.api.colony.requestsystem.requestable.StackList in project minecolonies by ldtteam.
the class EntityAIWorkFarmer method prepareForFarming.
/**
* Prepares the farmer for farming. Also requests the tools and checks if the farmer has sufficient fields.
*
* @return the next IAIState
*/
@NotNull
private IAIState prepareForFarming() {
@Nullable final BuildingFarmer building = getOwnBuilding();
if (building == null || building.getBuildingLevel() < 1) {
return PREPARING;
}
if (!job.getTaskQueue().isEmpty() || getActionsDoneUntilDumping() <= job.getActionsDone()) {
return START_WORKING;
}
worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
final FarmerFieldModule module = building.getFirstModuleOccurance(FarmerFieldModule.class);
module.syncWithColony(world);
if (module.getFarmerFields().size() < getOwnBuilding().getBuildingLevel() && !module.assignManually()) {
searchAndAddFields();
}
if (module.getFarmerFields().size() == getOwnBuilding().getMaxBuildingLevel()) {
AdvancementUtils.TriggerAdvancementPlayersForColony(building.getColony(), AdvancementTriggers.MAX_FIELDS::trigger);
}
final int amountOfCompostInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), this::isCompost);
final int amountOfCompostInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), this::isCompost);
if (amountOfCompostInBuilding + amountOfCompostInInv <= 0) {
if (getOwnBuilding().requestFertilizer() && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class))) {
final List<ItemStack> compostAbleItems = new ArrayList<>();
compostAbleItems.add(new ItemStack(ModItems.compost, 1));
compostAbleItems.add(new ItemStack(Items.BONE_MEAL, 1));
worker.getCitizenData().createRequestAsync(new StackList(compostAbleItems, FERTLIZER, STACKSIZE, 1));
}
} else if (amountOfCompostInInv <= 0 && amountOfCompostInBuilding > 0) {
needsCurrently = new Tuple<>(this::isCompost, STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
}
if (module.hasNoFields()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_FREE_FIELDS), ChatPriority.BLOCKING));
}
worker.getCitizenData().setIdleAtJob(true);
return PREPARING;
}
worker.getCitizenData().setIdleAtJob(false);
// If the farmer has no currentField and there is no field which needs work, check fields.
if (module.getCurrentField() == null && module.getFieldToWorkOn(world) == null) {
module.resetFields();
return IDLE;
}
@Nullable final BlockPos currentField = module.getCurrentField();
final TileEntity entity = world.getBlockEntity(currentField);
if (entity instanceof ScarecrowTileEntity && ((ScarecrowTileEntity) entity).needsWork()) {
if (((ScarecrowTileEntity) entity).getFieldStage() == ScarecrowFieldStage.PLANTED && checkIfShouldExecute((ScarecrowTileEntity) entity, this::shouldHarvest)) {
return FARMER_HARVEST;
} else if (((ScarecrowTileEntity) entity).getFieldStage() == ScarecrowFieldStage.HOED) {
return canGoPlanting((ScarecrowTileEntity) entity, building);
} else if (((ScarecrowTileEntity) entity).getFieldStage() == ScarecrowFieldStage.EMPTY && checkIfShouldExecute((ScarecrowTileEntity) entity, pos -> this.shouldHoe(pos, (ScarecrowTileEntity) entity))) {
return FARMER_HOE;
}
((ScarecrowTileEntity) entity).nextState();
} else {
module.setCurrentField(null);
}
return PREPARING;
}
use of com.minecolonies.api.colony.requestsystem.requestable.StackList in project minecolonies by ldtteam.
the class EntityAIWorkComposter method getMaterials.
/**
* Method for the AI to try to get the materials needed for the task he's doing. Will request if there are no materials
*
* @return the new IAIState after doing this
*/
private IAIState getMaterials() {
if (walkToBuilding()) {
setDelay(2);
return getState();
}
final List<ItemStorage> list = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(COMPOSTABLE_LIST)).getList();
if (list.isEmpty()) {
complain();
return getState();
}
if (InventoryUtils.hasItemInProvider(getOwnBuilding(), stack -> list.contains(new ItemStorage(stack)))) {
InventoryUtils.transferItemStackIntoNextFreeSlotFromProvider(getOwnBuilding(), InventoryUtils.findFirstSlotInProviderNotEmptyWith(getOwnBuilding(), stack -> list.contains(new ItemStorage(stack))), worker.getInventoryCitizen());
}
final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), stack -> list.contains(new ItemStorage(stack)));
if (slot >= 0) {
worker.setItemInHand(Hand.MAIN_HAND, worker.getInventoryCitizen().getStackInSlot(slot));
return START_WORKING;
}
worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
if (!getOwnBuilding().hasWorkerOpenRequests(worker.getCitizenData().getId())) {
final ArrayList<ItemStack> itemList = new ArrayList<>();
for (final ItemStorage item : list) {
final ItemStack itemStack = item.getItemStack();
itemStack.setCount(itemStack.getMaxStackSize());
itemList.add(itemStack);
}
if (!itemList.isEmpty()) {
worker.getCitizenData().createRequestAsync(new StackList(itemList, COM_MINECOLONIES_REQUESTS_COMPOSTABLE, Constants.STACKSIZE * getOwnBuilding().getBarrels().size(), 1, getOwnBuilding().getSetting(BuildingComposter.MIN).getValue()));
}
}
setDelay(2);
return START_WORKING;
}
Aggregations