Search in sources :

Example 6 with StackList

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

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;
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) Random(java.util.Random) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) JobComposter(com.minecolonies.coremod.colony.jobs.JobComposter) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) Constants(com.minecolonies.api.util.constant.Constants) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) BuildingComposter(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingComposter) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AIEventTarget(com.minecolonies.api.entity.ai.statemachine.AIEventTarget) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) AIBlockingEventType(com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType) BlockPos(net.minecraft.util.math.BlockPos) DOUBLE(com.minecolonies.api.util.constant.Constants.DOUBLE) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Blocks(net.minecraft.block.Blocks) List(java.util.List) MineColonies(com.minecolonies.coremod.MineColonies) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntityBarrel(com.minecolonies.coremod.tileentities.TileEntityBarrel) TileEntity(net.minecraft.tileentity.TileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) WorldUtil(com.minecolonies.api.util.WorldUtil) NotNull(org.jetbrains.annotations.NotNull) PODZOL_CHANCE(com.minecolonies.api.research.util.ResearchConstants.PODZOL_CHANCE) ArrayList(java.util.ArrayList) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 7 with StackList

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

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;
}
Also used : Tags(net.minecraftforge.common.Tags) ServerWorld(net.minecraft.world.server.ServerWorld) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) Item(net.minecraft.item.Item) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) Compatibility(com.minecolonies.api.compatibility.Compatibility) AdvancementUtils(com.minecolonies.coremod.util.AdvancementUtils) Direction(net.minecraft.util.Direction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) PacketDistributor(net.minecraftforge.fml.network.PacketDistributor) Tuple(com.minecolonies.api.util.Tuple) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) ModItems(com.minecolonies.api.items.ModItems) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) Network(com.minecolonies.coremod.Network) NonNullList(net.minecraft.util.NonNullList) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) Constants(com.minecolonies.api.util.constant.Constants) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) STACKSIZE(com.minecolonies.api.util.constant.Constants.STACKSIZE) TOOL_LEVEL_WOOD_OR_GOLD(com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD) JobFarmer(com.minecolonies.coremod.colony.jobs.JobFarmer) Predicate(java.util.function.Predicate) LootParameters(net.minecraft.loot.LootParameters) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) CompostParticleMessage(com.minecolonies.coremod.network.messages.client.CompostParticleMessage) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) List(java.util.List) BlockItem(net.minecraft.item.BlockItem) BlockScarecrow(com.minecolonies.coremod.blocks.BlockScarecrow) NotNull(org.jetbrains.annotations.NotNull) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) BLOCK_BREAK_SOUND_RANGE(com.minecolonies.api.util.constant.CitizenConstants.BLOCK_BREAK_SOUND_RANGE) BuildingFarmer(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingFarmer) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) TypeToken(com.google.common.reflect.TypeToken) PosBasedInteraction(com.minecolonies.coremod.colony.interactionhandling.PosBasedInteraction) ArrayList(java.util.ArrayList) ScarecrowFieldStage(com.minecolonies.api.tileentities.ScarecrowFieldStage) ItemStack(net.minecraft.item.ItemStack) LootContext(net.minecraft.loot.LootContext) net.minecraft.block(net.minecraft.block) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) Hand(net.minecraft.util.Hand) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) FARMING(com.minecolonies.api.research.util.ResearchConstants.FARMING) AdvancementTriggers(com.minecolonies.api.advancements.AdvancementTriggers) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) TileEntity(net.minecraft.tileentity.TileEntity) ToolType(com.minecolonies.api.util.constant.ToolType) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) ArrayList(java.util.ArrayList) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) BuildingFarmer(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingFarmer) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Tuple(com.minecolonies.api.util.Tuple) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with StackList

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

the class EntityAIWorkNether method checkAndRequestFood.

/**
 * Check if we need to request food, and do so if necessary.
 */
protected void checkAndRequestFood(int itemCount) {
    List<ItemStack> edibleList = getEdiblesList();
    final IDeliverable edible = new StackList(edibleList, "Edible Food", itemCount);
    List<ItemStack> foodInInv = InventoryUtils.getContainedFromItemHandler(edibleList, worker.getItemHandlerCitizen());
    double availSaturation = 0;
    for (ItemStack item : foodInInv) {
        // Figure out what the total saturation value of the stack is
        final Food itemFood = item.getItem().getFoodProperties();
        final double satIncrease = itemFood.getNutrition() * (1.0 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATURATION)) * item.getCount();
        // update the running total
        availSaturation += satIncrease;
    }
    if (availSaturation >= AVERAGE_SATURATION) {
        return;
    }
    if (InventoryUtils.getItemCountInProvider(getOwnBuilding(), item -> edible.matches(item)) < itemCount) {
        if (!getOwnBuilding().hasWorkerOpenRequestsOfType(-1, TypeToken.of(edible.getClass())) && !getOwnBuilding().hasWorkerOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(edible.getClass()))) {
            getOwnBuilding().createRequest(edible, true);
        }
    } else {
        int amountToTransfer = (int) (AVERAGE_SATURATION - availSaturation);
        InventoryUtils.transferFoodUpToSaturation(getOwnBuilding(), worker.getInventoryCitizen(), amountToTransfer, edible::matches);
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) IItemHandler(net.minecraftforge.items.IItemHandler) JobNetherWorker(com.minecolonies.coremod.colony.jobs.JobNetherWorker) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ScoreObjective(net.minecraft.scoreboard.ScoreObjective) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) CompoundNBT(net.minecraft.nbt.CompoundNBT) ToolLevelConstants(com.minecolonies.api.util.constant.ToolLevelConstants) GuardConstants(com.minecolonies.api.util.constant.GuardConstants) Direction(net.minecraft.util.Direction) Block(net.minecraft.block.Block) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) RenderType(net.minecraft.scoreboard.ScoreCriteria.RenderType) ResearchConstants(com.minecolonies.api.research.util.ResearchConstants) StringTextComponent(net.minecraft.util.text.StringTextComponent) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) EntityUtils(com.minecolonies.api.util.EntityUtils) BlockState(net.minecraft.block.BlockState) CitizenConstants(com.minecolonies.api.util.constant.CitizenConstants) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) BuildingNetherWorker(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingNetherWorker) LivingEntity(net.minecraft.entity.LivingEntity) Predicate(java.util.function.Predicate) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) net.minecraft.item(net.minecraft.item) GuardGearBuilder(com.minecolonies.api.entity.ai.citizen.guards.GuardGearBuilder) Collectors(java.util.stream.Collectors) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) FOOD_EXCLUSION_LIST(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingNetherWorker.FOOD_EXCLUSION_LIST) java.util(java.util) LootTable(net.minecraft.loot.LootTable) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) ICitizenData(com.minecolonies.api.colony.ICitizenData) TypeToken(com.google.common.reflect.TypeToken) LootContext(net.minecraft.loot.LootContext) ImmutableList(com.google.common.collect.ImmutableList) Score(net.minecraft.scoreboard.Score) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) IColonyManager(com.minecolonies.api.colony.IColonyManager) ItemAdventureToken(com.minecolonies.coremod.items.ItemAdventureToken) BlockPos(net.minecraft.util.math.BlockPos) PortalSize(net.minecraft.block.PortalSize) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) DamageSource(net.minecraft.util.DamageSource) Blocks(net.minecraft.block.Blocks) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) MathHelper(net.minecraft.util.math.MathHelper) InventoryUtils(com.minecolonies.api.util.InventoryUtils) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) TinkersToolHelper(com.minecolonies.api.compatibility.tinkers.TinkersToolHelper) ToolType(com.minecolonies.api.util.constant.ToolType) ScoreCriteria(net.minecraft.scoreboard.ScoreCriteria) GuardGear(com.minecolonies.api.entity.ai.citizen.guards.GuardGear) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)

Example 9 with StackList

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

the class EntityAIWorkNether method attemptToEat.

/**
 * Attempt to eat to restore some saturation
 */
protected void attemptToEat() {
    final IDeliverable edible = new StackList(getEdiblesList(), "Edible Food", 1);
    final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(worker, edible::matches);
    final ICitizenData citizenData = worker.getCitizenData();
    if (slot > -1) {
        final ItemStack stack = worker.getInventoryCitizen().getStackInSlot(slot);
        final Food itemFood = stack.getItem().getFoodProperties();
        final double satIncrease = itemFood.getNutrition() * (1.0 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATURATION));
        citizenData.increaseSaturation(satIncrease / 2.0);
        citizenData.getInventory().extractItem(slot, 1, false);
        final ItemStack containerItem = stack.getContainerItem();
        if (containerItem != null && !(containerItem.getItem() instanceof AirItem)) {
            if (citizenData.getInventory().isFull()) {
                InventoryUtils.spawnItemStack(worker.level, worker.getX(), worker.getY(), worker.getZ(), containerItem);
            } else {
                InventoryUtils.addItemStackToItemHandler(worker.getItemHandlerCitizen(), containerItem);
            }
        }
    }
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)

Example 10 with StackList

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

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)

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