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

Solved Block resistance

Comments in 'Plugin Development' started by Muqsit, Jul 27, 2016.

  1. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    Hi there, I was trying to port the famous "ObsidianBreaker" bukkit plugin to PocketMine. I got stuck on the resistance part.
    I've gone through the whole of \pocketmine\block\Block file but only found this:
    • getHardness()
    • getResistance()

    My question is.. how do I set a block's resistance? My aim is to make obsidian break when it's in comes in contact with TNT. And this can only be possible if there was a setResistance() parameter.

    I've tried my best in testing here and there, but no luck.

    *Probably waiting for the PocketMine Team to implement setResistance()*
  2. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    Couldn't you use ExplosionPrimeEvent to remove the Obsidian in the force of TNT's explosion?;)
  3. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    You can override the method and register your own block.
    You can find an example here:
    https://github.com/svilex/SkyWars-PocketMine/blob/master/SW/src/svile/sw/utils/Glass.php

    https://github.com/svilex/SkyWars-PocketMine/blob/master/SW/src/svile/sw/SWmain.php#L267
  4. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    @Survingo Nice one, but again, I don't want the TNT to destroy the obsidian at once. Maybe a few hits, then it should break.

    @Svile Wow... but isn't there a shorter way (as in less code) :p
  5. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Hardness is related to the time for breaking the block by hand.
  6. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    True, so I'm focusing on resistance!
  7. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    Um isn't this how it's supposed to be done?
    PHP:
    <?php
    namespace Muqsit;
    use 
    pocketmine\block\Obsidian as PmObsidian;

    class 
    Obsidian extends PmObsidian{

    public function 
    getResistance(){
    return 
    3000;
    }
    }
    ImagicalGamer likes this.
  8. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    Nvm, got it fixed :)

    ^That is how it must be done but the Main class should have this...

    PHP:
    const OBSIDIAN 49;
    public function 
    onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    $this->registerBlock(self::OBSIDIANObsidian::class);
    }
    public function 
    registerBlock($id$class){
    Block::$list[$id] = $class;
    $block = new $class();
    for(
    $data 0$data 16; ++$data){
    Block::$fullList[($id << 4) | $data] = new $class($data);
    }
    }
    SOFe likes this.
  9. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    cancel it on block break EV?
    or just replace it back the air to obb
    and a internal counter how many times it have been blowed after the counter is over EX been exploded over ex 5 break the block and maybe drop it?
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I managed to port my own version of "ObsidianBreaker" without creating my own Block class or overwriting PocketMines Obsidian Block class. The pocketmine\event\entity\EntityExplodeEvent::$blocks never contains obsidian or bedrock as their resistance stops the explosion passing into or through them (motion/gravity/physics laws) so you need to calculate the explosion radius and get the affected blocks yourself.
    PHP:
        /**
        * @param Position $center
        * @param $size
        *
        * @return Block[]|bool
        */
        
    public static function getExplosionAffectedBlocks(Position $center$size) {
            if(
    $size 0.1){
                return 
    false;
            }

            
    $affectedBlocks = [];
            
    $rays 16;
            
    $stepLen 0.3;
            
    $vector = new Vector3(000);
            
    $vBlock = new Vector3(000);
            
    $mRays intval($rays 1);

            for(
    $i 0$i $rays; ++$i){
                for(
    $j 0$j $rays; ++$j){
                    for(
    $k 0$k $rays; ++$k){
                        if(
    $i === or $i === $mRays or $j === or $j === $mRays or $k === or $k === $mRays){
                            
    $vector->setComponents($i $mRays 1$j $mRays 1$k $mRays 1);
                            
    $vector->setComponents(($vector->/ ($len $vector->length())) * $stepLen, ($vector->$len) * $stepLen, ($vector->$len) * $stepLen);
                            
    $pointerX $center->x;
                            
    $pointerY $center->y;
                            
    $pointerZ $center->z;

                            for(
    $blastForce $size * (mt_rand(7001300) / 1000); $blastForce 0$blastForce -= $stepLen 0.75){
                                
    $x = (int) $pointerX;
                                
    $y = (int) $pointerY;
                                
    $z = (int) $pointerZ;
                                
    $vBlock->$pointerX >= $x $x $x 1;
                                
    $vBlock->$pointerY >= $y $y $y 1;
                                
    $vBlock->$pointerZ >= $z $z $z 1;
                                if(
    $vBlock->or $vBlock->127){
                                    break;
                                }
                                
    $block $center->level->getBlock($vBlock);

                                if(
    $block->getId() !== 0){
                                    if(
    $blastForce 0){
                                        
    $blastForce -= ($block->getResistance() / 0.3) * $stepLen;
                                        if(!isset(
    $affectedBlocks[$index Level::blockHash($block->x$block->y$block->z)])){
                                            
    $affectedBlocks[$index] = $block;
                                        }
                                    }
                                }
                                
    $pointerX += $vector->x;
                                
    $pointerY += $vector->y;
                                
    $pointerZ += $vector->z;
                            }
                        }
                    }
                }
            }
            return 
    $affectedBlocks;
        }
    I just copied the pocketmine\level\Explosion::explodeA() function code and changed a few lines around. You'll need to make use of pocketmine\event\entity\ExplosionPrimeEvent to get the explosions size as pocketmine\event\entity\EntityExplodeEvent has no way to get an explosions size. Hopefully this helps you with your plugin :)
    luca28pet, SOFe and Muqsit like this.
  11. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    Nice one! :)

Share This Page

Advertisement