Search in sources :

Example 1 with BlockBed

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

the class WindowBuildBuilding method updateResources.

/**
 * Clears and resets/updates all resources.
 */
private void updateResources() {
    final World world = Minecraft.getMinecraft().world;
    resources.clear();
    final int nextLevel = building.getBuildingLevel() == building.getBuildingMaxLevel() ? building.getBuildingMaxLevel() : (building.getBuildingLevel() + 1);
    final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, styles.get(stylesDropDownList.getSelectedIndex()), building.getSchematicName() + nextLevel);
    final StructureWrapper wrapper = new StructureWrapper(world, sn.toString());
    wrapper.setPosition(building.getLocation());
    wrapper.rotate(building.getRotation(), world, building.getLocation(), building.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE);
    while (wrapper.findNextBlock()) {
        @Nullable final Template.BlockInfo blockInfo = wrapper.getBlockInfo();
        @Nullable final Template.EntityInfo entityInfo = wrapper.getEntityinfo();
        if (entityInfo != null) {
            for (final ItemStack stack : ItemStackUtils.getListOfStackForEntity(entityInfo, world, Minecraft.getMinecraft().player)) {
                if (!ItemStackUtils.isEmpty(stack)) {
                    addNeededResource(stack, 1);
                }
            }
        }
        if (blockInfo == null) {
            continue;
        }
        @Nullable final IBlockState blockState = blockInfo.blockState;
        @Nullable final Block block = blockState.getBlock();
        if (wrapper.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 != null && block != Blocks.AIR && !AbstractEntityAIStructure.isBlockFree(block, 0) && block != ModBlocks.blockSolidSubstitution && block != ModBlocks.blockSubstitution) {
            if (wrapper.getBlockInfo().tileentityData != null) {
                final List<ItemStack> itemList = new ArrayList<>();
                if (wrapper.getBlockInfo() != null && wrapper.getBlockInfo().tileentityData != null) {
                    itemList.addAll(ItemStackUtils.getItemStacksOfTileEntity(wrapper.getBlockInfo().tileentityData, world));
                }
                for (final ItemStack stack : itemList) {
                    addNeededResource(stack, 1);
                }
            }
            addNeededResource(BlockUtils.getItemStackFromBlockState(blockState), 1);
        }
    }
    window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
    updateResourceList();
}
Also used : StructureWrapper(com.minecolonies.coremod.util.StructureWrapper) IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) StructureName(com.minecolonies.coremod.colony.StructureName) BlockBed(net.minecraft.block.BlockBed) World(net.minecraft.world.World) Template(net.minecraft.world.gen.structure.template.Template) BlockDoor(net.minecraft.block.BlockDoor) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.minecolonies.blockout.views.ScrollingList) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with BlockBed

use of net.minecraft.block.BlockBed 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 BlockBed

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

the class BuildingHome method onWakeUp.

@Override
public void onWakeUp() {
    final World world = getColony().getWorld();
    if (world == null) {
        return;
    }
    for (final BlockPos pos : bedList) {
        IBlockState state = world.getBlockState(pos);
        state = state.getBlock().getActualState(state, world, pos);
        if (state.getBlock() instanceof BlockBed && state.getValue(BlockBed.OCCUPIED) && state.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.HEAD)) {
            world.setBlockState(pos, state.withProperty(BlockBed.OCCUPIED, false), 0x03);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockBed(net.minecraft.block.BlockBed) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 4 with BlockBed

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

the class BuildingHome method registerBlockPosition.

@Override
public void registerBlockPosition(@NotNull final IBlockState blockState, @NotNull final BlockPos pos, @NotNull final World world) {
    super.registerBlockPosition(blockState, pos, world);
    BlockPos registrationPosition = pos;
    if (blockState.getBlock() instanceof BlockBed) {
        if (blockState.getValue(BlockBed.PART) == BlockBed.EnumPartType.FOOT) {
            registrationPosition = registrationPosition.offset(blockState.getValue(BlockBed.FACING));
        }
        if (!bedList.contains(registrationPosition)) {
            bedList.add(registrationPosition);
        }
    }
}
Also used : BlockBed(net.minecraft.block.BlockBed) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with BlockBed

use of net.minecraft.block.BlockBed in project Armourers-Workshop by RiskyKen.

the class ItemArmourersHammer method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    if (block != null) {
        if (block instanceof BlockBed) {
            rotateBed(world, x, y, z, (BlockBed) block, ForgeDirection.getOrientation(side));
            player.swingItem();
            return !world.isRemote;
        }
        if (block instanceof BlockChest) {
            return false;
        }
        ForgeDirection dir = ForgeDirection.getOrientation(side);
        if (player.isSneaking()) {
            dir = dir.getOpposite();
        }
        if (block.rotateBlock(world, x, y, z, dir)) {
            player.swingItem();
            return !world.isRemote;
        }
    }
    return false;
}
Also used : BlockChest(net.minecraft.block.BlockChest) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block) BlockBed(net.minecraft.block.BlockBed)

Aggregations

BlockBed (net.minecraft.block.BlockBed)9 IBlockState (net.minecraft.block.state.IBlockState)4 BlockPos (net.minecraft.util.math.BlockPos)4 World (net.minecraft.world.World)4 Block (net.minecraft.block.Block)3 BlockChest (net.minecraft.block.BlockChest)2 BlockDoor (net.minecraft.block.BlockDoor)2 ItemStack (net.minecraft.item.ItemStack)2 Template (net.minecraft.world.gen.structure.template.Template)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 Nullable (org.jetbrains.annotations.Nullable)2 ScrollingList (com.minecolonies.blockout.views.ScrollingList)1 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 BlockSolidSubstitution (com.minecolonies.coremod.blocks.BlockSolidSubstitution)1 Colony (com.minecolonies.coremod.colony.Colony)1 StructureName (com.minecolonies.coremod.colony.StructureName)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 BuildingHome (com.minecolonies.coremod.colony.buildings.BuildingHome)1