Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Chance on drop

Comments in 'Plugin Development' started by Jelly9912, Nov 19, 2015.

  1. Jelly9912
    Offline

    Jelly9912 Active Member

    Joined:
    Aug 8, 2015
    Posts:
    118
    Minecraft User:
    Jelly9912
    PHP:
    public function blockBreak(BlockBreakEvent $event){

            
    $block $event->getBlock();
            
    $player $event->getPlayer();
            
    $id $block->getId();

            if(
    $id === Block::STONE){
                switch(
    mt_rand(1200)){
         case 
    1:
             
    $player->getLevel()->setBlock($block, new Block(Block::AIR), falsetrue);
             
    $player->getLevel()->dropItem($block, new Item(26401));
             
    $player->sendMessage("§e[§aJelly§6Craft§e] §bDiamond!");
             break;
         case 
    2:
             
    $player->getLevel()->setBlock($block, new Block(Block::AIR), falsetrue);
             
    $player->getLevel()->dropItem($block, new Item(26301));
             
    $player->sendMessage("§e[§aJelly§6Craft§e] §0Coal!");
             break;

    // [...]

         
    case 200:
             
    $player->getLevel()->setBlock($block, new Block(Block::AIR), falsetrue);
             
    $player->getLevel()->dropItem($block, new Item(401));
             break;
       }
      }
    }
      
    But this is so bad method i think, so how to make something like this but with % not mt_rand and cases
  2. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    You want to create a skyblock random items thing right?
    For everyone:
    He wants a random item if someone breaks a stone (not cobble?)

    @Jelly9912 Any item or just a random one? or just that ones that drop from ore
  3. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    $val > 100 && $val < 150
    where $val is your number maybe?
  4. Jelly9912
    Offline

    Jelly9912 Active Member

    Joined:
    Aug 8, 2015
    Posts:
    118
    Minecraft User:
    Jelly9912
    Yes stone, and i mean some 0.2% on diamond drop from stone, 0.5% on gold ore, 1% on iron ore etc...
  5. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I would do a case on
    case 1%$rand===1
    case 2%$rand===1
    Would be the easiest i guess
  6. Jelly9912
    Offline

    Jelly9912 Active Member

    Joined:
    Aug 8, 2015
    Posts:
    118
    Minecraft User:
    Jelly9912
    I don't understand it :confused:
  7. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Well.. % is modular.
    So you check if your case (e.g. 5) / random number = 0
  8. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    An easier way to do this would to be to use a config, have they key as the chance and then have a set of options under each key, that way you will be able to reduce your code and just use a foreach to run through the possible outcomes

Share This Page

Advertisement