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

@ -286,6 +286,35 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return false;
}
/**
* Helper function which creates minimal NBT needed to spawn an entity.
*
* @param Vector3 $pos
* @param Vector3|null $motion
* @param float $yaw
* @param float $pitch
*
* @return CompoundTag
*/
public static function createBaseNBT(Vector3 $pos, ?Vector3 $motion = null , float $yaw = 0.0, float $pitch = 0.0) : CompoundTag{
return new CompoundTag("", [
new ListTag("Pos", [
new DoubleTag("", $pos->x),
new DoubleTag("", $pos->y),
new DoubleTag("", $pos->z)
]),
new ListTag("Motion", [
new DoubleTag("", $motion ? $motion->x : 0.0),
new DoubleTag("", $motion ? $motion->y : 0.0),
new DoubleTag("", $motion ? $motion->z : 0.0)
]),
new ListTag("Rotation", [
new FloatTag("", $yaw),
new FloatTag("", $pitch)
])
]);
}
/**
* @var Player[]
*/