use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.
the class EntityAIWorkNether method decide.
@Override
protected IAIState decide() {
if (job.isInNether()) {
if (!worker.isInvisible()) {
goToVault();
}
return NETHER_AWAY;
}
if (worker.isInvisible()) {
returnFromVault();
}
IAIState crafterState = super.decide();
if (crafterState != IDLE && crafterState != START_WORKING) {
return crafterState;
}
// Get Armor if available.
// This is async, so we could go to the nether without it.
checkAndRequestArmor();
// Check for materials needed to go to the Nether:
IRecipeStorage rs = getOwnBuilding().getFirstModuleOccurance(BuildingNetherWorker.CraftingModule.class).getFirstRecipe(ItemStack::isEmpty);
if (rs != null) {
for (ItemStorage item : rs.getInput()) {
checkAndRequestMaterials(item.getItemStack(), item.getAmount());
}
}
// Make sure we have a stash of some food
checkAndRequestFood(16);
// Get other adventuring supplies. These are required.
// Done this way to get all the requests in parallel
boolean haveAxe = checkForToolOrWeapon(ToolType.AXE);
boolean havePick = checkForToolOrWeapon(ToolType.PICKAXE);
boolean haveShovel = checkForToolOrWeapon(ToolType.SHOVEL);
boolean haveSword = checkForToolOrWeapon(ToolType.SWORD);
boolean haveLighter = checkForToolOrWeapon(ToolType.FLINT_N_STEEL);
if (haveAxe || havePick || haveShovel || haveSword || haveLighter) {
worker.getCitizenData().setIdleAtJob(true);
return IDLE;
}
if (currentRecipeStorage == null) {
final ICraftingBuildingModule module = getOwnBuilding().getFirstModuleOccurance(BuildingNetherWorker.CraftingModule.class);
currentRecipeStorage = module.getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
if (getOwnBuilding().isReadyForTrip()) {
worker.getCitizenData().setIdleAtJob(true);
}
final BlockPos portal = getOwnBuilding().getPortalLocation();
if (portal != null && currentRecipeStorage == null && getOwnBuilding().shallClosePortalOnReturn()) {
final BlockState block = world.getBlockState(portal);
if (block.is(Blocks.NETHER_PORTAL)) {
return NETHER_CLOSEPORTAL;
}
}
return getState();
} else {
if (!getOwnBuilding().isReadyForTrip()) {
worker.getCitizenData().setIdleAtJob(false);
return IDLE;
}
if (walkTo != null || walkToBuilding()) {
return getState();
}
if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
return INVENTORY_FULL;
}
IAIState checkResult = checkForItems(currentRecipeStorage);
if (checkResult == GET_RECIPE) {
currentRecipeStorage = null;
worker.getCitizenData().setIdleAtJob(true);
return IDLE;
}
if (checkResult != CRAFT) {
return checkResult;
}
}
return NETHER_LEAVE;
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.
the class EntityAIWorkShepherd method decideWhatToDo.
@Override
public IAIState decideWhatToDo() {
final IAIState result = super.decideWhatToDo();
final List<SheepEntity> animals = new ArrayList<>(searchForAnimals());
final SheepEntity shearingSheep = animals.stream().filter(sheepie -> !sheepie.isSheared() && !sheepie.isBaby()).findFirst().orElse(null);
if (getOwnBuilding().getSetting(BuildingShepherd.SHEARING).getValue() && result.equals(START_WORKING) && shearingSheep != null) {
return SHEPHERD_SHEAR;
}
return result;
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.
the class EntityAIWorkPlanter method decide.
@Override
protected IAIState decide() {
final IAIState nextState = super.decide();
if (nextState != START_WORKING && nextState != IDLE) {
return nextState;
}
final BuildingPlantation plantation = getOwnBuilding();
final List<BlockPos> list = plantation.getPosForPhase();
for (final BlockPos pos : list) {
if (isAtLeastThreeHigh(pos)) {
this.workPos = pos;
return PLANTATION_FARM;
}
}
final Item current = plantation.nextPlantPhase();
final int plantInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), itemStack -> itemStack.sameItem(new ItemStack(current)));
final int plantInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), itemStack -> itemStack.sameItem(new ItemStack(current)));
if (plantInBuilding + plantInInv <= 0) {
requestPlantable(current);
return START_WORKING;
}
if (plantInInv == 0 && plantInBuilding > 0) {
needsCurrently = new Tuple<>(itemStack -> itemStack.sameItem(new ItemStack(current)), Math.min(plantInBuilding, PLANT_TO_REQUEST));
return GATHERING_REQUIRED_MATERIALS;
}
for (final BlockPos pos : list) {
if (world.getBlockState(pos.above()).getBlock() instanceof AirBlock) {
this.workPos = pos;
return PLANTATION_PLANT;
}
}
return START_WORKING;
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.
the class AbstractEntityAIRequestSmelter method checkForItems.
@Override
protected IAIState checkForItems(@NotNull final IRecipeStorage storage) {
if (storage.getIntermediate() != Blocks.FURNACE) {
return super.checkForItems(storage);
}
final List<ItemStorage> input = storage.getCleanedInput();
final int countInFurnaces = getExtendedCount(storage.getPrimaryOutput());
int outputInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, storage.getPrimaryOutput()));
for (final ItemStorage inputStorage : input) {
final Predicate<ItemStack> predicate = stack -> !ItemStackUtils.isEmpty(stack) && ItemStackUtils.compareItemStacksIgnoreStackSize(stack, inputStorage.getItemStack());
int inputInFurnace = getExtendedCount(inputStorage.getItemStack());
int inputInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), predicate);
if (countInFurnaces + inputInFurnace + inputInInv + outputInInv < inputStorage.getAmount() * job.getMaxCraftingCount()) {
if (InventoryUtils.hasItemInProvider(getOwnBuilding(), predicate)) {
needsCurrently = new Tuple<>(predicate, inputStorage.getAmount() * (job.getMaxCraftingCount() - countInFurnaces - inputInFurnace));
return GATHERING_REQUIRED_MATERIALS;
}
}
// if we don't have enough at all, cancel
int countOfInput = inputInInv + InventoryUtils.getCountFromBuilding(getOwnBuilding(), predicate) + countInFurnaces + inputInFurnace + outputInInv;
if (countOfInput < inputStorage.getAmount() * job.getMaxCraftingCount()) {
job.finishRequest(false);
resetValues();
}
}
return CRAFT;
}
use of com.minecolonies.api.entity.ai.statemachine.states.IAIState in project minecolonies by ldtteam.
the class AbstractEntityAIRequestSmelter method getRecipe.
@Override
protected IAIState getRecipe() {
final IRequest<? extends PublicCrafting> currentTask = job.getCurrentTask();
if (currentTask == null) {
worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
return START_WORKING;
}
job.setMaxCraftingCount(currentTask.getRequest().getCount());
final BlockPos furnacePosWithUsedFuel = getPositionOfOvenToRetrieveFuelFrom();
if (furnacePosWithUsedFuel != null) {
currentRequest = currentTask;
walkTo = furnacePosWithUsedFuel;
return RETRIEVING_USED_FUEL_FROM_FURNACE;
}
final BlockPos furnacePos = getPositionOfOvenToRetrieveFrom();
if (furnacePos != null) {
currentRequest = currentTask;
walkTo = furnacePos;
return RETRIEVING_END_PRODUCT_FROM_FURNACE;
}
if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
for (final BlockPos pos : getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces()) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof FurnaceTileEntity) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
if (furnace.isLit() || !isEmpty(furnace.getItem(RESULT_SLOT)) || !isEmpty(furnace.getItem(SMELTABLE_SLOT))) {
if (furnace.isLit()) {
setDelay(TICKS_20);
}
return CRAFT;
}
}
}
}
final IAIState newState = super.getRecipe();
final ItemListModule module = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
// This should only happen in the stonesmelter, but it could potentially happen with multiple fuels.
if (newState == QUERY_ITEMS && currentRecipeStorage != null && module.isItemInList(new ItemStorage(currentRecipeStorage.getPrimaryOutput()))) {
job.setCraftCounter(0);
}
return newState;
}
Aggregations