Hello, I'm having a problem with my code 1.11.2.
For some reason it is not working properly and when I break a spawner with silk touch, it gives me the spawner without the entity tag, it always gives me the spawner of pig.
This is my code, I would be grateful that someone could help me.
Thank you
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent e)
{
IBlockState state = e.getState();
World world = e.getWorld();
BlockPos pos = e.getPos();
EntityPlayer player = e.getPlayer();
ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
if (state.getBlock() == Blocks.MOB_SPAWNER) {
Map<Enchantment, Integer> enchants = EnchantmentHelper.getEnchantments(heldItem);
if (enchants.containsKey(Enchantments.SILK_TOUCH)) {
ItemStack stack = new ItemStack(Blocks.MOB_SPAWNER, 1, 0);
NBTTagCompound nbttagcompound = new NBTTagCompound();
world.getTileEntity(pos).writeToNBT(nbttagcompound);
stack.setTagInfo("BlockEntityTag", nbttagcompound);
e.setExpToDrop(0);
e.getWorld().spawnEntity(new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), stack));
}
}
}