Plugin Help Crafting Chance

Discussion in 'Plugin Help/Development/Requests' started by NetherSky, Dec 21, 2014.

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

    NetherSky


    1. Code:
      [LIST=1]
      [*]    ShapedRecipe diamond = new ShapedRecipe(new ItemStack(Material.DIAMOND, 1)).shape("%%%", "%%%", "& &")
      [*]                .setIngredient('%', Material.LEATHER)
      [*]                .setIngredient('&', Material.IRON_INGOT);
      [*]       
      [*]        getServer().addRecipe(diamond);
      [/LIST]
      


    1. but this is 100% for crafting diamond but i want 50% for successful crafting and 50% for fail crafting?

    help pls
     
    Last edited by a moderator: Dec 21, 2014
  2. Offline

    pie_flavor

    @NetherSky
    Code:java
    1. static ShapedRecipe diamond;
    2. //whatever method this is
    3. diamond = new ShapedRecipe(new ItemStack(Material.DIAMOND, 1)).shape("%%%","%%%","& &").setIngredient('%',Material.LEATHER).setIngredient('&'),Material.IRON_INGOT);


    Code:java
    1. @EventHandler
    2. public void onCraft(CraftItemEvent e) {
    3. if (e.getRecipe == diamond && new Random().nextBoolean() == true) {
    4. e.setCancelled(true);
    5. e.getInventory().clear();
     
    NetherSky likes this.
  3. Offline

    NetherSky

    First code in main yes?
    And how make 60% for successful crafting?
     
    Last edited: Dec 26, 2014
  4. Offline

    PogoStick29

    For 60%, generate a random number between 0 and 4 and check to see if it's less than 3. If it's 0, 1, or 2, that's 3 out of 5 possibilities.
     
    NetherSky likes this.
  5. Offline

    NetherSky

    Can you give an example
     
  6. Offline

    PogoStick29

    Code:
    int num = new Random().nextInt(4); // Generates a random number between 0 and 4.
    
    if (num < 3) {
      // Do the crafting.
    }
     
    NetherSky likes this.
  7. Offline

    pie_flavor

    Oh, guys, you actually want rand.nextInt(5). It is between 0 inclusive and the specified value exclusive. So nextInt(5) can generate 0, 1, 2, 3, or 4.

    Also, yes, put the first code wherever you put the recipe initially. Also, I just wrote diamond, but you would need to say <class>.diamond.
    And the second code goes in an eventhandler.
     
  8. Offline

    NetherSky

    Ok ty i try make it but i can't.
    Can u give me 1/2 code of plugin cuz im newbie ;/
     
  9. Online

    timtower Moderator Moderator

    Locked on request
     
Thread Status:
Not open for further replies.

Share This Page