Search in sources :

Example 6 with AbstractBlockHut

use of com.minecolonies.coremod.blocks.AbstractBlockHut 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 7 with AbstractBlockHut

use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.

the class EventHandler method onBlockBreak.

/**
     * Event when a block is broken.
     * Event gets cancelled when there no permission to break a hut.
     *
     * @param event {@link net.minecraftforge.event.world.BlockEvent.BreakEvent}
     */
@SubscribeEvent
public void onBlockBreak(@NotNull final BlockEvent.BreakEvent event) {
    final World world = event.getWorld();
    if (!world.isRemote && event.getState().getBlock() instanceof AbstractBlockHut) {
        @Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, event.getPos());
        if (building == null) {
            return;
        }
        if (!building.getColony().getPermissions().hasPermission(event.getPlayer(), Action.BREAK_HUTS)) {
            event.setCanceled(true);
            return;
        }
        building.destroy();
    }
}
Also used : World(net.minecraft.world.World) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) Nullable(org.jetbrains.annotations.Nullable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)7 Block (net.minecraft.block.Block)3 World (net.minecraft.world.World)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)2 BlockPos (net.minecraft.util.math.BlockPos)2 Template (net.minecraft.world.gen.structure.template.Template)2 Nullable (org.jetbrains.annotations.Nullable)2 BlockHutTownHall (com.minecolonies.coremod.blocks.BlockHutTownHall)1 BlockSolidSubstitution (com.minecolonies.coremod.blocks.BlockSolidSubstitution)1 Colony (com.minecolonies.coremod.colony.Colony)1 IColony (com.minecolonies.coremod.colony.IColony)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 ItemScanTool (com.minecolonies.coremod.items.ItemScanTool)1 BlockBed (net.minecraft.block.BlockBed)1 BlockContainer (net.minecraft.block.BlockContainer)1 BlockDoor (net.minecraft.block.BlockDoor)1