mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Added a helper function Entity->createBaseNBT() to cut down on boilerplate code
This commit is contained in:
@ -27,11 +27,6 @@ use pocketmine\block\Block;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\DoubleTag;
|
||||
use pocketmine\nbt\tag\FloatTag;
|
||||
use pocketmine\nbt\tag\ListTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\Player;
|
||||
|
||||
class SpawnEgg extends Item{
|
||||
@ -40,25 +35,10 @@ class SpawnEgg extends Item{
|
||||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
|
||||
$nbt = new CompoundTag("", [
|
||||
new ListTag("Pos", [
|
||||
new DoubleTag("", $blockReplace->getX() + 0.5),
|
||||
new DoubleTag("", $blockReplace->getY()),
|
||||
new DoubleTag("", $blockReplace->getZ() + 0.5)
|
||||
]),
|
||||
new ListTag("Motion", [
|
||||
new DoubleTag("", 0),
|
||||
new DoubleTag("", 0),
|
||||
new DoubleTag("", 0)
|
||||
]),
|
||||
new ListTag("Rotation", [
|
||||
new FloatTag("", lcg_value() * 360),
|
||||
new FloatTag("", 0)
|
||||
]),
|
||||
]);
|
||||
$nbt = Entity::createBaseNBT($blockReplace->add(0.5, 0, 0.5), null, lcg_value() * 360, 0);
|
||||
|
||||
if($this->hasCustomName()){
|
||||
$nbt->CustomName = new StringTag("CustomName", $this->getCustomName());
|
||||
$nbt->setString("CustomName", $this->getCustomName());
|
||||
}
|
||||
|
||||
$entity = Entity::createEntity($this->meta, $level, $nbt);
|
||||
|
Reference in New Issue
Block a user