Jump to content

Give player a random Enchanted book


AzureusNation123

Recommended Posts

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));
}
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

....

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);
}
}


Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.