Skip to content

Instantly share code, notes, and snippets.

Created April 4, 2017 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/28b892b90e2f73d2242a3f2b077e77ca to your computer and use it in GitHub Desktop.
Save anonymous/28b892b90e2f73d2242a3f2b077e77ca to your computer and use it in GitHub Desktop.
@SubscribeEvent
public void onPlayerDig(PlayerInteractEvent.LeftClickBlock event) {
World world = event.getWorld();
EntityPlayer player = event.getEntityPlayer();
if (event.getFace() == null || world.isRemote || StackUtils.isEmpty(player.getHeldItem(EnumHand.MAIN_HAND)) || player.isCreative())
return;
BlockPos pos = event.getPos();
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
int meta = block.getMetaFromState(state);
ItemStack drop = block.getItem(world, pos, state);
if (block.getItem(world, pos, state) == drop) {
if (drop == null)
drop = new ItemStack(block, 1, meta);
InventoryHelper.spawnItemStack(world, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), drop);
} else
block.harvestBlock(world, player, pos, state, world.getTileEntity(pos), drop);
world.setBlockToAir(pos);
world.playEvent(2001, pos, Block.getStateId(state));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment