@Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) { if (super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState)) { TileEntity tile = world.getTileEntity(pos); if (tile instanceof TileDemonCrystal) { ((TileDemonCrystal) tile).setPlacement(side); } return true; } return false; } }
if( super.placeBlockAt( stack, player, w, pos, side, hitX, hitY, hitZ, newState ) )
@Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) { if (super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState)) { TileFrequencyOwner tile = (TileFrequencyOwner) world.getTileEntity(pos); tile.setFreq(getFreq(stack)); return true; } return false; }
@Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) { MetaTileEntity metaTileEntity = getMetaTileEntity(stack); //prevent rendering glitch before meta tile entity sync to client, but after block placement //set opaque property on the placing on block, instead during set of meta tile entity return super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState.withProperty(BlockMachine.OPAQUE, metaTileEntity != null && metaTileEntity.isOpaqueCube())); }
@Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) { if (!super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState)) { return false; } NBTTagCompound tagCompound = stack.getTagCompound(); if (tagCompound != null) { TileEntityFluidInterface fluidInterface = TileUtil.getTile(world, pos, TileEntityFluidInterface.class); if (fluidInterface != null) { fluidInterface.readFilter(tagCompound); } } return true; } }
float hitX, float hitY, float hitZ, @Nonnull IBlockState newState) { boolean result = super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState); TileEntity te = world.getTileEntity(pos); if (!(te instanceof TileDialingDevice)) {
@Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) { if (!super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState)) { return false; } if (stack != null && stack.hasTagCompound()) { TileEntityCertusTank certusTank = (TileEntityCertusTank) world.getTileEntity(pos); FluidStack fluidStack = FluidUtil.getFluidContained(stack); certusTank.setFluid(fluidStack); } return true; } }
.placeBlockAt( maybeMultiPartStack.get(), player, world, te_pos, side, 0.5f, 0.5f, 0.5f, maybeMultiPartBlock.get().getDefaultState() ) )
@Override public IWrappedBlock registerStackWrapper(Item item, Predicate<ItemStack> predicate, Block block) { IMultipart part = getPart(block); Preconditions.checkState(part != null, "Attempted to wrap the placement of a block that's not registered as a multipart!"); WrappedBlock wrappedBlock = new WrappedBlock(); wrappedBlock.setPlacementInfo(block::getStateForPlacement); if (item instanceof ItemBlock) { wrappedBlock.setBlockPlacementLogic( (stack, player, world, pos, facing, hitX, hitY, hitZ, newState) -> player.canPlayerEdit(pos, facing, stack) && world.getBlockState(pos).getBlock().isReplaceable(world, pos) && block.canPlaceBlockAt(world, pos) && block.canPlaceBlockOnSide(world, pos, facing) && ((ItemBlock) item).placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, newState)); } STACK_WRAPPING_MAP.putIfAbsent(item, Pair.of(predicate, Pair.of(wrappedBlock, part))); return wrappedBlock; }
@Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) { boolean result = super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState); if (result && block.getDirection() != null) { TileEntity tile = world.getTileEntity(pos); if (tile instanceof TileBase) { ((TileBase) tile).setDirection(block.getDirection().getFrom(side, pos, player)); } } return result; } }
@Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) { if(!super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState)) { return false; } TileEntity te = world.getTileEntity(pos); if(te instanceof TileInventoryPanel) { TileInventoryPanel teInvPanel = (TileInventoryPanel) te; teInvPanel.setFacing(side); teInvPanel.readCustomNBT(stack); if(!world.isRemote) { IBlockState bs = world.getBlockState(pos); world.notifyBlockUpdate(pos, bs, bs, 3); } } return true; }
public boolean placeBlockAtTested(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, IBlockState newState) { return player.canPlayerEdit(pos, facing, stack) && world.getBlockState(pos).getBlock().isReplaceable(world, pos) && block.canPlaceBlockAt(world, pos) && block.canPlaceBlockOnSide(world, pos, facing) && super.placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, newState); }
@Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) { boolean placed = super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState); if (placed) { if (block.hasTileEntity(newState)) { if (stack.getItem() instanceof ItemBlockNBT && stack.getTagCompound() != null) { TileForestry tile = TileUtil.getTile(world, pos, TileForestry.class); if (tile != null) { tile.readFromNBT(stack.getTagCompound()); tile.setPos(pos); } } } if (block instanceof IBlockRotatable) { ((IBlockRotatable) block).rotateAfterPlacement(player, world, pos, side); } } return placed; } }
private EnumActionResult placeBlock(ItemStack itemstack, EntityPlayer player, BlockPos pos, EnumFacing facing, World worldIn, EnumHand hand, float hitX, float hitY, float hitZ) { IBlockState stateAt = worldIn.getBlockState(pos); if(!stateAt.getBlock().isReplaceable(worldIn, pos)) pos = pos.offset(facing); if(itemstack.getItem() instanceof ItemBlock) { ItemBlock item = (ItemBlock) itemstack.getItem(); Block block = item.getBlock(); if(player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(block, pos, false, facing, null)) { int i = item.getMetadata(itemstack.getMetadata()); IBlockState state = block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand); if(item.placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, state)) { state = worldIn.getBlockState(pos); SoundType soundtype = state.getBlock().getSoundType(state, worldIn, pos, player); worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); if(!player.capabilities.isCreativeMode) shrinkInventory(itemstack, player); } return EnumActionResult.SUCCESS; } } return EnumActionResult.FAIL; }
public static void placeBlock(EntityPlayer player, World world, BlockPos pos, int slot, boolean particles, boolean conjure) { if(!world.isBlockLoaded(pos) || !world.isBlockModifiable(player, pos)) return; IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if(block.isAir(state, world, pos) || block.isReplaceable(world, pos)) { if(conjure) { if(!world.isRemote) world.setBlockState(pos, ModBlocks.conjured.getDefaultState()); } else { ItemStack stack = player.inventory.getStackInSlot(slot); if(!stack.isEmpty() && stack.getItem() instanceof ItemBlock) { ItemStack rem = removeFromInventory(player, stack); ItemBlock iblock = (ItemBlock) rem.getItem(); Block blockToPlace = Block.getBlockFromItem(rem.getItem()); if(!world.isRemote) { IBlockState newState = blockToPlace.getStateForPlacement(world, pos, EnumFacing.UP, 0, 0, 0, rem.getItemDamage(), player, EnumHand.MAIN_HAND); iblock.placeBlockAt(stack, player, world, pos, EnumFacing.UP, 0, 0, 0, newState); } if(player.capabilities.isCreativeMode) HUDHandler.setRemaining(rem, -1); else HUDHandler.setRemaining(player, rem, null); } } if(particles && !world.isRemote) world.playEvent(2001, pos, Block.getStateId(world.getBlockState(pos))); } }
private void placeCrystal() { BlockPos pos = getCrystalPosition(); ItemStack crystalStack = inventoryHelper.getStackInSlot(PedestalContainer.SLOT_CRYSTAL); if (!crystalStack.isEmpty()) { if (crystalStack.getItem() instanceof ItemBlock) { ItemBlock itemBlock = (ItemBlock) (crystalStack.getItem()); itemBlock.placeBlockAt(crystalStack, FakePlayerFactory.getMinecraft((WorldServer) getWorld()), getWorld(), pos, null, 0, 0, 0, itemBlock.getBlock().getStateFromMeta(0)); inventoryHelper.decrStackSize(PedestalContainer.SLOT_CRYSTAL, 1); SoundTools.playSound(getWorld(), ModBlocks.resonatingCrystalBlock.getSoundType().breakSound, getPos().getX(), getPos().getY(), getPos().getZ(), 1.0f, 1.0f); if (findCollector()) { TileEntity tileEntity = getWorld().getTileEntity(new BlockPos(cachedLocator)); if (tileEntity instanceof EnergyCollectorTileEntity) { EnergyCollectorTileEntity energyCollectorTileEntity = (EnergyCollectorTileEntity) tileEntity; energyCollectorTileEntity.addCrystal(pos.getX(), pos.getY(), pos.getZ()); } } } } }
stack.getMetadata(), fake, EnumHand.MAIN_HAND); if (itemblock.placeBlockAt(stack, fake, world, placePos, EnumFacing.UP, placePos.getX(), placePos.getY(), placePos.getZ(), state)) { world.playSound(null, placePos, state.getBlock().getSoundType(state, world, placePos, fake).getPlaceSound(), SoundCategory.BLOCKS, 0.7F, 1.0F); stack.shrink(1);
((ItemBlock) item.getItem()).placeBlockAt( took, FakePlayerFactory.getMinecraft((WorldServer) world),