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

setBlock() help

Comments in 'Plugin Development' started by CrazedMiner, Jun 30, 2015.

  1. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I'm trying to basically remove the terrain damage from explosions by setting the effected blocks back to their old block type but I keep getting this same error....

    Code:
    PHP:
    public function onExplode(EntityExplodeEvent $event) {
            
    $block $event->getBlockList();
            foreach(
    $block as $blocks) {
                
    $blocks->getLevel()->setBlock(new Vector3($blocks->getX(), $blocks->getY(), $blocks->getZ(), Block::get($blocks->getId())));
            }
        }
    Error:
    Code:
    [18:43:36] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\entity\EntityExplodeEvent' to 'ExploasionControl v1': Argument 2 passed to pocketmine\level\Level::setBlock() must be an instance of pocketmine\block\Block, none given, called in C:\Users\Admin\Desktop\PocketMine\Plugin Tests\plugins\ExplosionControl\src\ExplosionControl\Main.php on line 55 and defined on ExplosionControl\Main
    [18:43:36] [Server thread/NOTICE]: InvalidArgumentException: "Argument 2 passed to pocketmine\level\Level::setBlock() must be an instance of pocketmine\block\Block, none given, called in C:\Users\Admin\Desktop\PocketMine\Plugin Tests\plugins\ExplosionControl\src\ExplosionControl\Main.php on line 55 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/level/Level__32bit" at line 1354
    
    
    any help would be appreciated, Thanks :D
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You placed the closing parenthesis at the wrong position. The pair of parentheses after Vector3 should only include xyz and the Block should be outside.
    CrazedMiner likes this.
  3. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Now it dose absolutely nothing when TNT explodes, no errors in the console and it doesn't replace the blocks .-.
    PHP:
    public function onExplode(EntityExplodeEvent $event) {
            
    $block $event->getBlockList();
            foreach(
    $block as $blocks) {
                
    $blocks->getLevel()->setBlock(new Vector3($blocks->getX(), $blocks->getY(), $blocks->getZ()), Block::get($blocks->getId()));
            }
        }
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why Block::get($blocks) instead of directly $blocks?

    Anyway, consider setting the blocks one tick later.
    CrazedMiner likes this.
  5. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Try putting
    PHP:
    if($block instanceof Block) {
    foreach(
    $block as $blocks) {
    //Your code goes here;
    }
    }
  6. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    It's working but it's delayed so much because of lag it isn't worth using.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Cancel the explosion directly.
    CrazedMiner likes this.
  8. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    That's what I'm going to do but I still want it to damage players so I'll have to add an explosion to the level and cancel the terrain damage or find away to cancel the terrain damage directly from the TNT.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Can't you setBlockList of the explosion to an empty array?
    CrazedMiner likes this.
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Didn't think of that when I was brain storming ways of doing it in my head at 10 PM last night :p

Share This Page

Advertisement