/* * This messy function is a work in progress. It is a temporary setup for * placing a custom block from my mod over the door of the given npch. * * Returns the location of where the sign should be placed. * * Needs to be rewritten badly. */ public static BlockPos placeBlockOverDoor( ItemStack stack, EntityPlayer playerIn, World worldIn, NPCHouse npch, String block_name, float hitX, float hitY, float hitZ) { String placeMe = ("bh_housing:" + block_name); BlockPos door = BlockHelper.findDoor(worldIn, npch); if (!door.equals(npch.getCorner(0))) { int north = npch.getCorner(0).getZ(); int south = npch.getCorner(2).getZ(); int west = npch.getCorner(0).getX(); int east = npch.getCorner(1).getX(); BlockPos placeHere = door; boolean shouldUse = false; EnumFacing direction = EnumFacing.NORTH; if (worldIn.getBlockState(placeHere).getBlock() instanceof NPCHouse_Block) { return placeHere; } else if (door.getX() == west) { placeHere = door.up().west(); direction = EnumFacing.WEST; } else if (door.getX() == east) { placeHere = door.up().east(); direction = EnumFacing.EAST; } else if (door.getZ() == north) { placeHere = door.up().north(); direction = EnumFacing.NORTH; } else if (door.getZ() == south) { placeHere = door.up().south(); direction = EnumFacing.SOUTH; } shouldUse = worldIn.setBlockState( placeHere, NPCHouse_Block.getBlockFromName(placeMe) .getDefaultState() .withProperty(NPCHouse_Block.FACING, direction), 3); if (shouldUse) { --stack.stackSize; if (stack.stackSize == 0) { playerIn.destroyCurrentEquippedItem(); } if (block_name == "npch_block") { NPCHouse_Block npchblock = (NPCHouse_Block) worldIn.getBlockState(placeHere).getBlock(); npchblock.setNPCHouse(npch); } IBlockState temp = worldIn.getBlockState(placeHere); if (temp.getBlock().getRegistryName() == "npch_block") { ItemBlock.setTileEntityNBT( worldIn, playerIn, placeHere, new ItemStack(Block.getBlockFromName("npch_block"), 1)); } } return placeHere; } return null; }
/** Called when a Block is right-clicked with this Item */ public boolean onItemUse( ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if (side == EnumFacing.DOWN) { return false; } else if (!worldIn.getBlockState(pos).getBlock().getMaterial().isSolid()) { return false; } else { pos = pos.offset(side); if (!playerIn.canPlayerEdit(pos, side, stack)) { return false; } else if (!Blocks.standing_sign.canPlaceBlockAt(worldIn, pos)) { return false; } else if (worldIn.isRemote) { return true; } else { if (side == EnumFacing.UP) { int i = MathHelper.floor_double( (double) ((playerIn.rotationYaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15; worldIn.setBlockState( pos, Blocks.standing_sign .getDefaultState() .withProperty(BlockStandingSign.ROTATION, Integer.valueOf(i)), 3); } else { worldIn.setBlockState( pos, Blocks.wall_sign.getDefaultState().withProperty(BlockWallSign.FACING, side), 3); } --stack.stackSize; TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntitySign && !ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack)) { playerIn.openEditSign((TileEntitySign) tileentity); } return true; } } }
public boolean onItemUse( ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { IBlockState var9 = worldIn.getBlockState(pos); Block var10 = var9.getBlock(); if (var10 == Blocks.snow_layer && ((Integer) var9.getValue(BlockSnow.LAYERS_PROP)).intValue() < 1) { side = EnumFacing.UP; } else if (!var10.isReplaceable(worldIn, pos)) { pos = pos.offset(side); } if (stack.stackSize == 0) { return false; } else if (!playerIn.func_175151_a(pos, side, stack)) { return false; } else if (pos.getY() == 255 && this.block.getMaterial().isSolid()) { return false; } else if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity) null, stack)) { int var11 = this.getMetadata(stack.getMetadata()); IBlockState var12 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, var11, playerIn); if (worldIn.setBlockState(pos, var12, 3)) { var12 = worldIn.getBlockState(pos); if (var12.getBlock() == this.block) { setTileEntityNBT(worldIn, pos, stack); this.block.onBlockPlacedBy(worldIn, pos, var12, playerIn, stack); } worldIn.playSoundEffect( (double) ((float) pos.getX() + 0.5F), (double) ((float) pos.getY() + 0.5F), (double) ((float) pos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F); --stack.stackSize; } return true; } else { return false; } }