New looks up a player state in the cache or creates one if not found
(data level.Player)
| 28 | |
| 29 | // New looks up a player state in the cache or creates one if not found |
| 30 | func (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 | |
| 63 | func (p *PlayerEntity) Abilities() level.PlayerAbilities { |
| 64 | return p.abilities.Get() |
nothing calls this directly
no test coverage detected