Skip to content

Commit

Permalink
Merge branch 'df-mc:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
RestartFU authored Feb 7, 2024
2 parents befff18 + f25a0df commit 8c666ac
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 13 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
}) {
}
}

Expand Down
7 changes: 6 additions & 1 deletion server/internal/blockinternal/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ type ComponentBuilder struct {
permutations map[string]map[string]any
properties []map[string]any
components map[string]any
blockID int32

identifier string
menuCategory category.Category
}

// 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(),
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/internal/blockinternal/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion server/internal/iteminternal/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/session/enchantment_texts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified server/world/block_states.nbt
Binary file not shown.

0 comments on commit 8c666ac

Please sign in to comment.