Смотри как сделан ItemBlock.
Любой блок в инвентаре - это предмет.
Дюрабилити, соответственно бери с инструментов или оружия.
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
if (!block.isReplaceable(worldIn, pos))
{
pos = pos.offset(facing);
}
ItemStack itemstack = player.getHeldItem(hand);
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(this.block, pos, false, facing, (Entity)null))
{
int i = this.getMetadata(itemstack.getMetadata());
IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);
if (placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1))
{
SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player);
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
}
return EnumActionResult.SUCCESS;
}
else
{
return EnumActionResult.FAIL;
}
}
IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);
package ru.vixtor.item;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemTest extends Item {
public ItemTest()
{
this.setRegistryName("item_test");
this.setUnlocalizedName("itemTest");
this.maxStackSize = 1;
this.setMaxDamage(64);
this.setCreativeTab(CreativeTabs.MATERIALS);
}
/**
* Called when a Block is right-clicked with this Item
*/
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
pos = pos.offset(facing);
ItemStack itemstack = player.getHeldItem(hand);
if (!player.canPlayerEdit(pos, facing, itemstack))
{
return EnumActionResult.FAIL;
}
else
{
if (worldIn.isAirBlock(pos))
{
worldIn.playSound(player, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
worldIn.setBlockState(pos, Blocks.WEB.getDefaultState(), 11);
}
itemstack.damageItem(1, player);
return EnumActionResult.SUCCESS;
}
}
}
package ru.vixtor.Block;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
public class BlockTest extends Block {
public BlockTest () {
super(Material.CARPET);
this.setRegistryName("block_test");
this.setUnlocalizedName("blockTest");
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
}
worldIn.setBlockState(pos, Blocks.WEB.getDefaultState(), 11);
public static final BlockTest TESTBLOCK = new BlockTest();
public class ItemTest extends Item {
public ItemTest()
{
this.setRegistryName("item_test");
this.setUnlocalizedName("itemTest");
this.maxStackSize = 1;
this.setMaxDamage(64);
this.setCreativeTab(CreativeTabs.MATERIALS);
}
/**
* Called when a Block is right-clicked with this Item
*/
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
pos = pos.offset(facing);
ItemStack itemstack = player.getHeldItem(hand);
if (!player.canPlayerEdit(pos, facing, itemstack))
{
return EnumActionResult.FAIL;
}
else
{
if (worldIn.isAirBlock(pos))
{
worldIn.playSound(player, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
worldIn.setBlockState(pos, Blocks.TESTBLOCK.getDefaultState(), 11);
}
itemstack.damageItem(1, player);
return EnumActionResult.SUCCESS;
}
}
}
/**
* Convenience method to update the block on both the client and server
*/
public boolean setBlockState(BlockPos pos, IBlockState state)
{
return this.setBlockState(pos, state, 3);
}
@Mod(modid = "testmod", name = "Test Mod", version = "1.0.0")
public class TestMod
{
public static final BlockTest TESTBLOCK = new BlockTest();
@SidedProxy(clientSide = "ru.vixtor.proxy.ClientProxy", serverSide = "ru.vixtor.proxy.ServerProxy")
public static CommonProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
proxy.preInit(event);
System.out.println("\u001B[32m" + "[Starting Test Mod PRE-INITIALIZATION]" + "\u001B[0m");
}
@EventHandler
public void init(FMLInitializationEvent event) {
proxy.init(event);
System.out.println("\u001B[32m" + "[Starting Test Mod INITIALIZATION]" + "\u001B[0m");
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit(event);
System.out.println("\u001B[32m" + "[Starting Test Mod POST-INITIALIZATION]" + "\u001B[0m");
}
}
Blocks.TESTBLOCK