PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
TNT.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\block;
23 
33 
34 class TNT extends Solid{
35 
36  protected $id = self::TNT;
37 
38  public function __construct(){
39 
40  }
41 
42  public function getName(){
43  return "TNT";
44  }
45 
46  public function getHardness(){
47  return 0;
48  }
49 
50  public function canBeActivated(){
51  return true;
52  }
53 
54  public function onActivate(Item $item, Player $player = null){
55  if($item->getId() === Item::FLINT_STEEL){
56  $item->useOn($this);
57  $this->getLevel()->setBlock($this, new Air(), true);
58 
59  $mot = (new Random())->nextSignedFloat() * M_PI * 2;
60  $tnt = Entity::createEntity("PrimedTNT", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new Compound("", [
61  "Pos" => new Enum("Pos", [
62  new Double("", $this->x + 0.5),
63  new Double("", $this->y),
64  new Double("", $this->z + 0.5)
65  ]),
66  "Motion" => new Enum("Motion", [
67  new Double("", -sin($mot) * 0.02),
68  new Double("", 0.2),
69  new Double("", -cos($mot) * 0.02)
70  ]),
71  "Rotation" => new Enum("Rotation", [
72  new Float("", 0),
73  new Float("", 0)
74  ]),
75  "Fuse" => new Byte("Fuse", 80)
76  ]));
77 
78  $tnt->spawnToAll();
79 
80  return true;
81  }
82 
83  return false;
84  }
85 }
static createEntity($type, FullChunk $chunk, Compound $nbt,...$args)
Definition: Entity.php:239