1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Help with a cobblestone generator

Discussion in 'Development' started by sindronik, May 20, 2017.

  1. sindronik

    sindronik Spider

    Messages:
    7
    Hello everyone, I'm noob in writing plugins, how to change the standard cobblestone generator (water + lava = cobblestone), instead of cobblestone, for example, iron ore appeared. Desirable sample code :)
    Sorry for my English.
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    This is a development question. It belongs in the development section. You will also have to provide evidence of a previous attempt.
     
  3. matija131

    matija131 Spider Jockey

    Messages:
    31
  4. sindronik

    sindronik Spider

    Messages:
    7
    YES)
    Here so did in a kernel and works
    PHP:
               if($colliding){
                   if(
    $this->getDamage() === 0){
                       
    $this->getLevel()->setBlock($thisBlock::get(Item::OBSIDIAN), true);
                   }elseif(
    $this->getDamage() <= 4){
                       
    //random spawn ore
                       
    $orerand mt_rand(1100);
                       if(
    $orerand <=5){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::DIAMOND_ORE), true);
                       }elseif(
    $orerand <=10){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::GOLD_ORE), true);
                       }elseif(
    $orerand <=15){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::LAPIS_ORE), true);
                       }elseif(
    $orerand <=25){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::IRON_ORE), true);
                       }elseif(
    $orerand <=35){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::COAL_ORE), true);
                       }elseif(
    $orerand <=78){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::COBBLESTONE), true);
                           }
                   }
                   
    $this->triggerLavaMixEffects($this);
               }
    But how to do it with the plugin? And optimize this code?
    Sorry for my bad english))
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    That's still very minimal information.
    What is $colliding? Does the class in which you wrote that code extend Block?
    Also, it's not mandatory to optimize, and optimizing while writing the code is the worst thing anyone could do. Optimization should be done once everything in code is written, and only if needed.
     
  6. sindronik

    sindronik Spider

    Messages:
    7
    Everything happens in a file pocketmine\block\liquid.php
    PHP:
    private function checkForHarden(){
           if(
    $this instanceof Lava){
               
    $colliding false;
               for(
    $side 0$side <= and !$colliding; ++$side){
                   
    $colliding $this->getSide($side) instanceof Water;
               }
               if(
    $colliding){
                   if(
    $this->getDamage() === 0){
                       
    $this->getLevel()->setBlock($thisBlock::get(Item::OBSIDIAN), true);
                   }elseif(
    $this->getDamage() <= 4){
                       
    //random spawn ore
                       
    $orerand mt_rand(1100);
                       if(
    $orerand <=5){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::DIAMOND_ORE), true);
                       }elseif(
    $orerand <=10){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::GOLD_ORE), true);
                       }elseif(
    $orerand <=15){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::LAPIS_ORE), true);
                       }elseif(
    $orerand <=25){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::IRON_ORE), true);
                       }elseif(
    $orerand <=35){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::COAL_ORE), true);
                       }elseif(
    $orerand <=78){
                           
    $this->getLevel()->setBlock($thisBlock::get(Item::COBBLESTONE), true);
                           }
                   }
                   
    $this->triggerLavaMixEffects($this);
               }
           }
       }
    The code does not work right away, because the lava does not immediately put the block.
     
  7. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    So this isn't a plugin, you're directly editing the PocketMine source? And what is
    PHP:
    $this->triggerLavaMixEffects($this)
    ?
     
  8. sindronik

    sindronik Spider

    Messages:
    7
    yes, and I want to do this with the plugin, but I do not know how.))
    PHP:
    $this->triggerLavaMixEffects($this)
    It's from tesseract...
     
  9. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    You won't get support for spoons here :)
    Use PocketMine & come back, everyone here uses PocketMine, so you're not gonna get support for Tesseract
     
    EdwardHamHam, SOFe, Kyd and 3 others like this.
  10. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    i dont think we give support for how to edit sources either so using PMMP and coming back will probably do you no good either ways
     
    EdwardHamHam and jasonwynn10 like this.
  11. sindronik

    sindronik Spider

    Messages:
    7
    Hmm ... I'm here asking for help in implementing the plugin ... but not in the kernel)) In the kernel I already did as of pmmp and other kernels))

    And now I ask how to do this with the help of the plugin, I do not care what kernel it will be)))
     
  12. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    PMMP should add a LavaAndWaterMergeEvent with the option to set the result. Wouldn't that be cool?
     
  13. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    or try overwriting the block somehow to gain access to the check harden function
     
  14. sindronik

    sindronik Spider

    Messages:
    7
    I would like not to touch the kernel, that it was free to drag the plugin to the new version of pmmp 1.1.0 without changing the kernel.
     
  15. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    no like i said try overwriting the block ONLY without touching the core PMMP via plugins, if that's possible
     
    jasonwynn10 likes this.
  16. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    It may be possible to register a subclass of the water class and/or the lava class and override the block update behaviour.
    Not compatible with multiple plugins though. Indeed, an API improvement is needed, but water-and-lava-merge is far too specific.
     
    jasonwynn10 likes this.
  17. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
    You will have to edit this inside PMMP. i'm pretty sure you want this for a SkyBlock server
     
  18. sindronik

    sindronik Spider

    Messages:
    7
    In the core, I did it, but I want in the plugin) yes for skyblock server
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.