net.minecraft.block.BlockBed Java Examples

The following examples show how to use net.minecraft.block.BlockBed. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockMapBuilder.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
protected void handleExtraBedBlock(IBlockState block, String c) {
	if (!isBed(c)) {
		return;
	}
	block = block.withProperty(BlockBed.PART, EnumPartType.HEAD);
	switch (block.getValue(BlockBed.FACING)) {
	case EAST:
		setBlockState(block, x + 1, y, z);
		break;
	case NORTH:
		setBlockState(block, x, y, z + 1);
		break;
	case SOUTH:
		setBlockState(block, x, y, z - 1);
		break;
	case WEST:
		setBlockState(block, x - 1, y, z);
		break;
	default:
		break;
	}
}
 
Example #2
Source File: VillagePieceBlockMap.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected IBlockState biomeSpecificDoor(IBlockState in) {
	BlockDoor newBlock;
	switch (this.structureType) {
	case 2:
		newBlock = Blocks.ACACIA_DOOR;
		break;
	case 3:
		newBlock = Blocks.SPRUCE_DOOR;
		break;
	default:
		newBlock = Blocks.OAK_DOOR;
		break;
	}
	return newBlock.getDefaultState().withProperty(BlockBed.FACING, in.getValue(BlockDoor.FACING));
}
 
Example #3
Source File: BaseMethods.java    From pycode-minecraft with MIT License 5 votes vote down vote up
protected void put(BlockPos pos, IBlockState block_state, EnumFacing facing) {
    // don't run on client
    if (this.world == null || this.world.isRemote) return;

    Block block = block_state.getBlock();

    FMLLog.info("Putting %s at %s", block_state, pos);

    // handle special cases
    if (block instanceof BlockDoor) {
        ItemDoor.placeDoor(this.world, pos, facing, block, true);
    } else if (block instanceof BlockBed) {
        BlockPos headpos = pos.offset(facing);
        if (this.world.getBlockState(pos.down()).isSideSolid(this.world, pos.down(), EnumFacing.UP) &&
                this.world.getBlockState(headpos.down()).isSideSolid(this.world, headpos.down(), EnumFacing.UP)) {
            block_state = block_state
                    .withProperty(BlockBed.OCCUPIED, false).withProperty(BlockBed.FACING, facing)
                    .withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);
            if (this.world.setBlockState(pos, block_state, 11)) {
                block_state = block_state.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD);
                this.world.setBlockState(headpos, block_state, 11);
            }
        }
    } else {
        this.world.setBlockState(pos, block_state);
    }
}
 
Example #4
Source File: MaterialCache.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nullable
protected ItemStack getStateToItemOverride(IBlockState state)
{
    Block block = state.getBlock();

    if (block == Blocks.PISTON_HEAD ||
        block == Blocks.PISTON_EXTENSION ||
        block == Blocks.PORTAL ||
        block == Blocks.END_PORTAL ||
        block == Blocks.END_GATEWAY)
    {
        return ItemStack.EMPTY;
    }
    else if (block == Blocks.FARMLAND)
    {
        return new ItemStack(Blocks.DIRT);
    }
    else if (block == Blocks.GRASS_PATH)
    {
        return new ItemStack(Blocks.GRASS);
    }
    else if (block == Blocks.BROWN_MUSHROOM_BLOCK)
    {
        return new ItemStack(Blocks.BROWN_MUSHROOM_BLOCK);
    }
    else if (block == Blocks.RED_MUSHROOM_BLOCK)
    {
        return new ItemStack(Blocks.RED_MUSHROOM_BLOCK);
    }
    else if (block == Blocks.LAVA)
    {
        if (state.getValue(BlockLiquid.LEVEL) == 0)
        {
            return new ItemStack(Items.LAVA_BUCKET);
        }
        else
        {
            return ItemStack.EMPTY;
        }
    }
    else if (block == Blocks.WATER)
    {
        if (state.getValue(BlockLiquid.LEVEL) == 0)
        {
            return new ItemStack(Items.WATER_BUCKET);
        }
        else
        {
            return ItemStack.EMPTY;
        }
    }
    else if (block instanceof BlockDoor && state.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.UPPER)
    {
        return ItemStack.EMPTY;
    }
    else if (block instanceof BlockBed && state.getValue(BlockBed.PART) == BlockBed.EnumPartType.HEAD)
    {
        return ItemStack.EMPTY;
    }
    else if (block instanceof BlockDoublePlant && state.getValue(BlockDoublePlant.HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
    {
        return ItemStack.EMPTY;
    }

    return null;
}
 
Example #5
Source File: BlockSurgeryTable.java    From Cyberware with MIT License 4 votes vote down vote up
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
	if (worldIn.isRemote)
	{
		return true;
	}
	else
	{
		if (state.getValue(PART) != BlockBed.EnumPartType.HEAD)
		{
			pos = pos.offset((EnumFacing)state.getValue(FACING));
			state = worldIn.getBlockState(pos);

			if (state.getBlock() != this)
			{
				return true;
			}
		}

		if (worldIn.provider.canRespawnHere() && worldIn.getBiomeGenForCoords(pos) != Biomes.HELL)
		{
			if (((Boolean)state.getValue(OCCUPIED)).booleanValue())
			{
				EntityPlayer entityplayer = this.getPlayerInBed(worldIn, pos);

				if (entityplayer != null)
				{
					playerIn.addChatComponentMessage(new TextComponentTranslation("tile.bed.occupied", new Object[0]));
					return true;
				}

				state = state.withProperty(OCCUPIED, Boolean.valueOf(false));
				worldIn.setBlockState(pos, state, 4);
			}

			EntityPlayer.SleepResult entityplayer$sleepresult = playerIn.trySleep(pos);

			if (entityplayer$sleepresult == EntityPlayer.SleepResult.OK)
			{
				state = state.withProperty(OCCUPIED, Boolean.valueOf(true));
				worldIn.setBlockState(pos, state, 4);
				return true;
			}
			else
			{
				if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_POSSIBLE_NOW)
				{
					playerIn.addChatComponentMessage(new TextComponentTranslation("tile.bed.noSleep", new Object[0]));
				}
				else if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_SAFE)
				{
					playerIn.addChatComponentMessage(new TextComponentTranslation("tile.bed.notSafe", new Object[0]));
				}

				return true;
			}
		}
		else
		{
			worldIn.setBlockToAir(pos);
			BlockPos blockpos = pos.offset(((EnumFacing)state.getValue(FACING)).getOpposite());

			if (worldIn.getBlockState(blockpos).getBlock() == this)
			{
				worldIn.setBlockToAir(blockpos);
			}

			worldIn.newExplosion((Entity)null, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 5.0F, true, true);
			return true;
		}
	}
}
 
Example #6
Source File: ItemAstroBed.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn,
		BlockPos pos, EnumHand hand, EnumFacing facing, float hitX,
		float hitY, float hitZ)
{
	if (worldIn.isRemote)
	{
		return EnumActionResult.SUCCESS;
	}
	else if (facing != EnumFacing.UP)
	{
		return EnumActionResult.FAIL;
	}
	else
	{
		ItemStack stack = playerIn.getHeldItem(hand);
		IBlockState iblockstate = worldIn.getBlockState(pos);
		Block block = iblockstate.getBlock();
		boolean flag = block.isReplaceable(worldIn, pos);

		if (!flag)
		{
			pos = pos.up();
		}

		int i = MathHelper.floor((double)(playerIn.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
		EnumFacing enumfacing = EnumFacing.getHorizontal(i);
		BlockPos blockpos = pos.offset(enumfacing);

		if (playerIn.canPlayerEdit(pos, facing, stack) && playerIn.canPlayerEdit(blockpos, facing, stack))
		{
			boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
			boolean flag2 = flag || worldIn.isAirBlock(pos);
			boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);

			if (flag2 && flag3 && worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP) && worldIn.getBlockState(blockpos.down()).isSideSolid(worldIn, blockpos.down(), EnumFacing.UP))
			{
				IBlockState iblockstate1 = AdvancedRocketryBlocks.blockAstroBed.getDefaultState().withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)).withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);

				if (worldIn.setBlockState(pos, iblockstate1, 11))
				{
					IBlockState iblockstate2 = iblockstate1.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD);
					worldIn.setBlockState(blockpos, iblockstate2, 11);
				}

				SoundType soundtype = iblockstate1.getBlock().getSoundType();
				worldIn.playSound((EntityPlayer)null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
				stack.setCount(stack.getCount() - 1);
				return EnumActionResult.SUCCESS;
			}
			else
			{
				return EnumActionResult.FAIL;
			}
		}
		else
		{
			return EnumActionResult.FAIL;
		}
	}
}
 
Example #7
Source File: BlockAstroBed.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
 public boolean onBlockActivated(World worldIn, BlockPos pos,
IBlockState state, EntityPlayer playerIn, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ) {
     if (worldIn.isRemote)
     {
         return true;
     }
     else
     {
         if (state.getValue(PART) != BlockBed.EnumPartType.HEAD)
         {
             pos = pos.offset((EnumFacing)state.getValue(FACING));
             state = worldIn.getBlockState(pos);

             if (state.getBlock() != this)
             {
                 return true;
             }
         }

         if (worldIn.provider instanceof WorldProviderPlanet)
         {
             if (((Boolean)state.getValue(OCCUPIED)).booleanValue())
             {
                 EntityPlayer entityplayer = this.getPlayerInBed(worldIn, pos);

                 if (entityplayer != null)
                 {
                     playerIn.sendMessage(new TextComponentTranslation("tile.bed.occupied", new Object[0]));
                     return true;
                 }

                 state = state.withProperty(OCCUPIED, Boolean.valueOf(false));
                 worldIn.setBlockState(pos, state, 4);
             }

             EntityPlayer.SleepResult entityplayer$sleepresult = playerIn.trySleep(pos);

             if (entityplayer$sleepresult == EntityPlayer.SleepResult.OK)
             {
                 state = state.withProperty(OCCUPIED, Boolean.valueOf(true));
                 worldIn.setBlockState(pos, state, 4);
                 return true;
             }
             else
             {
                 if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_POSSIBLE_NOW)
                 {
                     playerIn.sendMessage(new TextComponentTranslation("tile.bed.noSleep", new Object[0]));
                 }
                 else if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_SAFE)
                 {
                     playerIn.sendMessage(new TextComponentTranslation("tile.bed.notSafe", new Object[0]));
                 }

                 return true;
             }
         }
     }
     return false;
 }