I have an item, "diamond reeds", that I want to place as the block "diamond reed", which is a separate class and a separate registered block. What I tried to do is have the constructor for diamond reeds the item take a block:
public ItemDiamondReed(Block block)
{
setCreativeTab(CreativeTabs.tabMaterials);
setMaxStackSize(1);
setMaxDamage(0);
this.block = block;
}
Then have an event handler for the item that on item use places the block (straight out of the code for sugarcane item):
Then, in the ItemInit class, define it like so:
diamond_reeds = (new ItemDiamondReed(new BlockDiamondReed())).setUnlocalizedName("diamond_reeds").setCreativeTab(CreativeTabs.tabMaterials);
And it works, the item shows up. But, when I try to place it, it simply doesn't do anything. It doesn't place the block. The block works fine, and if I manually give myself the block I can place it. But the item doesn't place it. Upon some debugging, I've found the problem is in the following two lines:
IBlockState iblockstate1 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, 0, playerIn);
if (worldIn.setBlockState(pos, iblockstate1, 3))
{
It doesn't error, the if statement just always returns false. Does anyone know why?