Solved Spawn Random Item With Random Enchantments

Discussion in 'Spigot Plugin Development' started by Anshu, Jul 3, 2021.

  1. So I used this code to generate Random Int between a range
    Code (Java):
    (int) Math.floor(Math.random()*(max - min + 1) + min)));
     
  2. what the fucking hell
    why not look for the obvious
     
    • Funny Funny x 1
  3. Hey so I found this while looking for a solution to my own problem and I need some help with it. I'm working on a plugin that increases loot that mobs can drop, and I tried using this code to do that. The only thing is, I get a bunch of errors. The reason for them is that it's trying to give to item I want dropped an enchantment level of 0. I thought that if it was going to be level 0, it won't try to put it on, but I guess not. That's with .addEnchanment. Then I tried .addUnsafeEnchanments, but that one still puts the enchant on the item, just without the errors and saying enchanment.level.0. Can you help?
     
  4. you could not just create two lists (material and enchants) and both of them randomized (shuffled) and pick first material and enchant from the lists (rather than messing around with random numbers)?
     
  5. If you want to randomly enchant items using a pretty much 1:1 copy of the vanilla enchanting system you can use this class I made to do it. It isn't terribly elegant due to limitations in the Spigot API around enchantments but it works. Please note that it depends on a RandomCollection class which is in the same package.
     
  6. Please don't say harsh words like you say.
    Btw, Thank you all for support and great Thanks to @OnlyTheBest because he helped me a lot and he also explained me and my problem is solved and again Thanks to all.
     
  7. i badly had to express my feelings on that message
    you literally reinvented the wheel
    Anyways, congrats on solving your problem
     
    • Funny Funny x 1