public EntityRef newInstance(Vector3f spawnPosition, EntityRef controller) {
EntityBuilder builder = entityManager.newBuilder("engine:player");
builder.getComponent(LocationComponent.class).setWorldPosition(spawnPosition);
builder.setOwner(controller);
EntityRef transferSlot = entityManager.create("engine:transferSlot");
ClientComponent clientComp = controller.getComponent(ClientComponent.class);
if (clientComp != null) {
ColorComponent colorComp = clientComp.clientInfo.getComponent(ColorComponent.class);
MeshComponent meshComp = builder.getComponent(MeshComponent.class);
meshComp.color = colorComp.color;
}
CharacterComponent playerComponent = builder.getComponent(CharacterComponent.class);
playerComponent.spawnPosition.set(spawnPosition);
playerComponent.movingItem = transferSlot;
playerComponent.controller = controller;
EntityRef player = builder.build();
player.send(new SelectedItemChangedEvent(EntityRef.NULL, InventoryUtils.getItemAt(player, 0)));
return player;
}