44 private const TAG_FUSE =
"Fuse";
46 public static function getNetworkTypeId() :
string{
return EntityIds::TNT; }
49 protected bool $worksUnderwater =
false;
57 public function getFuse() : int{
61 public function setFuse(
int $fuse) : void{
62 if($fuse < 0 || $fuse > 32767){
63 throw new \InvalidArgumentException(
"Fuse must be in the range 0-32767");
66 $this->networkPropertiesDirty =
true;
69 public function worksUnderwater() : bool{ return $this->worksUnderwater; }
71 public function setWorksUnderwater(
bool $worksUnderwater) : void{
72 $this->worksUnderwater = $worksUnderwater;
73 $this->networkPropertiesDirty =
true;
76 public function attack(EntityDamageEvent $source) : void{
77 if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
78 parent::attack($source);
82 protected function initEntity(CompoundTag $nbt) : void{
83 parent::initEntity($nbt);
85 $this->fuse = $nbt->getShort(self::TAG_FUSE, 80);
88 public function canCollideWith(Entity $entity) : bool{
92 public function saveNBT() : CompoundTag{
93 $nbt = parent::saveNBT();
94 $nbt->setShort(self::TAG_FUSE, $this->fuse);
99 protected function entityBaseTick(
int $tickDiff = 1) : bool{
104 $hasUpdate = parent::entityBaseTick($tickDiff);
106 if(!$this->isFlaggedForDespawn()){
107 $this->fuse -= $tickDiff;
108 $this->networkPropertiesDirty =
true;
110 if($this->fuse <= 0){
111 $this->flagForDespawn();
116 return $hasUpdate || $this->fuse >= 0;
119 public function explode() : void{
120 $ev = new EntityPreExplodeEvent($this, 4);
122 if(!$ev->isCancelled()){
124 $explosion = new Explosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->getWorld()), $ev->getRadius(), $this);
125 if($ev->isBlockBreaking()){
126 $explosion->explodeA();
128 $explosion->explodeB();
133 return
VanillaBlocks::TNT()->setWorksUnderwater($this->worksUnderwater)->asItem();
137 parent::syncNetworkData($properties);
139 $properties->setGenericFlag(EntityMetadataFlags::IGNITED,
true);
140 $properties->setInt(EntityMetadataProperties::VARIANT, $this->worksUnderwater ? 1 : 0);
141 $properties->setInt(EntityMetadataProperties::FUSE_LENGTH, $this->fuse);
145 return $vector3->add(0, 0.49, 0);