forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decorated_pot.go
108 lines (95 loc) · 2.98 KB
/
decorated_pot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package block
import (
"fmt"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/block/cube"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/block/model"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/internal/nbtconv"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/item"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/world"
"github.com/go-gl/mathgl/mgl64"
)
// PotDecoration represents an item that can be used as a decoration on a pot.
type PotDecoration interface {
world.Item
PotDecoration() bool
}
// DecoratedPot is a decoration block that can be crafted from up to four pottery sherds, and bricks on the sides where
// no pattern should be displayed.
type DecoratedPot struct {
// Facing is the direction the pot is facing. The first decoration will be facing opposite of this direction.
Facing cube.Direction
// Decorations are the four decorations displayed on the sides of the pot. If a decoration is a brick or nil,
// the side will appear to be empty.
Decorations [4]PotDecoration
}
// BreakInfo ...
func (p DecoratedPot) BreakInfo() BreakInfo {
return newBreakInfo(0, alwaysHarvestable, nothingEffective, oneOf(p))
}
// MaxCount ...
func (DecoratedPot) MaxCount() int {
return 64
}
// EncodeItem ...
func (p DecoratedPot) EncodeItem() (name string, meta int16) {
return "minecraft:decorated_pot", 0
}
// EncodeBlock ...
func (p DecoratedPot) EncodeBlock() (name string, properties map[string]any) {
return "minecraft:decorated_pot", map[string]any{"direction": int32(horizontalDirection(p.Facing))}
}
// Model ...
func (p DecoratedPot) Model() world.BlockModel {
return model.DecoratedPot{}
}
// UseOnBlock ...
func (p DecoratedPot) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
pos, _, used = firstReplaceable(w, pos, face, p)
if !used {
return
}
p.Facing = user.Rotation().Direction().Opposite()
place(w, pos, p, user, ctx)
return placed(ctx)
}
// EncodeNBT ...
func (p DecoratedPot) EncodeNBT() map[string]any {
var sherds []string
for _, decoration := range p.Decorations {
if decoration == nil {
sherds = append(sherds, "minecraft:brick")
} else {
name, _ := decoration.EncodeItem()
sherds = append(sherds, name)
}
}
return map[string]any{
"sherds": sherds,
"id": "DecoratedPot",
}
}
// DecodeNBT ...
func (p DecoratedPot) DecodeNBT(data map[string]any) any {
p.Decorations = [4]PotDecoration{}
if sherds := nbtconv.Slice(data, "sherds"); sherds != nil {
for i, name := range sherds {
it, ok := world.ItemByName(name.(string), 0)
if !ok {
panic(fmt.Errorf("unknown item %s", name))
}
decoration, ok := it.(PotDecoration)
if !ok {
panic(fmt.Errorf("item %s is not a pot decoration", name))
}
p.Decorations[i] = decoration
}
}
return p
}
// allDecoratedPots ...
func allDecoratedPots() (pots []world.Block) {
for _, f := range cube.Directions() {
pots = append(pots, DecoratedPot{Facing: f})
}
return
}