Skip to content

Commit

Permalink
dragonfly: Cleanup custom block code
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Nov 3, 2023
1 parent 273b125 commit 9ec048c
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 318 deletions.
8 changes: 4 additions & 4 deletions cmd/blockhash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,24 @@ func (b *hashBuilder) writeConstants(w io.Writer) (bitSize int) {
i++
}

if _, err := fmt.Fprintln(w, "\thashBase\n)"); err != nil {
if _, err := fmt.Fprintln(w, "\thashCustomBlockBase\n)"); err != nil {
log.Fatalln(err)
}

return bits.Len64(i)
}

func (b *hashBuilder) writeNextHash(w io.Writer) {
if _, err := fmt.Fprintln(w, "\n// base represents the base hash for all custom blocks."); err != nil {
if _, err := fmt.Fprintln(w, "\n// customBlockBase represents the base hash for all custom blocks."); err != nil {
log.Fatalln(err)
}
if _, err := fmt.Fprintln(w, "var base = uint64(hashBase - 1)"); err != nil {
if _, err := fmt.Fprintln(w, "var customBlockBase = uint64(hashCustomBlockBase - 1)"); err != nil {
log.Fatalln(err)
}
if _, err := fmt.Fprintln(w, "\n// NextHash returns the next free hash for custom blocks."); err != nil {
log.Fatalln(err)
}
if _, err := fmt.Fprintln(w, "func NextHash() uint64 {\n\tbase++\n\treturn base\n}"); err != nil {
if _, err := fmt.Fprintln(w, "func NextHash() uint64 {\n\tcustomBlockBase++\n\treturn customBlockBase\n}"); err != nil {
log.Fatalln(err)
}
}
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/df-mc/worldupgrader v1.0.10
github.com/go-gl/mathgl v1.0.0
github.com/google/uuid v1.3.0
github.com/kr/pretty v0.3.1
github.com/pelletier/go-toml v1.9.5
github.com/rogpeppe/go-internal v1.9.0
github.com/sandertv/gophertunnel v1.33.0
Expand All @@ -25,7 +24,6 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/muhammadmuzzammil1998/jsonc v1.0.0 // indirect
github.com/sandertv/go-raknet v1.12.0 // indirect
golang.org/x/crypto v0.5.0 // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ github.com/brentp/intintmap v0.0.0-20190211203843-30dc0ade9af9 h1:/G0ghZwrhou0Wq
github.com/brentp/intintmap v0.0.0-20190211203843-30dc0ade9af9/go.mod h1:TOk10ahXejq9wkEaym3KPRNeuR/h5Jx+s8QRWIa2oTM=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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=
Expand Down Expand Up @@ -34,10 +33,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw=
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/muhammadmuzzammil1998/jsonc v1.0.0 h1:8o5gBQn4ZA3NBA9DlTujCj2a4w0tqWrPVjDwhzkgTIs=
github.com/muhammadmuzzammil1998/jsonc v1.0.0/go.mod h1:saF2fIVw4banK0H4+/EuqfFLpRnoy5S+ECwTOCcRcSU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand All @@ -47,7 +42,6 @@ github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
Expand Down
16 changes: 1 addition & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ package main
import (
"fmt"
"github.com/df-mc/dragonfly/server"
"github.com/df-mc/dragonfly/server/block"
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/item/creative"
"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 @@ -27,19 +21,11 @@ func main() {
log.Fatalln(err)
}

for _, direction := range cube.Directions() {
world.RegisterBlock(block.Pig{Facing: direction})
}
world.RegisterItem(block.Pig{})
creative.RegisterItem(item.NewStack(block.Pig{}, 1))

srv := conf.New()
srv.CloseOnProgramEnd()

srv.Listen()
for srv.Accept(func(p *player.Player) {
p.Inventory().AddItem(item.NewStack(block.Pig{}, 64))
}) {
for srv.Accept(nil) {
}
}

Expand Down
Binary file removed php.png
Binary file not shown.
Binary file removed pig.png
Binary file not shown.
6 changes: 6 additions & 0 deletions server/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ type Frictional interface {
Friction() float64
}

// Permutable represents a custom block that can have more permutations than its default state.
type Permutable interface {
// States returns a map of all the different properties for the block. The key is the property name, and the value
// is a slice of all the possible values for that property. It is important that a block is registered in dragonfly
// for each of the possible combinations of properties and values.
States() map[string][]any
// Permutations returns a slice of all the different permutations for the block. Multiple permutations can be
// applied at once if their conditions are met.
Permutations() []customblock.Permutation
}

Expand Down
2 changes: 1 addition & 1 deletion server/block/cube/axis.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (a Axis) RotateLeft() Axis {

// RotateRight rotates an Axis from X to Z or from Z to X.
func (a Axis) RotateRight() Axis {
// No difference in rotating left or right for an Facing.
// No difference in rotating left or right for an Axis.
return a.RotateLeft()
}

Expand Down
2 changes: 1 addition & 1 deletion server/block/customblock/material.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (m Material) WithoutAmbientOcclusion() Material {
return m
}

// Encode returns the material encoded as a map[string]any.
// Encode returns the material encoded as a map that can be sent over the network to the client.
func (m Material) Encode() map[string]any {
return map[string]any{
"texture": m.texture,
Expand Down
95 changes: 0 additions & 95 deletions server/block/customblock/material_target.go

This file was deleted.

35 changes: 28 additions & 7 deletions server/block/customblock/permutations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,40 @@ import (
"github.com/go-gl/mathgl/mgl64"
)

// Properties represents the different properties that can be applied to a block or a permutation.
type Properties struct {
// CollisionBox represents the bounding box of the block that the player can collide with. This cannot exceed the
// position of the current block in the world, otherwise it will be cut off at the edge.
CollisionBox cube.BBox
Cube bool
Geometry string
MapColour string
Rotation cube.Pos
Scale mgl64.Vec3
// Cube determines whether the block should inherit the default cube geometry. This will only be considered if the
// Geometry field is empty.
Cube bool
// Geometry represents the geometry identifier that should be used for the block. If you want to use the default
// cube geometry, leave this field empty and set Cube to true.
Geometry string
// MapColour represents the hex colour that should be used for the block on a map.
MapColour string
// Rotation represents the rotation of the block. Rotations are only applied in 90 degree increments, meaning
// 1 = 90 degrees, 2 = 180 degrees, 3 = 270 degrees and 4 = 360 degrees.
Rotation cube.Pos
// Scale is the scale of the block, with 1 being the default scale in all axes. When scaled, the block cannot
// exceed a 30x30x30 pixel area otherwise the client will not render the block.
Scale mgl64.Vec3
// SelectionBox represents the bounding box of the block that the player can interact with. This cannot exceed the
// position of the current block in the world, otherwise it will be cut off at the edge.
SelectionBox cube.BBox
Textures map[string]Material
Translation mgl64.Vec3
// Textures define the textures that should be used for the block. The key is the target of the texture, such as
// "*" for all sides, or one of "up", "down", "north", "south", "east", "west" for a specific side.
Textures map[string]Material
// Translation is the translation of the block within itself. When translated, the block cannot exceed a 30x30x30
// pixel area otherwise the client will not render the block.
Translation mgl64.Vec3
}

// Permutation represents a specific permutation for a block that is only applied when the condition is met.
type Permutation struct {
Properties
// Condition is a molang query that is used to determine whether the permutation should be applied.
// Only the latest version of molang is supported.
Condition string
}
11 changes: 5 additions & 6 deletions server/block/hash.go

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

Loading

0 comments on commit 9ec048c

Please sign in to comment.