/** * Return null if bed is invalid */ public static BlockPos getBedSpawnLocation(World worldIn, BlockPos bedLocation, boolean forceSpawn) { Block block = worldIn.getBlockState(bedLocation).getBlock(); if (block != Blocks.bed) { if (!forceSpawn) { return null; } else { boolean flag = block.func_181623_g(); boolean flag1 = worldIn.getBlockState(bedLocation.up()).getBlock().func_181623_g(); return flag && flag1 ? bedLocation : null; } } else { return BlockBed.getSafeExitLocation(worldIn, bedLocation, 0); } }
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; } }
@SubscribeEvent @SuppressWarnings("unused") public void onPlayerTryToSleep(PlayerInteractEvent.RightClickBlock event) { World world = event.getWorld(); BlockPos pos = event.getPos(); IBlockState state = world.getBlockState(pos); if(!(state.getBlock() instanceof BlockBed)) { return; } if(isBedOccupied(world, pos, state)) { event.setCanceled(true); event.setUseBlock(Event.Result.DENY); event.setUseItem(Event.Result.DENY); event.getEntityPlayer().sendMessage(new TextComponentString("Occupied")); } }
@Override public void onBuildingCompleted() { if(!getWorld().isRemote) { this.beds = new ArrayList<>(); for (BlockPos pos : this.getBoundingBox()) { IBlockState state = this.getWorld().getBlockState(pos); TileEntity tile = this.getWorld().getTileEntity(pos); if ((state.getBlock() instanceof BlockBed) && (state.getValue(BlockBed.PART) == BlockBed.EnumPartType.HEAD)) { this.beds.add(new BlockPos(pos)); } if(tile != null) { if (tile instanceof IInventory) { this.inventory().registerInventory(new BlockPos(pos), (IInventory) tile); } //TODO: IItemHandler support } } this.building().onBuildingCompleted(this); this.markDirty(); this.syncToClient(); } }
/** * Ensure that a block enabling respawning exists at the specified coordinates and find an empty space nearby to * spawn. */ public static ChunkCoordinates verifyRespawnCoordinates(World par0World, ChunkCoordinates par1ChunkCoordinates, boolean par2) { IChunkProvider var3 = par0World.getChunkProvider(); var3.loadChunk(par1ChunkCoordinates.posX - 3 >> 4, par1ChunkCoordinates.posZ - 3 >> 4); var3.loadChunk(par1ChunkCoordinates.posX + 3 >> 4, par1ChunkCoordinates.posZ - 3 >> 4); var3.loadChunk(par1ChunkCoordinates.posX - 3 >> 4, par1ChunkCoordinates.posZ + 3 >> 4); var3.loadChunk(par1ChunkCoordinates.posX + 3 >> 4, par1ChunkCoordinates.posZ + 3 >> 4); if (par0World.getBlock(par1ChunkCoordinates.posX, par1ChunkCoordinates.posY, par1ChunkCoordinates.posZ) == Blocks.bed) { ChunkCoordinates var8 = BlockBed.func_149977_a(par0World, par1ChunkCoordinates.posX, par1ChunkCoordinates.posY, par1ChunkCoordinates.posZ, 0); return var8; } else { Material var4 = par0World.getBlock(par1ChunkCoordinates.posX, par1ChunkCoordinates.posY, par1ChunkCoordinates.posZ).getMaterial(); Material var5 = par0World.getBlock(par1ChunkCoordinates.posX, par1ChunkCoordinates.posY + 1, par1ChunkCoordinates.posZ).getMaterial(); boolean var6 = !var4.isSolid() && !var4.isLiquid(); boolean var7 = !var5.isSolid() && !var5.isLiquid(); return par2 && var6 && var7 ? par1ChunkCoordinates : null; } }
/** * Returns the orientation of the bed in degrees. */ public float getBedOrientationInDegrees() { if (this.playerLocation != null) { int var1 = this.worldObj.getBlockMetadata(this.playerLocation.posX, this.playerLocation.posY, this.playerLocation.posZ); int var2 = BlockBed.func_149895_l(var1); switch (var2) { case 0: return 90.0F; case 1: return 0.0F; case 2: return 270.0F; case 3: return 180.0F; } } return 0.0F; }
protected boolean func_75398_a(World p_75398_1_, int p_75398_2_, int p_75398_3_, int p_75398_4_) { int var5 = p_75398_1_.func_72798_a(p_75398_2_, p_75398_3_, p_75398_4_); int var6 = p_75398_1_.func_72805_g(p_75398_2_, p_75398_3_, p_75398_4_); if(var5 == Block.field_72077_au.field_71990_ca) { TileEntityChest var7 = (TileEntityChest)p_75398_1_.func_72796_p(p_75398_2_, p_75398_3_, p_75398_4_); if(var7.field_70427_h < 1) { return true; } } else { if(var5 == Block.field_72052_aC.field_71990_ca) { return true; } if(var5 == Block.field_71959_S.field_71990_ca && !BlockBed.func_72229_a_(var6)) { return true; } } return false; }
public static ChunkCoordinates func_71056_a(World p_71056_0_, ChunkCoordinates p_71056_1_, boolean p_71056_2_) { IChunkProvider var3 = p_71056_0_.func_72863_F(); var3.func_73158_c(p_71056_1_.field_71574_a - 3 >> 4, p_71056_1_.field_71573_c - 3 >> 4); var3.func_73158_c(p_71056_1_.field_71574_a + 3 >> 4, p_71056_1_.field_71573_c - 3 >> 4); var3.func_73158_c(p_71056_1_.field_71574_a - 3 >> 4, p_71056_1_.field_71573_c + 3 >> 4); var3.func_73158_c(p_71056_1_.field_71574_a + 3 >> 4, p_71056_1_.field_71573_c + 3 >> 4); if(p_71056_0_.func_72798_a(p_71056_1_.field_71574_a, p_71056_1_.field_71572_b, p_71056_1_.field_71573_c) == Block.field_71959_S.field_71990_ca) { ChunkCoordinates var8 = BlockBed.func_72226_b(p_71056_0_, p_71056_1_.field_71574_a, p_71056_1_.field_71572_b, p_71056_1_.field_71573_c, 0); return var8; } else { Material var4 = p_71056_0_.func_72803_f(p_71056_1_.field_71574_a, p_71056_1_.field_71572_b, p_71056_1_.field_71573_c); Material var5 = p_71056_0_.func_72803_f(p_71056_1_.field_71574_a, p_71056_1_.field_71572_b + 1, p_71056_1_.field_71573_c); boolean var6 = !var4.func_76220_a() && !var4.func_76224_d(); boolean var7 = !var5.func_76220_a() && !var5.func_76224_d(); return p_71056_2_ && var6 && var7?p_71056_1_:null; } }
@SideOnly(Side.CLIENT) public float func_71051_bG() { if(this.field_71081_bT != null) { int var1 = this.field_70170_p.func_72805_g(this.field_71081_bT.field_71574_a, this.field_71081_bT.field_71572_b, this.field_71081_bT.field_71573_c); int var2 = BlockBed.func_72217_d(var1); switch(var2) { case 0: return 90.0F; case 1: return 0.0F; case 2: return 270.0F; case 3: return 180.0F; } } return 0.0F; }
@SuppressWarnings("ConstantConditions") @Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { IBlockState state = world.getBlockState(pos); if (state.getBlock().isBed(state, world, pos, player)) { Optional<EntityPlayer> victim = getPlayerFromBed(world, pos, state.getValue(BlockBed.OCCUPIED)); if (victim.isPresent()) { setVictim(player.getHeldItem(hand), victim.get()); } } return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand); }
/** * Return true to set given position as destination */ protected boolean shouldMoveTo(World worldIn, BlockPos pos) { if (!worldIn.isAirBlock(pos.up())) { return false; } else { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (block == Blocks.chest) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityChest && ((TileEntityChest)tileentity).numPlayersUsing < 1) { return true; } } else { if (block == Blocks.lit_furnace) { return true; } if (block == Blocks.bed && iblockstate.getValue(BlockBed.PART) != BlockBed.EnumPartType.HEAD) { return true; } } return false; } }
/** * Wake up the player if they're sleeping. */ public void wakeUpPlayer(boolean p_70999_1_, boolean updateWorldFlag, boolean setSpawn) { this.setSize(0.6F, 1.8F); IBlockState iblockstate = this.worldObj.getBlockState(this.playerLocation); if (this.playerLocation != null && iblockstate.getBlock() == Blocks.bed) { this.worldObj.setBlockState(this.playerLocation, iblockstate.withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)), 4); BlockPos blockpos = BlockBed.getSafeExitLocation(this.worldObj, this.playerLocation, 0); if (blockpos == null) { blockpos = this.playerLocation.up(); } this.setPosition((double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 0.1F), (double)((float)blockpos.getZ() + 0.5F)); } this.sleeping = false; if (!this.worldObj.isRemote && updateWorldFlag) { this.worldObj.updateAllPlayersSleepingFlag(); } this.sleepTimer = p_70999_1_ ? 0 : 100; if (setSpawn) { this.setSpawnPoint(this.playerLocation, false); } }
public void cacheActiveRenderInfo(World worldIn, FontRenderer textRendererIn, Entity livingPlayerIn, Entity pointedEntityIn, GameSettings optionsIn, float partialTicks) { this.worldObj = worldIn; this.options = optionsIn; this.livingPlayer = livingPlayerIn; this.pointedEntity = pointedEntityIn; this.textRenderer = textRendererIn; if (livingPlayerIn instanceof EntityLivingBase && ((EntityLivingBase)livingPlayerIn).isPlayerSleeping()) { IBlockState iblockstate = worldIn.getBlockState(new BlockPos(livingPlayerIn)); Block block = iblockstate.getBlock(); if (block == Blocks.bed) { int i = ((EnumFacing)iblockstate.getValue(BlockBed.FACING)).getHorizontalIndex(); this.playerViewY = (float)(i * 90 + 180); this.playerViewX = 0.0F; } } else { this.playerViewY = livingPlayerIn.prevRotationYaw + (livingPlayerIn.rotationYaw - livingPlayerIn.prevRotationYaw) * partialTicks; this.playerViewX = livingPlayerIn.prevRotationPitch + (livingPlayerIn.rotationPitch - livingPlayerIn.prevRotationPitch) * partialTicks; } if (optionsIn.thirdPersonView == 2) { this.playerViewY += 180.0F; } this.viewerPosX = livingPlayerIn.lastTickPosX + (livingPlayerIn.posX - livingPlayerIn.lastTickPosX) * (double)partialTicks; this.viewerPosY = livingPlayerIn.lastTickPosY + (livingPlayerIn.posY - livingPlayerIn.lastTickPosY) * (double)partialTicks; this.viewerPosZ = livingPlayerIn.lastTickPosZ + (livingPlayerIn.posZ - livingPlayerIn.lastTickPosZ) * (double)partialTicks; }
/** * Wake up the player if they're sleeping. */ public void wakeUpPlayer(boolean immediately, boolean updateWorldFlag, boolean setSpawn) { this.setSize(0.6F, 1.8F); IBlockState iblockstate = this.world.getBlockState(this.bedLocation); if (this.bedLocation != null && iblockstate.getBlock() == Blocks.BED) { this.world.setBlockState(this.bedLocation, iblockstate.withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)), 4); BlockPos blockpos = BlockBed.getSafeExitLocation(this.world, this.bedLocation, 0); if (blockpos == null) { blockpos = this.bedLocation.up(); } this.setPosition((double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 0.1F), (double)((float)blockpos.getZ() + 0.5F)); } this.sleeping = false; if (!this.world.isRemote && updateWorldFlag) { this.world.updateAllPlayersSleepingFlag(); } this.sleepTimer = immediately ? 0 : 100; if (setSpawn) { this.setSpawnPoint(this.bedLocation, false); } }
@Nullable /** * Return null if bed is invalid */ public static BlockPos getBedSpawnLocation(World worldIn, BlockPos bedLocation, boolean forceSpawn) { Block block = worldIn.getBlockState(bedLocation).getBlock(); if (block != Blocks.BED) { if (!forceSpawn) { return null; } else { boolean flag = block.canSpawnInBlock(); boolean flag1 = worldIn.getBlockState(bedLocation.up()).getBlock().canSpawnInBlock(); return flag && flag1 ? bedLocation : null; } } else { return BlockBed.getSafeExitLocation(worldIn, bedLocation, 0); } }
/** * Return true to set given position as destination */ protected boolean shouldMoveTo(World worldIn, BlockPos pos) { if (!worldIn.isAirBlock(pos.up())) { return false; } else { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (block == Blocks.CHEST) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityChest && ((TileEntityChest)tileentity).numPlayersUsing < 1) { return true; } } else { if (block == Blocks.LIT_FURNACE) { return true; } if (block == Blocks.BED && iblockstate.getValue(BlockBed.PART) != BlockBed.EnumPartType.HEAD) { return true; } } return false; } }
public static ForgeDirection[] getValidVanillaBlockRotations(Block block) { return (block instanceof BlockBed || block instanceof BlockPumpkin || block instanceof BlockFenceGate || block instanceof BlockEndPortalFrame || block instanceof BlockTripWireHook || block instanceof BlockCocoa || block instanceof BlockRailPowered || block instanceof BlockRailDetector || block instanceof BlockStairs || block instanceof BlockChest || block instanceof BlockEnderChest || block instanceof BlockFurnace || block instanceof BlockLadder || block == Blocks.field_150444_as || block == Blocks.field_150472_an || block instanceof BlockDoor || block instanceof BlockRail || block instanceof BlockButton || block instanceof BlockRedstoneRepeater || block instanceof BlockRedstoneComparator || block instanceof BlockTrapDoor || block instanceof BlockHugeMushroom || block instanceof BlockVine || block instanceof BlockSkull || block instanceof BlockAnvil) ? UP_DOWN_AXES : VALID_DIRECTIONS; }
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)); }
private static void PlaceBed(World world, BlockPos cornerPosition, EnumFacing facing) { // This is the "north west" corner. BlockPos itemPosition = cornerPosition.offset(facing.rotateY(), 1).offset(facing.getOpposite(), 2).down(); IBlockState bedFootState = Blocks.BED.getDefaultState().withProperty(BlockHorizontal.FACING, facing) .withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT); if (world.setBlockState(itemPosition, bedFootState, 3)) { IBlockState bedHeadState = bedFootState.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD); world.setBlockState(itemPosition.offset(facing), bedHeadState, 3); } }
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); } }
public boolean isBedOccupied(World world, BlockPos pos, IBlockState bed) { if(bed.getBlock() instanceof BlockBed) { if (bed.getValue(BlockBed.OCCUPIED)) { return true; } BlockPos head = getHeadPos(pos, bed); return occupiedBeds.containsKey(world) && occupiedBeds.get(world).contains(head); } return false; }
private BlockPos getHeadPos(BlockPos pos, IBlockState bed) { BlockBed.EnumPartType part = bed.getValue(BlockBed.PART); if(part == BlockBed.EnumPartType.FOOT) { EnumFacing facing = bed.getValue(BlockBed.FACING); return pos.offset(facing); } return pos; }
public static ForgeDirection[] getValidVanillaBlockRotations(Block block) { return (block instanceof BlockBed || block instanceof BlockPumpkin || block instanceof BlockFenceGate || block instanceof BlockEndPortalFrame || block instanceof BlockTripWireHook || block instanceof BlockCocoa || block instanceof BlockRailPowered || block instanceof BlockRailDetector || block instanceof BlockStairs || block instanceof BlockChest || block instanceof BlockEnderChest || block instanceof BlockFurnace || block instanceof BlockLadder || block == Blocks.wall_sign || block == Blocks.standing_sign || block instanceof BlockDoor || block instanceof BlockRail || block instanceof BlockButton || block instanceof BlockRedstoneRepeater || block instanceof BlockRedstoneComparator || block instanceof BlockTrapDoor || block instanceof BlockHugeMushroom || block instanceof BlockVine || block instanceof BlockSkull || block instanceof BlockAnvil) ? UP_DOWN_AXES : VALID_DIRECTIONS; }
private boolean func_151486_a(World p_151486_1_, int p_151486_2_, int p_151486_3_, int p_151486_4_) { Block var5 = p_151486_1_.getBlock(p_151486_2_, p_151486_3_, p_151486_4_); int var6 = p_151486_1_.getBlockMetadata(p_151486_2_, p_151486_3_, p_151486_4_); if (var5 == Blocks.chest) { TileEntityChest var7 = (TileEntityChest)p_151486_1_.getTileEntity(p_151486_2_, p_151486_3_, p_151486_4_); if (var7.field_145987_o < 1) { return true; } } else { if (var5 == Blocks.lit_furnace) { return true; } if (var5 == Blocks.bed && !BlockBed.func_149975_b(var6)) { return true; } } return false; }
/** * Called when a user either starts or stops sleeping in the bed. * * @param world The current world * @param x X Position * @param y Y Position * @param z Z Position * @param player The player or camera entity, null in some cases. * @param occupied True if we are occupying the bed, or false if they are stopping use of the bed */ @Override public void setBedOccupied(IBlockAccess world, int x, int y, int z, EntityPlayer player, boolean occupied) { if (world instanceof World) { BlockBed.func_149979_a((World)world, x, y, z, occupied); if (!occupied) { // Player woke up, collapse the stick shelter ((World) world).setBlockToAir(x, y, z); // TODO: quest generation } } }