Search in sources :

Example 1 with StackList

use of com.minecolonies.api.colony.requestsystem.requestable.StackList 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);
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStorage(com.minecolonies.api.crafting.ItemStorage) Tuple(com.minecolonies.api.util.Tuple) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 2 with StackList

use of com.minecolonies.api.colony.requestsystem.requestable.StackList 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;
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) BeeEntity(net.minecraft.entity.passive.BeeEntity) BeehiveBlock(net.minecraft.block.BeehiveBlock) java.util(java.util) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) Item(net.minecraft.item.Item) BuildingBeekeeper(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Compatibility(com.minecolonies.api.compatibility.Compatibility) BUILDING_FLOWER_LIST(com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST) TypeToken(com.google.common.reflect.TypeToken) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockTags(net.minecraft.tags.BlockTags) BeehiveTileEntity(net.minecraft.tileentity.BeehiveTileEntity) JobBeekeeper(com.minecolonies.coremod.colony.jobs.JobBeekeeper) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) Entity(net.minecraft.entity.Entity) ItemTags(net.minecraft.tags.ItemTags) TOOL_LEVEL_WOOD_OR_GOLD(com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD) World(net.minecraft.world.World) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Collectors(java.util.stream.Collectors) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ToolType(com.minecolonies.api.util.constant.ToolType) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) BlockStateProperties(net.minecraft.state.properties.BlockStateProperties) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 3 with StackList

use of com.minecolonies.api.colony.requestsystem.requestable.StackList in project minecolonies by ldtteam.

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;
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) BeeEntity(net.minecraft.entity.passive.BeeEntity) BeehiveBlock(net.minecraft.block.BeehiveBlock) java.util(java.util) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) Item(net.minecraft.item.Item) BuildingBeekeeper(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Compatibility(com.minecolonies.api.compatibility.Compatibility) BUILDING_FLOWER_LIST(com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST) TypeToken(com.google.common.reflect.TypeToken) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockTags(net.minecraft.tags.BlockTags) BeehiveTileEntity(net.minecraft.tileentity.BeehiveTileEntity) JobBeekeeper(com.minecolonies.coremod.colony.jobs.JobBeekeeper) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) Entity(net.minecraft.entity.Entity) ItemTags(net.minecraft.tags.ItemTags) TOOL_LEVEL_WOOD_OR_GOLD(com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD) World(net.minecraft.world.World) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Collectors(java.util.stream.Collectors) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ToolType(com.minecolonies.api.util.constant.ToolType) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) BlockStateProperties(net.minecraft.state.properties.BlockStateProperties) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 4 with StackList

use of com.minecolonies.api.colony.requestsystem.requestable.StackList in project minecolonies by ldtteam.

the class AbstractEntityAIRequestSmelter method checkFurnaceFuel.

/**
 * Check Fuel levels in the furnace
 */
private IAIState checkFurnaceFuel() {
    final World world = getOwnBuilding().getColony().getWorld();
    final List<ItemStack> possibleFuels = getActivePossibleFuels();
    final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels)) && !InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels)) && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
        worker.getCitizenData().createRequestAsync(new StackList(possibleFuels, COM_MINECOLONIES_REQUESTS_BURNABLE, STACKSIZE * module.getFurnaces().size(), 1));
        return getState();
    }
    for (final BlockPos pos : module.getFurnaces()) {
        if (WorldUtil.isBlockLoaded(world, pos)) {
            final TileEntity entity = world.getBlockEntity(pos);
            if (entity instanceof FurnaceTileEntity) {
                final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
                if (!furnace.isLit() && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
                    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels))) {
                        if (InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels))) {
                            needsCurrently = new Tuple<>(isCorrectFuel(possibleFuels), STACKSIZE);
                            // This could be set to a furnace at this point, and gathering requires it to be null, to find the right rack
                            walkTo = null;
                            return GATHERING_REQUIRED_MATERIALS;
                        }
                        // We need to wait for Fuel to arrive
                        return getState();
                    }
                    fuelPos = pos;
                    if (preFuelState == null) {
                        preFuelState = getState();
                    }
                    return ADD_FUEL_TO_FURNACE;
                }
            }
        }
    }
    return getState();
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Example 5 with StackList

use of com.minecolonies.api.colony.requestsystem.requestable.StackList in project minecolonies by Minecolonies.

the class AbstractEntityAIRequestSmelter method checkFurnaceFuel.

/**
 * Check Fuel levels in the furnace
 */
private IAIState checkFurnaceFuel() {
    final World world = getOwnBuilding().getColony().getWorld();
    final List<ItemStack> possibleFuels = getActivePossibleFuels();
    final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels)) && !InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels)) && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(StackList.class)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
        worker.getCitizenData().createRequestAsync(new StackList(possibleFuels, COM_MINECOLONIES_REQUESTS_BURNABLE, STACKSIZE * module.getFurnaces().size(), 1));
        return getState();
    }
    for (final BlockPos pos : module.getFurnaces()) {
        if (WorldUtil.isBlockLoaded(world, pos)) {
            final TileEntity entity = world.getBlockEntity(pos);
            if (entity instanceof FurnaceTileEntity) {
                final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
                if (!furnace.isLit() && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace)) && currentRecipeStorage != null && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
                    if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), isCorrectFuel(possibleFuels))) {
                        if (InventoryUtils.hasItemInProvider(getOwnBuilding(), isCorrectFuel(possibleFuels))) {
                            needsCurrently = new Tuple<>(isCorrectFuel(possibleFuels), STACKSIZE);
                            // This could be set to a furnace at this point, and gathering requires it to be null, to find the right rack
                            walkTo = null;
                            return GATHERING_REQUIRED_MATERIALS;
                        }
                        // We need to wait for Fuel to arrive
                        return getState();
                    }
                    fuelPos = pos;
                    if (preFuelState == null) {
                        preFuelState = getState();
                    }
                    return ADD_FUEL_TO_FURNACE;
                }
            }
        }
    }
    return getState();
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule)

Aggregations

StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)12 BlockPos (net.minecraft.util.math.BlockPos)11 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)9 ItemStack (net.minecraft.item.ItemStack)8 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)8 ItemStorage (com.minecolonies.api.crafting.ItemStorage)7 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)7 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)7 InventoryUtils (com.minecolonies.api.util.InventoryUtils)7 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)7 ItemListModule (com.minecolonies.coremod.colony.buildings.modules.ItemListModule)7 NotNull (org.jetbrains.annotations.NotNull)7 TICKS_SECOND (com.minecolonies.api.util.constant.Constants.TICKS_SECOND)6 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)6 StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)6 Hand (net.minecraft.util.Hand)6 World (net.minecraft.world.World)6 TypeToken (com.google.common.reflect.TypeToken)5 ToolType (com.minecolonies.api.util.constant.ToolType)5 TileEntity (net.minecraft.tileentity.TileEntity)5