initial world saving, doesnt work with multiple worlds yet, broken on most implementations
This commit is contained in:
parent
67a89bda7e
commit
c21f1f1412
|
@ -15,7 +15,7 @@ func Chunk2Img(c *chunk.Chunk) *image.RGBA {
|
|||
for x := uint8(0); x < 16; x++ {
|
||||
for z := uint8(0); z < 16; z++ {
|
||||
height := hm.At(x, z)
|
||||
col := color.RGBA{uint8(height), 0, uint8(height), 255}
|
||||
col := color.RGBA{uint8(height), 0, 0, 255}
|
||||
|
||||
block_rid := c.Block(x, height, z, 0)
|
||||
b, found := world.BlockByRuntimeID(block_rid)
|
||||
|
|
2
go.mod
2
go.mod
|
@ -16,7 +16,7 @@ require (
|
|||
//replace github.com/sandertv/gophertunnel => ./gophertunnel
|
||||
//replace github.com/df-mc/dragonfly => ./dragonfly
|
||||
|
||||
replace github.com/sandertv/gophertunnel => github.com/olebeck/gophertunnel v1.24.2-1
|
||||
replace github.com/sandertv/gophertunnel => github.com/olebeck/gophertunnel v1.24.3
|
||||
replace github.com/df-mc/dragonfly => github.com/olebeck/dragonfly v0.8.1-2
|
||||
|
||||
require (
|
||||
|
|
21
main.go
21
main.go
|
@ -53,6 +53,7 @@ var muted_packets = []string{
|
|||
"*packet.UpdateSubChunkBlocks",
|
||||
"*packet.SubChunk",
|
||||
"*packet.SubChunkRequest",
|
||||
"*packet.Animate",
|
||||
}
|
||||
|
||||
func PacketLogger(header packet.Header, payload []byte, src, dst net.Addr) {
|
||||
|
@ -76,7 +77,9 @@ func PacketLogger(header packet.Header, payload []byte, src, dst net.Addr) {
|
|||
if slices.Contains(muted_packets, pk_name) {
|
||||
return
|
||||
}
|
||||
switch pk.(type) {
|
||||
switch pk := pk.(type) {
|
||||
case *packet.Disconnect:
|
||||
fmt.Printf("Disconnect: %s", pk.Message)
|
||||
}
|
||||
fmt.Printf("P: %s 0x%x, %s\n", dir, pk.ID(), pk_name)
|
||||
}
|
||||
|
@ -97,6 +100,14 @@ func register_command(name, desc string, main_func func(context.Context, []strin
|
|||
}
|
||||
}
|
||||
|
||||
func exit() {
|
||||
fmt.Printf("\nExiting\n")
|
||||
for i := len(G_exit) - 1; i >= 0; i-- { // go through cleanup functions reversed
|
||||
G_exit[i]()
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.BoolVar(&G_debug, "debug", false, "debug mode")
|
||||
flag.BoolVar(&G_help, "help", false, "show help")
|
||||
|
@ -108,12 +119,8 @@ func main() {
|
|||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-sigs
|
||||
fmt.Printf("\nExiting\n")
|
||||
cancel()
|
||||
for i := len(G_exit) - 1; i >= 0; i-- { // go through cleanup functions reversed
|
||||
G_exit[i]()
|
||||
}
|
||||
os.Exit(0)
|
||||
exit()
|
||||
}()
|
||||
|
||||
// authenticate
|
||||
|
@ -160,7 +167,7 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
sigs <- nil
|
||||
exit()
|
||||
}
|
||||
|
||||
func token_main(ctx context.Context, args []string) error {
|
||||
|
|
39
world.go
39
world.go
|
@ -13,6 +13,7 @@ import (
|
|||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/df-mc/dragonfly/server/block/cube"
|
||||
"github.com/df-mc/dragonfly/server/world"
|
||||
"github.com/df-mc/dragonfly/server/world/chunk"
|
||||
"github.com/df-mc/dragonfly/server/world/mcdb"
|
||||
|
@ -35,7 +36,6 @@ type TPlayerPos struct {
|
|||
// the state used for drawing and saving
|
||||
|
||||
type WorldState struct {
|
||||
Provider *mcdb.Provider // provider for the current world
|
||||
chunks map[protocol.ChunkPos]*chunk.Chunk
|
||||
Dim world.Dimension
|
||||
WorldName string
|
||||
|
@ -50,7 +50,6 @@ type WorldState struct {
|
|||
|
||||
func NewWorldState() *WorldState {
|
||||
return &WorldState{
|
||||
Provider: nil,
|
||||
chunks: make(map[protocol.ChunkPos]*chunk.Chunk),
|
||||
Dim: nil,
|
||||
WorldName: "world",
|
||||
|
@ -189,15 +188,6 @@ func (w *WorldState) ProcessAnimate(pk *packet.Animate) {
|
|||
|
||||
func (w *WorldState) ProcessChangeDimension(pk *packet.ChangeDimension) {
|
||||
fmt.Printf("ChangeDimension %d\n", pk.Dimension)
|
||||
folder := path.Join("worlds", fmt.Sprintf("%s-dim-%d", w.WorldName, pk.Dimension))
|
||||
provider, err := mcdb.New(folder, opt.DefaultCompression)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if w.Provider != nil {
|
||||
w.Provider.Close()
|
||||
}
|
||||
w.Provider = provider
|
||||
w.Dim = dimension_ids[pk.Dimension]
|
||||
w.chunks = make(map[protocol.ChunkPos]*chunk.Chunk)
|
||||
w.ui.Reset()
|
||||
|
@ -212,6 +202,30 @@ func (w *WorldState) SetPlayerPos(Position mgl32.Vec3, Pitch, Yaw, HeadYaw float
|
|||
}
|
||||
}
|
||||
|
||||
// writes the world to a folder, resets all the chunks
|
||||
func (w *WorldState) SaveAndReset() {
|
||||
fmt.Println("Saving world")
|
||||
folder := path.Join("worlds", fmt.Sprintf("%s-dim-%d", w.WorldName, w.Dim))
|
||||
provider, err := mcdb.New(folder, opt.DefaultCompression)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for cp, c := range w.chunks {
|
||||
provider.SaveChunk((world.ChunkPos)(cp), c, w.Dim)
|
||||
}
|
||||
s := provider.Settings()
|
||||
s.Spawn = cube.Pos{
|
||||
int(w.PlayerPos.Position[0]),
|
||||
int(w.PlayerPos.Position[1]),
|
||||
int(w.PlayerPos.Position[2]),
|
||||
}
|
||||
provider.SaveSettings(s)
|
||||
provider.Close()
|
||||
w.chunks = make(map[protocol.ChunkPos]*chunk.Chunk)
|
||||
w.ui.Reset()
|
||||
}
|
||||
|
||||
func (w *WorldState) handleConn(ctx context.Context, conn *minecraft.Conn, listener *minecraft.Listener, target string) {
|
||||
w.ClientConn = conn
|
||||
|
||||
|
@ -245,8 +259,7 @@ func (w *WorldState) handleConn(ctx context.Context, conn *minecraft.Conn, liste
|
|||
})
|
||||
conn.Close()
|
||||
listener.Close()
|
||||
println("Closing Provider")
|
||||
w.Provider.Close()
|
||||
w.SaveAndReset()
|
||||
})
|
||||
|
||||
done := make(chan struct{})
|
||||
|
|
Loading…
Reference in New Issue