Randomizing Items

Discussion in 'Plugin Development' started by FabeGabeMC, Jan 6, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    FabeGabeMC

    Hello.
    I have been working on a plugin for KazukiMC which is called RandomBox.
    The bug I can't squish is Randomizing Items coming out of the Box.

    Is it possible that someone could send me the code for that?
    When I need it: As soon as possible.
     
  2. Offline

    Gater12

  3. Offline

    xTrollxDudex

    FabeGabeMC
    How are you going to grab the item? From an inventory? A totally random item from the Material enum?
     
  4. Offline

    FabeGabeMC

    xTrollxDudex
    What I meant is for example: When I right click the box (crate), it will automatically give me the reward with the ItemStack method.
    You understand what I mean?
     
  5. Offline

    Yonas

    FabeGabeMC
    Where is the problem?
    Code:
         @EventHandler
        public void onClick(PlayerInteractEvent e) {
            if(e.getClickedBlock().getType() != Material.CHEST) return;
            Chest chest = (Chest)e.getClickedBlock().getState();
            e.getPlayer().getInventory().addItem(chest.getInventory().getContents());
        }
    
     
  6. Offline

    FabeGabeMC

    Yonas
    The box is supposed to be a 6 sided piston which when you right click it gives you random items.
    When I tried placing the Random java util, it said it needed another integer.
     
  7. Offline

    Yonas

  8. Offline

    FabeGabeMC

    Yonas I meant it gives you a random weapon/armor/bow thingy.
     
  9. Offline

    FabeGabeMC

  10. Offline

    stirante

    FabeGabeMC Firstly create an array list of materials which can be aquired. Then do for example:
    Code:
    ItemStack i = new ItemStack(list.get((int)(list.size() * Math.random())));
     
  11. Offline

    jthort

    Use this, works perfectly:
    Code:
    Random rand = new Random();
                    Material[] materiallists = Material.values();
                   
                   
                    int size = materiallists.length;
                    int index = rand.nextInt(size);
                   
                   
                    Material randomMaterial = materiallists[index];
                    ItemStack item = new ItemStack(randomMaterial);
                    Material items = item.getType();
                   
                    p.getWorld().dropItemNaturally(world.getBlock().getLocation(), new ItemStack(items));
     
  12. Offline

    FabeGabeMC

    jthort That's not what I'm looking for. I'm looking for it to just randomize weapons and armor with random enchantments.
     
  13. Offline

    jthort

    FabeGabeMC It says you need code for randomizing items, thats what I gave you
     
  14. Offline

    JRL1004

    FabeGabeMC So you are not trying to get an item from a pre-existing group of items, instead you are trying to generate a new group of items?
     
  15. Offline

    FabeGabeMC

    JRL1004 Nope.

    jthort I'll try to see if that will work, again.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  16. Offline

    FabeGabeMC

Thread Status:
Not open for further replies.

Share This Page