update deps, add test util
This commit is contained in:
parent
ee67a26aba
commit
8c8892abb7
2
go.mod
2
go.mod
|
@ -19,7 +19,7 @@ require (
|
|||
|
||||
replace github.com/sandertv/gophertunnel => github.com/olebeck/gophertunnel v1.24.4
|
||||
|
||||
replace github.com/df-mc/dragonfly => github.com/olebeck/dragonfly v0.8.2
|
||||
replace github.com/df-mc/dragonfly => github.com/olebeck/dragonfly v0.8.2-1
|
||||
|
||||
require (
|
||||
github.com/brentp/intintmap v0.0.0-20190211203843-30dc0ade9af9 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -28,6 +28,8 @@ github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQan
|
|||
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
|
||||
github.com/muhammadmuzzammil1998/jsonc v1.0.0 h1:8o5gBQn4ZA3NBA9DlTujCj2a4w0tqWrPVjDwhzkgTIs=
|
||||
github.com/muhammadmuzzammil1998/jsonc v1.0.0/go.mod h1:saF2fIVw4banK0H4+/EuqfFLpRnoy5S+ECwTOCcRcSU=
|
||||
github.com/olebeck/dragonfly v0.8.2-1 h1:hC0iWH7WFOpsvR3XeTwJSRKtKO+GhEcMq+H+DHUwHWc=
|
||||
github.com/olebeck/dragonfly v0.8.2-1/go.mod h1:xgpCDhHoP03RygPaTrzzDwsSTcEZhxNPMV3CAxETj+I=
|
||||
github.com/olebeck/dragonfly v0.8.2 h1:UIFDpktsif5pzQp0ewJIOtpzbNzuKHSMCPT69HHhKyo=
|
||||
github.com/olebeck/dragonfly v0.8.2/go.mod h1:xgpCDhHoP03RygPaTrzzDwsSTcEZhxNPMV3CAxETj+I=
|
||||
github.com/olebeck/gophertunnel v1.24.4 h1:nX7Std61XpXW4VP7KKd2RvinRwx1nGB5l8QnbwrArLE=
|
||||
|
|
38
world.go
38
world.go
|
@ -13,6 +13,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/df-mc/dragonfly/server/block/cube"
|
||||
|
@ -67,6 +68,27 @@ var black_16x16 = image.NewRGBA(image.Rect(0, 0, 16, 16))
|
|||
func init() {
|
||||
draw.Draw(black_16x16, image.Rect(0, 0, 16, 16), image.Black, image.Point{}, draw.Src)
|
||||
register_command("world", "Launch world downloading proxy", world_main)
|
||||
register_command("test-chunk", "test chunk decode", test_chunk)
|
||||
}
|
||||
|
||||
func test_chunk(ctx context.Context, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("not enough args")
|
||||
}
|
||||
fname, air, count := args[0], args[1], args[2]
|
||||
_air, _ := strconv.Atoi(air)
|
||||
_count, _ := strconv.Atoi(count)
|
||||
data, err := os.ReadFile(fname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ch, err := chunk.NetworkDecode(uint32(_air), data, _count, cube.Range{-64, 319})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ch.Range()
|
||||
return nil
|
||||
}
|
||||
|
||||
func world_main(ctx context.Context, args []string) error {
|
||||
|
@ -181,7 +203,12 @@ func (w *WorldState) ProcessAnimate(pk *packet.Animate) {
|
|||
|
||||
func (w *WorldState) ProcessChangeDimension(pk *packet.ChangeDimension) {
|
||||
fmt.Printf("ChangeDimension %d\n", pk.Dimension)
|
||||
w.SaveAndReset()
|
||||
if len(w.chunks) > 0 {
|
||||
w.SaveAndReset()
|
||||
} else {
|
||||
fmt.Println("Info: Skipping save because the world didnt contain any chunks")
|
||||
w.Reset()
|
||||
}
|
||||
w.Dim = dimension_ids[pk.Dimension]
|
||||
}
|
||||
|
||||
|
@ -194,6 +221,11 @@ func (w *WorldState) SetPlayerPos(Position mgl32.Vec3, Pitch, Yaw, HeadYaw float
|
|||
}
|
||||
}
|
||||
|
||||
func (w *WorldState) Reset() {
|
||||
w.chunks = make(map[protocol.ChunkPos]*chunk.Chunk)
|
||||
w.ui.Reset()
|
||||
}
|
||||
|
||||
// writes the world to a folder, resets all the chunks
|
||||
func (w *WorldState) SaveAndReset() {
|
||||
fmt.Println("Saving world")
|
||||
|
@ -288,9 +320,6 @@ func (w *WorldState) SaveAndReset() {
|
|||
|
||||
provider.SaveSettings(s)
|
||||
provider.Close()
|
||||
w.chunks = make(map[protocol.ChunkPos]*chunk.Chunk)
|
||||
w.ui.Reset()
|
||||
|
||||
w.worldCounter += 1
|
||||
|
||||
filename := folder + ".mcworld"
|
||||
|
@ -318,6 +347,7 @@ func (w *WorldState) SaveAndReset() {
|
|||
f.Close()
|
||||
fmt.Printf("Saved: %s\n", filename)
|
||||
os.RemoveAll(folder)
|
||||
w.Reset()
|
||||
}
|
||||
|
||||
func handleConn(ctx context.Context, l *minecraft.Listener, cc, sc *minecraft.Conn, server_name string) {
|
||||
|
|
Loading…
Reference in New Issue