forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anvil.go
103 lines (89 loc) · 2.85 KB
/
anvil.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
package block
import (
"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/item"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/world"
"github.com/Adrian8115/dragonfly-Amethyst-Protocol/server/world/sound"
"github.com/go-gl/mathgl/mgl64"
)
// Anvil is a block that allows players to repair items, rename items, and combine enchantments.
type Anvil struct {
gravityAffected
transparent
// Type is the type of anvil.
Type AnvilType
// Facing is the direction that the anvil is facing.
Facing cube.Direction
}
// Model ...
func (a Anvil) Model() world.BlockModel {
return model.Anvil{Facing: a.Facing}
}
// BreakInfo ...
func (a Anvil) BreakInfo() BreakInfo {
return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(a)).withBlastResistance(6000)
}
// Activate ...
func (Anvil) Activate(pos cube.Pos, _ cube.Face, _ *world.World, u item.User, _ *item.UseContext) bool {
if opener, ok := u.(ContainerOpener); ok {
opener.OpenBlockContainer(pos)
return true
}
return false
}
// UseOnBlock ...
func (a Anvil) 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, a)
if !used {
return
}
a.Facing = user.Rotation().Direction().RotateRight()
place(w, pos, a, user, ctx)
return placed(ctx)
}
// NeighbourUpdateTick ...
func (a Anvil) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
a.fall(a, pos, w)
}
// Damage returns the damage per block fallen of the anvil and the maximum damage the anvil can deal.
func (Anvil) Damage() (damagePerBlock, maxDamage float64) {
return 2, 40
}
// Break breaks the anvil and moves it to the next damage stage. If the anvil is at the last damage stage, it will be
// destroyed.
func (a Anvil) Break() world.Block {
switch a.Type {
case UndamagedAnvil():
a.Type = SlightlyDamagedAnvil()
case SlightlyDamagedAnvil():
a.Type = VeryDamagedAnvil()
case VeryDamagedAnvil():
return Air{}
}
return a
}
// Landed is called when a falling anvil hits the ground, used to, for example, play a sound.
func (Anvil) Landed(w *world.World, pos cube.Pos) {
w.PlaySound(pos.Vec3Centre(), sound.AnvilLand{})
}
// EncodeItem ...
func (a Anvil) EncodeItem() (name string, meta int16) {
return "minecraft:anvil", int16(a.Type.Uint8() * 4)
}
// EncodeBlock ...
func (a Anvil) EncodeBlock() (string, map[string]any) {
return "minecraft:anvil", map[string]any{
"damage": a.Type.String(),
"minecraft:cardinal_direction": a.Facing.String(),
}
}
// allAnvils ...
func allAnvils() (anvils []world.Block) {
for _, t := range AnvilTypes() {
for _, d := range cube.Directions() {
anvils = append(anvils, Anvil{Type: t, Facing: d})
}
}
return
}