Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/blockhash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ func (b *hashBuilder) ftype(structName, s string, expr ast.Expr, directives map[
return "uint64(" + s + ".Uint8())", 5
case "GrindstoneAttachment":
return "uint64(" + s + ".Uint8())", 2
case "Connections":
return "uint64(" + s + ".Uint8())", 4
case "WoodType", "LeavesType", "FlowerType", "DoubleFlowerType", "Colour":
// Assuming these were all based on metadata, it should be safe to assume a bit size of 4 for this.
return "uint64(" + s + ".Uint8())", 4
case "CoralType", "SkullType":
case "CoralType", "SkullType", "StairsCorner":
return "uint64(" + s + ".Uint8())", 3
case "AnvilType", "SandstoneType", "PrismarineType", "StoneBricksType", "NetherBricksType", "FroglightType",
"WallConnectionType", "BlackstoneType", "DeepslateType", "TallGrassType", "CopperType", "OxidationType":
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ go 1.26.0
require (
github.com/brentp/intintmap v0.0.0-20251106190759-56907b1f8479
github.com/cespare/xxhash/v2 v2.3.0
github.com/df-mc/go-nethernet v1.0.20
github.com/df-mc/go-nethernet v1.0.20-0.20260819165039-03e28450b31f
github.com/df-mc/goleveldb v1.1.9
github.com/df-mc/worldupgrader v1.0.21
github.com/go-gl/mathgl v1.2.0
github.com/google/uuid v1.6.0
github.com/pelletier/go-toml v1.9.5
github.com/sandertv/gophertunnel v1.59.0
github.com/sandertv/gophertunnel v1.59.1-0.20260819162346-27901ba2e835
github.com/segmentio/fasthash v1.0.3
golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329
golang.org/x/mod v0.32.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/coreos/go-oidc/v3 v3.17.0 h1:hWBGaQfbi0iVviX4ibC7bk8OKT5qNr4klBaCHVNv
github.com/coreos/go-oidc/v3 v3.17.0/go.mod h1:wqPbKFrVnE90vty060SB40FCJ8fTHTxSwyXJqZH+sI8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/df-mc/go-nethernet v1.0.20-0.20260819165039-03e28450b31f h1:gA9heSifQCNz7aSfodEX6CJEsCIVDlqZqgqz5FT0QyY=
github.com/df-mc/go-nethernet v1.0.20-0.20260819165039-03e28450b31f/go.mod h1:11MfQo5F7PDKfHg1H0zM5mMkrCv29jRE0lK5B4egW9w=
github.com/df-mc/go-nethernet v1.0.20 h1:H0MO0GkVlAypu9IDQhzg5Pph3mCD7r40+ExiImsXT2M=
github.com/df-mc/go-nethernet v1.0.20/go.mod h1:11MfQo5F7PDKfHg1H0zM5mMkrCv29jRE0lK5B4egW9w=
github.com/df-mc/go-playfab/v2 v2.0.2 h1:JqOsrpe0nt6Ni4V2JrdmOAhbBgTm7LBw1ppGXlmknhs=
Expand Down Expand Up @@ -88,8 +90,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sandertv/go-raknet v1.15.2-0.20260705184311-0d1fd09e2cf6 h1:Oj7QsiwWTOLmCpOjjmW0Qwde4BE8F5+Kjz817qzICyk=
github.com/sandertv/go-raknet v1.15.2-0.20260705184311-0d1fd09e2cf6/go.mod h1:/yysjwfCXm2+2OY8mBazLzcxJ3irnylKCyG3FLgUPVU=
github.com/sandertv/gophertunnel v1.59.0 h1:hIjmLycavwSjrqRlKFDMiV8LrP64tgzjgEUqWOOxvuQ=
github.com/sandertv/gophertunnel v1.59.0/go.mod h1:JMKsf8DmVmn+qEVJ1IA9m7zEo9qHJ3ZN6IEvySEk9bs=
github.com/sandertv/gophertunnel v1.59.1-0.20260819162346-27901ba2e835 h1:lF1kkxzIGnMAn/vNN8NXNlBsk7mgyc+RQIxLRgp9lUY=
github.com/sandertv/gophertunnel v1.59.1-0.20260819162346-27901ba2e835/go.mod h1:LZsch9elPoPzsJGDbx7ClWEHFjgHZ/lONvXF7m16Qn8=
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/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
Expand Down
50 changes: 50 additions & 0 deletions server/block/connections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package block

import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/world"
)

// Connections holds the sides that a block such as a fence connects to.
type Connections struct {
north, east, south, west bool
}

// Uint8 returns the Connections as a uint8.
func (c Connections) Uint8() uint8 {
return boolByte(c.north) | boolByte(c.east)<<1 | boolByte(c.south)<<2 | boolByte(c.west)<<3
}

// properties returns the block state properties of the Connections.
func (c Connections) properties() map[string]any {
return map[string]any{
"minecraft:connection_north": c.north,
"minecraft:connection_east": c.east,
"minecraft:connection_south": c.south,
"minecraft:connection_west": c.west,
}
}

// connector is a block or block model that reports the sides it connects to.
type connector interface {
// Connects returns true if the block connects to the block at the face passed.
Connects(pos cube.Pos, face cube.Face, src world.BlockSource) bool
}

// calculateConnections returns the Connections of the connector at a position.
func calculateConnections(c connector, tx *world.Tx, pos cube.Pos) Connections {
return Connections{
north: c.Connects(pos, cube.FaceNorth, tx),
east: c.Connects(pos, cube.FaceEast, tx),
south: c.Connects(pos, cube.FaceSouth, tx),
west: c.Connects(pos, cube.FaceWest, tx),
}
}

// allConnections returns a list of all combinations of Connections.
func allConnections() (all []Connections) {
for i := range 16 {
all = append(all, Connections{north: i&0x1 != 0, east: i&0x2 != 0, south: i&0x4 != 0, west: i&0x8 != 0})
}
return
}
16 changes: 14 additions & 2 deletions server/block/copper_bars.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ type CopperBars struct {
Oxidation OxidationType
// Waxed bool is whether the copper bars has been waxed with honeycomb.
Waxed bool
// Connections holds the sides that the copper bars connects to.
Connections Connections
}

// NeighbourUpdateTick ...
func (c CopperBars) NeighbourUpdateTick(pos, _ cube.Pos, tx *world.Tx) {
if connections := calculateConnections(c.Model().(connector), tx, pos); connections != c.Connections {
c.Connections = connections
tx.SetBlock(pos, c, nil)
}
}

// BreakInfo ...
Expand Down Expand Up @@ -80,14 +90,16 @@ func (c CopperBars) EncodeItem() (name string, meta int16) {

// EncodeBlock ...
func (c CopperBars) EncodeBlock() (name string, properties map[string]any) {
return copperBlockName("copper_bars", c.Oxidation, c.Waxed), nil
return copperBlockName("copper_bars", c.Oxidation, c.Waxed), c.Connections.properties()
}

// allCopperBars ...
func allCopperBars() (bars []world.Block) {
f := func(waxed bool) {
for _, o := range OxidationTypes() {
bars = append(bars, CopperBars{Oxidation: o, Waxed: waxed})
for _, conn := range allConnections() {
bars = append(bars, CopperBars{Oxidation: o, Waxed: waxed, Connections: conn})
}
}
}
f(true)
Expand Down
23 changes: 21 additions & 2 deletions server/block/glass_pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ type GlassPane struct {
thin
clicksAndSticks
sourceWaterDisplacer

// Connections holds the sides that the glass pane connects to.
Connections Connections
}

// NeighbourUpdateTick ...
func (p GlassPane) NeighbourUpdateTick(pos, _ cube.Pos, tx *world.Tx) {
if connections := calculateConnections(p.Model().(connector), tx, pos); connections != p.Connections {
p.Connections = connections
tx.SetBlock(pos, p, nil)
}
}

// SideClosed ...
Expand All @@ -29,6 +40,14 @@ func (GlassPane) EncodeItem() (name string, meta int16) {
}

// EncodeBlock ...
func (GlassPane) EncodeBlock() (string, map[string]any) {
return "minecraft:glass_pane", nil
func (p GlassPane) EncodeBlock() (string, map[string]any) {
return "minecraft:glass_pane", p.Connections.properties()
}

// allGlassPane ...
func allGlassPane() (panes []world.Block) {
for _, c := range allConnections() {
panes = append(panes, GlassPane{Connections: c})
}
return
}
22 changes: 11 additions & 11 deletions server/block/hash.go

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

23 changes: 21 additions & 2 deletions server/block/iron_bars.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ type IronBars struct {
transparent
thin
sourceWaterDisplacer

// Connections holds the sides that the iron bars connects to.
Connections Connections
}

// NeighbourUpdateTick ...
func (i IronBars) NeighbourUpdateTick(pos, _ cube.Pos, tx *world.Tx) {
if connections := calculateConnections(i.Model().(connector), tx, pos); connections != i.Connections {
i.Connections = connections
tx.SetBlock(pos, i, nil)
}
}

// BreakInfo ...
Expand All @@ -28,6 +39,14 @@ func (IronBars) EncodeItem() (name string, meta int16) {
}

// EncodeBlock ...
func (IronBars) EncodeBlock() (string, map[string]any) {
return "minecraft:iron_bars", nil
func (i IronBars) EncodeBlock() (string, map[string]any) {
return "minecraft:iron_bars", i.Connections.properties()
}

// allIronBars ...
func allIronBars() (bars []world.Block) {
for _, c := range allConnections() {
bars = append(bars, IronBars{Connections: c})
}
return
}
10 changes: 6 additions & 4 deletions server/block/model/fence.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const (
func (f Fence) BBox(pos cube.Pos, s world.BlockSource) []cube.BBox {
boxes := make([]cube.BBox, 0, 2)

connectWest, connectEast := f.checkConnection(pos, cube.FaceWest, s), f.checkConnection(pos, cube.FaceEast, s)
connectNorth, connectSouth := f.checkConnection(pos, cube.FaceNorth, s), f.checkConnection(pos, cube.FaceSouth, s)
connectWest, connectEast := f.Connects(pos, cube.FaceWest, s), f.Connects(pos, cube.FaceEast, s)
connectNorth, connectSouth := f.Connects(pos, cube.FaceNorth, s), f.Connects(pos, cube.FaceSouth, s)

// Check if we have any connections on the Z axis
if connectWest || connectEast {
Expand Down Expand Up @@ -60,8 +60,10 @@ func (f Fence) FaceSolid(_ cube.Pos, face cube.Face, _ world.BlockSource) bool {
return face == cube.FaceDown || face == cube.FaceUp
}

// checkConnection checks if the block at the given position and face has a connection to the current fence block.
func (f Fence) checkConnection(pos cube.Pos, face cube.Face, src world.BlockSource) bool {
// Connects returns true if the Fence connects to the block at the face passed.
// A Fence connects to fences of the same kind, to fence gates and to blocks
// with a solid face towards it.
func (f Fence) Connects(pos cube.Pos, face cube.Face, src world.BlockSource) bool {
sidePos := pos.Side(face)
sideBlock := src.Block(sidePos)
if fence, ok := sideBlock.Model().(Fence); ok && fence.Wood == f.Wood {
Expand Down
Loading