Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandertv committed Dec 16, 2024
2 parents c9ded13 + 1c2ac18 commit a158baa
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 14 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
76 changes: 76 additions & 0 deletions server/block/end_rod.go
Original file line number Diff line number Diff line change
@@ -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
}
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
10 changes: 10 additions & 0 deletions server/block/hash.go

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

16 changes: 9 additions & 7 deletions server/block/ladder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 ...
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions server/block/model/end_rod.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions server/block/model/ladder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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
}
4 changes: 4 additions & 0 deletions server/block/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func init() {
registerAll(allDoors())
registerAll(allDoubleFlowers())
registerAll(allDoubleTallGrass())
registerAll(allEndRods())
registerAll(allEnderChests())
registerAll(allFarmland())
registerAll(allFence())
Expand Down Expand Up @@ -174,6 +175,7 @@ func init() {
registerAll(allMuddyMangroveRoots())
registerAll(allNetherBricks())
registerAll(allNetherWart())
registerAll(allPinkPetals())
registerAll(allPlanks())
registerAll(allPotato())
registerAll(allPrismarine())
Expand Down Expand Up @@ -258,6 +260,7 @@ func init() {
world.RegisterItem(Emerald{})
world.RegisterItem(EnchantingTable{})
world.RegisterItem(EndBricks{})
world.RegisterItem(EndRod{})
world.RegisterItem(EndStone{})
world.RegisterItem(EnderChest{})
world.RegisterItem(Farmland{})
Expand Down Expand Up @@ -307,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
3 changes: 3 additions & 0 deletions server/item/book_and_quill.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit a158baa

Please sign in to comment.