Search in sources :

Example 1 with BuildingBuilder

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

the class EntityAIStructureBuilder method requestEntityToBuildingIfRequired.

/**
     * Adds entities to the builder building if he needs it.
     */
private void requestEntityToBuildingIfRequired(final Template.EntityInfo entityInfo) {
    if (entityInfo != null) {
        final Entity entity = getEntityFromEntityInfoOrNull(entityInfo);
        if (entity != null) {
            final List<ItemStack> request = new ArrayList<>();
            if (entity instanceof EntityItemFrame) {
                final ItemStack stack = ((EntityItemFrame) entity).getDisplayedItem();
                if (!InventoryUtils.isItemStackEmpty(stack)) {
                    stack.setCount(1);
                    request.add(stack);
                }
                request.add(new ItemStack(Items.ITEM_FRAME, 1));
            } else if (entity instanceof EntityArmorStand) {
                request.add(entity.getPickedResult(new RayTraceResult(worker)));
                entity.getArmorInventoryList().forEach(request::add);
            } else if (entity instanceof EntityMob) {
            //Don't try to request the monster.
            } else {
                request.add(entity.getPickedResult(new RayTraceResult(worker)));
            }
            for (final ItemStack stack : request) {
                final BuildingBuilder building = (BuildingBuilder) getOwnBuilding();
                if (stack != null && stack.getItem() != null) {
                    building.addNeededResource(stack, 1);
                }
            }
        }
    }
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) BuildingBuilder(com.minecolonies.coremod.colony.buildings.BuildingBuilder) ArrayList(java.util.ArrayList) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand) ItemStack(net.minecraft.item.ItemStack)

Example 2 with BuildingBuilder

use of com.minecolonies.coremod.colony.buildings.BuildingBuilder 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) {
            for (final ItemStack stack : ItemStackUtils.getListOfStackForEntity(entityInfo, world, worker)) {
                final BuildingBuilder building = (BuildingBuilder) getOwnBuilding();
                if (!ItemStackUtils.isEmpty(stack)) {
                    building.addNeededResource(stack, 1);
                }
            }
        }
        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 : IBlockState(net.minecraft.block.state.IBlockState) BlockSolidSubstitution(com.minecolonies.coremod.blocks.BlockSolidSubstitution) BlockBed(net.minecraft.block.BlockBed) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) Template(net.minecraft.world.gen.structure.template.Template) BlockDoor(net.minecraft.block.BlockDoor) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) BuildingBuilder(com.minecolonies.coremod.colony.buildings.BuildingBuilder) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with BuildingBuilder

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

the class EntityAIStructureBuilder method executeSpecificCompleteActions.

@Override
public void executeSpecificCompleteActions() {
    if (job.getStructure() == null && job.hasWorkOrder()) {
        // fix for bad structures
        job.complete();
    }
    if (job.getStructure() == null) {
        return;
    }
    final String structureName = job.getStructure().getName();
    worker.sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDCOMPLETE, structureName);
    final WorkOrderBuildDecoration wo = job.getWorkOrder();
    if (wo == null) {
        Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing work order(%d)", worker.getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
    } else {
        final WorkOrderBuild woh = (wo instanceof WorkOrderBuild) ? (WorkOrderBuild) wo : null;
        if (woh != null) {
            final AbstractBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getBuildingLocation());
            if (building == null) {
                Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getColony().getID(), worker.getCitizenData().getId(), woh.getBuildingLocation()));
            } else {
                building.setBuildingLevel(woh.getUpgradeLevel());
            }
        }
        job.complete();
    }
    final BuildingBuilder workerBuilding = (BuildingBuilder) getOwnBuilding();
    workerBuilding.resetNeededResources();
    resetTask();
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) BuildingBuilder(com.minecolonies.coremod.colony.buildings.BuildingBuilder) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 4 with BuildingBuilder

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

the class EntityAIStructureBuilder method getTotalRequiredAmount.

@Override
public int getTotalRequiredAmount(final ItemStack deliveredItemStack) {
    if (getOwnBuilding() instanceof BuildingBuilder) {
        if (ItemStackUtils.isEmpty(deliveredItemStack)) {
            return 0;
        }
        final int hashCode = deliveredItemStack.hasTagCompound() ? deliveredItemStack.getTagCompound().hashCode() : 0;
        final BuildingBuilderResource resource = ((BuildingBuilder) getOwnBuilding()).getNeededResources().get(deliveredItemStack.getUnlocalizedName() + ":" + deliveredItemStack.getItemDamage() + "-" + hashCode);
        if (resource != null) {
            return resource.getAmount();
        }
    }
    return super.getTotalRequiredAmount(deliveredItemStack);
}
Also used : BuildingBuilder(com.minecolonies.coremod.colony.buildings.BuildingBuilder) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)

Aggregations

BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)4 ItemStack (net.minecraft.item.ItemStack)2 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 BlockSolidSubstitution (com.minecolonies.coremod.blocks.BlockSolidSubstitution)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)1 WorkOrderBuildDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)1 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 BlockBed (net.minecraft.block.BlockBed)1 BlockDoor (net.minecraft.block.BlockDoor)1 IBlockState (net.minecraft.block.state.IBlockState)1 Entity (net.minecraft.entity.Entity)1 EntityArmorStand (net.minecraft.entity.item.EntityArmorStand)1 EntityItemFrame (net.minecraft.entity.item.EntityItemFrame)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 TileEntity (net.minecraft.tileentity.TileEntity)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1