44 private const TAG_SHOWBASE =
"ShowBottom";
46 private const TAG_BLOCKTARGET_X =
"BlockTargetX";
47 private const TAG_BLOCKTARGET_Y =
"BlockTargetY";
48 private const TAG_BLOCKTARGET_Z =
"BlockTargetZ";
50 public static function getNetworkTypeId() :
string{
return EntityIds::ENDER_CRYSTAL; }
52 protected bool $showBase =
false;
53 protected ?
Vector3 $beamTarget =
null;
61 public function isFireProof() : bool{
69 public function showBase() : bool{
70 return $this->showBase;
73 public function setShowBase(
bool $showBase) : void{
74 $this->showBase = $showBase;
75 $this->networkPropertiesDirty =
true;
78 public function getBeamTarget() : ?Vector3{
79 return $this->beamTarget;
82 public function setBeamTarget(?Vector3 $beamTarget) : void{
83 $this->beamTarget = $beamTarget;
84 $this->networkPropertiesDirty =
true;
87 public function attack(EntityDamageEvent $source) : void{
88 parent::attack($source);
90 $source->getCause() !== EntityDamageEvent::CAUSE_VOID &&
91 !$this->isFlaggedForDespawn() &&
92 !$source->isCancelled()
94 $this->flagForDespawn();
99 protected function initEntity(CompoundTag $nbt) : void{
100 parent::initEntity($nbt);
102 $this->setMaxHealth(1);
105 $this->setShowBase($nbt->getByte(self::TAG_SHOWBASE, 0) === 1);
108 ($beamXTag = $nbt->getTag(self::TAG_BLOCKTARGET_X)) instanceof IntTag &&
109 ($beamYTag = $nbt->getTag(self::TAG_BLOCKTARGET_Y)) instanceof IntTag &&
110 ($beamZTag = $nbt->getTag(self::TAG_BLOCKTARGET_Z)) instanceof IntTag
112 $this->setBeamTarget(
new Vector3($beamXTag->getValue(), $beamYTag->getValue(), $beamZTag->getValue()));
116 public function saveNBT() : CompoundTag{
117 $nbt = parent::saveNBT();
119 $nbt->setByte(self::TAG_SHOWBASE, $this->showBase ? 1 : 0);
120 if($this->beamTarget !==
null){
121 $nbt->setInt(self::TAG_BLOCKTARGET_X, $this->beamTarget->getFloorX());
122 $nbt->setInt(self::TAG_BLOCKTARGET_Y, $this->beamTarget->getFloorY());
123 $nbt->setInt(self::TAG_BLOCKTARGET_Z, $this->beamTarget->getFloorZ());
128 public function explode() : void{
129 $ev = new EntityPreExplodeEvent($this, 6);
131 if(!$ev->isCancelled()){
132 $explosion = new Explosion($this->getPosition(), $ev->getRadius(), $this);
133 if($ev->isBlockBreaking()){
134 $explosion->explodeA();
136 $explosion->explodeB();
140 protected function syncNetworkData(EntityMetadataCollection $properties) : void{
141 parent::syncNetworkData($properties);
143 $properties->setGenericFlag(EntityMetadataFlags::SHOWBASE, $this->showBase);
144 $properties->setBlockPos(EntityMetadataProperties::BLOCK_TARGET, BlockPosition::fromVector3($this->beamTarget ?? Vector3::zero()));