use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.
the class EntityAIWorkCrusher method craft.
/**
* The actual crafting logic.
*
* @return the next state to go to.
*/
@Override
protected IAIState craft() {
if (currentRecipeStorage == null) {
return START_WORKING;
}
if (currentRequest == null && job.getCurrentTask() != null) {
return GET_RECIPE;
}
if (walkToBuilding()) {
return getState();
}
job.setProgress(job.getProgress() + 1);
worker.setItemInHand(Hand.MAIN_HAND, currentRecipeStorage.getCleanedInput().get(worker.getRandom().nextInt(currentRecipeStorage.getCleanedInput().size())).getItemStack().copy());
worker.setItemInHand(Hand.OFF_HAND, currentRecipeStorage.getPrimaryOutput().copy());
worker.getCitizenItemHandler().hitBlockWithToolInHand(getOwnBuilding().getPosition());
currentRequest = job.getCurrentTask();
if (currentRequest != null && (currentRequest.getState() == RequestState.CANCELLED || currentRequest.getState() == RequestState.FAILED)) {
currentRequest = null;
incrementActionsDone(getActionRewardForCraftingSuccess());
currentRecipeStorage = null;
return START_WORKING;
}
final IAIState check = crush();
if (check == getState()) {
if (job.getCraftCounter() >= job.getMaxCraftingCount()) {
incrementActionsDone(getActionRewardForCraftingSuccess());
currentRecipeStorage = null;
resetValues();
if (inventoryNeedsDump()) {
if (job.getMaxCraftingCount() == 0 && job.getProgress() == 0 && job.getCraftCounter() == 0 && currentRequest != null) {
job.finishRequest(true);
}
}
}
} else {
currentRequest = null;
job.finishRequest(false);
incrementActionsDoneAndDecSaturation();
resetValues();
}
return getState();
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState 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;
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.
the class EntityAIWorkFisherman method doFishing.
/**
* Main fishing methods, let's the fisherman gather xp orbs next to him, check if all requirements to fish are given. Actually fish, retrieve his rod if stuck or if a fish
* bites.
*
* @return the next IAIState the fisherman should switch to, after executing this method.
*/
@Nullable
private IAIState doFishing() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.fishing"));
@Nullable final IAIState notReadyState = isReadyToFish();
if (notReadyState != null) {
return notReadyState;
}
if (caughtFish()) {
playCaughtFishSound();
this.incrementActionsDoneAndDecSaturation();
if (worker.getRandom().nextDouble() < CHANCE_NEW_POND) {
job.setWater(null);
return FISHERMAN_SEARCHING_WATER;
}
return FISHERMAN_WALKING_TO_WATER;
}
return throwOrRetrieveHook();
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.
the class EntityAIWorkCowboy method decideWhatToDo.
@Override
public IAIState decideWhatToDo() {
final IAIState result = super.decideWhatToDo();
final BuildingCowboy building = getOwnBuilding();
final boolean hasBucket = InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), Items.BUCKET);
if (building != null && getOwnBuilding().getSetting(BuildingCowboy.MILKING).getValue() && result.equals(START_WORKING) && hasBucket) {
return COWBOY_MILK;
}
return result;
}
Aggregations