mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Added a helper function Entity->createBaseNBT() to cut down on boilerplate code
This commit is contained in:
@ -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[]
|
||||
*/
|
||||
|
Reference in New Issue
Block a user