Search in sources :

Example 1 with ITEM_HANDLER_CAPABILITY

use of net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY in project minecolonies by Minecolonies.

the class BuildingResourcesModule method updateAvailableResources.

/**
 * Update the available resources.
 * <p>
 * which are needed for the build and in the structureBuilder's chest or inventory
 */
private void updateAvailableResources() {
    final Set<ICitizenData> set = building.getAllAssignedCitizen();
    final ICitizenData data = set.isEmpty() ? null : set.iterator().next();
    if (data == null) {
        return;
    }
    data.getEntity().ifPresent(structureBuilder -> {
        final InventoryCitizen structureBuilderInventory = data.getInventory();
        if (structureBuilderInventory == null) {
            return;
        }
        for (@NotNull final Map.Entry<String, BuildingBuilderResource> entry : neededResources.entrySet()) {
            final BuildingBuilderResource resource = entry.getValue();
            resource.setAvailable(0);
            if (structureBuilderInventory != null) {
                resource.addAvailable(InventoryUtils.getItemCountInItemHandler(structureBuilderInventory, stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack(), true, true)));
            }
            if (building.getTileEntity() != null) {
                resource.addAvailable(InventoryUtils.getItemCountInItemHandler(building.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack(), true, true)));
            }
            if (data.getJob() instanceof IJobWithExternalWorkStations) {
                for (final IBuilding station : ((IJobWithExternalWorkStations) data.getJob()).getWorkStations()) {
                    resource.addAvailable(InventoryUtils.getItemCountInItemHandler(station.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack(), true, true)));
                }
            }
        }
    });
}
Also used : AbstractBuildingModule(com.minecolonies.api.colony.buildings.modules.AbstractBuildingModule) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) BuilderBucket(com.minecolonies.coremod.colony.buildings.utils.BuilderBucket) java.util(java.util) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) TypeToken(com.google.common.reflect.TypeToken) ItemStack(net.minecraft.item.ItemStack) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ImmutableList(com.google.common.collect.ImmutableList) TAG_CURR_STAGE(com.minecolonies.api.util.constant.NbtTagConstants.TAG_CURR_STAGE) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) TAG_TOTAL_STAGES(com.minecolonies.api.util.constant.NbtTagConstants.TAG_TOTAL_STAGES) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) IPersistentModule(com.minecolonies.api.colony.buildings.modules.IPersistentModule) Nullable(org.jetbrains.annotations.Nullable) IJobWithExternalWorkStations(com.minecolonies.api.colony.jobs.IJobWithExternalWorkStations) InventoryCitizen(com.minecolonies.api.inventory.InventoryCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryUtils(com.minecolonies.api.util.InventoryUtils) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) AbstractJobStructure(com.minecolonies.coremod.colony.jobs.AbstractJobStructure) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryCitizen(com.minecolonies.api.inventory.InventoryCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData) IJobWithExternalWorkStations(com.minecolonies.api.colony.jobs.IJobWithExternalWorkStations) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ITEM_HANDLER_CAPABILITY

use of net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY in project minecolonies by Minecolonies.

the class InteractionValidatorInitializer method init.

/**
 * Init method called on startup.
 */
public static void init() {
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_FUEL), citizen -> citizen.getWorkBuilding() != null && citizen.getWorkBuilding().hasModule(FurnaceUserModule.class) && citizen.getWorkBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST)).getList().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), citizen -> citizen.getWorkBuilding() != null && citizen.getWorkBuilding().hasModule(FurnaceUserModule.class) && citizen.getWorkBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(RAW_FOOD), citizen -> InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventory(), ISCOOKABLE) != -1 && InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventory(), stack -> CAN_EAT.test(stack) && (citizen.getWorkBuilding() == null || citizen.getWorkBuilding().canEat(stack))) == -1);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BETTER_FOOD), citizen -> citizen.getSaturation() == 0 && !citizen.isChild() && citizen.needsBetterFood());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BETTER_FOOD_CHILDREN), citizen -> citizen.getSaturation() == 0 && citizen.isChild() && citizen.needsBetterFood());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_RESTAURANT), citizen -> citizen.getColony() != null && citizen.getSaturation() <= LOW_SATURATION && citizen.getEntity().isPresent() && citizen.getColony().getBuildingManager().getBestBuilding(citizen.getEntity().get(), BuildingCook.class) == null && InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventory(), ISFOOD) == -1);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_HOSPITAL), citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && citizen.getEntity().get().getCitizenDiseaseHandler().isSick() && citizen.getColony().getBuildingManager().getBestBuilding(citizen.getEntity().get(), BuildingHospital.class) == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(WAITING_FOR_CURE), citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && !citizen.getEntity().get().getCitizenDiseaseHandler().getDisease().isEmpty());
    InteractionValidatorRegistry.registerPosBasedPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), (citizen, pos) -> {
        if (citizen.getJob() instanceof JobDeliveryman) {
            final IColony colony = citizen.getColony();
            if (colony != null) {
                final IBuilding building = colony.getBuildingManager().getBuilding(pos);
                if (building != null) {
                    final IItemHandler inv = building.getCapability(ITEM_HANDLER_CAPABILITY, null).resolve().orElse(null);
                    if (inv != null) {
                        return InventoryUtils.openSlotCount(inv) > 0;
                    }
                }
            }
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NOWAREHOUSE), cit -> {
        if (cit.getJob() instanceof JobDeliveryman && cit.getWorkBuilding() != null) {
            return ((JobDeliveryman) cit.getJob()).findWareHouse() == null;
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_FREE_FIELDS), citizen -> citizen.getWorkBuilding() instanceof BuildingFarmer && ((BuildingFarmer) citizen.getWorkBuilding()).getFirstModuleOccurance(FarmerFieldModule.class).hasNoFields());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(INVALID_MINESHAFT), citizen -> citizen.getWorkBuilding() instanceof BuildingMiner && citizen.getJob() instanceof JobMiner && (((BuildingMiner) citizen.getWorkBuilding()).getCobbleLocation() == null || ((BuildingMiner) citizen.getWorkBuilding()).getLadderLocation() == null));
    InteractionValidatorRegistry.registerPosBasedPredicate(new TranslationTextComponent(NO_SEED_SET), (citizen, pos) -> {
        if (citizen.getJob() instanceof JobFarmer) {
            final IColony colony = citizen.getColony();
            if (colony != null) {
                final World world = colony.getWorld();
                if (world != null) {
                    final TileEntity tileEntity = world.getBlockEntity(pos);
                    if (tileEntity instanceof ScarecrowTileEntity) {
                        return ((ScarecrowTileEntity) tileEntity).getSeed() == null;
                    }
                }
            }
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_INVENTORYFULLCHEST), citizen -> citizen.getWorkBuilding() != null && InventoryUtils.isProviderFull(citizen.getWorkBuilding()));
    InteractionValidatorRegistry.registerPosBasedPredicate(new TranslationTextComponent(BUILDING_LEVEL_TOO_LOW), (citizen, pos) -> {
        final IBuilding workBuilding = citizen.getWorkBuilding();
        if (workBuilding != null) {
            final IColony colony = citizen.getColony();
            if (colony != null) {
                final World world = colony.getWorld();
                if (world != null) {
                    return workBuilding.getMaxToolLevel() < WorkerUtil.getCorrectHarvestLevelForBlock(world.getBlockState(pos));
                }
            }
        }
        return false;
    });
    InteractionValidatorRegistry.registerTokenBasedPredicate(new TranslationTextComponent(NORMAL_REQUEST), (citizen, token) -> {
        final IColony colony = citizen.getColony();
        if (colony != null) {
            return RequestUtils.requestChainNeedsPlayer(token, citizen.getColony().getRequestManager());
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_ORE), citizen -> {
        if (citizen.getWorkBuilding() instanceof BuildingSmeltery) {
            final List<ItemStorage> oreList = ((BuildingSmeltery) citizen.getWorkBuilding()).getModuleMatching(ItemListModule.class, m -> m.getId().equals(ORE_LIST)).getList();
            for (final ItemStorage storage : IColonyManager.getInstance().getCompatibilityManager().getSmeltableOres()) {
                if (!oreList.contains(storage)) {
                    return true;
                }
            }
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(PATIENT_FULL_INVENTORY), citizen -> citizen.getEntity().isPresent() && citizen.getEntity().get().getCitizenDiseaseHandler().isSick() && InventoryUtils.isItemHandlerFull(citizen.getEntity().get().getInventoryCitizen()));
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(PUPIL_NO_CARPET), citizen -> citizen.getEntity().isPresent() && citizen.isChild() && citizen.getWorkBuilding() instanceof BuildingSchool && ((BuildingSchool) citizen.getWorkBuilding()).getRandomPlaceToSit() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(WATER_TOO_FAR), citizen -> citizen.getJob() instanceof JobFisherman && ((JobFisherman) citizen.getJob()).getPonds().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_FUEL), citizen -> citizen.getWorkBuilding() != null && citizen.getWorkBuilding().hasModule(FurnaceUserModule.class) && citizen.getWorkBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST)).getList().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_FOOD), citizen -> {
        if (!(citizen.getWorkBuilding() instanceof BuildingCook)) {
            return false;
        }
        final ImmutableList<ItemStorage> exclusionList = ((BuildingCook) citizen.getWorkBuilding()).getModuleMatching(ItemListModule.class, m -> m.getId().equals(FOOD_EXCLUSION_LIST)).getList();
        for (final ItemStorage storage : IColonyManager.getInstance().getCompatibilityManager().getEdibles(citizen.getWorkBuilding().getBuildingLevel() - 1)) {
            if (!exclusionList.contains(storage)) {
                return false;
            }
        }
        return true;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(SIFTER_NO_MESH), citizen -> {
        if (!(citizen.getWorkBuilding() instanceof BuildingSifter)) {
            return false;
        }
        return InventoryUtils.getItemCountInProvider(citizen.getWorkBuilding(), item -> ModTags.meshes.contains(item.getItem())) <= 0 && InventoryUtils.getItemCountInItemHandler(citizen.getInventory(), item -> ModTags.meshes.contains(item.getItem())) <= 0;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), citizen -> citizen.getWorkBuilding() instanceof BuildingBaker && citizen.getWorkBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_HIVES), citizen -> citizen.getWorkBuilding() instanceof BuildingBeekeeper && ((BuildingBeekeeper) citizen.getWorkBuilding()).getHives().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_BEES), citizen -> citizen.getWorkBuilding() instanceof BuildingBeekeeper && citizen.getJob(JobBeekeeper.class).checkForBeeInteraction());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_WORKERS_TO_DRAIN_SET), citizen -> citizen.getWorkBuilding() instanceof BuildingEnchanter && ((BuildingEnchanter) citizen.getWorkBuilding()).getFirstModuleOccurance(EnchanterStationsModule.class).getBuildingsToGatherFrom().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_PLANT_GROUND_FLORIST), citizen -> citizen.getWorkBuilding() instanceof BuildingFlorist && ((BuildingFlorist) citizen.getWorkBuilding()).getPlantGround().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_FLOWERS_IN_CONFIG), citizen -> citizen.getWorkBuilding() instanceof BuildingFlorist && ItemStackUtils.isEmpty(((BuildingFlorist) citizen.getWorkBuilding()).getFlowerToGrow()));
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_COMPOST), citizen -> {
        final IBuilding buildingFlorist = citizen.getWorkBuilding();
        if (buildingFlorist instanceof BuildingFlorist && buildingFlorist.getColony().getWorld() != null) {
            return InventoryUtils.getItemCountInItemHandler(citizen.getInventory(), IS_COMPOST) == 0 && !isThereCompostedLand((BuildingFlorist) buildingFlorist, buildingFlorist.getColony().getWorld());
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NEEDS_BETTER_HUT), citizen -> {
        final AbstractBuilding buildingMiner = (AbstractBuilding) citizen.getWorkBuilding();
        if (buildingMiner instanceof BuildingMiner && citizen.getColony() != null && citizen.getColony().getWorld() != null && citizen.getJob() instanceof JobMiner) {
            return getLastLadder(((BuildingMiner) buildingMiner).getLadderLocation(), citizen.getColony().getWorld()) < ((BuildingMiner) buildingMiner).getDepthLimit() && ((BuildingMiner) buildingMiner).getFirstModuleOccurance(MinerLevelManagementModule.class).getNumberOfLevels() == 0;
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(WORKER_AI_EXCEPTION), citizen -> citizen.getJob() != null && ((AbstractEntityAIBasic<?, ?>) citizen.getJob().getWorkerAI()).getExceptionTimer() > 1);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(DEMANDS + HOMELESSNESS), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(HOMELESSNESS).getDays() > DEMANDS_DAYS_WITHOUT_HOUSE && citizen.getHomeBuilding() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + HOMELESSNESS), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(HOMELESSNESS).getDays() > COMPLAIN_DAYS_WITHOUT_HOUSE && (citizen.getCitizenHappinessHandler()).getModifier(HOMELESSNESS).getDays() <= DEMANDS_DAYS_WITHOUT_HOUSE && citizen.getHomeBuilding() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(DEMANDS + UNEMPLOYMENT), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(UNEMPLOYMENT).getDays() > DEMANDS_DAYS_WITHOUT_JOB && citizen.getJob() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + UNEMPLOYMENT), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(UNEMPLOYMENT).getDays() > COMPLAIN_DAYS_WITHOUT_JOB && (citizen.getCitizenHappinessHandler()).getModifier(UNEMPLOYMENT).getDays() <= DEMANDS_DAYS_WITHOUT_JOB && citizen.getJob() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(DEMANDS + IDLEATJOB), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(IDLEATJOB).getDays() > IDLE_AT_JOB_DEMANDS_DAYS);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + IDLEATJOB), citizen -> citizen.getCitizenHappinessHandler().getModifier(IDLEATJOB).getDays() > IDLE_AT_JOB_COMPLAINS_DAYS && citizen.getCitizenHappinessHandler().getModifier(IDLEATJOB).getDays() <= IDLE_AT_JOB_DEMANDS_DAYS);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + SLEPTTONIGHT), citizen -> !(citizen.getJob() instanceof AbstractJobGuard) && citizen.getCitizenHappinessHandler().getModifier(SLEPTTONIGHT).getDays() <= 0);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_BEEKEEPER_NOFLOWERS), citizen -> citizen.getWorkBuilding() instanceof BuildingBeekeeper && ((BuildingBeekeeper) citizen.getWorkBuilding()).getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST)).getList().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAINING), citizen -> citizen.getEntity().isPresent() && citizen.getEntity().get().getCommandSenderWorld().isRaining() && !citizen.getColony().getRaiderManager().isRaided() && !citizen.getCitizenMournHandler().isMourning());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAID), citizen -> citizen.getEntity().isPresent() && citizen.getColony().getRaiderManager().isRaided());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_SLEEPING), citizen -> citizen.getEntity().isPresent() && citizen.isAsleep());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_MOURNING), citizen -> citizen.getEntity().isPresent() && citizen.getCitizenMournHandler().isMourning() && !citizen.getColony().getRaiderManager().isRaided());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(CITIZEN_NOT_GUARD_NEAR_WORK), citizen -> citizen.getWorkBuilding() != null && !citizen.getWorkBuilding().isGuardBuildingNear());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(CITIZEN_NOT_GUARD_NEAR_HOME), citizen -> citizen.getHomeBuilding() != null && !citizen.getHomeBuilding().isGuardBuildingNear());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(QUARRY_MINER_NO_QUARRY), citizen -> citizen.getJob() instanceof JobQuarrier && ((JobQuarrier) citizen.getJob()).findQuarry() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(QUARRY_MINER_FINISHED_QUARRY), citizen -> citizen.getJob() instanceof JobQuarrier && ((JobQuarrier) citizen.getJob()).findQuarry() != null && ((JobQuarrier) citizen.getJob()).findQuarry().getFirstModuleOccurance(QuarryModule.class).isFinished());
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) WorkerUtil.isThereCompostedLand(com.minecolonies.coremod.util.WorkerUtil.isThereCompostedLand) HappinessConstants(com.minecolonies.api.util.constant.HappinessConstants) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) BUILDING_FLOWER_LIST(com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST) LOW_SATURATION(com.minecolonies.api.util.constant.CitizenConstants.LOW_SATURATION) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FOOD_EXCLUSION_LIST(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCook.FOOD_EXCLUSION_LIST) AbstractEntityAIBasic(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIBasic) com.minecolonies.coremod.colony.buildings.workerbuildings(com.minecolonies.coremod.colony.buildings.workerbuildings) ImmutableList(com.google.common.collect.ImmutableList) WorkerUtil.getLastLadder(com.minecolonies.coremod.util.WorkerUtil.getLastLadder) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) FUEL_LIST(com.minecolonies.api.util.constant.BuildingConstants.FUEL_LIST) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ModTags(com.minecolonies.api.items.ModTags) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) InteractionValidatorRegistry(com.minecolonies.api.colony.interactionhandling.InteractionValidatorRegistry) List(java.util.List) RequestUtils(com.minecolonies.api.colony.requestsystem.request.RequestUtils) WorkerUtil(com.minecolonies.coremod.util.WorkerUtil) ORE_LIST(com.minecolonies.coremod.entity.ai.citizen.smelter.EntityAIWorkSmelter.ORE_LIST) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryUtils(com.minecolonies.api.util.InventoryUtils) IColony(com.minecolonies.api.colony.IColony) TileEntity(net.minecraft.tileentity.TileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) com.minecolonies.coremod.colony.jobs(com.minecolonies.coremod.colony.jobs) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) com.minecolonies.coremod.colony.buildings.modules(com.minecolonies.coremod.colony.buildings.modules) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) World(net.minecraft.world.World) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) TileEntity(net.minecraft.tileentity.TileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) IItemHandler(net.minecraftforge.items.IItemHandler) IColony(com.minecolonies.api.colony.IColony)

Example 3 with ITEM_HANDLER_CAPABILITY

use of net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY in project GT-4-Reimagined by Trinsdar.

the class CoverConveyor method onUpdate.

@Override
public void onUpdate(CoverStack<?> instance, Direction side) {
    if (instance.getTile() == null || instance.getTile().getWorld().getGameTime() % (speeds.get(tier)) != 0)
        return;
    boolean isMachine = instance.getTile() instanceof TileEntityMachine;
    BlockState state = instance.getTile().getWorld().getBlockState(instance.getTile().getPos().offset(side));
    // Drop into world.
    if (state == Blocks.AIR.getDefaultState() && isMachine) {
        World world = instance.getTile().getWorld();
        BlockPos pos = instance.getTile().getPos();
        ItemStack stack = ((TileEntityMachine) instance.getTile()).itemHandler.map(ih -> Utils.extractAny(ih.getOutputHandler())).orElse(ItemStack.EMPTY);
        if (stack.isEmpty())
            return;
        world.addEntity(new ItemEntity(world, pos.getX() + side.getXOffset(), pos.getY() + side.getYOffset(), pos.getZ() + side.getZOffset(), stack));
    }
    if (!(state.hasTileEntity()))
        return;
    TileEntity adjTile = instance.getTile().getWorld().getTileEntity(instance.getTile().getPos().offset(side));
    if (adjTile == null) {
        return;
    }
    if (isMachine) {
        ((TileEntityMachine) instance.getTile()).itemHandler.ifPresent(ih -> adjTile.getCapability(ITEM_HANDLER_CAPABILITY).ifPresent(other -> Utils.transferItems(ih.getOutputHandler(), other, true)));
    } else {
        Utils.transferItemsOnCap(instance.getTile(), adjTile, true);
    }
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) CoverTiered(muramasa.antimatter.cover.CoverTiered) Utils(muramasa.antimatter.util.Utils) Blocks(net.minecraft.block.Blocks) ItemStack(net.minecraft.item.ItemStack) Tier(muramasa.antimatter.machine.Tier) Map(java.util.Map) CoverStack(muramasa.antimatter.cover.CoverStack) TileEntity(net.minecraft.tileentity.TileEntity) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) Ref(trinsdar.gt4r.Ref) BlockState(net.minecraft.block.BlockState) ItemEntity(net.minecraft.entity.item.ItemEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) BlockState(net.minecraft.block.BlockState) TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ITEM_HANDLER_CAPABILITY

use of net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY in project minecolonies by ldtteam.

the class BuildingResourcesModule method updateAvailableResources.

/**
 * Update the available resources.
 * <p>
 * which are needed for the build and in the structureBuilder's chest or inventory
 */
private void updateAvailableResources() {
    final Set<ICitizenData> set = building.getAllAssignedCitizen();
    final ICitizenData data = set.isEmpty() ? null : set.iterator().next();
    if (data == null) {
        return;
    }
    data.getEntity().ifPresent(structureBuilder -> {
        final InventoryCitizen structureBuilderInventory = data.getInventory();
        if (structureBuilderInventory == null) {
            return;
        }
        for (@NotNull final Map.Entry<String, BuildingBuilderResource> entry : neededResources.entrySet()) {
            final BuildingBuilderResource resource = entry.getValue();
            resource.setAvailable(0);
            if (structureBuilderInventory != null) {
                resource.addAvailable(InventoryUtils.getItemCountInItemHandler(structureBuilderInventory, stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack(), true, true)));
            }
            if (building.getTileEntity() != null) {
                resource.addAvailable(InventoryUtils.getItemCountInItemHandler(building.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack(), true, true)));
            }
            if (data.getJob() instanceof IJobWithExternalWorkStations) {
                for (final IBuilding station : ((IJobWithExternalWorkStations) data.getJob()).getWorkStations()) {
                    resource.addAvailable(InventoryUtils.getItemCountInItemHandler(station.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack(), true, true)));
                }
            }
        }
    });
}
Also used : AbstractBuildingModule(com.minecolonies.api.colony.buildings.modules.AbstractBuildingModule) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) BuilderBucket(com.minecolonies.coremod.colony.buildings.utils.BuilderBucket) java.util(java.util) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) TypeToken(com.google.common.reflect.TypeToken) ItemStack(net.minecraft.item.ItemStack) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ImmutableList(com.google.common.collect.ImmutableList) TAG_CURR_STAGE(com.minecolonies.api.util.constant.NbtTagConstants.TAG_CURR_STAGE) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) TAG_TOTAL_STAGES(com.minecolonies.api.util.constant.NbtTagConstants.TAG_TOTAL_STAGES) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) IPersistentModule(com.minecolonies.api.colony.buildings.modules.IPersistentModule) Nullable(org.jetbrains.annotations.Nullable) IJobWithExternalWorkStations(com.minecolonies.api.colony.jobs.IJobWithExternalWorkStations) InventoryCitizen(com.minecolonies.api.inventory.InventoryCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryUtils(com.minecolonies.api.util.InventoryUtils) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) AbstractJobStructure(com.minecolonies.coremod.colony.jobs.AbstractJobStructure) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryCitizen(com.minecolonies.api.inventory.InventoryCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData) IJobWithExternalWorkStations(com.minecolonies.api.colony.jobs.IJobWithExternalWorkStations) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ITEM_HANDLER_CAPABILITY

use of net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY in project minecolonies by ldtteam.

the class InteractionValidatorInitializer method init.

/**
 * Init method called on startup.
 */
public static void init() {
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_FUEL), citizen -> citizen.getWorkBuilding() != null && citizen.getWorkBuilding().hasModule(FurnaceUserModule.class) && citizen.getWorkBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST)).getList().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), citizen -> citizen.getWorkBuilding() != null && citizen.getWorkBuilding().hasModule(FurnaceUserModule.class) && citizen.getWorkBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(RAW_FOOD), citizen -> InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventory(), ISCOOKABLE) != -1 && InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventory(), stack -> CAN_EAT.test(stack) && (citizen.getWorkBuilding() == null || citizen.getWorkBuilding().canEat(stack))) == -1);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BETTER_FOOD), citizen -> citizen.getSaturation() == 0 && !citizen.isChild() && citizen.needsBetterFood());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BETTER_FOOD_CHILDREN), citizen -> citizen.getSaturation() == 0 && citizen.isChild() && citizen.needsBetterFood());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_RESTAURANT), citizen -> citizen.getColony() != null && citizen.getSaturation() <= LOW_SATURATION && citizen.getEntity().isPresent() && citizen.getColony().getBuildingManager().getBestBuilding(citizen.getEntity().get(), BuildingCook.class) == null && InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventory(), ISFOOD) == -1);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_HOSPITAL), citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && citizen.getEntity().get().getCitizenDiseaseHandler().isSick() && citizen.getColony().getBuildingManager().getBestBuilding(citizen.getEntity().get(), BuildingHospital.class) == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(WAITING_FOR_CURE), citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && !citizen.getEntity().get().getCitizenDiseaseHandler().getDisease().isEmpty());
    InteractionValidatorRegistry.registerPosBasedPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), (citizen, pos) -> {
        if (citizen.getJob() instanceof JobDeliveryman) {
            final IColony colony = citizen.getColony();
            if (colony != null) {
                final IBuilding building = colony.getBuildingManager().getBuilding(pos);
                if (building != null) {
                    final IItemHandler inv = building.getCapability(ITEM_HANDLER_CAPABILITY, null).resolve().orElse(null);
                    if (inv != null) {
                        return InventoryUtils.openSlotCount(inv) > 0;
                    }
                }
            }
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NOWAREHOUSE), cit -> {
        if (cit.getJob() instanceof JobDeliveryman && cit.getWorkBuilding() != null) {
            return ((JobDeliveryman) cit.getJob()).findWareHouse() == null;
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_FREE_FIELDS), citizen -> citizen.getWorkBuilding() instanceof BuildingFarmer && ((BuildingFarmer) citizen.getWorkBuilding()).getFirstModuleOccurance(FarmerFieldModule.class).hasNoFields());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(INVALID_MINESHAFT), citizen -> citizen.getWorkBuilding() instanceof BuildingMiner && citizen.getJob() instanceof JobMiner && (((BuildingMiner) citizen.getWorkBuilding()).getCobbleLocation() == null || ((BuildingMiner) citizen.getWorkBuilding()).getLadderLocation() == null));
    InteractionValidatorRegistry.registerPosBasedPredicate(new TranslationTextComponent(NO_SEED_SET), (citizen, pos) -> {
        if (citizen.getJob() instanceof JobFarmer) {
            final IColony colony = citizen.getColony();
            if (colony != null) {
                final World world = colony.getWorld();
                if (world != null) {
                    final TileEntity tileEntity = world.getBlockEntity(pos);
                    if (tileEntity instanceof ScarecrowTileEntity) {
                        return ((ScarecrowTileEntity) tileEntity).getSeed() == null;
                    }
                }
            }
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_INVENTORYFULLCHEST), citizen -> citizen.getWorkBuilding() != null && InventoryUtils.isProviderFull(citizen.getWorkBuilding()));
    InteractionValidatorRegistry.registerPosBasedPredicate(new TranslationTextComponent(BUILDING_LEVEL_TOO_LOW), (citizen, pos) -> {
        final IBuilding workBuilding = citizen.getWorkBuilding();
        if (workBuilding != null) {
            final IColony colony = citizen.getColony();
            if (colony != null) {
                final World world = colony.getWorld();
                if (world != null) {
                    return workBuilding.getMaxToolLevel() < WorkerUtil.getCorrectHarvestLevelForBlock(world.getBlockState(pos));
                }
            }
        }
        return false;
    });
    InteractionValidatorRegistry.registerTokenBasedPredicate(new TranslationTextComponent(NORMAL_REQUEST), (citizen, token) -> {
        final IColony colony = citizen.getColony();
        if (colony != null) {
            return RequestUtils.requestChainNeedsPlayer(token, citizen.getColony().getRequestManager());
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_ORE), citizen -> {
        if (citizen.getWorkBuilding() instanceof BuildingSmeltery) {
            final List<ItemStorage> oreList = ((BuildingSmeltery) citizen.getWorkBuilding()).getModuleMatching(ItemListModule.class, m -> m.getId().equals(ORE_LIST)).getList();
            for (final ItemStorage storage : IColonyManager.getInstance().getCompatibilityManager().getSmeltableOres()) {
                if (!oreList.contains(storage)) {
                    return true;
                }
            }
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(PATIENT_FULL_INVENTORY), citizen -> citizen.getEntity().isPresent() && citizen.getEntity().get().getCitizenDiseaseHandler().isSick() && InventoryUtils.isItemHandlerFull(citizen.getEntity().get().getInventoryCitizen()));
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(PUPIL_NO_CARPET), citizen -> citizen.getEntity().isPresent() && citizen.isChild() && citizen.getWorkBuilding() instanceof BuildingSchool && ((BuildingSchool) citizen.getWorkBuilding()).getRandomPlaceToSit() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(WATER_TOO_FAR), citizen -> citizen.getJob() instanceof JobFisherman && ((JobFisherman) citizen.getJob()).getPonds().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_FUEL), citizen -> citizen.getWorkBuilding() != null && citizen.getWorkBuilding().hasModule(FurnaceUserModule.class) && citizen.getWorkBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST)).getList().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_FOOD), citizen -> {
        if (!(citizen.getWorkBuilding() instanceof BuildingCook)) {
            return false;
        }
        final ImmutableList<ItemStorage> exclusionList = ((BuildingCook) citizen.getWorkBuilding()).getModuleMatching(ItemListModule.class, m -> m.getId().equals(FOOD_EXCLUSION_LIST)).getList();
        for (final ItemStorage storage : IColonyManager.getInstance().getCompatibilityManager().getEdibles(citizen.getWorkBuilding().getBuildingLevel() - 1)) {
            if (!exclusionList.contains(storage)) {
                return false;
            }
        }
        return true;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(SIFTER_NO_MESH), citizen -> {
        if (!(citizen.getWorkBuilding() instanceof BuildingSifter)) {
            return false;
        }
        return InventoryUtils.getItemCountInProvider(citizen.getWorkBuilding(), item -> ModTags.meshes.contains(item.getItem())) <= 0 && InventoryUtils.getItemCountInItemHandler(citizen.getInventory(), item -> ModTags.meshes.contains(item.getItem())) <= 0;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), citizen -> citizen.getWorkBuilding() instanceof BuildingBaker && citizen.getWorkBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_HIVES), citizen -> citizen.getWorkBuilding() instanceof BuildingBeekeeper && ((BuildingBeekeeper) citizen.getWorkBuilding()).getHives().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_BEES), citizen -> citizen.getWorkBuilding() instanceof BuildingBeekeeper && citizen.getJob(JobBeekeeper.class).checkForBeeInteraction());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_WORKERS_TO_DRAIN_SET), citizen -> citizen.getWorkBuilding() instanceof BuildingEnchanter && ((BuildingEnchanter) citizen.getWorkBuilding()).getFirstModuleOccurance(EnchanterStationsModule.class).getBuildingsToGatherFrom().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_PLANT_GROUND_FLORIST), citizen -> citizen.getWorkBuilding() instanceof BuildingFlorist && ((BuildingFlorist) citizen.getWorkBuilding()).getPlantGround().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_FLOWERS_IN_CONFIG), citizen -> citizen.getWorkBuilding() instanceof BuildingFlorist && ItemStackUtils.isEmpty(((BuildingFlorist) citizen.getWorkBuilding()).getFlowerToGrow()));
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_COMPOST), citizen -> {
        final IBuilding buildingFlorist = citizen.getWorkBuilding();
        if (buildingFlorist instanceof BuildingFlorist && buildingFlorist.getColony().getWorld() != null) {
            return InventoryUtils.getItemCountInItemHandler(citizen.getInventory(), IS_COMPOST) == 0 && !isThereCompostedLand((BuildingFlorist) buildingFlorist, buildingFlorist.getColony().getWorld());
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NEEDS_BETTER_HUT), citizen -> {
        final AbstractBuilding buildingMiner = (AbstractBuilding) citizen.getWorkBuilding();
        if (buildingMiner instanceof BuildingMiner && citizen.getColony() != null && citizen.getColony().getWorld() != null && citizen.getJob() instanceof JobMiner) {
            return getLastLadder(((BuildingMiner) buildingMiner).getLadderLocation(), citizen.getColony().getWorld()) < ((BuildingMiner) buildingMiner).getDepthLimit() && ((BuildingMiner) buildingMiner).getFirstModuleOccurance(MinerLevelManagementModule.class).getNumberOfLevels() == 0;
        }
        return false;
    });
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(WORKER_AI_EXCEPTION), citizen -> citizen.getJob() != null && ((AbstractEntityAIBasic<?, ?>) citizen.getJob().getWorkerAI()).getExceptionTimer() > 1);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(DEMANDS + HOMELESSNESS), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(HOMELESSNESS).getDays() > DEMANDS_DAYS_WITHOUT_HOUSE && citizen.getHomeBuilding() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + HOMELESSNESS), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(HOMELESSNESS).getDays() > COMPLAIN_DAYS_WITHOUT_HOUSE && (citizen.getCitizenHappinessHandler()).getModifier(HOMELESSNESS).getDays() <= DEMANDS_DAYS_WITHOUT_HOUSE && citizen.getHomeBuilding() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(DEMANDS + UNEMPLOYMENT), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(UNEMPLOYMENT).getDays() > DEMANDS_DAYS_WITHOUT_JOB && citizen.getJob() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + UNEMPLOYMENT), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(UNEMPLOYMENT).getDays() > COMPLAIN_DAYS_WITHOUT_JOB && (citizen.getCitizenHappinessHandler()).getModifier(UNEMPLOYMENT).getDays() <= DEMANDS_DAYS_WITHOUT_JOB && citizen.getJob() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(DEMANDS + IDLEATJOB), citizen -> citizen.getJob() != null && (citizen.getCitizenHappinessHandler()).getModifier(IDLEATJOB).getDays() > citizen.getJob().getIdleSeverity(true));
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + IDLEATJOB), citizen -> citizen.getJob() != null && citizen.getCitizenHappinessHandler().getModifier(IDLEATJOB).getDays() > citizen.getJob().getIdleSeverity(false) && citizen.getCitizenHappinessHandler().getModifier(IDLEATJOB).getDays() <= citizen.getJob().getIdleSeverity(true));
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + SLEPTTONIGHT), citizen -> !(citizen.getJob() instanceof AbstractJobGuard) && citizen.getCitizenHappinessHandler().getModifier(SLEPTTONIGHT).getDays() <= 0);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_BEEKEEPER_NOFLOWERS), citizen -> citizen.getWorkBuilding() instanceof BuildingBeekeeper && ((BuildingBeekeeper) citizen.getWorkBuilding()).getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST)).getList().isEmpty());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAINING), citizen -> citizen.getEntity().isPresent() && citizen.getEntity().get().getCommandSenderWorld().isRaining() && !citizen.getColony().getRaiderManager().isRaided() && !citizen.getCitizenMournHandler().isMourning());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAID), citizen -> citizen.getEntity().isPresent() && citizen.getColony().getRaiderManager().isRaided());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_SLEEPING), citizen -> citizen.getEntity().isPresent() && citizen.isAsleep());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_MOURNING), citizen -> citizen.getEntity().isPresent() && citizen.getCitizenMournHandler().isMourning() && !citizen.getColony().getRaiderManager().isRaided());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(CITIZEN_NOT_GUARD_NEAR_WORK), citizen -> citizen.getWorkBuilding() != null && !citizen.getWorkBuilding().isGuardBuildingNear());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(CITIZEN_NOT_GUARD_NEAR_HOME), citizen -> citizen.getHomeBuilding() != null && !citizen.getHomeBuilding().isGuardBuildingNear());
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(QUARRY_MINER_NO_QUARRY), citizen -> citizen.getJob() instanceof JobQuarrier && ((JobQuarrier) citizen.getJob()).findQuarry() == null);
    InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(QUARRY_MINER_FINISHED_QUARRY), citizen -> citizen.getJob() instanceof JobQuarrier && ((JobQuarrier) citizen.getJob()).findQuarry() != null && ((JobQuarrier) citizen.getJob()).findQuarry().getFirstModuleOccurance(QuarryModule.class).isFinished());
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) WorkerUtil.isThereCompostedLand(com.minecolonies.coremod.util.WorkerUtil.isThereCompostedLand) HappinessConstants(com.minecolonies.api.util.constant.HappinessConstants) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) BUILDING_FLOWER_LIST(com.minecolonies.api.util.constant.BuildingConstants.BUILDING_FLOWER_LIST) LOW_SATURATION(com.minecolonies.api.util.constant.CitizenConstants.LOW_SATURATION) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FOOD_EXCLUSION_LIST(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCook.FOOD_EXCLUSION_LIST) AbstractEntityAIBasic(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIBasic) com.minecolonies.coremod.colony.buildings.workerbuildings(com.minecolonies.coremod.colony.buildings.workerbuildings) ImmutableList(com.google.common.collect.ImmutableList) WorkerUtil.getLastLadder(com.minecolonies.coremod.util.WorkerUtil.getLastLadder) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) FUEL_LIST(com.minecolonies.api.util.constant.BuildingConstants.FUEL_LIST) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ModTags(com.minecolonies.api.items.ModTags) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) InteractionValidatorRegistry(com.minecolonies.api.colony.interactionhandling.InteractionValidatorRegistry) List(java.util.List) RequestUtils(com.minecolonies.api.colony.requestsystem.request.RequestUtils) WorkerUtil(com.minecolonies.coremod.util.WorkerUtil) ORE_LIST(com.minecolonies.coremod.entity.ai.citizen.smelter.EntityAIWorkSmelter.ORE_LIST) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryUtils(com.minecolonies.api.util.InventoryUtils) IColony(com.minecolonies.api.colony.IColony) TileEntity(net.minecraft.tileentity.TileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) com.minecolonies.coremod.colony.jobs(com.minecolonies.coremod.colony.jobs) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) com.minecolonies.coremod.colony.buildings.modules(com.minecolonies.coremod.colony.buildings.modules) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) World(net.minecraft.world.World) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) TileEntity(net.minecraft.tileentity.TileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) IItemHandler(net.minecraftforge.items.IItemHandler) IColony(com.minecolonies.api.colony.IColony)

Aggregations

IBuilding (com.minecolonies.api.colony.buildings.IBuilding)6 ItemStorage (com.minecolonies.api.crafting.ItemStorage)6 InventoryUtils (com.minecolonies.api.util.InventoryUtils)6 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)6 ITEM_HANDLER_CAPABILITY (net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)6 ItemStack (net.minecraft.item.ItemStack)5 TileEntity (net.minecraft.tileentity.TileEntity)5 ImmutableList (com.google.common.collect.ImmutableList)4 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)4 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)4 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)4 List (java.util.List)4 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)4 World (net.minecraft.world.World)3 IItemHandler (net.minecraftforge.items.IItemHandler)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 TypeToken (com.google.common.reflect.TypeToken)2 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IColony (com.minecolonies.api.colony.IColony)2