Search in sources :

Example 51 with StandardInteraction

use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by ldtteam.

the class AbstractEntityAIUsesFurnace method fillUpFurnace.

/**
 * Smelt the smeltable after the required items are in the inv.
 *
 * @return the next state to go to.
 */
private IAIState fillUpFurnace() {
    if (getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces().isEmpty()) {
        if (worker.getCitizenData() != null) {
            worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
        }
        return START_WORKING;
    }
    if (walkTo == null || world.getBlockState(walkTo).getBlock() != Blocks.FURNACE) {
        walkTo = null;
        return START_WORKING;
    }
    if (walkToBlock(walkTo)) {
        return getState();
    }
    final TileEntity entity = world.getBlockEntity(walkTo);
    if (entity instanceof FurnaceTileEntity) {
        final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
        if (InventoryUtils.hasItemInItemHandler((worker.getInventoryCitizen()), this::isSmeltable) && (hasFuelInFurnaceAndNoSmeltable(furnace) || hasNeitherFuelNorSmeltAble(furnace))) {
            InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler((worker.getInventoryCitizen()), this::isSmeltable, STACKSIZE, new InvWrapper(furnace), SMELTABLE_SLOT);
        }
        final ItemListModule module = getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
        if (InventoryUtils.hasItemInItemHandler((worker.getInventoryCitizen()), stack -> module.isItemInList(new ItemStorage(stack))) && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace))) {
            InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler((worker.getInventoryCitizen()), stack -> module.isItemInList(new ItemStorage(stack)), STACKSIZE, new InvWrapper(furnace), FUEL_SLOT);
        }
    }
    walkTo = null;
    return START_WORKING;
}
Also used : FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) FurnaceUserModule(com.minecolonies.coremod.colony.buildings.modules.FurnaceUserModule) AbstractJob(com.minecolonies.coremod.colony.jobs.AbstractJob) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Tuple(com.minecolonies.api.util.Tuple) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) FUEL_LIST(com.minecolonies.api.util.constant.BuildingConstants.FUEL_LIST) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) Constants(com.minecolonies.api.util.constant.Constants) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AIEventTarget(com.minecolonies.api.entity.ai.statemachine.AIEventTarget) World(net.minecraft.world.World) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) AIBlockingEventType(com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Blocks(net.minecraft.block.Blocks) List(java.util.List) InventoryUtils(com.minecolonies.api.util.InventoryUtils) TileEntity(net.minecraft.tileentity.TileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) WorldUtil(com.minecolonies.api.util.WorldUtil) FurnaceBlock(net.minecraft.block.FurnaceBlock) NotNull(org.jetbrains.annotations.NotNull) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 52 with StandardInteraction

use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by ldtteam.

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 53 with StandardInteraction

use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by ldtteam.

the class EntityAIWorkCook method getSmeltAbleClass.

@Override
protected IRequestable getSmeltAbleClass() {
    final List<ItemStorage> blockedItems = new ArrayList<>(getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FOOD_EXCLUSION_LIST)).getList());
    for (final Map.Entry<ItemStorage, Integer> content : getOwnBuilding().getTileEntity().getAllContent().entrySet()) {
        if (content.getValue() > content.getKey().getItem().getMaxStackSize() * 6 && ItemStackUtils.CAN_EAT.test(content.getKey().getItemStack())) {
            blockedItems.add(content.getKey());
        }
    }
    blockedItems.removeIf(item -> item.getItem().getFoodProperties() == null || item.getItem().getFoodProperties().getNutrition() < getOwnBuilding().getBuildingLevel() - 1);
    if (!blockedItems.isEmpty()) {
        if (IColonyManager.getInstance().getCompatibilityManager().getEdibles(getOwnBuilding().getBuildingLevel() - 1).size() <= blockedItems.size()) {
            if (worker.getCitizenData() != null) {
                worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FOOD), ChatPriority.BLOCKING));
                return null;
            }
        }
        return new Food(STACKSIZE, blockedItems, getOwnBuilding().getBuildingLevel() - 1);
    }
    return new Food(STACKSIZE, getOwnBuilding().getBuildingLevel() - 1);
}
Also used : StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStorage(com.minecolonies.api.crafting.ItemStorage) Food(com.minecolonies.api.colony.requestsystem.requestable.Food)

Example 54 with StandardInteraction

use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by ldtteam.

the class EntityAIWorkDeliveryman method checkIfExecute.

/**
 * Check if the deliveryman code should be executed. More concretely if he has a warehouse to work at.
 *
 * @return false if should continue as planned.
 */
private boolean checkIfExecute() {
    final IWareHouse wareHouse = getAndCheckWareHouse();
    if (wareHouse != null) {
        worker.getCitizenData().setWorking(true);
        if (wareHouse.getTileEntity() == null) {
            return false;
        }
        {
            return true;
        }
    }
    worker.getCitizenData().setWorking(false);
    if (worker.getCitizenData() != null) {
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NOWAREHOUSE), ChatPriority.BLOCKING));
    }
    return false;
}
Also used : IWareHouse(com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Aggregations

StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)54 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)53 BlockPos (net.minecraft.util.math.BlockPos)26 ItemStack (net.minecraft.item.ItemStack)25 NotNull (org.jetbrains.annotations.NotNull)21 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)19 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)17 ItemStorage (com.minecolonies.api.crafting.ItemStorage)15 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)15 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)15 InventoryUtils (com.minecolonies.api.util.InventoryUtils)12 TypeToken (com.google.common.reflect.TypeToken)11 StackList (com.minecolonies.api.colony.requestsystem.requestable.StackList)11 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)11 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)11 Network (com.minecolonies.coremod.Network)11 Hand (net.minecraft.util.Hand)11 ICitizenData (com.minecolonies.api.colony.ICitizenData)10 ItemListModule (com.minecolonies.coremod.colony.buildings.modules.ItemListModule)10 TileEntity (net.minecraft.tileentity.TileEntity)9