From 257250dbe60e4830e29802d6a7933929b5f0ea72 Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Sat, 14 Dec 2024 23:57:12 -0800 Subject: [PATCH 1/4] block/ladder.go: Use `cube.Direction` --- server/block/ladder.go | 16 +++++++++------- server/block/model/ladder.go | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/server/block/ladder.go b/server/block/ladder.go index 913fa1bf1..91a520095 100644 --- a/server/block/ladder.go +++ b/server/block/ladder.go @@ -15,14 +15,13 @@ type Ladder struct { transparent sourceWaterDisplacer - // Facing is the side of the block the ladder is currently attached to. cube.FaceDown and cube.FaceUp - // do not do anything in game but they are still valid states. - Facing cube.Face + // Facing is the side of the block the ladder is currently attached to. + Facing cube.Direction } // NeighbourUpdateTick ... func (l Ladder) NeighbourUpdateTick(pos, _ cube.Pos, tx *world.Tx) { - if _, ok := tx.Block(pos.Side(l.Facing.Opposite())).(LightDiffuser); ok { + if _, ok := tx.Block(pos.Side(l.Facing.Face().Opposite())).(LightDiffuser); ok { breakBlock(l, pos, tx) } } @@ -49,7 +48,7 @@ func (l Ladder) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, tx *world return false } } - l.Facing = face + l.Facing = face.Direction() place(tx, pos, l, user, ctx) return placed(ctx) @@ -84,7 +83,10 @@ func (l Ladder) EncodeItem() (name string, meta int16) { // EncodeBlock ... func (l Ladder) EncodeBlock() (string, map[string]any) { - return "minecraft:ladder", map[string]any{"facing_direction": int32(l.Facing)} + if l.Facing == unknownDirection { + return "minecraft:ladder", map[string]any{"facing_direction": int32(0)} + } + return "minecraft:ladder", map[string]any{"facing_direction": int32(l.Facing + 2)} } // Model ... @@ -94,7 +96,7 @@ func (l Ladder) Model() world.BlockModel { // allLadders ... func allLadders() (b []world.Block) { - for _, f := range cube.Faces() { + for _, f := range append(cube.Directions(), unknownDirection) { b = append(b, Ladder{Facing: f}) } return diff --git a/server/block/model/ladder.go b/server/block/model/ladder.go index 57802e064..e2f1193e4 100644 --- a/server/block/model/ladder.go +++ b/server/block/model/ladder.go @@ -8,12 +8,12 @@ import ( // Ladder is the model for a ladder block. type Ladder struct { // Facing is the side opposite to the block the Ladder is currently attached to. - Facing cube.Face + Facing cube.Direction } // BBox returns one physics.BBox that depends on the facing direction of the Ladder. func (l Ladder) BBox(cube.Pos, world.BlockSource) []cube.BBox { - return []cube.BBox{full.ExtendTowards(l.Facing, -0.8125)} + return []cube.BBox{full.ExtendTowards(l.Facing.Face(), -0.8125)} } // FaceSolid always returns false. From 0384ad5d20861a8909aae22925dca34439ffec4d Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Sun, 15 Dec 2024 00:04:49 -0800 Subject: [PATCH 2/4] item/book_and_quill.go: Only encode "pages" NBT if a page exists --- server/item/book_and_quill.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/item/book_and_quill.go b/server/item/book_and_quill.go index 76ef0d313..d7309f574 100644 --- a/server/item/book_and_quill.go +++ b/server/item/book_and_quill.go @@ -102,6 +102,9 @@ func (b BookAndQuill) DecodeNBT(data map[string]any) any { // EncodeNBT ... func (b BookAndQuill) EncodeNBT() map[string]any { + if len(b.Pages) == 0 { + return nil + } pages := make([]any, 0, len(b.Pages)) for _, page := range b.Pages { pages = append(pages, map[string]any{"text": page}) From 209541a4f491d4e77d87f2e5362531aeee5009fe Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Mon, 16 Dec 2024 01:47:53 -0800 Subject: [PATCH 3/4] server/block: Add End Rod block --- server/block/end_rod.go | 76 +++++++++++++++++++++++++++++++++++ server/block/hash.go | 5 +++ server/block/model/end_rod.go | 22 ++++++++++ server/block/register.go | 2 + 4 files changed, 105 insertions(+) create mode 100644 server/block/end_rod.go create mode 100644 server/block/model/end_rod.go diff --git a/server/block/end_rod.go b/server/block/end_rod.go new file mode 100644 index 000000000..cbb367388 --- /dev/null +++ b/server/block/end_rod.go @@ -0,0 +1,76 @@ +package block + +import ( + "github.com/df-mc/dragonfly/server/block/cube" + "github.com/df-mc/dragonfly/server/block/model" + "github.com/df-mc/dragonfly/server/item" + "github.com/df-mc/dragonfly/server/world" + "github.com/go-gl/mathgl/mgl64" +) + +// EndRod is a decorative light source that emits white particles. +type EndRod struct { + transparent + flowingWaterDisplacer + + // Facing is the direction the white end point of the end rod is facing. + Facing cube.Face +} + +// UseOnBlock ... +func (e EndRod) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, tx *world.Tx, user item.User, ctx *item.UseContext) bool { + pos, face, used := firstReplaceable(tx, pos, face, e) + if !used { + return false + } + + e.Facing = face + if other, ok := tx.Block(pos.Side(face.Opposite())).(EndRod); ok { + if face == other.Facing { + e.Facing = face.Opposite() + } + } + place(tx, pos, e, user, ctx) + return placed(ctx) +} + +// SideClosed ... +func (EndRod) SideClosed(cube.Pos, cube.Pos, *world.Tx) bool { + return false +} + +// Model ... +func (e EndRod) Model() world.BlockModel { + return model.EndRod{Axis: e.Facing.Axis()} +} + +// LightEmissionLevel ... +func (EndRod) LightEmissionLevel() uint8 { + return 14 +} + +// BreakInfo ... +func (e EndRod) BreakInfo() BreakInfo { + return newBreakInfo(0, alwaysHarvestable, nothingEffective, oneOf(e)) +} + +// EncodeItem ... +func (EndRod) EncodeItem() (name string, meta int16) { + return "minecraft:end_rod", 0 +} + +// EncodeBlock ... +func (e EndRod) EncodeBlock() (string, map[string]any) { + if e.Facing.Axis() == cube.Y { + return "minecraft:end_rod", map[string]any{"facing_direction": int32(e.Facing)} + } + return "minecraft:end_rod", map[string]any{"facing_direction": int32(e.Facing.Opposite())} +} + +// allEndRods ... +func allEndRods() (b []world.Block) { + for _, f := range cube.Faces() { + b = append(b, EndRod{Facing: f}) + } + return +} diff --git a/server/block/hash.go b/server/block/hash.go index 17f49b4df..ab0cfed5f 100644 --- a/server/block/hash.go +++ b/server/block/hash.go @@ -68,6 +68,7 @@ const ( hashEmeraldOre hashEnchantingTable hashEndBricks + hashEndRod hashEndStone hashEnderChest hashFarmland @@ -448,6 +449,10 @@ func (EndBricks) Hash() (uint64, uint64) { return hashEndBricks, 0 } +func (e EndRod) Hash() (uint64, uint64) { + return hashEndRod, uint64(e.Facing) +} + func (EndStone) Hash() (uint64, uint64) { return hashEndStone, 0 } diff --git a/server/block/model/end_rod.go b/server/block/model/end_rod.go new file mode 100644 index 000000000..f26f8fd30 --- /dev/null +++ b/server/block/model/end_rod.go @@ -0,0 +1,22 @@ +package model + +import ( + "github.com/df-mc/dragonfly/server/block/cube" + "github.com/df-mc/dragonfly/server/world" +) + +// EndRod is a model used by end rod blocks. +type EndRod struct { + // Axis is the axis which the end rod faces. + Axis cube.Axis +} + +// BBox ... +func (e EndRod) BBox(cube.Pos, world.BlockSource) []cube.BBox { + return []cube.BBox{cube.Box(0.375, 0.375, 0.375, 0.625, 0.625, 0.625).Stretch(e.Axis, 0.375)} +} + +// FaceSolid ... +func (EndRod) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { + return false +} diff --git a/server/block/register.go b/server/block/register.go index 9c1652ee6..eb782b067 100644 --- a/server/block/register.go +++ b/server/block/register.go @@ -147,6 +147,7 @@ func init() { registerAll(allDoors()) registerAll(allDoubleFlowers()) registerAll(allDoubleTallGrass()) + registerAll(allEndRods()) registerAll(allEnderChests()) registerAll(allFarmland()) registerAll(allFence()) @@ -258,6 +259,7 @@ func init() { world.RegisterItem(Emerald{}) world.RegisterItem(EnchantingTable{}) world.RegisterItem(EndBricks{}) + world.RegisterItem(EndRod{}) world.RegisterItem(EndStone{}) world.RegisterItem(EnderChest{}) world.RegisterItem(Farmland{}) From 1c2ac18a5d85aa922e305ff4e233deb8afce1ee7 Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Mon, 16 Dec 2024 01:12:37 -0800 Subject: [PATCH 4/4] server/block: Add Pink Petals block --- server/block/dirt.go | 2 +- server/block/farmland.go | 2 +- server/block/grass.go | 2 +- server/block/hash.go | 5 ++ server/block/mud.go | 2 +- server/block/muddy_mangrove_roots.go | 2 +- server/block/pink_petals.go | 104 +++++++++++++++++++++++++++ server/block/register.go | 2 + 8 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 server/block/pink_petals.go diff --git a/server/block/dirt.go b/server/block/dirt.go index a25deafb3..4ba7a311f 100644 --- a/server/block/dirt.go +++ b/server/block/dirt.go @@ -19,7 +19,7 @@ func (d Dirt) SoilFor(block world.Block) bool { switch block.(type) { case ShortGrass, Fern, DoubleTallGrass, DeadBush: return !d.Coarse - case Flower, DoubleFlower, NetherSprouts, SugarCane: + case Flower, DoubleFlower, NetherSprouts, PinkPetals, SugarCane: return true } return false diff --git a/server/block/farmland.go b/server/block/farmland.go index 33d53d05c..d18d12b21 100644 --- a/server/block/farmland.go +++ b/server/block/farmland.go @@ -21,7 +21,7 @@ type Farmland struct { // SoilFor ... func (f Farmland) SoilFor(block world.Block) bool { switch block.(type) { - case ShortGrass, Fern, DoubleTallGrass, Flower, DoubleFlower, NetherSprouts: + case ShortGrass, Fern, DoubleTallGrass, Flower, DoubleFlower, NetherSprouts, PinkPetals: return true } return false diff --git a/server/block/grass.go b/server/block/grass.go index 08b6b6c02..6d85c53e5 100644 --- a/server/block/grass.go +++ b/server/block/grass.go @@ -37,7 +37,7 @@ func init() { // SoilFor ... func (g Grass) SoilFor(block world.Block) bool { switch block.(type) { - case ShortGrass, Fern, DoubleTallGrass, Flower, DoubleFlower, NetherSprouts, SugarCane: + case ShortGrass, Fern, DoubleTallGrass, Flower, DoubleFlower, NetherSprouts, PinkPetals, SugarCane: return true } return false diff --git a/server/block/hash.go b/server/block/hash.go index ab0cfed5f..c010760ab 100644 --- a/server/block/hash.go +++ b/server/block/hash.go @@ -128,6 +128,7 @@ const ( hashObsidian hashPackedIce hashPackedMud + hashPinkPetals hashPlanks hashPodzol hashPolishedBlackstoneBrick @@ -689,6 +690,10 @@ func (PackedMud) Hash() (uint64, uint64) { return hashPackedMud, 0 } +func (p PinkPetals) Hash() (uint64, uint64) { + return hashPinkPetals, uint64(p.AdditionalCount) | uint64(p.Facing)<<8 +} + func (p Planks) Hash() (uint64, uint64) { return hashPlanks, uint64(p.Wood.Uint8()) } diff --git a/server/block/mud.go b/server/block/mud.go index 2390265c7..272bee672 100644 --- a/server/block/mud.go +++ b/server/block/mud.go @@ -10,7 +10,7 @@ type Mud struct { // SoilFor ... func (Mud) SoilFor(block world.Block) bool { switch block.(type) { - case ShortGrass, Fern, DoubleTallGrass, Flower, DoubleFlower, NetherSprouts: + case ShortGrass, Fern, DoubleTallGrass, Flower, DoubleFlower, NetherSprouts, PinkPetals: return true } return false diff --git a/server/block/muddy_mangrove_roots.go b/server/block/muddy_mangrove_roots.go index 4bb5a3705..548e934dd 100644 --- a/server/block/muddy_mangrove_roots.go +++ b/server/block/muddy_mangrove_roots.go @@ -23,7 +23,7 @@ func (m MuddyMangroveRoots) BreakInfo() BreakInfo { // SoilFor ... func (MuddyMangroveRoots) SoilFor(block world.Block) bool { switch block.(type) { - case ShortGrass, Fern, DoubleTallGrass, Flower, DoubleFlower, NetherSprouts: + case ShortGrass, Fern, DoubleTallGrass, Flower, DoubleFlower, NetherSprouts, PinkPetals: return true } return false diff --git a/server/block/pink_petals.go b/server/block/pink_petals.go new file mode 100644 index 000000000..1df913167 --- /dev/null +++ b/server/block/pink_petals.go @@ -0,0 +1,104 @@ +package block + +import ( + "github.com/df-mc/dragonfly/server/block/cube" + "github.com/df-mc/dragonfly/server/item" + "github.com/df-mc/dragonfly/server/world" + "github.com/go-gl/mathgl/mgl64" +) + +// PinkPetals is a decorative block that generates in cherry grove biomes. +type PinkPetals struct { + empty + transparent + + // AdditionalCount is the amount of additional pink petals. This can range + // from 0-7, where only 0-3 can occur in-game. + AdditionalCount int + // Facing is the direction the pink petals are facing. This is opposite to + // the direction the player is facing when placing. + Facing cube.Direction +} + +// BoneMeal ... +func (p PinkPetals) BoneMeal(pos cube.Pos, tx *world.Tx) bool { + if p.AdditionalCount < 3 { + p.AdditionalCount++ + tx.SetBlock(pos, p, nil) + return true + } + dropItem(tx, item.NewStack(p, 1), pos.Vec3Centre()) + return true +} + +// UseOnBlock ... +func (p PinkPetals) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, tx *world.Tx, user item.User, ctx *item.UseContext) bool { + if existing, ok := tx.Block(pos).(PinkPetals); ok { + if existing.AdditionalCount >= 3 { + return false + } + + existing.AdditionalCount++ + place(tx, pos, existing, user, ctx) + return placed(ctx) + } + + pos, _, used := firstReplaceable(tx, pos, face, p) + if !used { + return false + } + if !supportsVegetation(p, tx.Block(pos.Side(cube.FaceDown))) { + return false + } + + p.Facing = user.Rotation().Direction().Opposite() + place(tx, pos, p, user, ctx) + return placed(ctx) +} + +// NeighbourUpdateTick ... +func (p PinkPetals) NeighbourUpdateTick(pos, _ cube.Pos, tx *world.Tx) { + if !supportsVegetation(p, tx.Block(pos.Side(cube.FaceDown))) { + breakBlock(p, pos, tx) + } +} + +// HasLiquidDrops ... +func (PinkPetals) HasLiquidDrops() bool { + return true +} + +// BreakInfo ... +func (p PinkPetals) BreakInfo() BreakInfo { + return newBreakInfo(0, alwaysHarvestable, nothingEffective, simpleDrops(item.NewStack(p, p.AdditionalCount+1))) +} + +// FlammabilityInfo ... +func (p PinkPetals) FlammabilityInfo() FlammabilityInfo { + return newFlammabilityInfo(30, 100, true) +} + +// CompostChance ... +func (PinkPetals) CompostChance() float64 { + return 0.3 +} + +// EncodeItem ... +func (PinkPetals) EncodeItem() (name string, meta int16) { + return "minecraft:pink_petals", 0 +} + +// EncodeBlock ... +func (p PinkPetals) EncodeBlock() (string, map[string]any) { + return "minecraft:pink_petals", map[string]any{"growth": int32(p.AdditionalCount), "minecraft:cardinal_direction": p.Facing.String()} +} + +// allPinkPetals ... +func allPinkPetals() (b []world.Block) { + for i := 0; i <= 7; i++ { + for _, d := range cube.Directions() { + b = append(b, PinkPetals{AdditionalCount: i, Facing: d}) + } + } + return +} diff --git a/server/block/register.go b/server/block/register.go index eb782b067..a482dab43 100644 --- a/server/block/register.go +++ b/server/block/register.go @@ -175,6 +175,7 @@ func init() { registerAll(allMuddyMangroveRoots()) registerAll(allNetherBricks()) registerAll(allNetherWart()) + registerAll(allPinkPetals()) registerAll(allPlanks()) registerAll(allPotato()) registerAll(allPrismarine()) @@ -309,6 +310,7 @@ func init() { world.RegisterItem(Obsidian{}) world.RegisterItem(PackedIce{}) world.RegisterItem(PackedMud{}) + world.RegisterItem(PinkPetals{}) world.RegisterItem(Podzol{}) world.RegisterItem(PolishedBlackstoneBrick{Cracked: true}) world.RegisterItem(PolishedBlackstoneBrick{})