PocketMine-MP 5.16.1 git-585aee9386a787c95e73dd0a05ffca8329606b68
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
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
40use function cos;
41use function sin;
42use const M_PI;
43
44class TNT extends Opaque{
45 protected bool $unstable = false; //TODO: Usage unclear, seems to be a weird hack in vanilla
46 protected bool $worksUnderwater = false;
47
48 public function describeBlockItemState(RuntimeDataDescriber $w) : void{
49 $w->bool($this->worksUnderwater);
50 }
51
52 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
53 $w->bool($this->unstable);
54 }
55
56 public function isUnstable() : bool{ return $this->unstable; }
57
59 public function setUnstable(bool $unstable) : self{
60 $this->unstable = $unstable;
61 return $this;
62 }
63
64 public function worksUnderwater() : bool{ return $this->worksUnderwater; }
65
67 public function setWorksUnderwater(bool $worksUnderwater) : self{
68 $this->worksUnderwater = $worksUnderwater;
69 return $this;
70 }
71
72 public function onBreak(Item $item, ?Player $player = null, array &$returnedItems = []) : bool{
73 if($this->unstable){
74 $this->ignite();
75 return true;
76 }
77 return parent::onBreak($item, $player, $returnedItems);
78 }
79
80 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
81 if($item->getTypeId() === ItemTypeIds::FIRE_CHARGE){
82 $item->pop();
83 $this->ignite();
84 return true;
85 }
86 if($item instanceof FlintSteel || $item->hasEnchantment(VanillaEnchantments::FIRE_ASPECT())){
87 if($item instanceof Durable){
88 $item->applyDamage(1);
89 }
90 $this->ignite();
91 return true;
92 }
93
94 return false;
95 }
96
97 public function ignite(int $fuse = 80) : void{
98 $world = $this->position->getWorld();
99 $world->setBlock($this->position, VanillaBlocks::AIR());
100
101 $mot = (new Random())->nextSignedFloat() * M_PI * 2;
102
103 $tnt = new PrimedTNT(Location::fromObject($this->position->add(0.5, 0, 0.5), $world));
104 $tnt->setFuse($fuse);
105 $tnt->setWorksUnderwater($this->worksUnderwater);
106 $tnt->setMotion(new Vector3(-sin($mot) * 0.02, 0.2, -cos($mot) * 0.02));
107
108 $tnt->spawnToAll();
109 $tnt->broadcastSound(new IgniteSound());
110 }
111
112 public function getFlameEncouragement() : int{
113 return 15;
114 }
115
116 public function getFlammability() : int{
117 return 100;
118 }
119
120 public function onIncinerate() : void{
121 $this->ignite();
122 }
123
124 public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{
125 if($projectile->isOnFire()){
126 $this->ignite();
127 }
128 }
129}
setWorksUnderwater(bool $worksUnderwater)
Definition: TNT.php:67
onProjectileHit(Projectile $projectile, RayTraceResult $hitResult)
Definition: TNT.php:124
setUnstable(bool $unstable)
Definition: TNT.php:59
onBreak(Item $item, ?Player $player=null, array &$returnedItems=[])
Definition: TNT.php:72
describeBlockItemState(RuntimeDataDescriber $w)
Definition: TNT.php:48
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition: TNT.php:80
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition: TNT.php:52
pop(int $count=1)
Definition: Item.php:430