Guest User

getItems Method

a guest
Mar 20th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. public static ItemStack getDropsWithTool(Block b, Player p) throws Exception {
  2.  
  3.         net.minecraft.server.v1_9_R1.Chunk nmsChunk = ((CraftChunk) b.getChunk()).getHandle();
  4.         BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
  5.         net.minecraft.server.v1_9_R1.Block nmsBlock = CraftMagicNumbers.getBlock(b);
  6.  
  7.         net.minecraft.server.v1_9_R1.ItemStack itemstack = CraftItemStack.asNMSCopy(p.getInventory().getItemInMainHand());
  8.         IBlockData iblockdata = nmsChunk.getBlockData(blockPosition);
  9.  
  10.         Method blockStateCheck = net.minecraft.server.v1_9_R1.Block.class.getDeclaredMethod("o");
  11.         blockStateCheck.setAccessible(true);
  12.  
  13.         if (((Boolean) blockStateCheck.invoke(nmsBlock)) && EnchantmentManager.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemstack) > 0) {
  14.  
  15.             //noinspection unchecked
  16.             Method getSilkedMethod = net.minecraft.server.v1_9_R1.Block.class.getDeclaredMethod("u", IBlockData.class);
  17.             getSilkedMethod.setAccessible(true);
  18.  
  19.             net.minecraft.server.v1_9_R1.ItemStack i1 = (net.minecraft.server.v1_9_R1.ItemStack) getSilkedMethod.invoke(nmsBlock, iblockdata);
  20.             if (i1 != null) {
  21.                 return CraftItemStack.asBukkitCopy(i1);
  22.             }
  23.         } else {
  24.             int i = EnchantmentManager.getEnchantmentLevel(Enchantments.LOOT_BONUS_BLOCKS, itemstack);
  25.  
  26.             net.minecraft.server.v1_9_R1.World world = nmsChunk.getWorld();
  27.             ItemStack item = null;
  28.  
  29.             if (!world.isClientSide) {
  30.                 int j = nmsBlock.getDropCount(i, world.random);
  31.  
  32.                 for (int k = 0; k < j; ++k) {
  33.                     if (world.random.nextFloat() < 1.0F) {
  34.                         Item temp = nmsBlock.getDropType(iblockdata, world.random, i);
  35.                         if (temp != null) {
  36.                             if (item == null) {
  37.                                 item = CraftItemStack.asBukkitCopy(new net.minecraft.server.v1_9_R1.ItemStack(temp, 1, nmsBlock.getDropData(iblockdata)));
  38.                             } else {
  39.                                 item.setAmount(item.getAmount() + 1);
  40.                             }
  41.                         }
  42.                     }
  43.                 }
  44.  
  45.                 return (item != null ? (item.getAmount() > 0 ? item : null) : null);
  46.             }
  47.  
  48.         }
  49.  
  50.         return null;
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment