Search in sources :

Example 6 with BlockBed

use of net.minecraft.block.BlockBed in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onPlayerRightClickEvent.

@SubscribeEvent
public void onPlayerRightClickEvent(PlayerInteractEvent.RightClickBlock event) {
    World world = event.getWorld();
    if (world.isRemote)
        return;
    BlockPos pos = event.getPos();
    WorldProvider provider = world.provider;
    if (!(world.getBlockState(pos).getBlock() instanceof BlockBed && provider instanceof GenericWorldProvider))
        return;
    // We are in an RFTools dimension.
    switch(GeneralConfiguration.bedBehaviour) {
        case 0:
            event.setCanceled(true);
            Logging.message(event.getEntityPlayer(), "You cannot sleep in this dimension!");
            break;
        // In case 1, just do the usual thing (this typically mean explosion).
        case 2:
            event.setCanceled(true);
            event.getEntityPlayer().setSpawnChunk(pos, true, provider.getDimension());
            Logging.message(event.getEntityPlayer(), "Spawn point set!");
    }
}
Also used : GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) WorldProvider(net.minecraft.world.WorldProvider) BlockBed(net.minecraft.block.BlockBed) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 7 with BlockBed

use of net.minecraft.block.BlockBed in project MC-Prefab by Brian-Wuest.

the class StructureAlternateStart method CustomBlockProcessingHandled.

@Override
protected Boolean CustomBlockProcessingHandled(StructureConfiguration configuration, BuildBlock block, World world, BlockPos originalPos, EnumFacing assumedNorth, Block foundBlock, IBlockState blockState, EntityPlayer player) {
    HouseConfiguration houseConfig = (HouseConfiguration) configuration;
    if ((!houseConfig.addBed && foundBlock instanceof BlockBed) || (!houseConfig.addChest && foundBlock instanceof BlockChest) || (!houseConfig.addTorches && foundBlock instanceof BlockTorch) || (!houseConfig.addCraftingTable && (foundBlock instanceof BlockWorkbench || foundBlock instanceof BlockFurnace))) {
        // "handled"
        return true;
    }
    if (foundBlock instanceof BlockFurnace) {
        this.furnacePosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
    } else if (foundBlock instanceof BlockTrapDoor && houseConfig.addMineShaft) {
        // The trap door will still be added, but the mine shaft may not be
        // built.
        this.trapDoorPosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
    } else if (foundBlock instanceof BlockChest && this.chestPosition == null) {
        this.chestPosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
    } else if (foundBlock instanceof BlockStandingSign) {
        this.signPosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
    }
    if (foundBlock.getRegistryName().getResourceDomain().equals(Blocks.STAINED_GLASS.getRegistryName().getResourceDomain()) && foundBlock.getRegistryName().getResourcePath().equals(Blocks.STAINED_GLASS.getRegistryName().getResourcePath())) {
        blockState = blockState.withProperty(BlockStainedGlass.COLOR, houseConfig.glassColor);
        block.setBlockState(blockState);
        this.priorityOneBlocks.add(block);
        return true;
    } else if (foundBlock.getRegistryName().getResourceDomain().equals(Blocks.STAINED_GLASS_PANE.getRegistryName().getResourceDomain()) && foundBlock.getRegistryName().getResourcePath().equals(Blocks.STAINED_GLASS_PANE.getRegistryName().getResourcePath())) {
        block.setBlockState(foundBlock.getStateFromMeta(houseConfig.glassColor.getMetadata()));
        this.priorityOneBlocks.add(block);
        return true;
    }
    return false;
}
Also used : BlockFurnace(net.minecraft.block.BlockFurnace) BlockChest(net.minecraft.block.BlockChest) BlockWorkbench(net.minecraft.block.BlockWorkbench) BlockTrapDoor(net.minecraft.block.BlockTrapDoor) BlockStandingSign(net.minecraft.block.BlockStandingSign) BlockBed(net.minecraft.block.BlockBed) HouseConfiguration(com.wuest.prefab.Config.Structures.HouseConfiguration) BlockTorch(net.minecraft.block.BlockTorch)

Example 8 with BlockBed

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

the class EntityAISleep method shouldContinueExecuting.

/**
 * Continue executing if he should sleep.
 * Call the wake up method as soon as this isn't the case anymore.
 * Might search a bed while he is trying to sleep.
 *
 * @return true while he should sleep.
 */
@Override
public boolean shouldContinueExecuting() {
    if (citizen.getDesiredActivity() == EntityCitizen.DesiredActivity.SLEEP) {
        wokeUp = false;
        final Colony colony = citizen.getColony();
        if (colony == null || colony.getBuildingManager().getBuilding(citizen.getHomePosition()) == null) {
            return true;
        }
        if (usedBed == null) {
            final AbstractBuilding hut = colony.getBuildingManager().getBuilding(citizen.getHomePosition());
            if (hut instanceof BuildingHome) {
                for (final BlockPos pos : ((BuildingHome) hut).getBedList()) {
                    final World world = citizen.world;
                    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)) {
                        usedBed = pos;
                        citizen.world.setBlockState(pos, state.withProperty(BlockBed.OCCUPIED, true), 0x03);
                        final BlockPos feetPos = pos.offset(state.getValue(BlockBed.FACING).getOpposite());
                        final IBlockState feetState = citizen.world.getBlockState(feetPos);
                        citizen.world.setBlockState(feetPos, feetState.withProperty(BlockBed.OCCUPIED, true), 0x03);
                        return true;
                    }
                }
            }
            usedBed = citizen.getHomePosition();
        } else {
            if (citizen.isWorkerAtSiteWithMove(usedBed, 1)) {
                citizen.trySleep(usedBed);
                return true;
            }
        }
        return true;
    }
    citizen.onWakeUp();
    if (usedBed != null) {
        final IBlockState state = citizen.world.getBlockState(usedBed);
        if (state.getBlock() instanceof BlockBed) {
            final IBlockState headState = citizen.world.getBlockState(usedBed);
            citizen.world.setBlockState(usedBed, headState.withProperty(BlockBed.OCCUPIED, false), 0x03);
            final BlockPos feetPos = usedBed.offset(headState.getValue(BlockBed.FACING).getOpposite());
            final IBlockState feetState = citizen.world.getBlockState(feetPos);
            citizen.world.setBlockState(feetPos, feetState.withProperty(BlockBed.OCCUPIED, true), 0x03);
        }
        usedBed = null;
    }
    wokeUp = true;
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BuildingHome(com.minecolonies.coremod.colony.buildings.BuildingHome) Colony(com.minecolonies.coremod.colony.Colony) BlockBed(net.minecraft.block.BlockBed) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 9 with BlockBed

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

the class ItemArmourersHammer method rotateBed.

private boolean rotateBed(World world, int x, int y, int z, BlockBed block, ForgeDirection axis) {
    int meta = world.getBlockMetadata(x, y, z);
    ForgeDirection[] bedRots = { ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.NORTH, ForgeDirection.EAST };
    int bedDir = ((BlockBed) block).getDirection(meta);
    ForgeDirection bedRot = bedRots[bedDir];
    ForgeDirection otherHalf = bedRot;
    boolean isHead = block.isBlockHeadOfBed(meta);
    if (isHead) {
        otherHalf = bedRot.getOpposite();
    }
    if (world.getBlock(x + otherHalf.offsetX, y + otherHalf.offsetY, z + otherHalf.offsetZ) == block) {
        int otherMeta = world.getBlockMetadata(x + otherHalf.offsetX, y + otherHalf.offsetY, z + otherHalf.offsetZ);
        int newMeta = (meta & 3) + 2 % 3;
        if (!isHead) {
            newMeta += 8;
        }
        world.setBlockMetadataWithNotify(x, y, z, newMeta, 3);
        newMeta = (otherMeta & 3) + 2 % 3;
        if (isHead) {
            newMeta += 8;
        }
        world.setBlockMetadataWithNotify(x + otherHalf.offsetX, y + otherHalf.offsetY, z + otherHalf.offsetZ, newMeta, 3);
        return true;
    }
    return false;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) 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