Skip to content

Commit

Permalink
Merge upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jul 12, 2024
2 parents 3b53f07 + 56780ca commit 5630455
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion server/block/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (b Banner) EncodeNBT() map[string]any {
func (b Banner) DecodeNBT(m map[string]any) any {
b.Colour = invertColourID(int16(nbtconv.Int32(m, "Base")))
b.Illager = nbtconv.Int32(m, "Type") == 1
if patterns := nbtconv.Slice[any](m, "Patterns"); patterns != nil {
if patterns := nbtconv.Slice(m, "Patterns"); patterns != nil {
b.Patterns = make([]BannerPatternLayer, len(patterns))
for i, p := range b.Patterns {
b.Patterns[i] = p.DecodeNBT(patterns[i].(map[string]any)).(BannerPatternLayer)
Expand Down
2 changes: 1 addition & 1 deletion server/block/barrel.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (b Barrel) DecodeNBT(data map[string]any) any {
b = NewBarrel()
b.Facing = facing
b.CustomName = nbtconv.String(data, "CustomName")
nbtconv.InvFromNBT(b.inventory, nbtconv.Slice[any](data, "Items"))
nbtconv.InvFromNBT(b.inventory, nbtconv.Slice(data, "Items"))
return b
}

Expand Down
2 changes: 1 addition & 1 deletion server/block/blast_furnace.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (b BlastFurnace) DecodeNBT(data map[string]interface{}) interface{} {
b.Lit = lit
b.setExperience(xp)
b.setDurations(remaining, maximum, cook)
nbtconv.InvFromNBT(b.Inventory(), nbtconv.Slice[any](data, "Items"))
nbtconv.InvFromNBT(b.Inventory(), nbtconv.Slice(data, "Items"))
return b
}

Expand Down
2 changes: 1 addition & 1 deletion server/block/chest.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c Chest) DecodeNBT(data map[string]any) any {
c = NewChest()
c.Facing = facing
c.CustomName = nbtconv.String(data, "CustomName")
nbtconv.InvFromNBT(c.inventory, nbtconv.Slice[any](data, "Items"))
nbtconv.InvFromNBT(c.inventory, nbtconv.Slice(data, "Items"))
return c
}

Expand Down
6 changes: 3 additions & 3 deletions server/block/decorated_pot.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (p DecoratedPot) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *

// EncodeNBT ...
func (p DecoratedPot) EncodeNBT() map[string]any {
var sherds []string
var sherds []any
for _, decoration := range p.Decorations {
if decoration == nil {
sherds = append(sherds, "minecraft:brick")
Expand All @@ -83,9 +83,9 @@ func (p DecoratedPot) EncodeNBT() map[string]any {
// DecodeNBT ...
func (p DecoratedPot) DecodeNBT(data map[string]any) any {
p.Decorations = [4]PotDecoration{}
if sherds := nbtconv.Slice[string](data, "sherds"); sherds != nil {
if sherds := nbtconv.Slice(data, "sherds"); sherds != nil {
for i, name := range sherds {
it, ok := world.ItemByName(name, 0)
it, ok := world.ItemByName(name.(string), 0)
if !ok {
panic(fmt.Errorf("unknown item %s", name))
}
Expand Down
2 changes: 1 addition & 1 deletion server/block/furnace.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (f Furnace) DecodeNBT(data map[string]interface{}) interface{} {
f.Lit = lit
f.setExperience(xp)
f.setDurations(remaining, maximum, cook)
nbtconv.InvFromNBT(f.Inventory(), nbtconv.Slice[any](data, "Items"))
nbtconv.InvFromNBT(f.Inventory(), nbtconv.Slice(data, "Items"))
return f
}

Expand Down
4 changes: 2 additions & 2 deletions server/block/skull.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s Skull) EncodeItem() (name string, meta int16) {
// DecodeNBT ...
func (s Skull) DecodeNBT(data map[string]interface{}) interface{} {
s.Type = SkullType{skull(nbtconv.Uint8(data, "SkullType"))}
s.Attach.o = cube.Orientation(nbtconv.Uint8(data, "Rot"))
s.Attach.o = cube.OrientationFromYaw(float64(nbtconv.Float32(data, "Rotation")))
if s.Attach.facing >= 0 {
s.Attach.hanging = true
}
Expand All @@ -98,7 +98,7 @@ func (s Skull) DecodeNBT(data map[string]interface{}) interface{} {

// EncodeNBT ...
func (s Skull) EncodeNBT() map[string]interface{} {
return map[string]interface{}{"id": "Skull", "SkullType": s.Type.Uint8(), "Rot": byte(s.Attach.o)}
return map[string]interface{}{"id": "Skull", "SkullType": s.Type.Uint8(), "Rotation": float32(s.Attach.o.Yaw())}
}

// EncodeBlock ...
Expand Down
2 changes: 1 addition & 1 deletion server/block/smoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s Smoker) DecodeNBT(data map[string]interface{}) interface{} {
s.Lit = lit
s.setExperience(xp)
s.setDurations(remaining, maximum, cook)
nbtconv.InvFromNBT(s.Inventory(), nbtconv.Slice[any](data, "Items"))
nbtconv.InvFromNBT(s.Inventory(), nbtconv.Slice(data, "Items"))
return s
}

Expand Down
8 changes: 4 additions & 4 deletions server/internal/nbtconv/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func Float64(m map[string]any, k string) float64 {
return v
}

// Slice reads a []T value from a map at key k.
func Slice[T any](m map[string]any, k string) []T {
v, _ := m[k].([]T)
// Slice reads a []any value from a map at key k.
func Slice(m map[string]any, k string) []any {
v, _ := m[k].([]any)
return v
}

Expand Down Expand Up @@ -242,7 +242,7 @@ func readArmourTrim(m map[string]any, s *item.Stack) {
func readEnchantments(m map[string]any, s *item.Stack) {
enchantments, ok := m["ench"].([]map[string]any)
if !ok {
for _, e := range Slice[any](m, "ench") {
for _, e := range Slice(m, "ench") {
if v, ok := e.(map[string]any); ok {
enchantments = append(enchantments, v)
}
Expand Down
2 changes: 1 addition & 1 deletion server/item/creative/creative.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func init() {
st := item.NewStack(it, 1)
if len(data.NBT) > 0 {
var invalid bool
for _, e := range nbtconv.Slice[any](data.NBT, "ench") {
for _, e := range nbtconv.Slice(data.NBT, "ench") {
if v, ok := e.(map[string]any); ok {
t, ok := item.EnchantmentByID(int(nbtconv.Int16(v, "id")))
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions server/player/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type Handler interface {
HandlePunchAir(ctx *event.Context)
// HandleSignEdit handles the player editing a sign. It is called for every keystroke while editing a sign and
// has both the old text passed and the text after the edit. This typically only has a change of one character.
HandleSignEdit(ctx *event.Context, frontSide bool, oldText, newText string)
HandleSignEdit(ctx *event.Context, pos cube.Pos, frontSide bool, oldText, newText string)
// HandleLecternPageTurn handles the player turning a page in a lectern. ctx.Cancel() may be called to cancel the
// page turn. The page number may be changed by assigning to *page.
HandleLecternPageTurn(ctx *event.Context, pos cube.Pos, oldPage int, newPage *int)
Expand Down Expand Up @@ -156,7 +156,7 @@ func (NopHandler) HandleStartBreak(*event.Context, cube.Pos)
func (NopHandler) HandleBlockBreak(*event.Context, cube.Pos, *[]item.Stack, *int) {}
func (NopHandler) HandleBlockPlace(*event.Context, cube.Pos, world.Block) {}
func (NopHandler) HandleBlockPick(*event.Context, cube.Pos, world.Block) {}
func (NopHandler) HandleSignEdit(*event.Context, bool, string, string) {}
func (NopHandler) HandleSignEdit(*event.Context, cube.Pos, bool, string, string) {}
func (NopHandler) HandleLecternPageTurn(*event.Context, cube.Pos, int, *int) {}
func (NopHandler) HandleItemPickup(*event.Context, *item.Stack) {}
func (NopHandler) HandleItemUse(*event.Context) {}
Expand Down
4 changes: 2 additions & 2 deletions server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -2642,14 +2642,14 @@ func (p *Player) EditSign(pos cube.Pos, frontText, backText string) error {

ctx := event.C()
if frontText != sign.Front.Text {
if p.Handler().HandleSignEdit(ctx, true, sign.Front.Text, frontText); ctx.Cancelled() {
if p.Handler().HandleSignEdit(ctx, pos, true, sign.Front.Text, frontText); ctx.Cancelled() {
p.resendBlock(pos, w)
return nil
}
sign.Front.Text = frontText
sign.Front.Owner = p.XUID()
} else {
if p.Handler().HandleSignEdit(ctx, false, sign.Back.Text, backText); ctx.Cancelled() {
if p.Handler().HandleSignEdit(ctx, pos, false, sign.Back.Text, backText); ctx.Cancelled() {
p.resendBlock(pos, w)
return nil
}
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.

15 changes: 14 additions & 1 deletion server/world/block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/df-mc/dragonfly/server/world/chunk"
"github.com/sandertv/gophertunnel/minecraft/nbt"
"github.com/segmentio/fasthash/fnv1"
"maps"
"math"
"slices"
"sort"
Expand Down Expand Up @@ -82,7 +83,7 @@ func registerBlockState(s blockState, order bool) {
blockProperties[s.Name] = s.Properties
}
rid := uint32(len(blocks))
blocks = append(blocks, unknownBlock{s})
blocks = append(blocks, unknownBlock{blockState: s})
if order {
sort.SliceStable(blocks, func(i, j int) bool {
nameOne, _ := blocks[i].EncodeBlock()
Expand Down Expand Up @@ -121,6 +122,7 @@ func registerBlockState(s blockState, order bool) {
// states that haven't yet been added.
type unknownBlock struct {
blockState
data map[string]any
}

// EncodeBlock ...
Expand All @@ -138,6 +140,17 @@ func (b unknownBlock) Hash() uint64 {
return math.MaxUint64
}

// EncodeNBT ...
func (b unknownBlock) EncodeNBT() map[string]any {
return b.data
}

// DecodeNBT ...
func (b unknownBlock) DecodeNBT(data map[string]any) any {
b.data = maps.Clone(data)
return b
}

// blockState holds a combination of a name and properties, together with a version.
type blockState struct {
Name string `nbt:"name"`
Expand Down
15 changes: 9 additions & 6 deletions server/world/chunk/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ func anyLightBlocks(sub *SubChunk) bool {
// chunk. In addition, any skylight above those nodes will be set to 15.
func (a *lightArea) insertSkyLightNodes(queue *list.List) {
a.iterHeightmap(func(x, z int, height, highestNeighbour, highestY, lowestY int) {
// If we hit a block like water or leaves (something that diffuses but does not block light), we
// need a node above this block regardless of the neighbours.
pos := cube.Pos{x, height, z}
a.setLight(pos, SkyLight, 15)
if height <= a.r.Max() {
// Only set light if we're not at the top of the world.
a.setLight(pos, SkyLight, 15)

if pos[1] > lowestY {
if level := a.highest(pos.Sub(cube.Pos{0, 1}), FilteringBlocks); level != 15 && level != 0 {
queue.PushBack(node(pos, 15, SkyLight))
if pos[1] > lowestY {
if level := a.highest(pos.Sub(cube.Pos{0, 1}), FilteringBlocks); level != 15 && level != 0 {
// If we hit a block like water or leaves (something that diffuses but does not block light), we
// need a node above this block regardless of the neighbours.
queue.PushBack(node(pos, 15, SkyLight))
}
}
}
for y := pos[1]; y < highestY; y++ {
Expand Down

0 comments on commit 5630455

Please sign in to comment.