Hi, thanks for the help! I'm trying to make a block which if you mine it without silk touch or are not using a proper tool, it will leave a block of lava. I overridden the harvestBlock method in my block's class, and here is the code:
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
player.addStat(StatList.BLOCK_MINED.get(this));
player.addExhaustion(0.005F);
if (this.canSilkHarvest(state, worldIn, pos, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0)
{
NonNullList<ItemStack> items = NonNullList.create();
ItemStack itemstack = this.getSilkTouchDrop(state);
if (!itemstack.isEmpty()) items.add(itemstack);
net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(items, worldIn, pos, state, 0, 1.0f, true, player);
items.forEach(e -> spawnAsEntity(worldIn, pos, e));
} else {
harvesters.set(player);
int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
state.dropBlockAsItem(worldIn, pos, i);
harvesters.set(null);
worldIn.setBlockState(pos, Blocks.LAVA.getDefaultState());
}
if (!player.canHarvestBlock(state))
{
worldIn.setBlockState(pos, Blocks.LAVA.getDefaultState());
}
}
Now the silk touch part is working fine (it probably should because I just copied them from Block class), but when I mine it with an iron pickaxe, nothing happens. I think I misused the method canHarvestBlock.
By the way, this block's material is ROCK, and required harvestLevel 3 or higher.