Skip to content

Commit

Permalink
server/block: Add Pink Petals block
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed Dec 16, 2024
1 parent 209541a commit 1c2ac18
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/block/dirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/block/farmland.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/block/grass.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions server/block/hash.go

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

2 changes: 1 addition & 1 deletion server/block/mud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/block/muddy_mangrove_roots.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
104 changes: 104 additions & 0 deletions server/block/pink_petals.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions server/block/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func init() {
registerAll(allMuddyMangroveRoots())
registerAll(allNetherBricks())
registerAll(allNetherWart())
registerAll(allPinkPetals())
registerAll(allPlanks())
registerAll(allPotato())
registerAll(allPrismarine())
Expand Down Expand Up @@ -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{})
Expand Down

0 comments on commit 1c2ac18

Please sign in to comment.