-
-
Save anonymous/28b892b90e2f73d2242a3f2b077e77ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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