private static @Nonnull ItemBlock itemBlock(@Nonnull Block b) { ItemBlock item = new ItemBlock(b); //noinspection ConstantConditions item.setRegistryName(b.getRegistryName()); return item; }
private IFlowerComponent getFlowerComponent(ItemStack stack) { IFlowerComponent c = null; if(stack.getItem() instanceof IFlowerComponent) c = (IFlowerComponent) stack.getItem(); else if(stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock() instanceof IFlowerComponent) c = (IFlowerComponent) ((ItemBlock) stack.getItem()).getBlock(); return c; }
@Override public @Nonnull String getUnlocalizedNameForTooltip(@Nonnull ItemStack itemStack) { return super.getUnlocalizedName(itemStack); }
@SuppressWarnings("ConstantConditions") private static void registerItemBlock(IForgeRegistry<Item> r, ItemBlock item) { item.setRegistryName(item.getBlock().getRegistryName()); item.setCreativeTab(item.getBlock().getCreativeTab()); r.register(item); }
blockMeta = 0; stateToPlace = ((ItemBlock) stackItem).getBlock().getStateFromMeta(blockMeta); supertile.getWorld().playEvent(2001, coords, Block.getStateId(stateToPlace)); validPositions.remove(coords); ItemBlock.setTileEntityNBT(supertile.getWorld(), null, coords, stack);
@Nullable private ItemBlock constructItemFromBlock( Block block ) { if( this.disableItem ) { return null; } if( this.itemFactory != null ) { return this.itemFactory.apply( block ); } else if( block instanceof AEBaseBlock ) { return new AEBaseItemBlock( block ); } else { return new ItemBlock( block ); } } }
public static void registerBlockWithCustomItem(Block block, ItemBlock iBlock, String registryname) { block.setRegistryName(JurassiCraft.MODID, registryname); iBlock.setRegistryName(JurassiCraft.MODID, registryname); blocksToReg.add(block); itemsToReg.add(iBlock); blockItems.put(block, iBlock); }
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; }
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()); } } } } }
@Override public <T extends Block> void registerBlock(T block, ItemBlock itemBlock) { registerBlock(block); if (itemBlock.getRegistryName() == null) { itemBlock.setRegistryName(block.getRegistryName()); } registerItem(itemBlock); }
public static IBlockState getStateFromItem( final ItemStack bitItemStack ) { if ( bitItemStack != null && bitItemStack.getItem() instanceof ItemBlock ) { final ItemBlock blkItem = (ItemBlock) bitItemStack.getItem(); return blkItem.getBlock().getStateFromMeta( blkItem.getMetadata( bitItemStack ) ); } return null; }
if( super.placeBlockAt( stack, player, w, pos, side, hitX, hitY, hitZ, newState ) )
@Override public ItemBlock getItem() { return new ItemBlock(this); } }
if( item != null ) item.setRegistryName( AppEng.MOD_ID, this.registryName );
@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; } }
/** * Registery block at gameregistry. * * @param registry the registry to use. */ @Override public void registerItemBlock(final IForgeRegistry<Item> registry) { registry.register((new ItemBlock(this)).setRegistryName(this.getRegistryName())); } }
Block block = ( (ItemBlock) item ).getBlock();
@Override public ItemBlock getItem() { return new ItemBlock(this); } }
private static void registerBlock(Block block, ItemBlock item) { if(block.getRegistryName() == null) throw new IllegalArgumentException("A block being registered does not have a registry name and could be successfully registered."); RegistrationHandler.Blocks.add(block); if(item != null) { item.setRegistryName(block.getRegistryName()); RegistrationHandler.Items.add(item); } } }
@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; }