Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/blockhash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ func (b *hashBuilder) ftype(structName, s string, expr ast.Expr, directives map[
return "uint64(" + s + ".Uint8())", 2
case "OreType", "FireType", "DoubleTallGrassType":
return "uint64(" + s + ".Uint8())", 1
case "TorchColour":
return "uint64(" + s + ".Uint8())", 2
case "Direction", "Axis":
return "uint64(" + s + ")", 2
case "Face":
Expand Down
102 changes: 102 additions & 0 deletions server/block/coloured_torch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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"
)

// ColouredTorch are non-solid blocks that emit light.
type ColouredTorch struct {
transparent
empty

// Facing is the direction from the torch to the block.
Facing cube.Face
// Colour is the colour of the torch.
Colour TorchColour
}

// BreakInfo ...
func (t ColouredTorch) BreakInfo() BreakInfo {
return newBreakInfo(0, alwaysHarvestable, nothingEffective, oneOf(t))
}

// LightEmissionLevel ...
func (t ColouredTorch) LightEmissionLevel() uint8 {
return 14
}

// UseOnBlock ...
func (t ColouredTorch) 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, t)
if !used {
return false
}
if face == cube.FaceDown {
return false
}
if !tx.Block(pos.Side(face.Opposite())).Model().FaceSolid(pos.Side(face.Opposite()), face, tx) {
found := false
for _, i := range []cube.Face{cube.FaceSouth, cube.FaceWest, cube.FaceNorth, cube.FaceEast, cube.FaceDown} {
if tx.Block(pos.Side(i)).Model().FaceSolid(pos.Side(i), i.Opposite(), tx) {
found = true
face = i.Opposite()
break
}
}
if !found {
return false
}
}
t.Facing = face.Opposite()

place(tx, pos, t, user, ctx)
return placed(ctx)
}

// NeighbourUpdateTick ...
func (t ColouredTorch) NeighbourUpdateTick(pos, _ cube.Pos, tx *world.Tx) {
if !tx.Block(pos.Side(t.Facing)).Model().FaceSolid(pos.Side(t.Facing), t.Facing.Opposite(), tx) {
breakBlock(t, pos, tx)
}
}

// HasLiquidDrops ...
func (t ColouredTorch) HasLiquidDrops() bool {
return true
}

// EncodeItem ...
func (t ColouredTorch) EncodeItem() (name string, meta int16) {
return "minecraft:colored_torch_" + t.Colour.String(), 0
}

// EncodeBlock ...
func (t ColouredTorch) EncodeBlock() (name string, properties map[string]any) {
var face string
if t.Facing == cube.FaceDown {
face = "top"
} else if t.Facing == unknownFace {
face = "unknown"
} else {
face = t.Facing.String()
}

return "minecraft:colored_torch_" + t.Colour.String(), map[string]any{"torch_facing_direction": face}
}

// allColouredTorches ...
func allColouredTorches() (torch []world.Block) {
for _, face := range cube.Faces() {
if face == cube.FaceUp {
face = unknownFace
}

for _, colour := range TorchColours() {
torch = append(torch, ColouredTorch{Facing: face, Colour: colour})
}
}
return
}
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.

4 changes: 4 additions & 0 deletions server/block/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func init() {
registerAll(allCampfires())
registerAll(allCarpet())
registerAll(allCarrots())
registerAll(allColouredTorches())
registerAll(allIronChains())
registerAll(allChests())
registerAll(allCocoaBeans())
Expand Down Expand Up @@ -493,6 +494,9 @@ func init() {
world.RegisterItem(Copper{Type: c, Oxidation: o, Waxed: true})
}
}
for _, c := range TorchColours() {
world.RegisterItem(ColouredTorch{Colour: c})
}
}

func registerAll(blocks []world.Block) {
Expand Down
68 changes: 68 additions & 0 deletions server/block/torch_colour.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package block

// TorchColour ...
type TorchColour struct {
colouredTorch
}

type colouredTorch uint8

// TorchColourPurple ...
func TorchColourPurple() TorchColour {
return TorchColour{0}
}

// TorchColourBlue ...
func TorchColourBlue() TorchColour {
return TorchColour{1}
}

// TorchColourGreen ...
func TorchColourGreen() TorchColour {
return TorchColour{2}
}

// TorchColourRed ...
func TorchColourRed() TorchColour {
return TorchColour{3}
}

// Name ...
func (c colouredTorch) Name() string {
switch c {
case 0:
return "Purple Torch"
case 1:
return "Blue Torch"
case 2:
return "Green Torch"
case 3:
return "Red Torch"
}
panic("unknown torch colour")
}

// String ...
func (c colouredTorch) String() string {
switch c {
case 0:
return "purple"
case 1:
return "blue"
case 2:
return "green"
case 3:
return "red"
}
panic("unknown torch colour")
}

// Uint8 ...
func (c colouredTorch) Uint8() uint8 {
return uint8(c)
}

// TorchColours ...
func TorchColours() []TorchColour {
return []TorchColour{TorchColourPurple(), TorchColourBlue(), TorchColourGreen(), TorchColourRed()}
}