Skip to content

Commit

Permalink
1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
olebeck committed Jun 20, 2024
1 parent 94c5d65 commit b9bbb29
Show file tree
Hide file tree
Showing 26 changed files with 186 additions and 579 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ entityflags.py
*.ignore

/libbedrocktool.h
/libbedrocktool.so
/libbedrocktool.so
/tex.png
2 changes: 1 addition & 1 deletion cmd/generate-color-lookup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
}

var entries []protocol.BlockEntry
for _, block := range world.Blocks() {
for _, block := range world.DefaultBlockRegistry.Blocks() {
if block, ok := block.(world.UnknownBlock); ok {
entries = append(entries, protocol.BlockEntry{
Name: block.Name,
Expand Down
2 changes: 1 addition & 1 deletion dragonfly
Submodule dragonfly updated 118 files
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.21.0
go 1.22.0

toolchain go1.21.4

Expand Down
30 changes: 25 additions & 5 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
cloud.google.com/go/compute v1.20.1/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM=
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20221208032759-85de2813cf6b/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d/go.mod h1:OYVuxibdk9OSLX8vAqydtRPP87PyTFcT9uH3MlEGBQA=
git.sr.ht/~jackmordaunt/go-toast v1.0.0/go.mod h1:aIuRX/HdBOz7yRS8rOVYQCwJQlFS7DbYBTpUV0SHeeg=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/andybalholm/stroke v0.0.0-20221221101821-bd29b49d73f0/go.mod h1:ccdDYaY5+gO+cbnQdFxEXqfy0RkoV25H3jLXUDNM3wg=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
github.com/chromedp/chromedp v0.9.2/go.mod h1:LkSXJKONWTCHAfQasKFUZI+mxqS4tZqhmtGzzhLsnLs=
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
Expand All @@ -20,33 +22,51 @@ github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u1
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY=
github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kamstrup/intmap v0.2.0/go.mod h1:z3uar6/7HP2QxJJoFTWAKsA5k7Uy1UJjAZoT3f62KEE=
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/sandertv/gophertunnel v1.37.0/go.mod h1:4El8ZfEpUmOMIJhPt5SCc1PyLNiuQ2+grWczrBvSGVs=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/sandertv/go-raknet v1.14.0/go.mod h1:/yysjwfCXm2+2OY8mBazLzcxJ3irnylKCyG3FLgUPVU=
github.com/sandertv/gophertunnel v1.38.0/go.mod h1:nqbZPCBZmKot/DHiY4efq8QQj6gvLvIk8LWPxXF8+6g=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
golang.org/x/exp/shiny v0.0.0-20231127185646-65229373498e/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0=
golang.org/x/image v0.3.0/go.mod h1:fXd9211C/0VTlYuAcOhW8dY/RtEJqODXOWBDpmYBf+A=
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/image v0.17.0 h1:nTRVVdajgB8zCMZVsViyzhnMKPwYeroEERRC64JuLco=
golang.org/x/image v0.17.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a/go.mod h1:Ede7gF0KGoHlj822RtphAHK1jLdrcuRBZg0sF1Q+SPc=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240208230135-b75ee8823808/go.mod h1:KG1lNk5ZFNssSZLrpVb4sMXKMpGwGXOxSG3rnu2gZQQ=
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
2 changes: 1 addition & 1 deletion gophertunnel
Submodule gophertunnel updated 39 files
+4 −4 .github/workflows/go.yml
+3 −1 README.md
+12 −15 go.mod
+36 −24 go.sum
+12 −10 main.go
+1 −1 minecraft/auth/minecraft.go
+2 −2 minecraft/auth/xbox.go
+20 −18 minecraft/conn.go
+18 −14 minecraft/dial.go
+1 −1 minecraft/example_listener_test.go
+3 −0 minecraft/game_data.go
+10 −10 minecraft/listener.go
+1 −1 minecraft/nbt/dump.go
+6 −5 minecraft/packet.go
+20 −0 minecraft/protocol/events.go
+2 −2 minecraft/protocol/info.go
+18 −12 minecraft/protocol/login/data.go
+7 −7 minecraft/protocol/login/request.go
+21 −0 minecraft/protocol/packet/award_achievement.go
+16 −8 minecraft/protocol/packet/code_builder_source.go
+2 −0 minecraft/protocol/packet/completed_using_item.go
+1 −1 minecraft/protocol/packet/compression.go
+4 −0 minecraft/protocol/packet/container_close.go
+7 −7 minecraft/protocol/packet/decoder.go
+6 −13 minecraft/protocol/packet/encoder.go
+1 −1 minecraft/protocol/packet/encryption.go
+1 −0 minecraft/protocol/packet/id.go
+128 −124 minecraft/protocol/packet/level_event.go
+44 −0 minecraft/protocol/packet/level_sound_event.go
+1 −0 minecraft/protocol/packet/player_auth_input.go
+1 −0 minecraft/protocol/packet/pool.go
+9 −0 minecraft/protocol/packet/start_game.go
+3 −0 minecraft/protocol/packet/text.go
+30 −0 minecraft/protocol/recipe.go
+17 −17 minecraft/resource/pack.go
+1 −1 minecraft/resource_pack_queue.go
+20 −27 minecraft/server_status_provider.go
+1 −1 query/packet.go
+1 −1 query/query.go
4 changes: 2 additions & 2 deletions handlers/worlds/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (w *worldsHandler) processLevelChunk(pk *packet.LevelChunk) {

//os.WriteFile("chunk.bin", pk.RawPayload, 0777)

ch, blockNBTs, err := chunk.NetworkDecode(world.AirRID(), pk.RawPayload, subChunkCount, w.serverState.useOldBiomes, w.serverState.useHashedRids, w.currentWorld.Range())
ch, blockNBTs, err := chunk.NetworkDecode(w.serverState.blocks, pk.RawPayload, subChunkCount, w.serverState.useOldBiomes, w.serverState.useHashedRids, w.currentWorld.Range())
if err != nil {
logrus.Error(err)
return
Expand Down Expand Up @@ -162,7 +162,7 @@ func (w *worldsHandler) processSubChunk(pk *packet.SubChunk) error {
index := uint8(absY)
sub, err := chunk.DecodeSubChunk(
buf,
world.AirRID(),
w.serverState.blocks,
w.currentWorld.Dimension().Range(),
&index,
chunk.NetworkEncoding,
Expand Down
71 changes: 46 additions & 25 deletions handlers/worlds/packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/bedrock-tool/bedrocktool/locale"
"github.com/bedrock-tool/bedrocktool/utils"
"github.com/bedrock-tool/bedrocktool/utils/behaviourpack"
"github.com/bedrock-tool/bedrocktool/utils/nbtconv"
"github.com/bedrock-tool/bedrocktool/utils/resourcepack"
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/item/inventory"
"github.com/df-mc/dragonfly/server/nbtconv"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl32"
"github.com/gregwebs/go-recovery"
Expand All @@ -31,13 +31,20 @@ func (w *worldsHandler) getEntity(id worldstate.EntityRuntimeID) *worldstate.Ent
func (w *worldsHandler) packetCB(_pk packet.Packet, toServer bool, timeReceived time.Time, preLogin bool) (packet.Packet, error) {
// general / startup
switch pk := _pk.(type) {
case *packet.CompressedBiomeDefinitionList: // for client side generation, disabled by proxy
return nil, nil

case *packet.RequestChunkRadius:
pk.ChunkRadius = w.settings.ChunkRadius
pk.MaxChunkRadius = w.settings.ChunkRadius

case *packet.ChunkRadiusUpdated:
w.serverState.radius = pk.ChunkRadius
pk.ChunkRadius = w.settings.ChunkRadius

case *packet.SetCommandsEnabled:
pk.Enabled = true

case *packet.SetTime:
w.currentWorld.SetTime(timeReceived, int(pk.Time))

Expand All @@ -47,6 +54,8 @@ func (w *worldsHandler) packetCB(_pk packet.Packet, toServer bool, timeReceived
w.currentWorld.SetTime(timeReceived, int(pk.Time))
w.serverState.useHashedRids = pk.UseBlockNetworkIDHashes

w.serverState.blocks = world.DefaultBlockRegistry.Clone().(*world.BlockRegistryImpl)

world.InsertCustomItems(pk.Items)
for _, ie := range pk.Items {
w.bp.AddItem(ie)
Expand All @@ -56,10 +65,10 @@ func (w *worldsHandler) packetCB(_pk packet.Packet, toServer bool, timeReceived
for _, be := range pk.Blocks {
w.bp.AddBlock(be)
}
// telling the chunk code what custom blocks there are so it can generate offsets
world.InsertCustomBlocks(pk.Blocks)
world.AddCustomBlocks(w.serverState.blocks, pk.Blocks)
w.customBlocks = pk.Blocks
}
w.serverState.blocks.Finalize()

w.serverState.WorldName = pk.WorldName
if pk.WorldName != "" {
Expand Down Expand Up @@ -90,6 +99,8 @@ func (w *worldsHandler) packetCB(_pk packet.Packet, toServer bool, timeReceived
dim, _ := world.DimensionByID(int(pk.Dimension))
w.currentWorld.SetDimension(dim)

w.currentWorld.BiomeRegistry = w.serverState.biomes
w.currentWorld.BlockRegistry = w.serverState.blocks
w.openWorldState(w.settings.StartPaused)
}

Expand All @@ -104,20 +115,22 @@ func (w *worldsHandler) packetCB(_pk packet.Packet, toServer bool, timeReceived
w.bp.ApplyComponentEntries(pk.Items)

case *packet.BiomeDefinitionList:
err := nbt.UnmarshalEncoding(pk.SerialisedBiomeDefinitions, &w.serverState.biomes, nbt.NetworkLittleEndian)
var biomes map[string]any
err := nbt.UnmarshalEncoding(pk.SerialisedBiomeDefinitions, &biomes, nbt.NetworkLittleEndian)
if err != nil {
logrus.Error(err)
}
for k, v := range w.serverState.biomes {
_, ok := world.BiomeByName(k)

for k, v := range biomes {
_, ok := w.serverState.biomes.BiomeByName(k)
if !ok {
world.RegisterBiome(&customBiome{
w.serverState.biomes.Register(&customBiome{
name: k,
data: v.(map[string]any),
})
}
}
w.bp.AddBiomes(w.serverState.biomes)
w.bp.AddBiomes(biomes)
}

_pk = w.itemPackets(_pk)
Expand Down Expand Up @@ -157,35 +170,43 @@ func (w *worldsHandler) playersPackets(_pk packet.Packet) {

geometryName := resourcePatch["geometry"]["default"]

var geom *resourcepack.Geometry
var geometry *resourcepack.GeometryFile
var isDefault bool
if len(skin.SkinGeometry) > 0 {
skinGeometry, _, err := utils.ParseSkinGeometry(skin.SkinGeometry)
if err != nil {
logrus.Error(err)
return
}
geom = &resourcepack.Geometry{
Description: skinGeometry.Description,
Bones: skinGeometry.Bones,
if skinGeometry != nil {
geometry = &resourcepack.GeometryFile{
FormatVersion: string(skin.GeometryDataEngineVersion),
Geometry: []*resourcepack.Geometry{
&resourcepack.Geometry{
Description: skinGeometry.Description,
Bones: skinGeometry.Bones,
},
},
}
}
} else {
geom = &resourcepack.Geometry{
Description: utils.SkinGeometryDescription{
Identifier: geometryName,
TextureWidth: int(skin.SkinImageWidth),
TextureHeight: int(skin.SkinImageHeight),
}
if geometry == nil {
geometry = &resourcepack.GeometryFile{
FormatVersion: string(skin.GeometryDataEngineVersion),
Geometry: []*resourcepack.Geometry{
&resourcepack.Geometry{
Description: utils.SkinGeometryDescription{
Identifier: geometryName,
TextureWidth: int(skin.SkinImageWidth),
TextureHeight: int(skin.SkinImageHeight),
},
},
},
}
isDefault = true
}

var geometry = resourcepack.GeometryFile{
FormatVersion: string(skin.GeometryDataEngineVersion),
Geometry: []*resourcepack.Geometry{geom},
}

w.rp.AddPlayer(pk.UUID.String(), skinTexture, capeTexture, skin.CapeID, &geometry, isDefault)
w.rp.AddPlayer(pk.UUID.String(), skinTexture, capeTexture, skin.CapeID, geometry, isDefault)
}
case *packet.PlayerList:
if pk.ActionType == packet.PlayerListActionRemove { // remove
Expand Down Expand Up @@ -475,7 +496,7 @@ func (w *worldsHandler) itemPackets(_pk packet.Packet) packet.Packet {
// create inventory
inv := inventory.New(len(existing.Content.Content), nil)
for i, c := range existing.Content.Content {
item := utils.StackToItem(c.Stack)
item := utils.StackToItem(w.serverState.blocks, c.Stack)
inv.SetItem(i, item)
}

Expand Down
4 changes: 2 additions & 2 deletions handlers/worlds/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package worlds

import (
"github.com/bedrock-tool/bedrocktool/utils"
"github.com/bedrock-tool/bedrocktool/utils/nbtconv"
"github.com/df-mc/dragonfly/server/item/inventory"
"github.com/df-mc/dragonfly/server/nbtconv"
)

func (w *worldsHandler) playerData() (ret map[string]any) {
Expand All @@ -15,7 +15,7 @@ func (w *worldsHandler) playerData() (ret map[string]any) {
if len(w.serverState.playerInventory) > 0 && w.settings.SaveInventories {
inv := inventory.New(len(w.serverState.playerInventory), nil)
for i, ii := range w.serverState.playerInventory {
inv.SetItem(i, utils.StackToItem(ii.Stack))
inv.SetItem(i, utils.StackToItem(w.serverState.blocks, ii.Stack))
}
ret["Inventory"] = nbtconv.InvToNBT(inv)
}
Expand Down
24 changes: 8 additions & 16 deletions handlers/worlds/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/bedrock-tool/bedrocktool/utils/resourcepack"
"github.com/google/uuid"

"github.com/df-mc/dragonfly/server/block"
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/world"
_ "github.com/df-mc/dragonfly/server/world/biome"
Expand Down Expand Up @@ -55,9 +54,11 @@ type serverState struct {
haveStartGame bool
worldCounter int
WorldName string
biomes map[string]any
radius int32

biomes *world.BiomeRegistry
blocks *world.BlockRegistryImpl

openItemContainers map[byte]*itemContainer
playerInventory []protocol.ItemInstance
packs []utils.Pack
Expand Down Expand Up @@ -92,15 +93,6 @@ type itemContainer struct {
Content *packet.InventoryContent
}

// resets dragonfly globals
func resetGlobals() {
world.ClearStates()
world.LoadBlockStates()
block.InitBlocks()
world.FinaliseBlockRegistry()
world.ResetBiomes()
}

func NewWorldsHandler(settings WorldSettings) *proxy.Handler {
settings.ExcludedMobs = slices.DeleteFunc(settings.ExcludedMobs, func(mob string) bool {
return mob == ""
Expand All @@ -120,6 +112,7 @@ func NewWorldsHandler(settings WorldSettings) *proxy.Handler {
openItemContainers: make(map[byte]*itemContainer),
dimensions: make(map[int]protocol.DimensionDefinition),
playerSkins: make(map[uuid.UUID]*protocol.Skin),
biomes: world.DefaultBiomes.Clone(),
},
settings: settings,
}
Expand Down Expand Up @@ -201,7 +194,7 @@ func NewWorldsHandler(settings WorldSettings) *proxy.Handler {
w.serverState.Name = hostname

// initialize a worldstate
w.currentWorld, err = worldstate.New(w.chunkCB, w.serverState.dimensions)
w.currentWorld, err = worldstate.New(w.chunkCB, w.serverState.dimensions, nil, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -271,7 +264,6 @@ func NewWorldsHandler(settings WorldSettings) *proxy.Handler {
OnEnd: func() {
w.SaveAndReset(true, nil)
w.wg.Wait()
resetGlobals()
},
Deferred: cancel,
}
Expand All @@ -286,7 +278,7 @@ func (w *worldsHandler) preloadReplay() error {
var conn minecraft.IConn
var err error
conn, err = proxy.CreateReplayConnector(context.Background(), w.settings.PreloadReplay, func(header packet.Header, payload []byte, src, dst net.Addr) {
pk, ok := proxy.DecodePacket(header, payload)
pk, ok := proxy.DecodePacket(header, payload, conn.ShieldID())
if !ok {
logrus.Error("unknown packet", header)
return
Expand Down Expand Up @@ -315,7 +307,7 @@ func (w *worldsHandler) preloadReplay() error {
w.proxy.Server = nil

logrus.Info("finished preload")
resetGlobals()
w.serverState.blocks = nil
return nil
}

Expand Down Expand Up @@ -457,7 +449,7 @@ func (w *worldsHandler) chunkCB(cp world.ChunkPos, c *chunk.Chunk) {

func (w *worldsHandler) reset(dim world.Dimension) (err error) {
// create new world state
w.currentWorld, err = worldstate.New(w.chunkCB, w.serverState.dimensions)
w.currentWorld, err = worldstate.New(w.chunkCB, w.serverState.dimensions, w.serverState.blocks, w.serverState.biomes)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit b9bbb29

Please sign in to comment.