Skip to content

Commit 385711a

Browse files
authored
server/block: Implement Copper Age Blocks (#1125)
1 parent 6f0cd10 commit 385711a

File tree

12 files changed

+724
-53
lines changed

12 files changed

+724
-53
lines changed

server/block/copper_bars.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package block
2+
3+
import (
4+
"math/rand/v2"
5+
6+
"github.com/df-mc/dragonfly/server/block/cube"
7+
"github.com/df-mc/dragonfly/server/world"
8+
"github.com/df-mc/dragonfly/server/world/sound"
9+
"github.com/go-gl/mathgl/mgl64"
10+
)
11+
12+
// CopperBars are blocks that serve a similar purpose to glass panes, but made of copper instead of glass.
13+
type CopperBars struct {
14+
transparent
15+
thin
16+
sourceWaterDisplacer
17+
18+
// Oxidation is the level of oxidation of the copper bars.
19+
Oxidation OxidationType
20+
// Waxed bool is whether the copper bars has been waxed with honeycomb.
21+
Waxed bool
22+
}
23+
24+
// BreakInfo ...
25+
func (c CopperBars) BreakInfo() BreakInfo {
26+
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(c)).withBlastResistance(30)
27+
}
28+
29+
// SideClosed ...
30+
func (c CopperBars) SideClosed(cube.Pos, cube.Pos, *world.Tx) bool {
31+
return false
32+
}
33+
34+
// Wax waxes the copper bars to stop it from oxidising further.
35+
func (c CopperBars) Wax(cube.Pos, mgl64.Vec3) (world.Block, bool) {
36+
if c.Waxed {
37+
return c, false
38+
}
39+
c.Waxed = true
40+
return c, true
41+
}
42+
43+
// Strip ...
44+
func (c CopperBars) Strip() (world.Block, world.Sound, bool) {
45+
if c.Waxed {
46+
c.Waxed = false
47+
return c, sound.WaxRemoved{}, true
48+
} else if ot, ok := c.Oxidation.Decrease(); ok {
49+
c.Oxidation = ot
50+
return c, sound.CopperScraped{}, true
51+
}
52+
return c, nil, false
53+
}
54+
55+
// CanOxidate ...
56+
func (c CopperBars) CanOxidate() bool {
57+
return !c.Waxed
58+
}
59+
60+
// OxidationLevel ...
61+
func (c CopperBars) OxidationLevel() OxidationType {
62+
return c.Oxidation
63+
}
64+
65+
// WithOxidationLevel ...
66+
func (c CopperBars) WithOxidationLevel(o OxidationType) Oxidisable {
67+
c.Oxidation = o
68+
return c
69+
}
70+
71+
// RandomTick ...
72+
func (c CopperBars) RandomTick(pos cube.Pos, tx *world.Tx, r *rand.Rand) {
73+
attemptOxidation(pos, tx, r, c)
74+
}
75+
76+
// EncodeItem ...
77+
func (c CopperBars) EncodeItem() (name string, meta int16) {
78+
return copperBlockName("copper_bars", c.Oxidation, c.Waxed), 0
79+
}
80+
81+
// EncodeBlock ...
82+
func (c CopperBars) EncodeBlock() (name string, properties map[string]any) {
83+
return copperBlockName("copper_bars", c.Oxidation, c.Waxed), nil
84+
}
85+
86+
// allCopperBars ...
87+
func allCopperBars() (bars []world.Block) {
88+
f := func(waxed bool) {
89+
for _, o := range OxidationTypes() {
90+
bars = append(bars, CopperBars{Oxidation: o, Waxed: waxed})
91+
}
92+
}
93+
f(true)
94+
f(false)
95+
return
96+
}

server/block/copper_chain.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package block
2+
3+
import (
4+
"math/rand/v2"
5+
6+
"github.com/df-mc/dragonfly/server/block/cube"
7+
"github.com/df-mc/dragonfly/server/block/model"
8+
"github.com/df-mc/dragonfly/server/item"
9+
"github.com/df-mc/dragonfly/server/world"
10+
"github.com/df-mc/dragonfly/server/world/sound"
11+
"github.com/go-gl/mathgl/mgl64"
12+
)
13+
14+
// CopperChain is a metallic decoration block.
15+
type CopperChain struct {
16+
transparent
17+
sourceWaterDisplacer
18+
19+
// Axis is the axis which the chain faces.
20+
Axis cube.Axis
21+
// Oxidation is the level of oxidation of the copper chain.
22+
Oxidation OxidationType
23+
// Waxed bool is whether the copper chain has been waxed with honeycomb.
24+
Waxed bool
25+
}
26+
27+
// SideClosed ...
28+
func (CopperChain) SideClosed(cube.Pos, cube.Pos, *world.Tx) bool {
29+
return false
30+
}
31+
32+
// UseOnBlock ...
33+
func (c CopperChain) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, tx *world.Tx, user item.User, ctx *item.UseContext) (used bool) {
34+
pos, face, used = firstReplaceable(tx, pos, face, c)
35+
if !used {
36+
return
37+
}
38+
c.Axis = face.Axis()
39+
40+
place(tx, pos, c, user, ctx)
41+
return placed(ctx)
42+
}
43+
44+
// BreakInfo ...
45+
func (c CopperChain) BreakInfo() BreakInfo {
46+
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(c)).withBlastResistance(30)
47+
}
48+
49+
// Wax waxes the copper chain to stop it from oxidising further.
50+
func (c CopperChain) Wax(cube.Pos, mgl64.Vec3) (world.Block, bool) {
51+
if c.Waxed {
52+
return c, false
53+
}
54+
c.Waxed = true
55+
return c, true
56+
}
57+
58+
// Strip ...
59+
func (c CopperChain) Strip() (world.Block, world.Sound, bool) {
60+
if c.Waxed {
61+
c.Waxed = false
62+
return c, sound.WaxRemoved{}, true
63+
} else if ot, ok := c.Oxidation.Decrease(); ok {
64+
c.Oxidation = ot
65+
return c, sound.CopperScraped{}, true
66+
}
67+
return c, nil, false
68+
}
69+
70+
// CanOxidate ...
71+
func (c CopperChain) CanOxidate() bool {
72+
return !c.Waxed
73+
}
74+
75+
// OxidationLevel ...
76+
func (c CopperChain) OxidationLevel() OxidationType {
77+
return c.Oxidation
78+
}
79+
80+
// WithOxidationLevel ...
81+
func (c CopperChain) WithOxidationLevel(o OxidationType) Oxidisable {
82+
c.Oxidation = o
83+
return c
84+
}
85+
86+
// RandomTick ...
87+
func (c CopperChain) RandomTick(pos cube.Pos, tx *world.Tx, r *rand.Rand) {
88+
attemptOxidation(pos, tx, r, c)
89+
}
90+
91+
// EncodeItem ...
92+
func (c CopperChain) EncodeItem() (name string, meta int16) {
93+
return copperBlockName("copper_chain", c.Oxidation, c.Waxed), 0
94+
}
95+
96+
// EncodeBlock ...
97+
func (c CopperChain) EncodeBlock() (name string, properties map[string]any) {
98+
return copperBlockName("copper_chain", c.Oxidation, c.Waxed), map[string]any{"pillar_axis": c.Axis.String()}
99+
}
100+
101+
// Model ...
102+
func (c CopperChain) Model() world.BlockModel {
103+
return model.Chain{Axis: c.Axis}
104+
}
105+
106+
// allCopperChains ...
107+
func allCopperChains() (chains []world.Block) {
108+
f := func(waxed bool) {
109+
for _, o := range OxidationTypes() {
110+
for _, axis := range cube.Axes() {
111+
chains = append(chains, CopperChain{Axis: axis, Oxidation: o, Waxed: waxed})
112+
}
113+
}
114+
}
115+
f(true)
116+
f(false)
117+
return
118+
}

server/block/copper_door.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package block
22

33
import (
4+
"math/rand/v2"
5+
46
"github.com/df-mc/dragonfly/server/block/cube"
57
"github.com/df-mc/dragonfly/server/block/model"
68
"github.com/df-mc/dragonfly/server/item"
79
"github.com/df-mc/dragonfly/server/world"
810
"github.com/df-mc/dragonfly/server/world/sound"
911
"github.com/go-gl/mathgl/mgl64"
10-
"math/rand/v2"
1112
)
1213

1314
// CopperDoor is a block that can be used as an openable 1x2 barrier.
@@ -167,26 +168,12 @@ func (d CopperDoor) SideClosed(cube.Pos, cube.Pos, *world.Tx) bool {
167168

168169
// EncodeItem ...
169170
func (d CopperDoor) EncodeItem() (name string, meta int16) {
170-
name = "copper_door"
171-
if d.Oxidation != UnoxidisedOxidation() {
172-
name = d.Oxidation.String() + "_" + name
173-
}
174-
if d.Waxed {
175-
name = "waxed_" + name
176-
}
177-
return "minecraft:" + name, 0
171+
return copperBlockName("copper_door", d.Oxidation, d.Waxed), 0
178172
}
179173

180174
// EncodeBlock ...
181175
func (d CopperDoor) EncodeBlock() (name string, properties map[string]any) {
182-
name = "copper_door"
183-
if d.Oxidation != UnoxidisedOxidation() {
184-
name = d.Oxidation.String() + "_" + name
185-
}
186-
if d.Waxed {
187-
name = "waxed_" + name
188-
}
189-
return "minecraft:" + name, map[string]any{"minecraft:cardinal_direction": d.Facing.RotateRight().String(), "door_hinge_bit": d.Right, "open_bit": d.Open, "upper_block_bit": d.Top}
176+
return copperBlockName("copper_door", d.Oxidation, d.Waxed), map[string]any{"minecraft:cardinal_direction": d.Facing.RotateRight().String(), "door_hinge_bit": d.Right, "open_bit": d.Open, "upper_block_bit": d.Top}
190177
}
191178

192179
// allCopperDoors returns a list of all copper door types

server/block/copper_golem_pose.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package block
2+
3+
// CopperGolemPose represents a pose of a copper golem statue.
4+
type CopperGolemPose struct {
5+
pose
6+
}
7+
8+
type pose uint8
9+
10+
// StandingPose is the standing pose.
11+
func StandingPose() CopperGolemPose {
12+
return CopperGolemPose{0}
13+
}
14+
15+
// SittingPose is the sitting pose.
16+
func SittingPose() CopperGolemPose {
17+
return CopperGolemPose{1}
18+
}
19+
20+
// RunningPose is the running pose.
21+
func RunningPose() CopperGolemPose {
22+
return CopperGolemPose{2}
23+
}
24+
25+
// StarPose is the head button pressing pose.
26+
func StarPose() CopperGolemPose {
27+
return CopperGolemPose{3}
28+
}
29+
30+
// Uint8 returns the pose as a uint8.
31+
func (p pose) Uint8() uint8 {
32+
return uint8(p)
33+
}
34+
35+
// Name returns the pose as a string.
36+
func (p pose) Name() string {
37+
switch p {
38+
case 0:
39+
return "Standing"
40+
case 1:
41+
return "Sitting"
42+
case 2:
43+
return "Running"
44+
case 3:
45+
return "Star"
46+
}
47+
panic("unknown copper golem pose")
48+
}
49+
50+
// CopperGolemPoses returns all copper golem poses.
51+
func CopperGolemPoses() []CopperGolemPose {
52+
return []CopperGolemPose{StandingPose(), SittingPose(), RunningPose(), StarPose()}
53+
}

0 commit comments

Comments
 (0)