Search in sources :

Example 1 with BlockDoor

use of net.minecraft.block.BlockDoor 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 2 with BlockDoor

use of net.minecraft.block.BlockDoor in project minecolonies by Minecolonies.

the class StructureWrapper method isStructureBlockEqualWorldBlock.

/**
     * Checks if the block in the world is the same as what is in the structure.
     *
     * @return true if the structure block equals the world block.
     */
public boolean isStructureBlockEqualWorldBlock() {
    final IBlockState structureBlockState = structure.getBlockState(this.getLocalPosition());
    final Block structureBlock = structureBlockState.getBlock();
    //All worldBlocks are equal the substitution block
    if (structureBlock == ModBlocks.blockSubstitution) {
        return true;
    }
    final BlockPos worldPos = this.getBlockPosition();
    final IBlockState worldBlockState = world.getBlockState(worldPos);
    if (structureBlock == ModBlocks.blockSolidSubstitution && worldBlockState.getMaterial().isSolid()) {
        return true;
    }
    //For the time being any flower pot is equal to each other.
    if (structureBlock instanceof BlockDoor || structureBlock == Blocks.FLOWER_POT) {
        return structureBlock == worldBlockState.getBlock();
    } else if ((structureBlock instanceof BlockStairs && structureBlockState == worldBlockState) || BlockUtils.isGrassOrDirt(structureBlock, worldBlockState.getBlock(), structureBlockState, worldBlockState)) {
        return true;
    }
    final Template.EntityInfo entityInfo = structure.getEntityinfo(this.getLocalPosition());
    if (entityInfo != null) {
        return false;
    //todo get entity at position.
    }
    //had this problem in a super flat world, causes builder to sit doing nothing because placement failed
    return worldPos.getY() <= 0 || structureBlockState == worldBlockState;
}
Also used : BlockDoor(net.minecraft.block.BlockDoor) IBlockState(net.minecraft.block.state.IBlockState) BlockStairs(net.minecraft.block.BlockStairs) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Template(net.minecraft.world.gen.structure.template.Template)

Aggregations

Block (net.minecraft.block.Block)2 BlockDoor (net.minecraft.block.BlockDoor)2 IBlockState (net.minecraft.block.state.IBlockState)2 Template (net.minecraft.world.gen.structure.template.Template)2 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 BlockSolidSubstitution (com.minecolonies.coremod.blocks.BlockSolidSubstitution)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 BlockBed (net.minecraft.block.BlockBed)1 BlockStairs (net.minecraft.block.BlockStairs)1 BlockPos (net.minecraft.util.math.BlockPos)1 Nullable (org.jetbrains.annotations.Nullable)1