diff --git a/go.mod b/go.mod index 3f8da3ce7..bcea2f8b6 100644 --- a/go.mod +++ b/go.mod @@ -7,12 +7,12 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 github.com/df-mc/atomic v1.10.0 github.com/df-mc/goleveldb v1.1.9 - github.com/df-mc/worldupgrader v1.0.11 + github.com/df-mc/worldupgrader v1.0.12 github.com/go-gl/mathgl v1.1.0 github.com/google/uuid v1.4.0 github.com/pelletier/go-toml v1.9.5 github.com/rogpeppe/go-internal v1.11.0 - github.com/sandertv/gophertunnel v1.34.1 + github.com/sandertv/gophertunnel v1.35.0 github.com/segmentio/fasthash v1.0.3 github.com/sirupsen/logrus v1.9.3 golang.org/x/exp v0.0.0-20230206171751-46f607a40771 diff --git a/go.sum b/go.sum index 023d3986f..25afe848a 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/df-mc/atomic v1.10.0 h1:0ZuxBKwR/hxcFGorKiHIp+hY7hgY+XBTzhCYD2NqSEg= github.com/df-mc/atomic v1.10.0/go.mod h1:Gw9rf+rPIbydMjA329Jn4yjd/O2c/qusw3iNp4tFGSc= github.com/df-mc/goleveldb v1.1.9 h1:ihdosZyy5jkQKrxucTQmN90jq/2lUwQnJZjIYIC/9YU= github.com/df-mc/goleveldb v1.1.9/go.mod h1:+NHCup03Sci5q84APIA21z3iPZCuk6m6ABtg4nANCSk= -github.com/df-mc/worldupgrader v1.0.11 h1:7dlebxDXY8QND3MnDPnty7qeAqtxJE8kVqvs6VDs1YI= -github.com/df-mc/worldupgrader v1.0.11/go.mod h1:tsSOLTRm9mpG7VHvYpAjjZrkRHWmSbKZAm9bOLNnlDk= +github.com/df-mc/worldupgrader v1.0.12 h1:Ry6XkcwclSMfRPdiwcfSFRWqTkVglu0u3oLd0X2CxZ4= +github.com/df-mc/worldupgrader v1.0.12/go.mod h1:tsSOLTRm9mpG7VHvYpAjjZrkRHWmSbKZAm9bOLNnlDk= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-gl/mathgl v1.1.0 h1:0lzZ+rntPX3/oGrDzYGdowSLC2ky8Osirvf5uAwfIEA= github.com/go-gl/mathgl v1.1.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ= @@ -50,8 +50,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/sandertv/go-raknet v1.12.0 h1:olUzZlIJyX/pgj/mrsLCZYjKLNDsYiWdvQ4NIm3z0DA= github.com/sandertv/go-raknet v1.12.0/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y= -github.com/sandertv/gophertunnel v1.34.1 h1:gRU9KVT8GewlSPRCn3sQNw6RbTGyd02yyXZOXyIjz+o= -github.com/sandertv/gophertunnel v1.34.1/go.mod h1:4El8ZfEpUmOMIJhPt5SCc1PyLNiuQ2+grWczrBvSGVs= +github.com/sandertv/gophertunnel v1.35.0 h1:1QQ/FSvSBQ4nqYus7Br4ihDDoI6g+L4/4MYNpPrIDKs= +github.com/sandertv/gophertunnel v1.35.0/go.mod h1:4El8ZfEpUmOMIJhPt5SCc1PyLNiuQ2+grWczrBvSGVs= github.com/segmentio/fasthash v1.0.3 h1:EI9+KE1EwvMLBWwjpRDc+fEM+prwxDYbslddQGtrmhM= github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= diff --git a/main.go b/main.go index 89c129769..49294ec7a 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,11 @@ package main import ( "fmt" "github.com/df-mc/dragonfly/server" + "github.com/df-mc/dragonfly/server/block" + "github.com/df-mc/dragonfly/server/item" + "github.com/df-mc/dragonfly/server/player" "github.com/df-mc/dragonfly/server/player/chat" + "github.com/df-mc/dragonfly/server/world" "github.com/pelletier/go-toml" "github.com/sirupsen/logrus" "os" @@ -25,7 +29,11 @@ func main() { srv.CloseOnProgramEnd() srv.Listen() - for srv.Accept(nil) { + for srv.Accept(func(p *player.Player) { + p.SetGameMode(world.GameModeSurvival) + p.Inventory().AddItem(item.NewStack(block.CraftingTable{}, 64)) + p.Inventory().AddItem(item.NewStack(block.Planks{}, 64)) + }) { } } diff --git a/server/internal/blockinternal/builder.go b/server/internal/blockinternal/builder.go index e320ab585..233c660c2 100644 --- a/server/internal/blockinternal/builder.go +++ b/server/internal/blockinternal/builder.go @@ -11,6 +11,7 @@ type ComponentBuilder struct { permutations map[string]map[string]any properties []map[string]any components map[string]any + blockID int32 identifier string menuCategory category.Category @@ -18,13 +19,14 @@ type ComponentBuilder struct { // NewComponentBuilder returns a new component builder with the provided block data, using the provided components map // as a base. -func NewComponentBuilder(identifier string, components map[string]any) *ComponentBuilder { +func NewComponentBuilder(identifier string, components map[string]any, blockID int32) *ComponentBuilder { if components == nil { components = map[string]any{} } return &ComponentBuilder{ permutations: make(map[string]map[string]any), components: components, + blockID: blockID, identifier: identifier, menuCategory: category.Construction(), @@ -79,6 +81,9 @@ func (builder *ComponentBuilder) Construct() map[string]any { "category": builder.menuCategory.String(), "group": builder.menuCategory.Group(), }, + "vanilla_block_data": map[string]any{ + "block_id": builder.blockID, + }, } if len(properties) > 0 { result["properties"] = properties diff --git a/server/internal/blockinternal/components.go b/server/internal/blockinternal/components.go index affec240e..c4ee35ccc 100644 --- a/server/internal/blockinternal/components.go +++ b/server/internal/blockinternal/components.go @@ -9,9 +9,9 @@ import ( ) // Components returns all the components for the custom block, including permutations and properties. -func Components(identifier string, b world.CustomBlock) map[string]any { +func Components(identifier string, b world.CustomBlock, blockID int32) map[string]any { components := componentsFromProperties(b.Properties()) - builder := NewComponentBuilder(identifier, components) + builder := NewComponentBuilder(identifier, components, blockID) if emitter, ok := b.(block.LightEmitter); ok { builder.AddComponent("minecraft:block_light_emission", map[string]any{ "emission": float32(emitter.LightEmissionLevel() / 15), diff --git a/server/internal/iteminternal/builder.go b/server/internal/iteminternal/builder.go index 7ae9a5719..bdc2e24e0 100644 --- a/server/internal/iteminternal/builder.go +++ b/server/internal/iteminternal/builder.go @@ -52,7 +52,9 @@ func (builder *ComponentBuilder) Construct() map[string]any { // not modify the builder's properties map directly otherwise Empty() will return false in future use of the builder. func (builder *ComponentBuilder) applyDefaultProperties(x map[string]any) { x["minecraft:icon"] = map[string]any{ - "texture": strings.Split(builder.identifier, ":")[1], + "textures": map[string]any{ + "default": strings.Split(builder.identifier, ":")[1], + }, } x["creative_group"] = builder.category.Group() x["creative_category"] = int32(builder.category.Uint8()) diff --git a/server/server.go b/server/server.go index e8bae1f35..8508305e8 100644 --- a/server/server.go +++ b/server/server.go @@ -297,7 +297,7 @@ func (srv *Server) makeBlockEntries() { name, _ := b.EncodeBlock() srv.customBlocks[i] = protocol.BlockEntry{ Name: name, - Properties: blockinternal.Components(name, b), + Properties: blockinternal.Components(name, b, 10000+int32(i)), } } } diff --git a/server/world/block_states.nbt b/server/world/block_states.nbt index 7867d4964..274cc2a2c 100644 Binary files a/server/world/block_states.nbt and b/server/world/block_states.nbt differ