public void b(ICommandListener icommandlistener, String[] astring) { if (astring.length < 2) { throw new ExceptionUsage("commands.enchant.usage", new Object[0]); } else { EntityPlayer entityplayer = d(icommandlistener, astring[0]); int i = a(icommandlistener, astring[1], 0, Enchantment.byId.length - 1); int j = 1; ItemStack itemstack = entityplayer.bx(); if (itemstack == null) { throw new CommandException("commands.enchant.noItem", new Object[0]); } else { Enchantment enchantment = Enchantment.byId[i]; if (enchantment == null) { throw new ExceptionInvalidNumber( "commands.enchant.notFound", new Object[] {Integer.valueOf(i)}); } else if (!enchantment.canEnchant(itemstack)) { throw new CommandException("commands.enchant.cantEnchant", new Object[0]); } else { if (astring.length >= 3) { j = a( icommandlistener, astring[2], enchantment.getStartLevel(), enchantment.getMaxLevel()); } if (itemstack.hasTag()) { NBTTagList nbttaglist = itemstack.getEnchantments(); if (nbttaglist != null) { for (int k = 0; k < nbttaglist.size(); ++k) { short short1 = ((NBTTagCompound) nbttaglist.get(k)).getShort("id"); if (Enchantment.byId[short1] != null) { Enchantment enchantment1 = Enchantment.byId[short1]; if (!enchantment1.a(enchantment)) { throw new CommandException( "commands.enchant.cantCombine", new Object[] { enchantment.c(j), enchantment1.c(((NBTTagCompound) nbttaglist.get(k)).getShort("lvl")) }); } } } } } itemstack.addEnchantment(enchantment, j); a(icommandlistener, "commands.enchant.success", new Object[0]); } } } }
private static void a(EnchantmentModifier enchantmentmodifier, ItemStack itemstack) { if (itemstack != null) { NBTTagList nbttaglist = itemstack.getEnchantments(); if (nbttaglist != null) { for (int i = 0; i < nbttaglist.size(); ++i) { short short1 = nbttaglist.get(i).getShort("id"); short short2 = nbttaglist.get(i).getShort("lvl"); if (Enchantment.byId[short1] != null) { enchantmentmodifier.a(Enchantment.byId[short1], short2); } } } } }
public static Map a(ItemStack itemstack) { LinkedHashMap linkedhashmap = new LinkedHashMap(); NBTTagList nbttaglist = itemstack.getItem() == Items.ENCHANTED_BOOK ? Items.ENCHANTED_BOOK.g(itemstack) : itemstack.getEnchantments(); if (nbttaglist != null) { for (int i = 0; i < nbttaglist.size(); ++i) { short short1 = nbttaglist.get(i).getShort("id"); short short2 = nbttaglist.get(i).getShort("lvl"); linkedhashmap.put(Integer.valueOf(short1), Integer.valueOf(short2)); } } return linkedhashmap; }
public static int getEnchantmentLevel(int i, ItemStack itemstack) { if (itemstack == null) { return 0; } else { NBTTagList nbttaglist = itemstack.getEnchantments(); if (nbttaglist == null) { return 0; } else { for (int j = 0; j < nbttaglist.size(); ++j) { short short1 = nbttaglist.get(j).getShort("id"); short short2 = nbttaglist.get(j).getShort("lvl"); if (short1 == i) { return short2; } } return 0; } } }
// CraftBukkit - priv to public public void dispense(World world, int i, int j, int k, Random random) { int l = world.getData(i, j, k); byte b0 = 0; byte b1 = 0; if (l == 3) { b1 = 1; } else if (l == 2) { b1 = -1; } else if (l == 5) { b0 = 1; } else { b0 = -1; } TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k); if (tileentitydispenser != null) { // CraftBukkit start int dispenseSlot = tileentitydispenser.findDispenseSlot(); ItemStack itemstack = null; if (dispenseSlot > -1) { itemstack = tileentitydispenser.getContents()[dispenseSlot]; // Copy item stack, because we want it to have 1 item itemstack = new ItemStack(itemstack.id, 1, itemstack.getData(), itemstack.getEnchantments()); } // CraftBukkit end double d0 = (double) i + (double) b0 * 0.6D + 0.5D; double d1 = (double) j + 0.5D; double d2 = (double) k + (double) b1 * 0.6D + 0.5D; if (itemstack == null) { world.triggerEffect(1001, i, j, k, 0); } else { // CraftBukkit start double d3 = random.nextDouble() * 0.1D + 0.2D; double motX = (double) b0 * d3; double motY = 0.20000000298023224D; double motZ = (double) b1 * d3; motX += random.nextGaussian() * 0.007499999832361937D * 6.0D; motY += random.nextGaussian() * 0.007499999832361937D * 6.0D; motZ += random.nextGaussian() * 0.007499999832361937D * 6.0D; org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k); org.bukkit.inventory.ItemStack bukkitItem = new CraftItemStack(itemstack).clone(); BlockDispenseEvent event = new BlockDispenseEvent(block, bukkitItem, new Vector(motX, motY, motZ)); world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } if (event.getItem().equals(bukkitItem)) { // Actually remove the item tileentitydispenser.splitStack(dispenseSlot, 1); } motX = event.getVelocity().getX(); motY = event.getVelocity().getY(); motZ = event.getVelocity().getZ(); itemstack = CraftItemStack.createNMSItemStack(event.getItem()); // CraftBukkit end if (itemstack.id == Item.ARROW.id) { EntityArrow entityarrow = new EntityArrow(world, d0, d1, d2); entityarrow.shoot((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F); entityarrow.fromPlayer = true; world.addEntity(entityarrow); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.EGG.id) { EntityEgg entityegg = new EntityEgg(world, d0, d1, d2); entityegg.a((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F); world.addEntity(entityegg); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.SNOW_BALL.id) { EntitySnowball entitysnowball = new EntitySnowball(world, d0, d1, d2); entitysnowball.a((double) b0, 0.10000000149011612D, (double) b1, 1.1F, 6.0F); world.addEntity(entitysnowball); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.POTION.id && ItemPotion.c(itemstack.getData())) { EntityPotion entitypotion = new EntityPotion(world, d0, d1, d2, itemstack.getData()); entitypotion.a((double) b0, 0.10000000149011612D, (double) b1, 1.375F, 3.0F); world.addEntity(entitypotion); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.EXP_BOTTLE.id) { EntityThrownExpBottle entitythrownexpbottle = new EntityThrownExpBottle(world, d0, d1, d2); entitythrownexpbottle.a((double) b0, 0.10000000149011612D, (double) b1, 1.375F, 3.0F); world.addEntity(entitythrownexpbottle); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.MONSTER_EGG.id) { ItemMonsterEgg.a( world, itemstack.getData(), d0 + (double) b0 * 0.3D, d1 - 0.3D, d2 + (double) b1 * 0.3D); world.triggerEffect(1002, i, j, k, 0); } else if (itemstack.id == Item.FIREBALL.id) { EntitySmallFireball entitysmallfireball = new EntitySmallFireball( world, d0 + (double) b0 * 0.3D, d1, d2 + (double) b1 * 0.3D, (double) b0 + random.nextGaussian() * 0.05D, random.nextGaussian() * 0.05D, (double) b1 + random.nextGaussian() * 0.05D); world.addEntity(entitysmallfireball); world.triggerEffect(1009, i, j, k, 0); } else { EntityItem entityitem = new EntityItem(world, d0, d1 - 0.3D, d2, itemstack); // CraftBukkit start // double d3 = random.nextDouble() * 0.1D + 0.2D; // Moved up entityitem.motX = motX; entityitem.motY = motY; entityitem.motZ = motZ; // CraftBukkit end world.addEntity(entityitem); world.triggerEffect(1000, i, j, k, 0); } world.triggerEffect(2000, i, j, k, b0 + 1 + (b1 + 1) * 3); } } }