MCPcopy Create free account
hub / github.com/ZeppelinMC/Zeppelin / New

Method New

server/player/state/playerEntity.go:30–61  ·  view source on GitHub ↗

New looks up a player state in the cache or creates one if not found

(data level.Player)

Source from the content-addressed store, hash-verified

28
29// New looks up a player state in the cache or creates one if not found
30func (mgr *PlayerEntityManager) New(data level.Player) *PlayerEntity {
31 if p, ok := mgr.lookup(data.UUID.UUID()); ok {
32 return p
33 }
34
35 pl := &PlayerEntity{
36 LivingEntity: entity.NewLiving(entity.New(data.UUID.UUID(), registry.EntityType.Get("minecraft:player"), metadata.Player(data.Health), data.Attributes)),
37
38 //recipeBook: atomic.Value(data.RecipeBook),
39
40 abilities: atomic.Value(data.Abilities),
41
42 inventory: &data.Inventory,
43
44 data: data,
45 }
46
47 pl.gameMode.Store(int32(data.PlayerGameType))
48 pl.selectedItemSlot.Store(data.SelectedItemSlot)
49
50 pl.SetPosition(data.Pos[0], data.Pos[1], data.Pos[2])
51 pl.SetMotion(data.Motion[0], data.Motion[1], data.Motion[2])
52 pl.SetRotation(data.Rotation[0], data.Rotation[1])
53 pl.SetOnGround(data.OnGround)
54 pl.SetDimensionName(data.Dimension)
55 pl.SetHealth(data.Health)
56 pl.SetFood(data.FoodLevel, data.FoodSaturationLevel, data.FoodExhaustionLevel)
57
58 mgr.add(pl)
59
60 return pl
61}
62
63func (p *PlayerEntity) Abilities() level.PlayerAbilities {
64 return p.abilities.Get()

Callers

nothing calls this directly

Calls 15

lookupMethod · 0.95
addMethod · 0.95
NewLivingFunction · 0.92
NewFunction · 0.92
PlayerFunction · 0.92
ValueFunction · 0.92
SetPositionMethod · 0.80
SetMotionMethod · 0.80
SetRotationMethod · 0.80
SetOnGroundMethod · 0.80
SetDimensionNameMethod · 0.80
SetHealthMethod · 0.80

Tested by

no test coverage detected