Skip to content

Commit

Permalink
Merge branch 'master' into fix/block-lag
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.sum
  • Loading branch information
Flonja committed Sep 26, 2023
2 parents 9f777b0 + 2868284 commit e2bfaed
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 49 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module github.com/df-mc/dragonfly

go 1.18
go 1.19

require (
github.com/brentp/intintmap v0.0.0-20190211203843-30dc0ade9af9
github.com/cespare/xxhash v1.1.0
github.com/df-mc/atomic v1.10.0
github.com/df-mc/goleveldb v1.1.9
github.com/df-mc/worldupgrader v1.0.8
github.com/df-mc/worldupgrader v1.0.9
github.com/go-gl/mathgl v1.0.0
github.com/google/uuid v1.3.0
github.com/pelletier/go-toml v1.9.5
github.com/rogpeppe/go-internal v1.9.0
github.com/sandertv/gophertunnel v1.31.1-0.20230822231139-d4949d32a3ad
github.com/sandertv/gophertunnel v1.32.2
github.com/sirupsen/logrus v1.9.0
go.uber.org/atomic v1.10.0
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 @@ -11,8 +11,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.8 h1:T9p7d6o9Yx65qsnK20VYXUNOl9ZY9/5D/fbJBXKsi3o=
github.com/df-mc/worldupgrader v1.0.8/go.mod h1:tsSOLTRm9mpG7VHvYpAjjZrkRHWmSbKZAm9bOLNnlDk=
github.com/df-mc/worldupgrader v1.0.9 h1:hJxbovEEzhTg/TPZqpwg8BsVTVeoVgDp6q7dMoBlwmA=
github.com/df-mc/worldupgrader v1.0.9/go.mod h1:tsSOLTRm9mpG7VHvYpAjjZrkRHWmSbKZAm9bOLNnlDk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-gl/mathgl v1.0.0 h1:t9DznWJlXxxjeeKLIdovCOVJQk/GzDEL7h/h+Ro2B68=
github.com/go-gl/mathgl v1.0.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
Expand Down Expand Up @@ -48,8 +48,8 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
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.31.1-0.20230822231139-d4949d32a3ad h1:6RuPYCE0y+6nUe9h4AYJ1tVAcUwg9VFKdssqszxcCsA=
github.com/sandertv/gophertunnel v1.31.1-0.20230822231139-d4949d32a3ad/go.mod h1:ekREo7U9TPHh86kbuPMaWA93NMyWsfVvP/iNT3XhAb8=
github.com/sandertv/gophertunnel v1.32.2 h1:vlm6TonrgdESjcgY8Ixt4mHT4/bdih+NrnsqlBhaUok=
github.com/sandertv/gophertunnel v1.32.2/go.mod h1:+Dbhj3bs74gZoSkyab7kglx1Rbq8S5G7sJd/wr5Qm9g=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
Expand Down
4 changes: 2 additions & 2 deletions server/block/anvil.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (a Anvil) EncodeItem() (name string, meta int16) {
// EncodeBlock ...
func (a Anvil) EncodeBlock() (string, map[string]any) {
return "minecraft:anvil", map[string]any{
"damage": a.Type.String(),
"direction": int32(horizontalDirection(a.Facing)),
"damage": a.Type.String(),
"minecraft:cardinal_direction": a.Facing.String(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions server/block/blast_furnace.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func (b BlastFurnace) EncodeItem() (name string, meta int16) {
// EncodeBlock ...
func (b BlastFurnace) EncodeBlock() (name string, properties map[string]interface{}) {
if b.Lit {
return "minecraft:lit_blast_furnace", map[string]interface{}{"facing_direction": int32(b.Facing)}
return "minecraft:lit_blast_furnace", map[string]interface{}{"minecraft:cardinal_direction": b.Facing.String()}
}
return "minecraft:blast_furnace", map[string]interface{}{"facing_direction": int32(b.Facing)}
return "minecraft:blast_furnace", map[string]interface{}{"minecraft:cardinal_direction": b.Facing.String()}
}

// UseOnBlock ...
Expand Down Expand Up @@ -122,7 +122,7 @@ func (b BlastFurnace) DecodeNBT(data map[string]interface{}) interface{} {

// allBlastFurnaces ...
func allBlastFurnaces() (furnaces []world.Block) {
for _, face := range cube.Faces() {
for _, face := range cube.HorizontalFaces() {
furnaces = append(furnaces, BlastFurnace{Facing: face})
furnaces = append(furnaces, BlastFurnace{Facing: face, Lit: true})
}
Expand Down
4 changes: 2 additions & 2 deletions server/block/concrete_powder.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func (c ConcretePowder) BreakInfo() BreakInfo {

// EncodeItem ...
func (c ConcretePowder) EncodeItem() (name string, meta int16) {
return "minecraft:concrete_powder", int16(c.Colour.Uint8())
return "minecraft:" + c.Colour.String() + "_concrete_powder", 0
}

// EncodeBlock ...
func (c ConcretePowder) EncodeBlock() (name string, properties map[string]any) {
return "minecraft:concrete_powder", map[string]any{"color": c.Colour.SilverString()}
return "minecraft:" + c.Colour.String() + "_concrete_powder", nil
}

// allConcretePowder returns concrete powder with all possible colours.
Expand Down
26 changes: 16 additions & 10 deletions server/block/decorated_pot.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func (p DecoratedPot) BreakInfo() BreakInfo {
return newBreakInfo(0, alwaysHarvestable, nothingEffective, oneOf(p))
}

// MaxCount ...
func (DecoratedPot) MaxCount() int {
return 1
}

// EncodeItem ...
func (p DecoratedPot) EncodeItem() (name string, meta int16) {
return "minecraft:decorated_pot", 0
Expand Down Expand Up @@ -76,18 +81,19 @@ func (p DecoratedPot) EncodeNBT() map[string]any {

// DecodeNBT ...
func (p DecoratedPot) DecodeNBT(data map[string]any) any {
sherds := data["sherds"].([]any)
p.Decorations = [4]PotDecoration{}
for i, name := range sherds {
it, ok := world.ItemByName(name.(string), 0)
if !ok {
panic(fmt.Errorf("unknown item %s", name))
}
decoration, ok := it.(PotDecoration)
if !ok {
panic(fmt.Errorf("item %s is not a pot decoration", name))
if sherds, ok := data["sherds"]; ok {
for i, name := range sherds.([]any) {
it, ok := world.ItemByName(name.(string), 0)
if !ok {
panic(fmt.Errorf("unknown item %s", name))
}
decoration, ok := it.(PotDecoration)
if !ok {
panic(fmt.Errorf("item %s is not a pot decoration", name))
}
p.Decorations[i] = decoration
}
p.Decorations[i] = decoration
}
return p
}
Expand Down
6 changes: 3 additions & 3 deletions server/block/furnace.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func (f Furnace) EncodeItem() (name string, meta int16) {
// EncodeBlock ...
func (f Furnace) EncodeBlock() (name string, properties map[string]interface{}) {
if f.Lit {
return "minecraft:lit_furnace", map[string]interface{}{"facing_direction": int32(f.Facing)}
return "minecraft:lit_furnace", map[string]interface{}{"minecraft:cardinal_direction": f.Facing.String()}
}
return "minecraft:furnace", map[string]interface{}{"facing_direction": int32(f.Facing)}
return "minecraft:furnace", map[string]interface{}{"minecraft:cardinal_direction": f.Facing.String()}
}

// UseOnBlock ...
Expand Down Expand Up @@ -121,7 +121,7 @@ func (f Furnace) DecodeNBT(data map[string]interface{}) interface{} {

// allFurnaces ...
func allFurnaces() (furnaces []world.Block) {
for _, face := range cube.Faces() {
for _, face := range cube.HorizontalFaces() {
furnaces = append(furnaces, Furnace{Facing: face})
furnaces = append(furnaces, Furnace{Facing: face, Lit: true})
}
Expand Down
12 changes: 6 additions & 6 deletions server/block/lectern.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Lectern struct {
sourceWaterDisplacer

// Facing represents the direction the Lectern is facing.
Facing cube.Direction
Facing cube.Face
// Book is the book currently held by the Lectern.
Book item.Stack
// Page is the page the Lectern is currently on in the book.
Expand Down Expand Up @@ -57,7 +57,7 @@ func (l Lectern) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world
if !used {
return false
}
l.Facing = user.Rotation().Direction().Opposite()
l.Facing = user.Rotation().Direction().Face().Opposite()
place(w, pos, l, user, ctx)
return placed(ctx)
}
Expand Down Expand Up @@ -152,15 +152,15 @@ func (Lectern) EncodeItem() (name string, meta int16) {
// EncodeBlock ...
func (l Lectern) EncodeBlock() (string, map[string]any) {
return "minecraft:lectern", map[string]any{
"direction": int32(horizontalDirection(l.Facing)),
"powered_bit": uint8(0), // We don't support redstone, anyway.
"minecraft:cardinal_direction": l.Facing.String(),
"powered_bit": uint8(0), // We don't support redstone, anyway.
}
}

// allLecterns ...
func allLecterns() (lecterns []world.Block) {
for _, d := range cube.Directions() {
lecterns = append(lecterns, Lectern{Facing: d})
for _, f := range cube.HorizontalFaces() {
lecterns = append(lecterns, Lectern{Facing: f})
}
return
}
9 changes: 8 additions & 1 deletion server/block/slab.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (s Slab) EncodeItem() (string, int16) {
// EncodeBlock ...
func (s Slab) EncodeBlock() (string, map[string]any) {
id, slabType, _ := encodeSlabBlock(s.Block)
properties := map[string]any{"top_slot_bit": s.Top}
properties := map[string]any{"minecraft:vertical_half": s.verticalHalf()}
if slabType != "" {
properties[slabType] = id
id = encodeLegacySlabId(slabType)
Expand All @@ -176,6 +176,13 @@ func (s Slab) EncodeBlock() (string, map[string]any) {
return "minecraft:" + id, properties
}

func (s Slab) verticalHalf() string {
if s.Top {
return "top"
}
return "bottom"
}

// allSlabs ...
func allSlabs() (b []world.Block) {
for _, s := range SlabBlocks() {
Expand Down
6 changes: 3 additions & 3 deletions server/block/smoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func (s Smoker) EncodeItem() (name string, meta int16) {
// EncodeBlock ...
func (s Smoker) EncodeBlock() (name string, properties map[string]interface{}) {
if s.Lit {
return "minecraft:lit_smoker", map[string]interface{}{"facing_direction": int32(s.Facing)}
return "minecraft:lit_smoker", map[string]interface{}{"minecraft:cardinal_direction": s.Facing.String()}
}
return "minecraft:smoker", map[string]interface{}{"facing_direction": int32(s.Facing)}
return "minecraft:smoker", map[string]interface{}{"minecraft:cardinal_direction": s.Facing.String()}
}

// UseOnBlock ...
Expand Down Expand Up @@ -122,7 +122,7 @@ func (s Smoker) DecodeNBT(data map[string]interface{}) interface{} {

// allSmokers ...
func allSmokers() (smokers []world.Block) {
for _, face := range cube.Faces() {
for _, face := range cube.HorizontalFaces() {
smokers = append(smokers, Smoker{Facing: face})
smokers = append(smokers, Smoker{Facing: face, Lit: true})
}
Expand Down
4 changes: 2 additions & 2 deletions server/block/stained_glass.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func (g StainedGlass) BreakInfo() BreakInfo {

// EncodeItem ...
func (g StainedGlass) EncodeItem() (name string, meta int16) {
return "minecraft:stained_glass", int16(g.Colour.Uint8())
return "minecraft:" + g.Colour.String() + "_stained_glass", 0
}

// EncodeBlock ...
func (g StainedGlass) EncodeBlock() (name string, properties map[string]any) {
return "minecraft:stained_glass", map[string]any{"color": g.Colour.SilverString()}
return "minecraft:" + g.Colour.String() + "_stained_glass", nil
}

// allStainedGlass returns stained-glass blocks with all possible colours.
Expand Down
4 changes: 2 additions & 2 deletions server/block/stained_glass_pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func (p StainedGlassPane) BreakInfo() BreakInfo {

// EncodeItem ...
func (p StainedGlassPane) EncodeItem() (name string, meta int16) {
return "minecraft:stained_glass_pane", int16(p.Colour.Uint8())
return "minecraft:" + p.Colour.String() + "_stained_glass_pane", 0
}

// EncodeBlock ...
func (p StainedGlassPane) EncodeBlock() (name string, properties map[string]any) {
return "minecraft:stained_glass_pane", map[string]any{"color": p.Colour.SilverString()}
return "minecraft:" + p.Colour.String() + "_stained_glass_pane", nil
}

// allStainedGlassPane returns stained-glass panes with all possible colours.
Expand Down
4 changes: 2 additions & 2 deletions server/block/stained_terracotta.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func (t StainedTerracotta) SmeltInfo() item.SmeltInfo {

// EncodeItem ...
func (t StainedTerracotta) EncodeItem() (name string, meta int16) {
return "minecraft:stained_hardened_clay", int16(t.Colour.Uint8())
return "minecraft:" + t.Colour.String() + "_terracotta", 0
}

// EncodeBlock ...
func (t StainedTerracotta) EncodeBlock() (name string, properties map[string]any) {
return "minecraft:stained_hardened_clay", map[string]any{"color": t.Colour.SilverString()}
return "minecraft:" + t.Colour.String() + "_terracotta", nil
}

// allStainedTerracotta returns stained terracotta blocks with all possible colours.
Expand Down
2 changes: 1 addition & 1 deletion server/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func loadResources(dir string) ([]*resource.Pack, error) {
}
packs := make([]*resource.Pack, len(resources))
for i, entry := range resources {
packs[i], err = resource.Compile(filepath.Join(dir, entry.Name()))
packs[i], err = resource.ReadPath(filepath.Join(dir, entry.Name()))
if err != nil {
return nil, fmt.Errorf("compile resource (%v): %w", entry.Name(), err)
}
Expand Down
2 changes: 1 addition & 1 deletion server/internal/packbuilder/resource_pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func BuildResourcePack() (*resource.Pack, bool) {
copy(header[:], hash)
copy(module[:], hash[16:])
buildManifest(dir, header, module)
return resource.MustCompile(dir), true
return resource.MustReadPath(dir), true
}
return nil, false
}
Binary file modified server/item/creative/creative_items.nbt
Binary file not shown.
Binary file modified server/item/recipe/crafting_data.nbt
Binary file not shown.
15 changes: 11 additions & 4 deletions server/item/recipe/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,27 @@ type inputItems []struct {
Meta int32 `nbt:"meta"`
// Count is the amount of the item.
Count int32 `nbt:"count"`
// State is included if the output is a block. If it's not included, the meta can be discarded and the output item can be incorrect.
State struct {
Name string `nbt:"name"`
Properties map[string]interface{} `nbt:"states"`
Version int32 `nbt:"version"`
} `nbt:"block"`
}

// Stacks converts input items to item stacks.
func (d inputItems) Stacks() ([]item.Stack, bool) {
s := make([]item.Stack, 0, len(d))
for _, i := range d {
if len(i.Name) == 0 {
s = append(s, item.Stack{})
continue
}
it, ok := world.ItemByName(i.Name, int16(i.Meta))
if !ok {
return nil, false
}
if b, ok := world.BlockByName(i.State.Name, i.State.Properties); ok {
if it, ok = b.(world.Item); !ok {
return nil, false
}
}
st := item.NewStack(it, int(i.Count))
if i.Meta == math.MaxInt16 {
st = st.WithValue("variants", true)
Expand Down
Binary file modified server/item/recipe/smithing_data.nbt
Binary file not shown.
Binary file modified server/world/block_states.nbt
Binary file not shown.
Binary file modified server/world/item_runtime_ids.nbt
Binary file not shown.
4 changes: 4 additions & 0 deletions server/world/mcdb/leveldat/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ type Data struct {
PermissionsLevel int32 `nbt:"permissionsLevel"`
PlayerPermissionsLevel int32 `nbt:"playerPermissionsLevel"`
IsRandomSeedAllowed bool `nbt:"isRandomSeedAllowed"`
DoLimitedCrafting bool `nbt:"dolimitedcrafting"`
EditorWorldType int32 `nbt:"editorWorldType"`
PlayersSleepingPercentage int32 `nbt:"playerssleepingpercentage"`
RecipesUnlock bool `nbt:"recipesunlock"`
}

// FillDefault fills out d with all the default level.dat values.
Expand Down

0 comments on commit e2bfaed

Please sign in to comment.