From 9ec048cccca8faa84e403de0c12ece614fd55f5a Mon Sep 17 00:00:00 2001 From: TwistedAsylumMC Date: Fri, 3 Nov 2023 13:36:43 +0000 Subject: [PATCH] dragonfly: Cleanup custom block code --- cmd/blockhash/main.go | 8 +- go.mod | 2 - go.sum | 6 - main.go | 16 +-- php.png | Bin 9980 -> 0 bytes pig.png | Bin 3205 -> 0 bytes server/block/block.go | 6 + server/block/cube/axis.go | 2 +- server/block/customblock/material.go | 2 +- server/block/customblock/material_target.go | 95 ------------- server/block/customblock/permutations.go | 35 ++++- server/block/hash.go | 11 +- server/block/pig.go | 142 -------------------- server/internal/blockinternal/builder.go | 15 ++- server/internal/blockinternal/components.go | 7 +- server/internal/packbuilder/blocks.go | 2 +- server/server.go | 4 - skull.geo.json | 25 ---- 18 files changed, 60 insertions(+), 318 deletions(-) delete mode 100644 php.png delete mode 100644 pig.png delete mode 100644 server/block/customblock/material_target.go delete mode 100644 server/block/pig.go delete mode 100644 skull.geo.json diff --git a/cmd/blockhash/main.go b/cmd/blockhash/main.go index c463b9bb1..adf052679 100644 --- a/cmd/blockhash/main.go +++ b/cmd/blockhash/main.go @@ -113,7 +113,7 @@ 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) } @@ -121,16 +121,16 @@ func (b *hashBuilder) writeConstants(w io.Writer) (bitSize int) { } 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) } } diff --git a/go.mod b/go.mod index 7cfb799f4..c408fda2b 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 708ec87d9..a288fc13c 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/main.go b/main.go index 91d101814..89c129769 100644 --- a/main.go +++ b/main.go @@ -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" @@ -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) { } } diff --git a/php.png b/php.png deleted file mode 100644 index f1b933bbf1465ba5691e2dbefe283b4f8627c3cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9980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Xk_gS_?{$7V!)x)3tE z->)e-JkFk(d9}u$kz<{VZPv&9o7`-!z7K?^7Pclx9;1|r%j{%ujw3MZak6O zaZe)|RZ4~cTFH35AIo^x1bv1PgHxNu&L&OTI8YafPSBamIY`%Tm;L-pjw=g?OUHeJ zRs-Yn8_F|TY+YL;j*O!>q@#C|(;M&iK0%^CUD^3XViamn@(XlnW{ zto!;j{=O_iOlRq?@CyW><&{Jn#!@u{FxVt{OiSK4HT%*0u=C;HG7&-ogT)&vY+f5C zm6m6>^N~-~MX6n%kcBv{t$QC!>L5CxG!AJ02ze{)|2#cu6hWqNdC=n`G!BqbUzC(u zBy&{MrkA#?N^HavrBclS$VXmSmc>bsUMcwK^t8s5mXWGFYmk#*yywO5r|o^#0gAkM zHDlUih}1grienPD)v_PTVx)e*m*CBUS(a diff --git a/pig.png b/pig.png deleted file mode 100644 index 938d405c0126989e95948f65bd04257c603b73bf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3205 zcmV;040`j4P)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?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W+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z00057Nkl1vug|;+-I0z|d(b2!)PjT}P=%5JB;-W4(xw#20{tQ>$ zIykgcF$WbIxP&%C6Ne~nhWDsZ#o}JN!;mTE;Ybaas@u%l)Dg&GY4j@>PJ59PM2_Fot51KCP|EU zahCEJfK{ipvrok^c|JcO?sVx#K5I0zMgB@K|$OS~au3UCru`VuVOX z%gM(2yXpbVp74l=qapzGL>ck&=9cjBkAGo*A}Ah?=m{@tL&jB~tVPD% z_ErMWt~qHBt(l%>!oz9W3vwNYx#YO7Fh rIr@g$Ap>xTpS&W^42s;&JI>nxD8=FuDx_$$00000NkvXXu0mjfodfxr diff --git a/server/block/block.go b/server/block/block.go index 3795330c3..4fa16ba14 100644 --- a/server/block/block.go +++ b/server/block/block.go @@ -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 } diff --git a/server/block/cube/axis.go b/server/block/cube/axis.go index 0a24a8755..352c5d4dd 100644 --- a/server/block/cube/axis.go +++ b/server/block/cube/axis.go @@ -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() } diff --git a/server/block/customblock/material.go b/server/block/customblock/material.go index 1a7590574..8b018947a 100644 --- a/server/block/customblock/material.go +++ b/server/block/customblock/material.go @@ -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, diff --git a/server/block/customblock/material_target.go b/server/block/customblock/material_target.go deleted file mode 100644 index 48789310b..000000000 --- a/server/block/customblock/material_target.go +++ /dev/null @@ -1,95 +0,0 @@ -package customblock - -// Target represents a material target for a custom block. These are limited to either all targets, or the top, -// bottom, and sides. -type Target struct { - materialTarget -} - -// MaterialTargetAll represents the material target for all targets. -func MaterialTargetAll() Target { - return Target{0} -} - -// MaterialTargetUp represents the material target for the top of the block. -func MaterialTargetUp() Target { - return Target{1} -} - -// MaterialTargetDown represents the material target for the bottom of the block. -func MaterialTargetDown() Target { - return Target{2} -} - -// MaterialTargetSides represents the material target for the sides of the block. -func MaterialTargetSides() Target { - return Target{3} -} - -// MaterialTargetNorth represents the material target for the north face of the block. -func MaterialTargetNorth() Target { - return Target{4} -} - -// MaterialTargetEast represents the material target for the east face of the block. -func MaterialTargetEast() Target { - return Target{5} -} - -// MaterialTargetSouth represents the material target for the south face of the block. -func MaterialTargetSouth() Target { - return Target{6} -} - -// MaterialTargetWest represents the material target for the west face of the block. -func MaterialTargetWest() Target { - return Target{7} -} - -type materialTarget uint8 - -// Name returns the name of the material target. -func (m materialTarget) Name() string { - switch m { - case 0: - return "all" - case 1: - return "up" - case 2: - return "down" - case 3: - return "sides" - case 4: - return "north" - case 5: - return "east" - case 6: - return "south" - case 7: - return "west" - } - panic("should never happen") -} - -// String returns the string representation of the material target. -func (m materialTarget) String() string { - switch m { - case 0: - return "*" - case 1: - return "up" - case 2: - return "down" - case 3: - return "sides" - case 4: - return "north" - case 5: - return "east" - case 6: - return "south" - case 7: - return "west" - } - panic("should never happen") -} diff --git a/server/block/customblock/permutations.go b/server/block/customblock/permutations.go index 24df9be93..ae55bf620 100644 --- a/server/block/customblock/permutations.go +++ b/server/block/customblock/permutations.go @@ -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 } diff --git a/server/block/hash.go b/server/block/hash.go index 6bbbe2ffd..3a2a0b80c 100644 --- a/server/block/hash.go +++ b/server/block/hash.go @@ -118,7 +118,6 @@ const ( hashObsidian hashPackedIce hashPackedMud - hashPig hashPlanks hashPodzol hashPolishedBlackstoneBrick @@ -172,16 +171,16 @@ const ( hashWoodFenceGate hashWoodTrapdoor hashWool - hashBase + hashCustomBlockBase ) -// base represents the base hash for all custom blocks. -var base = uint64(hashBase - 1) +// customBlockBase represents the base hash for all custom blocks. +var customBlockBase = uint64(hashCustomBlockBase - 1) // NextHash returns the next free hash for custom blocks. func NextHash() uint64 { - base++ - return base + customBlockBase++ + return customBlockBase } // Hash ... diff --git a/server/block/pig.go b/server/block/pig.go deleted file mode 100644 index 47f2a6c2e..000000000 --- a/server/block/pig.go +++ /dev/null @@ -1,142 +0,0 @@ -package block - -import ( - "github.com/df-mc/dragonfly/server/block/cube" - "github.com/df-mc/dragonfly/server/block/customblock" - "github.com/df-mc/dragonfly/server/item" - "github.com/df-mc/dragonfly/server/item/category" - "github.com/df-mc/dragonfly/server/world" - "github.com/go-gl/mathgl/mgl64" - "image" - "image/png" - "os" -) - -// Pig represents the Pig block. -type Pig struct { - empty - transparent - - // Facing ... - Facing cube.Direction -} - -// Name ... -func (p Pig) Name() string { - return "Pig Head" -} - -// Category ... -func (p Pig) Category() category.Category { - return category.Nature() -} - -// FlammabilityInfo ... -func (p Pig) FlammabilityInfo() FlammabilityInfo { - return newFlammabilityInfo(5, 20, true) -} - -// BreakInfo ... -func (p Pig) BreakInfo() BreakInfo { - return newBreakInfo(1, alwaysHarvestable, nothingEffective, oneOf(Pig{})) -} - -// Textures ... -func (p Pig) Textures() map[string]image.Image { - return map[string]image.Image{ - "pig": p.Texture(), - } -} - -// Texture ... -func (p Pig) Texture() image.Image { - texture, err := os.OpenFile("pig.png", os.O_RDONLY, os.ModePerm) - if err != nil { - panic(err) - } - defer texture.Close() - img, err := png.Decode(texture) - if err != nil { - panic(err) - } - return img -} - -// Geometry ... -func (p Pig) Geometry() []byte { - data, err := os.ReadFile("skull.geo.json") - if err != nil { - panic(err) - } - return data -} - -// UseOnBlock ... -func (p Pig) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) { - pos, _, used = firstReplaceable(w, pos, face, p) - if !used { - return - } - - p.Facing = user.Rotation().Direction() - place(w, pos, p, user, ctx) - return placed(ctx) -} - -// EncodeItem ... -func (p Pig) EncodeItem() (name string, meta int16) { - return "dragonfly:pig", 0 -} - -// EncodeBlock ... -func (p Pig) EncodeBlock() (string, map[string]any) { - return "dragonfly:pig", map[string]any{"rotation": int32(p.Facing)} -} - -// pigHash ... -var pigHash = NextHash() - -// Hash ... -func (p Pig) Hash() uint64 { - return pigHash | (uint64(p.Facing) << 8) -} - -func (p Pig) Properties() customblock.Properties { - return customblock.Properties{ - CollisionBox: cube.Box(0.25, 0, 0.25, 0.75, 0.5, 0.75), - SelectionBox: cube.Box(0.25, 0, 0.25, 0.75, 0.5, 0.75), - Geometry: "geometry.skull", - Textures: map[string]customblock.Material{ - "*": customblock.NewMaterial("pig", customblock.OpaqueRenderMethod()), - }, - } -} - -func (p Pig) States() map[string][]any { - return map[string][]any{ - "rotation": {int32(0), int32(1), int32(2), int32(3)}, - } -} - -func (p Pig) Permutations() []customblock.Permutation { - return []customblock.Permutation{ - { - Condition: "query.block_state('rotation') == 1", - Properties: customblock.Properties{ - Rotation: cube.Pos{0, 3, 0}, - }, - }, - { - Condition: "query.block_state('rotation') == 2", - Properties: customblock.Properties{ - Rotation: cube.Pos{0, 2, 0}, - }, - }, - { - Condition: "query.block_state('rotation') == 3", - Properties: customblock.Properties{ - Rotation: cube.Pos{0, 1, 0}, - }, - }, - } -} diff --git a/server/internal/blockinternal/builder.go b/server/internal/blockinternal/builder.go index bac24aa15..7651ebfb5 100644 --- a/server/internal/blockinternal/builder.go +++ b/server/internal/blockinternal/builder.go @@ -16,7 +16,8 @@ type ComponentBuilder struct { menuCategory category.Category } -// NewComponentBuilder returns a new component builder with the provided block data. +// 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 { if components == nil { components = map[string]any{} @@ -30,7 +31,7 @@ func NewComponentBuilder(identifier string, components map[string]any) *Componen } } -// AddProperty adds the provided property to the builder. +// AddProperty adds the provided block property to the builder. func (builder *ComponentBuilder) AddProperty(name string, values []any) { builder.properties = append(builder.properties, map[string]any{ "name": name, @@ -38,12 +39,13 @@ func (builder *ComponentBuilder) AddProperty(name string, values []any) { }) } -// AddComponent adds the provided component to the builder. +// AddComponent adds the provided component to the builder. If the component already exists, it will be overwritten. func (builder *ComponentBuilder) AddComponent(name string, value any) { builder.components[name] = value } -// AddPermutation adds a permutation to the builder. +// AddPermutation adds a permutation to the builder. If there is already an existing permutation for the provided +// condition, the new components will be added to the existing permutation. func (builder *ComponentBuilder) AddPermutation(condition string, components map[string]any) { if len(builder.permutations) == 0 { // This trigger really does not matter at all, the component just needs to be set for custom block placements to @@ -60,13 +62,12 @@ func (builder *ComponentBuilder) AddPermutation(condition string, components map } } -// SetMenuCategory sets the menu category for the block. +// SetMenuCategory sets the creative category for the current block. func (builder *ComponentBuilder) SetMenuCategory(category category.Category) { builder.menuCategory = category } -// Construct constructs the final block components map and returns it. It also applies the default properties required -// for the block to work without modifying the original maps in the builder. +// Construct constructs the final block components map that is ready to be sent to the client. func (builder *ComponentBuilder) Construct() map[string]any { properties := slices.Clone(builder.properties) components := maps.Clone(builder.components) diff --git a/server/internal/blockinternal/components.go b/server/internal/blockinternal/components.go index cd832522e..affec240e 100644 --- a/server/internal/blockinternal/components.go +++ b/server/internal/blockinternal/components.go @@ -8,8 +8,7 @@ import ( "github.com/go-gl/mathgl/mgl64" ) -// Components returns all the components of the given custom block group. If the group has no components, a nil map -// and false are returned. +// Components returns all the components for the custom block, including permutations and properties. func Components(identifier string, b world.CustomBlock) map[string]any { components := componentsFromProperties(b.Properties()) builder := NewComponentBuilder(identifier, components) @@ -51,6 +50,8 @@ func Components(identifier string, b world.CustomBlock) map[string]any { return builder.Construct() } +// componentsFromProperties builds a base components map that includes all the common data between a regular block and +// a custom permutation. func componentsFromProperties(props customblock.Properties) map[string]any { components := make(map[string]any) if props.CollisionBox != (cube.BBox{}) { @@ -103,6 +104,8 @@ func componentsFromProperties(props customblock.Properties) map[string]any { return components } +// bboxComponent returns the component data for a bounding box. It translates the coordinates to the origin and size +// format that the client expects. func bboxComponent(box cube.BBox) map[string]any { min, max := box.Min(), box.Max() originX, originY, originZ := min.X()*16, min.Y()*16, min.Z()*16 diff --git a/server/internal/packbuilder/blocks.go b/server/internal/packbuilder/blocks.go index 051be3a43..f2a281601 100644 --- a/server/internal/packbuilder/blocks.go +++ b/server/internal/packbuilder/blocks.go @@ -12,7 +12,7 @@ import ( _ "unsafe" // Imported for compiler directives. ) -// buildBlocks builds all of the block-related files for the resource pack. This includes textures, geometries, language +// buildBlocks builds all the block-related files for the resource pack. This includes textures, geometries, language // entries and terrain texture atlas. func buildBlocks(dir string) (count int, lang []string) { if err := os.MkdirAll(filepath.Join(dir, "models/blocks"), os.ModePerm); err != nil { diff --git a/server/server.go b/server/server.go index 5cb337555..adf2700d9 100644 --- a/server/server.go +++ b/server/server.go @@ -5,7 +5,6 @@ import ( "context" _ "embed" "encoding/base64" - "encoding/json" "fmt" "github.com/df-mc/atomic" "github.com/df-mc/dragonfly/server/cmd" @@ -303,9 +302,6 @@ func (srv *Server) makeBlockEntries() { Properties: blockinternal.Components(name, b), } } - - data, _ := json.Marshal(srv.customBlocks) - os.WriteFile("custom_blocks.json", data, 0644) } // makeItemComponents initializes the server's item components map using the diff --git a/skull.geo.json b/skull.geo.json deleted file mode 100644 index 8a1d2b4a7..000000000 --- a/skull.geo.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "format_version": "1.12.0", - "minecraft:geometry": [ - { - "description": { - "identifier": "geometry.skull", - "texture_width": 32, - "texture_height": 16, - "visible_bounds_width": 2, - "visible_bounds_height": 1.5, - "visible_bounds_offset": [0, 0.25, 0] - }, - "bones": [ - { - "name": "root", - "pivot": [0, 0, 0], - "rotation": [0, 180, 0], - "cubes": [ - {"origin": [-4, 0, -4], "size": [8, 8, 8], "uv": [0, 0]} - ] - } - ] - } - ] -} \ No newline at end of file