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

[NEW API] Help with Explosion Event

Comments in 'Plugin Development' started by Darunia18, Jun 18, 2014.

  1. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    Hello. I'm updating my plugin Claymores to the new API, and I've learned a lot just from trial and error, but I can't seem to understand how to create an explosion no matter what I try. The docs (found here) are a bit confusing to me. Maybe I'm comparing it too much to the old API. I obviously know how to make the explosion, but I can't seem to figure out how to set the explosion size or position at all. If anyone can make sense of those docs and try to explain what I'm missing, I think I can learn a lot! :D Thanks
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    It looks pretty much the same. Just use the explosion class and then do (new Explosion(new Position($x, $y, $z, $level), $size))-> explode()
  3. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    Hmm I thought I did that, but maybe I messed something up. I'll try it again. Thanks :)
  4. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    Hmmm....I did that, and here's the error I'm getting:
    01:36:42 [NOTICE] A E_RECOVERABLE_ERROR error happened: "Argument 4 passed to pocketmine\level\Position::__construct() must be an instance of pocketmine\level\Level, instance of WeakRef given, called in C:\Users\Darunia18\Desktop\PocketMine-MP-1.4\plugins\ClaymoresSource\src\Darunia18\Claymores\Main.php on line 44 and defined" in "phar://C:/Users/Darunia18/Desktop/PocketMine-MP-1.4/PocketMine-MP.phar/src/pocketmine/level/Position.php" at line 38
    01:36:42 [NOTICE] A E_NOTICE error happened: "Undefined property: WeakRef::$level" in "phar://C:/Users/Darunia18/Desktop/PocketMine-MP-1.4/PocketMine-MP.phar/src/pocketmine/level/Explosion.php" at line 75

    Fatal error: Call to a member function getBlockID() on a non-object in phar://C:/Users/Darunia18/Desktop/PocketMine-MP-1.4/PocketMine-MP.phar/src/pocketmine/level/Explosion.php on line 75
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use $pos->getLevel() not $pos->level because of WeakRef.
    Yeah and you have to change all ->level into ->getLevel() now.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Like $player->getLevel() not $player->level.
  7. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    Ok. I did that and it got rid of some of the errors, but I'm still getting

    [NOTICE] A E_NOTICE error happened: "Undefined property: WeakRef::$level" in "phar://C:/Users/Darunia18/Desktop/PocketMine-MP-1.4/PocketMine-MP.phar/src/pocketmine/level/Explosion.php" at line 75

    Fatal error: Call to a member function getBlockID() on a non-object in phar://C:/Users/Darunia18/Desktop/PocketMine-MP-1.4/PocketMine-MP.phar/src/pocketmine/level/Explosion.php on line 75
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How did you define $pos?
  9. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    PHP:
    $entity $event->getEntity();
    $explosion = new Explosion(new Position($entity->x, ($entity->-1), $entity->z$entity->getLevel()), $this->explosionSize);
    $explosion->explode();
    That's what I have. This is all the code that would be related to the errors (the others are just if statements that I've had no problems with).
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I'm not sure. Probably a PocketMine error?
    Try passing $entity->subtract(0, -1)?
  11. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    Ok. I guess I'll just keep looking through things, ask @shoghicp about it tomorrow :) Thanks for your help guys! At least I got half the errors fixed! :D
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I found it. It is a PocketMine issue. I will make a pull request.
    iJoshuaHD likes this.
  13. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    Awesome. Thank you very much! :D I'm guessing it was never found because no one's really used the explosion event yet XD
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The error is at Explosion.php not the event :)
    Well, in fact we aren't even touching the event at all xD
    https://github.com/PocketMine/PocketMine-MP/issues/1508 :) pull request sent
    Falk likes this.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oh and yeah I was a bit lazy and hurried so I forked it into LegendOfMCPE
  16. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    Yeah I saw that. Thanks! :D I guess I'll just start figuring out some other features I wanted to add until he merges and releases the phar :p Thanks so much for all the help! :D
    PEMapModder likes this.

Share This Page

Advertisement