Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ItemStack getDropsWithTool(Block b, Player p) throws Exception {
- net.minecraft.server.v1_9_R1.Chunk nmsChunk = ((CraftChunk) b.getChunk()).getHandle();
- BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
- net.minecraft.server.v1_9_R1.Block nmsBlock = CraftMagicNumbers.getBlock(b);
- net.minecraft.server.v1_9_R1.ItemStack itemstack = CraftItemStack.asNMSCopy(p.getInventory().getItemInMainHand());
- IBlockData iblockdata = nmsChunk.getBlockData(blockPosition);
- Method blockStateCheck = net.minecraft.server.v1_9_R1.Block.class.getDeclaredMethod("o");
- blockStateCheck.setAccessible(true);
- if (((Boolean) blockStateCheck.invoke(nmsBlock)) && EnchantmentManager.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemstack) > 0) {
- //noinspection unchecked
- Method getSilkedMethod = net.minecraft.server.v1_9_R1.Block.class.getDeclaredMethod("u", IBlockData.class);
- getSilkedMethod.setAccessible(true);
- net.minecraft.server.v1_9_R1.ItemStack i1 = (net.minecraft.server.v1_9_R1.ItemStack) getSilkedMethod.invoke(nmsBlock, iblockdata);
- if (i1 != null) {
- return CraftItemStack.asBukkitCopy(i1);
- }
- } else {
- int i = EnchantmentManager.getEnchantmentLevel(Enchantments.LOOT_BONUS_BLOCKS, itemstack);
- net.minecraft.server.v1_9_R1.World world = nmsChunk.getWorld();
- ItemStack item = null;
- if (!world.isClientSide) {
- int j = nmsBlock.getDropCount(i, world.random);
- for (int k = 0; k < j; ++k) {
- if (world.random.nextFloat() < 1.0F) {
- Item temp = nmsBlock.getDropType(iblockdata, world.random, i);
- if (temp != null) {
- if (item == null) {
- item = CraftItemStack.asBukkitCopy(new net.minecraft.server.v1_9_R1.ItemStack(temp, 1, nmsBlock.getDropData(iblockdata)));
- } else {
- item.setAmount(item.getAmount() + 1);
- }
- }
- }
- }
- return (item != null ? (item.getAmount() > 0 ? item : null) : null);
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment