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

Explodable Obsidian

Discussion in 'Development' started by NickteeChunky, Oct 26, 2019.

  1. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    After doing some research and then finally coming to a realization. I discovered that obsidian cannot be blown up using TNT and I was looking for a plugin on Poggit to see if there was one and there wasn't. I wanted to know how you could change a block's durability or hardness if it's an instance of primed TNT for example or if that is even possible in PocketMine.
     
  2. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    I Have Not Tested The Code, Test And Ve If there are any serious errors that I correct, even more
    Sorry (google translate)
    PHP:
    public static $obsidians = [];
    public static 
    $durability 5;

    public function 
    addToList(Block $b){
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
    if(!isset(
    self::$obsidians[$pos])){
     
    self::$obsidians[$pos] = self::$durability;
      }
    }
    public function 
    existsBlock(Block $b){
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
    return isset(
    self::$obsidians[$pos]);
    }
    public function 
    getDurability(Block $b){
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
    if(
    $this->existsBlock($b)){
    return 
    self::$obsidians[$pos];
      }
    return 
    self::$durability;
    }
    public function 
    reduceDurability(Block $bint $v 1){
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
    if(
    $this->existsBlock($b)){
     
    self::$obsidians[$pos] = $this->getDurability($b) - $v;
    return 
    true;
    }
    return 
    false;
    }
    public function 
    onExplode(EntityExplodeEvent $e){
    if(
    $e->isCancelled()) return;
    $bl $e->getBlockList();
    $nbl = [];
    foreach(
    $bl as $b){
    if(
    $b->getId() == Item::OBSIDIAN){
    if(
    $this->existsBlock($b) and $this->getDurability($b) <= 0){
    $nbl[] = $b;
           }else{
    $this->addToBlockList($b);
    $this->reduceDurability($b);
    }
        }else{
    $nbl[] = $b;
         }
      }
    $e->setBlockList($nbl);
    }
     
  3. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    Thank you for your attempt to help, although I did run into an error with this line.

    ParseError: "syntax error, unexpected 'public static ' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)" (EXCEPTION)

    PHP:
    public static $obsidians = [];
     
  4. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    Send me your entire code Please!
     
  5. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    PHP:
    <?php

    namespace NickteeChunky;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\entity\EntityExplodeEvent;
    use 
    pocketmine\block\Block;

    class 
    Main extends PluginBase implements Listener{

    public static 
    $obsidians = [];
    public static 
    $durability 5;

      public function 
    addToList(Block $b){
         
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
         if(!isset(
    self::$obsidians[$pos])){
             
    self::$obsidians[$pos] = self::$durability;
         }
        }
    public function 
    existsBlock(Block $b){
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
    return isset(
    self::$obsidians[$pos]);
    }
    public function 
    getDurability(Block $b){
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
    if(
    $this->existsBlock($b)){
    return 
    self::$obsidians[$pos];
      }
    return 
    self::$durability;
    }
    public function 
    reduceDurability(Block $bint $v 1){
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
    if(
    $this->existsBlock($b)){
     
    self::$obsidians[$pos] = $this->getDurability($b) - $v;
    return 
    true;
    }
    return 
    false;
    }
    public function 
    onExplode(EntityExplodeEvent $e){
    if(
    $e->isCancelled()) return;
    $bl $e->getBlockList();
    $nbl = [];
    foreach(
    $bl as $b){
    if(
    $b->getId() == Item::OBSIDIAN){
    if(
    $this->existsBlock($b) and $this->getDurability($b) <= 0){
    $nbl[] = $b;
           }else{
    $this->addToBlockList($b);
    $this->reduceDurability($b);
    }
        }else{
    $nbl[] = $b;
         }
      }
    $e->setBlockList($nbl);
    }
     
  6. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
  7. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    PHP:

    <?php

    namespace NickteeChunky;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\entity\EntityExplodeEvent;
    use 
    pocketmine\block\Block;

    class 
    Main extends PluginBase implements Listener{

    public 
    $obsidians = [];
    public static 
    $durability 5;

      public function 
    addToList(Block $b){
         
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
         if(!isset(
    $this->obsidians[$pos])){
             
    $this->obsidians[$pos] = self::$durability;
         }
        }
    public function 
    existsBlock(Block $b){
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
    return isset(
    $this->obsidians[$pos]);
    }
    public function 
    getDurability(Block $b){
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
    if(
    $this->existsBlock($b)){
    return 
    $this->obsidians[$pos];
      }
    return 
    self::$durability;
    }
    public function 
    reduceDurability(Block $bint $v 1){
    $pos $b->getFloorX()."_".$b->getFloorY()."_".$b->getFloorZ()."_".$b->getLevel()->getName();
    if(
    $this->existsBlock($b)){
     
    $this->obsidians[$pos] = $this->getDurability($b) - $v;
    return 
    true;
    }
    return 
    false;
    }
    public function 
    onExplode(EntityExplodeEvent $e){
    if(
    $e->isCancelled()) return;
    $bl $e->getBlockList();
    $nbl = [];
    foreach(
    $bl as $b){
    if(
    $b->getId() == Item::OBSIDIAN){
    if(
    $this->existsBlock($b) and $this->getDurability($b) <= 0){
    $nbl[] = $b;
           }else{
    $this->addToBlockList($b);
    $this->reduceDurability($b);
    }
        }else{
    $nbl[] = $b;
         }
      }
    $e->setBlockList($nbl);
    }
    }

     
  8. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    I've just tested it and the obsidian still isn't breaking whatsoever. @HeyDeniis_
     
  9. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
  10. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You would have to override the block
    PHP:
    class Main extends PluginBase{
    public function 
    onEnable(){
    BlockFactory::registerBlock(new MyObsidian());
    }
    }
    class 
    MyObsidian extends \pocketmine\block\Obsidian{
    public function 
    getBlastResistance() : float{
    return 
    7.5;//same as stone
    }
    }
     
  11. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    I got an error for "Trying to overwrite an already registered block", and when I remove the onEnable function but the MyObsidian file, it didn't make a difference and the obsidian still wouldn't blow up.
     
  12. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Oops i forgot
    PHP:
    BlockFactory::registerBlock(new MyObsidian(),true);
     
  13. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    Amazing! It works, thank you so much @wolfdale, @HeyDeniis_ . I just have one question, if I want to set it so obsidian is broken every 4 explosions, what blast resistance would I have to set it to?

    Or what do I set the $durability to in main?
     
    Last edited: Oct 30, 2019
  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.