Posted August 5, 201312 yr Hey, Is the a simple way to give a player a random enchanted book? Basicly what im doing is when a player right clicks my item, i want it to give them a random enchanted book. Please help im using this. public class RandomEnchantedBook { public static double rand; private static Random random = new Random(); private static Item EnchantedBook [] = { }; public static void EnchantedBook(EntityPlayer par3EntityPlayer) { par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(EnchantedBook[random.nextInt(EnchantedBook.length)], 1)); } }
August 5, 201312 yr From ItemEnchantedBook Enchantment enchantment = Enchantment.enchantmentsBookList[par1Random.nextInt(Enchantment.enchantmentsBookList.length)]; ItemStack itemstack = new ItemStack(this.itemID, 1, 0); int l = MathHelper.getRandomIntegerInRange(par1Random, enchantment.getMinLevel(), enchantment.getMaxLevel()); this.getEnchantedItemStack_do(itemstack, new EnchantmentData(enchantment, l)); itemStack is then a stack of 1 randomly enchanted book
August 5, 201312 yr Author sorry im going to be a pain again :L do you mean put it in Item EnchantedBook [*], or put it Item EnchatedBook [] = { *
August 5, 201312 yr .... No I mean public class RandomEnchantedBook { public static double rand; private static Random random = new Random(); public static void EnchantedBook(EntityPlayer par3EntityPlayer) { Enchantment enchantment = Enchantment.enchantmentsBookList[random.nextInt(Enchantment.enchantmentsBookList.length)]; ItemStack itemstack = new ItemStack(Item.enchantedBook.itemID, 1, 0); int l = MathHelper.getRandomIntegerInRange(par1Random, enchantment.getMinLevel(), enchantment.getMaxLevel()); Item.enchantedBook.getEnchantedItemStack_do(itemstack, new EnchantmentData(enchantment, l)); par3EntityPlayer.inventory.addItemStackToInventory(itemstack); } }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.