use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by Minecolonies.
the class EntityAIConcreteMixer method mixConcrete.
/**
* Mix the concrete and mine it.
*
* @return next state.
*/
private IAIState mixConcrete() {
int slot = -1;
if (currentRequest != null && currentRecipeStorage != null) {
ItemStack inputStack = currentRecipeStorage.getCleanedInput().get(0).getItemStack();
if (CONCRETE.test(inputStack)) {
slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, inputStack));
} else {
return START_WORKING;
}
} else {
slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), CONCRETE);
}
if (slot != -1) {
final ItemStack stack = worker.getInventoryCitizen().getStackInSlot(slot);
final Block block = ((BlockItem) stack.getItem()).getBlock();
final BlockPos posToPlace = getOwnBuilding().getBlockToPlace();
if (posToPlace != null) {
if (walkToBlock(posToPlace)) {
walkTo = posToPlace;
return START_WORKING;
}
walkTo = null;
if (InventoryUtils.attemptReduceStackInItemHandler(worker.getInventoryCitizen(), stack, 1)) {
world.setBlock(posToPlace, block.defaultBlockState().updateShape(Direction.DOWN, block.defaultBlockState(), world, posToPlace, posToPlace), 0x03);
}
return START_WORKING;
}
}
final BlockPos pos = getOwnBuilding().getBlockToMine();
if (pos != null) {
if (walkToBlock(pos)) {
walkTo = pos;
return START_WORKING;
}
walkTo = null;
if (mineBlock(pos)) {
this.resetActionsDone();
return CRAFT;
}
return START_WORKING;
}
if (InventoryUtils.hasItemInItemHandler(getOwnBuilding().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), CONCRETE)) {
needsCurrently = new Tuple<>(CONCRETE, STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
} else {
incrementActionsDone();
}
return START_WORKING;
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by Minecolonies.
the class AbstractEntityAIUsesFurnace method startWorking.
/**
* Central method of the furnace user, he decides about what to do next from here. First check if any of the workers has important tasks to handle first. If not check if there
* is an oven with an item which has to be retrieved. If not check if fuel and smeltable are available and request if necessary and get into inventory. Then check if able to
* smelt already.
*
* @return the next state to go to.
*/
public IAIState startWorking() {
if (walkToBuilding()) {
return getState();
}
final FurnaceUserModule furnaceModule = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
final ItemListModule itemListModule = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
if (itemListModule.getList().isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FUEL), ChatPriority.BLOCKING));
}
return getState();
}
if (furnaceModule.getFurnaces().isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
}
return getState();
}
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_DECIDING));
final IAIState nextState = checkForImportantJobs();
if (nextState != START_WORKING) {
return nextState;
}
final BlockPos posOfUsedFuelOven = getPositionOfOvenToRetrieveFuelFrom();
if (posOfUsedFuelOven != null) {
walkTo = posOfUsedFuelOven;
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
return RETRIEVING_USED_FUEL_FROM_FURNACE;
}
final BlockPos posOfOven = getPositionOfOvenToRetrieveFrom();
if (posOfOven != null) {
walkTo = posOfOven;
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
return RETRIEVING_END_PRODUCT_FROM_FURNACE;
}
final int amountOfSmeltableInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), this::isSmeltable);
final int amountOfSmeltableInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), this::isSmeltable);
final int amountOfFuelInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), itemListModule.getList());
final int amountOfFuelInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), stack -> itemListModule.isItemInList(new ItemStorage(stack)));
if (amountOfSmeltableInBuilding + amountOfSmeltableInInv <= 0 && !reachedMaxToKeep()) {
requestSmeltable();
}
if (amountOfFuelInBuilding + amountOfFuelInInv <= 0 && !getOwnBuilding().hasWorkerOpenRequestsFiltered(worker.getCitizenData().getId(), req -> req.getShortDisplayString().getSiblings().contains(new TranslationTextComponent(COM_MINECOLONIES_REQUESTS_BURNABLE)))) {
worker.getCitizenData().createRequestAsync(new StackList(getAllowedFuel(), COM_MINECOLONIES_REQUESTS_BURNABLE, STACKSIZE * furnaceModule.getFurnaces().size(), 1));
}
if (amountOfSmeltableInBuilding > 0 && amountOfSmeltableInInv == 0) {
needsCurrently = new Tuple<>(this::isSmeltable, STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
} else if (amountOfFuelInBuilding > 0 && amountOfFuelInInv == 0) {
needsCurrently = new Tuple<>(stack -> itemListModule.isItemInList(new ItemStorage(stack)), STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
}
return checkIfAbleToSmelt(amountOfFuelInBuilding + amountOfFuelInInv, amountOfSmeltableInBuilding + amountOfSmeltableInInv);
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by Minecolonies.
the class EntityAIWorkBeekeeper method decideWhatToDo.
/**
* Decides what job the beekeeper should switch to, breeding or harvesting.
*
* @return The next {@link IAIState} the beekeeper should switch to, after executing this method.
*/
private IAIState decideWhatToDo() {
setDelay(DECIDING_DELAY + (99 / getSecondarySkillLevel() - 1));
final Set<BlockPos> hives = getOwnBuilding().getHives();
if (hives.isEmpty()) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_HIVES), ChatPriority.BLOCKING));
setDelay(NO_HIVES_DELAY);
return DECIDE;
}
ItemListModule flowersModule = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST));
if (flowersModule.getList().isEmpty()) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_BEEKEEPER_NOFLOWERS), ChatPriority.BLOCKING));
setDelay(NO_FLOWERS_DELAY);
return DECIDE;
}
for (BlockPos pos : hives) {
if (!(world.getBlockState(pos).getBlock() instanceof BeehiveBlock)) {
getOwnBuilding().removeHive(pos);
}
}
final Optional<BlockPos> hive = getOwnBuilding().getHives().stream().filter(pos -> BeehiveTileEntity.getHoneyLevel(world.getBlockState(pos)) >= 5).findFirst();
if (hive.isPresent()) {
return BEEKEEPER_HARVEST;
}
final List<BeeEntity> bees = new ArrayList<>(searchForAnimals(world, getOwnBuilding()));
final JobBeekeeper job = worker.getCitizenJobHandler().getColonyJob(JobBeekeeper.class);
if (bees.isEmpty()) {
if (getBeesInHives() <= 0) {
job.tickNoBees();
if (job.checkForBeeInteraction()) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_BEES), ChatPriority.BLOCKING));
}
} else {
job.resetCounter();
}
setDelay(NO_ANIMALS_DELAY);
return DECIDE;
} else {
job.resetCounter();
}
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_DECIDING));
final int breedableAnimals = (int) bees.stream().filter(animal -> animal.getAge() == 0).count();
final boolean hasBreedingItem = InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), (stack) -> flowersModule.isItemInList(new ItemStorage(stack)));
if (getOwnBuilding().getSetting(BuildingBeekeeper.BREEDING).getValue() && !hasMaxAnimals(bees) && breedableAnimals >= NUM_OF_ANIMALS_TO_BREED && hasBreedingItem) {
return HERDER_BREED;
}
return START_WORKING;
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by Minecolonies.
the class EntityAIWorkBeekeeper method prepareForHerding.
/**
* Prepares the beekeeper for herding
*
* @return The next {@link IAIState}.
*/
private IAIState prepareForHerding() {
setDelay(DECIDING_DELAY);
if (!getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEY)) {
if (checkForToolOrWeapon(ToolType.SHEARS)) {
return getState();
}
}
if (!getOwnBuilding().getHarvestTypes().equals(BuildingBeekeeper.HONEYCOMB)) {
checkIfRequestForItemExistOrCreateAsynch(new ItemStack(Items.GLASS_BOTTLE));
}
List<ItemStorage> allowedFlowers = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST)).getList();
;
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), (stack) -> allowedFlowers.contains(new ItemStorage(stack))) && InventoryUtils.getCountFromBuilding(getOwnBuilding(), allowedFlowers) == 0 && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class))) {
worker.getCitizenData().createRequestAsync(new StackList(allowedFlowers.stream().map((item) -> item.getItemStack()).peek((stack) -> stack.setCount(16)).collect(Collectors.toList()), COM_MINECOLONIES_COREMOD_REQUEST_FLOWERS, 16, 1));
}
return DECIDE;
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by Minecolonies.
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