startGame finishes the initialization for the player and logs it into the world
()
| 139 | |
| 140 | // startGame finishes the initialization for the player and logs it into the world |
| 141 | func (p *Player) startGame() error { |
| 142 | if err := p.sendCommandGraph(); err != nil { |
| 143 | return err |
| 144 | } |
| 145 | |
| 146 | if err := p.WritePacket(&play.Login{ |
| 147 | EntityID: p.entityId, |
| 148 | DimensionName: p.DimensionName(), |
| 149 | GameMode: byte(p.GameMode()), |
| 150 | DimensionType: int32(slices.Index(p.registryIndexes["minecraft:dimension_type"], p.DimensionName())), |
| 151 | ViewDistance: p.serverProperties.ViewDistance, |
| 152 | SimulationDistance: p.serverProperties.SimulationDistance, |
| 153 | HashedSeed: p.worldLevel.Data.WorldGenSettings.Seed.Hash(), |
| 154 | EnforcesSecureChat: p.serverProperties.EnforceSecureProfile, |
| 155 | }); err != nil { |
| 156 | return err |
| 157 | } |
| 158 | |
| 159 | // todo add all other stuff |
| 160 | if err := p.WritePacket(&play.SetDefaultSpawnPosition{ |
| 161 | X: p.worldLevel.Data.SpawnX, |
| 162 | Y: p.worldLevel.Data.SpawnY, |
| 163 | Z: p.worldLevel.Data.SpawnZ, |
| 164 | Angle: p.worldLevel.Data.SpawnAngle, |
| 165 | }); err != nil { |
| 166 | return err |
| 167 | } |
| 168 | |
| 169 | x, y, z := p.Position() |
| 170 | yaw, pitch := p.Rotation() |
| 171 | |
| 172 | if err := p.SynchronizePosition(x, y, z, yaw, pitch); err != nil { |
| 173 | return err |
| 174 | } |
| 175 | |
| 176 | if err := p.sendSpawnChunks(); err != nil { |
| 177 | return err |
| 178 | } |
| 179 | |
| 180 | if err := p.SynchronizePosition(x, y, z, yaw, pitch); err != nil { |
| 181 | return err |
| 182 | } |
| 183 | |
| 184 | if err := p.WritePacket(&play.GameEvent{Event: play.GameEventStartWaitingChunks}); err != nil { |
| 185 | return err |
| 186 | } |
| 187 | p.playerList.AddPlayer(p) |
| 188 | |
| 189 | return nil |
| 190 | } |
| 191 | |
| 192 | // SynchronizePosition teleports the player to the specified coordinates |
| 193 | func (p *Player) SynchronizePosition(x, y, z float64, yaw, pitch float32) error { |
no test coverage detected