42 private const TAG_FUSE =
"Fuse";
44 public static function getNetworkTypeId() :
string{
return EntityIds::TNT; }
47 protected bool $worksUnderwater =
false;
55 public function getFuse() : int{
59 public function setFuse(
int $fuse) : void{
60 if($fuse < 0 || $fuse > 32767){
61 throw new \InvalidArgumentException(
"Fuse must be in the range 0-32767");
64 $this->networkPropertiesDirty =
true;
67 public function worksUnderwater() : bool{ return $this->worksUnderwater; }
69 public function setWorksUnderwater(
bool $worksUnderwater) : void{
70 $this->worksUnderwater = $worksUnderwater;
71 $this->networkPropertiesDirty =
true;
74 public function attack(EntityDamageEvent $source) : void{
75 if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
76 parent::attack($source);
80 protected function initEntity(CompoundTag $nbt) : void{
81 parent::initEntity($nbt);
83 $this->fuse = $nbt->getShort(self::TAG_FUSE, 80);
86 public function canCollideWith(Entity $entity) : bool{
90 public function saveNBT() : CompoundTag{
91 $nbt = parent::saveNBT();
92 $nbt->setShort(self::TAG_FUSE, $this->fuse);
97 protected function entityBaseTick(
int $tickDiff = 1) : bool{
102 $hasUpdate = parent::entityBaseTick($tickDiff);
104 if(!$this->isFlaggedForDespawn()){
105 $this->fuse -= $tickDiff;
106 $this->networkPropertiesDirty =
true;
108 if($this->fuse <= 0){
109 $this->flagForDespawn();
114 return $hasUpdate || $this->fuse >= 0;
117 public function explode() : void{
118 $ev = new EntityPreExplodeEvent($this, 4);
120 if(!$ev->isCancelled()){
122 $explosion = new Explosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->getWorld()), $ev->getRadius(), $this);
123 if($ev->isBlockBreaking()){
124 $explosion->explodeA();
126 $explosion->explodeB();
130 protected function syncNetworkData(EntityMetadataCollection $properties) : void{
131 parent::syncNetworkData($properties);
133 $properties->setGenericFlag(EntityMetadataFlags::IGNITED,
true);
134 $properties->setInt(EntityMetadataProperties::VARIANT, $this->worksUnderwater ? 1 : 0);
135 $properties->setInt(EntityMetadataProperties::FUSE_LENGTH, $this->fuse);
138 public function getOffsetPosition(Vector3 $vector3) : Vector3{
139 return $vector3->add(0, 0.49, 0);