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