-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
77 lines (68 loc) · 1.59 KB
/
main.go
File metadata and controls
77 lines (68 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"github.com/justtaldevelops/expresso/expresso"
"github.com/justtaldevelops/expresso/expresso/protocol"
"github.com/justtaldevelops/expresso/expresso/protocol/packet"
)
func main() {
l, err := expresso.Listen(":25565")
if err != nil {
panic(err)
}
for {
conn, err := l.Accept()
if err != nil {
panic(err)
}
go handleConnection(conn)
}
}
func handleConnection(conn *expresso.Connection) {
// Join the game client side.
err := conn.WritePacket(&packet.JoinGame{
GameMode: 1,
PreviousGameMode: 1,
Worlds: []string{"minecraft:world"},
World: "minecraft:world",
HashedSeed: 100,
ViewDistance: 16,
})
if err != nil {
panic(err)
}
// Set the player's position and rotation.
err = conn.WritePacket(&packet.ServerPlayerPositionRotation{})
if err != nil {
panic(err)
}
// Initialize a new column.
column := protocol.NewColumn(protocol.ColumnPos{0, 0})
err = column.SetBlockState(protocol.BlockPos{0, 1, 0}, 10)
if err != nil {
panic(err)
}
err = column.SetBlockState(protocol.BlockPos{1, 3, 0}, 10)
if err != nil {
panic(err)
}
// Write the column data for this specific chunk.
err = conn.WritePacket(&packet.ChunkData{Column: column})
// Update the player's viewing column.
err = conn.WritePacket(&packet.UpdateViewPosition{})
if err != nil {
panic(err)
}
// The client should now be spawned in.
fmt.Println("We should be spawned in!")
go func() {
for {
fmt.Println("Reading packet...")
pk, err := conn.ReadPacket()
if err != nil {
break
}
fmt.Printf("%+v\n", pk)
}
}()
}