forked from pmmp/PocketMine-MP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
184 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
namespace pocketmine\entity\object; | ||
|
||
use pocketmine\entity\Entity; | ||
use pocketmine\entity\EntitySizeInfo; | ||
use pocketmine\entity\Explosive; | ||
use pocketmine\event\entity\EntityDamageEvent; | ||
use pocketmine\event\entity\EntityPreExplodeEvent; | ||
use pocketmine\math\Vector3; | ||
use pocketmine\nbt\tag\CompoundTag; | ||
use pocketmine\nbt\tag\IntTag; | ||
use pocketmine\network\mcpe\protocol\types\BlockPosition; | ||
use pocketmine\network\mcpe\protocol\types\entity\EntityIds; | ||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection; | ||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags; | ||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; | ||
use pocketmine\world\Explosion; | ||
|
||
class EndCrystal extends Entity implements Explosive{ | ||
private const TAG_SHOWBASE = "ShowBottom"; //TAG_Byte | ||
|
||
private const TAG_BLOCKTARGET_X = "BlockTargetX"; //TAG_Int | ||
private const TAG_BLOCKTARGET_Y = "BlockTargetY"; //TAG_Int | ||
private const TAG_BLOCKTARGET_Z = "BlockTargetZ"; //TAG_Int | ||
|
||
public static function getNetworkTypeId() : string{ | ||
return EntityIds::ENDER_CRYSTAL; | ||
} | ||
|
||
protected bool $showBase = false; | ||
protected ?Vector3 $beamTarget = null; | ||
|
||
protected function getInitialSizeInfo() : EntitySizeInfo{ | ||
return new EntitySizeInfo(2.0, 2.0); | ||
} | ||
|
||
protected function getInitialDragMultiplier() : float{ | ||
return 1.0; | ||
} | ||
|
||
protected function getInitialGravity() : float{ | ||
return 0.0; | ||
} | ||
|
||
public function isFireProof() : bool{ | ||
return true; | ||
} | ||
|
||
public function showBase() : bool{ | ||
return $this->showBase; | ||
} | ||
|
||
public function setShowBase(bool $showBase) : void{ | ||
$this->showBase = $showBase; | ||
$this->networkPropertiesDirty = true; | ||
} | ||
|
||
public function getBeamTarget() : ?Vector3{ | ||
return $this->beamTarget; | ||
} | ||
|
||
public function setBeamTarget(?Vector3 $beamTarget) : void{ | ||
$this->beamTarget = $beamTarget; | ||
$this->networkPropertiesDirty = true; | ||
} | ||
|
||
public function attack(EntityDamageEvent $source) : void{ | ||
parent::attack($source); | ||
if ( | ||
$source->getCause() !== EntityDamageEvent::CAUSE_VOID && | ||
!$this->isFlaggedForDespawn() && | ||
!$source->isCancelled() | ||
) { | ||
$this->flagForDespawn(); | ||
$this->explode(); | ||
} | ||
} | ||
|
||
protected function initEntity(CompoundTag $nbt) : void{ | ||
parent::initEntity($nbt); | ||
|
||
$this->setMaxHealth(1); | ||
$this->setHealth(1); | ||
|
||
$this->setShowBase($nbt->getByte(self::TAG_SHOWBASE, 0) === 1); | ||
|
||
if ( | ||
($beamXTag = $nbt->getTag(self::TAG_BLOCKTARGET_X)) instanceof IntTag && | ||
($beamYTag = $nbt->getTag(self::TAG_BLOCKTARGET_Y)) instanceof IntTag && | ||
($beamZTag = $nbt->getTag(self::TAG_BLOCKTARGET_Z)) instanceof IntTag | ||
) { | ||
$this->setBeamTarget(new Vector3($beamXTag->getValue(), $beamYTag->getValue(), $beamZTag->getValue())); | ||
} | ||
} | ||
|
||
public function saveNBT() : CompoundTag{ | ||
$nbt = parent::saveNBT(); | ||
|
||
$nbt->setByte(self::TAG_SHOWBASE, $this->showBase ? 1 : 0); | ||
if ($this->beamTarget !== null) { | ||
$nbt->setInt(self::TAG_BLOCKTARGET_X, $this->beamTarget->getFloorX()); | ||
$nbt->setInt(self::TAG_BLOCKTARGET_Y, $this->beamTarget->getFloorY()); | ||
$nbt->setInt(self::TAG_BLOCKTARGET_Z, $this->beamTarget->getFloorZ()); | ||
} | ||
return $nbt; | ||
} | ||
|
||
public function explode() : void{ | ||
$ev = new EntityPreExplodeEvent($this, 6); | ||
$ev->call(); | ||
if (!$ev->isCancelled()) { | ||
$explosion = new Explosion($this->getPosition(), $ev->getRadius(), $this); | ||
if ($ev->isBlockBreaking()) { | ||
$explosion->explodeA(); | ||
} | ||
$explosion->explodeB(); | ||
} | ||
} | ||
|
||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{ | ||
parent::syncNetworkData($properties); | ||
|
||
$properties->setGenericFlag(EntityMetadataFlags::SHOWBASE, $this->showBase); | ||
$properties->setBlockPos(EntityMetadataProperties::BLOCK_TARGET, BlockPosition::fromVector3($this->beamTarget ?? Vector3::zero())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace pocketmine\item; | ||
|
||
use pocketmine\block\Block; | ||
use pocketmine\block\BlockTypeIds; | ||
use pocketmine\entity\Location; | ||
use pocketmine\math\AxisAlignedBB; | ||
use pocketmine\math\Facing; | ||
use pocketmine\math\Vector3; | ||
use pocketmine\player\Player; | ||
use pocketmine\entity\object\EndCrystal as EntityEndCrystal; | ||
|
||
class EndCrystal extends Item{ | ||
|
||
public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ | ||
if ($blockClicked->getTypeId() === BlockTypeIds::OBSIDIAN || $blockClicked->getTypeId() === BlockTypeIds::BEDROCK) { | ||
$pos = $blockClicked->getPosition(); | ||
$world = $pos->getWorld(); | ||
$bb = AxisAlignedBB::one() | ||
->offset($pos->getX(), $pos->getY(), $pos->getZ()) | ||
->extend(Facing::UP, 1); | ||
if ( | ||
count($world->getNearbyEntities($bb)) === 0 && | ||
$blockClicked->getSide(Facing::UP)->getTypeId() === BlockTypeIds::AIR && | ||
$blockClicked->getSide(Facing::UP, 2)->getTypeId() === BlockTypeIds::AIR | ||
) { | ||
$crystal = new EntityEndCrystal(Location::fromObject($pos->add(0.5, 1, 0.5), $world)); | ||
$crystal->spawnToAll(); | ||
|
||
$this->pop(); | ||
return ItemUseResult::SUCCESS; | ||
} | ||
} | ||
return ItemUseResult::NONE; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters