Added a helper function Entity->createBaseNBT() to cut down on boilerplate code

This commit is contained in:
Dylan K. Taylor
2017-10-19 17:36:51 +01:00
parent 67c6fca0ed
commit 50be26958a
7 changed files with 69 additions and 141 deletions

View File

@ -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);