Search in sources :

Example 1 with AbstractBuildingWorker

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.

the class EntityAIStructureBuilder method getTotalAmount.

/**
     * Check how much of a certain stuck is actually required.
     *
     * @param stack the stack to check.
     * @return the new stack with the correct amount.
     */
@Override
@Nullable
public ItemStack getTotalAmount(@Nullable final ItemStack stack) {
    final AbstractBuildingWorker buildingWorker = getOwnBuilding();
    if (stack == null || stack.getItem() == null) {
        return null;
    }
    final BuildingBuilderResource resource = ((BuildingBuilder) buildingWorker).getNeededResources().get(stack.getUnlocalizedName());
    return resource == null ? stack : new ItemStack(resource.getItem(), resource.getAmount(), resource.getDamageValue());
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AbstractBuildingWorker

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.

the class HireFireMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final HireFireMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony != null) {
        //Verify player has permission to change this huts settings
        if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
            return;
        }
        if (message.hire) {
            final CitizenData citizen = colony.getCitizen(message.citizenID);
            ((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(citizen);
        } else {
            ((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(null);
        }
    }
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData)

Example 3 with AbstractBuildingWorker

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.

the class EntityAIStructureBuilder method requestMaterials.

/**
     * Iterates through all the required resources and stores them in the building.
     * Suppressing Sonar Rule Squid:S135
     * The rule thinks we should have less continue and breaks.
     * But in this case the rule does not apply because code would become unreadable and uneffective without.
     */
@SuppressWarnings(LOOPS_SHOULD_NOT_CONTAIN_MORE_THAN_A_SINGLE_BREAK_OR_CONTINUE_STATEMENT)
private void requestMaterials() {
    if (job.getWorkOrder().isRequested()) {
        return;
    }
    final AbstractBuildingWorker buildingWorker = getOwnBuilding();
    if (buildingWorker instanceof BuildingBuilder) {
        ((BuildingBuilder) buildingWorker).resetNeededResources();
    }
    while (job.getStructure().findNextBlock()) {
        @Nullable final Template.BlockInfo blockInfo = job.getStructure().getBlockInfo();
        @Nullable final Template.EntityInfo entityInfo = job.getStructure().getEntityinfo();
        if (entityInfo != null) {
            requestEntityToBuildingIfRequired(entityInfo);
        }
        if (blockInfo == null) {
            continue;
        }
        @Nullable IBlockState blockState = blockInfo.blockState;
        @Nullable Block block = blockState.getBlock();
        if (job.getStructure().isStructureBlockEqualWorldBlock() || (blockState.getBlock() instanceof BlockBed && blockState.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.FOOT)) || (blockState.getBlock() instanceof BlockDoor && blockState.getValue(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.UPPER))) {
            continue;
        }
        if (block instanceof BlockSolidSubstitution) {
            blockState = getSolidSubstitution(job.getStructure().getBlockPosition());
            block = blockState.getBlock();
        }
        final Block worldBlock = BlockPosUtil.getBlock(world, job.getStructure().getBlockPosition());
        if (block != null && block != Blocks.AIR && worldBlock != Blocks.BEDROCK && !(worldBlock instanceof AbstractBlockHut) && !isBlockFree(block, 0)) {
            requestBlockToBuildingIfRequired((BuildingBuilder) getOwnBuilding(), blockState);
        }
    }
    job.getWorkOrder().setRequested(true);
}
Also used : BlockDoor(net.minecraft.block.BlockDoor) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) IBlockState(net.minecraft.block.state.IBlockState) BlockSolidSubstitution(com.minecolonies.coremod.blocks.BlockSolidSubstitution) BuildingBuilder(com.minecolonies.coremod.colony.buildings.BuildingBuilder) Block(net.minecraft.block.Block) BlockBed(net.minecraft.block.BlockBed) Nullable(org.jetbrains.annotations.Nullable) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) Template(net.minecraft.world.gen.structure.template.Template)

Example 4 with AbstractBuildingWorker

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method dumpOneMoreSlot.

/**
     * Dumps one inventory slot into the building chest.
     *
     * @param keepIt used to test it that stack should be kept
     * @return true if is has to dump more.
     */
private boolean dumpOneMoreSlot(@NotNull final Predicate<ItemStack> keepIt) {
    //Items already kept in the inventory
    final Map<ItemStorage, Integer> alreadyKept = new HashMap<>();
    final Map<ItemStorage, Integer> shouldKeep = getOwnBuilding().getRequiredItemsAndAmount();
    @Nullable final AbstractBuildingWorker buildingWorker = getOwnBuilding();
    return buildingWorker != null && (walkToBuilding() || InventoryFunctions.matchFirstInProvider(worker, (slot, stack) -> !(InventoryUtils.isItemStackEmpty(stack) || keepIt.test(stack)) && shouldDumpItem(alreadyKept, shouldKeep, buildingWorker, stack, slot)));
}
Also used : InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen) java.util(java.util) Blocks(net.minecraft.init.Blocks) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) AbstractJob(com.minecolonies.coremod.colony.jobs.AbstractJob) TextComponentBase(net.minecraft.util.text.TextComponentBase) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) TileEntityChest(net.minecraft.tileentity.TileEntityChest) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) AITarget(com.minecolonies.coremod.entity.ai.util.AITarget) Block(net.minecraft.block.Block) com.minecolonies.api.util(com.minecolonies.api.util) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ItemStorage(com.minecolonies.coremod.entity.ai.item.handling.ItemStorage) WalkToProxy(com.minecolonies.coremod.entity.pathfinding.WalkToProxy) Predicate(java.util.function.Predicate) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) AIState(com.minecolonies.coremod.entity.ai.util.AIState) Nullable(org.jetbrains.annotations.Nullable) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) ItemStorage(com.minecolonies.coremod.entity.ai.item.handling.ItemStorage) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with AbstractBuildingWorker

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method isToolInHut.

/**
     * Check all chests in the worker hut for a required tool.
     *
     * @param tool the type of tool requested (amount is ignored)
     * @return true if a stack of that type was found
     */
public boolean isToolInHut(final String tool) {
    @Nullable final AbstractBuildingWorker building = getOwnBuilding();
    boolean hasItem;
    if (building != null) {
        hasItem = isToolInTileEntity(building.getTileEntity(), tool);
        if (hasItem) {
            return true;
        }
        for (final BlockPos pos : building.getAdditionalCountainers()) {
            final TileEntity entity = world.getTileEntity(pos);
            if (entity instanceof TileEntityChest) {
                hasItem = isToolInTileEntity((TileEntityChest) entity, tool);
                if (hasItem) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) BlockPos(net.minecraft.util.math.BlockPos) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)10 Nullable (org.jetbrains.annotations.Nullable)6 BlockPos (net.minecraft.util.math.BlockPos)5 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 TileEntityChest (net.minecraft.tileentity.TileEntityChest)3 NotNull (org.jetbrains.annotations.NotNull)3 CitizenData (com.minecolonies.coremod.colony.CitizenData)2 Colony (com.minecolonies.coremod.colony.Colony)2 Block (net.minecraft.block.Block)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 com.minecolonies.api.util (com.minecolonies.api.util)1 InventoryUtils (com.minecolonies.api.util.InventoryUtils)1 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)1 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 BlockSolidSubstitution (com.minecolonies.coremod.blocks.BlockSolidSubstitution)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 BuildingMiner (com.minecolonies.coremod.colony.buildings.BuildingMiner)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1 AbstractJob (com.minecolonies.coremod.colony.jobs.AbstractJob)1