-
Notifications
You must be signed in to change notification settings - Fork 150
/
shears.go
69 lines (58 loc) · 1.59 KB
/
shears.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
package item
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
)
// Shears is a tool used to shear sheep, mine a few types of blocks, and carve pumpkins.
type Shears struct{}
// UseOnBlock ...
func (s Shears) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, _ User, ctx *UseContext) bool {
if face == cube.FaceUp || face == cube.FaceDown {
// Pumpkins can only be carved when one of the horizontal faces is clicked.
return false
}
if c, ok := w.Block(pos).(carvable); ok {
if res, ok := c.Carve(face); ok {
// TODO: Drop pumpkin seeds.
w.SetBlock(pos, res, nil)
ctx.DamageItem(1)
return true
}
}
return false
}
// carvable represents a block that may be carved by using shears on it.
type carvable interface {
// Carve returns the resulting block of carving this block. If carving it has no result, Carve returns false.
Carve(f cube.Face) (world.Block, bool)
}
// ToolType ...
func (s Shears) ToolType() ToolType {
return TypeShears
}
// HarvestLevel ...
func (s Shears) HarvestLevel() int {
return 1
}
// BaseMiningEfficiency ...
func (s Shears) BaseMiningEfficiency(world.Block) float64 {
return 1.5
}
// DurabilityInfo ...
func (s Shears) DurabilityInfo() DurabilityInfo {
return DurabilityInfo{
MaxDurability: 238,
BrokenItem: simpleItem(Stack{}),
AttackDurability: 0,
BreakDurability: 1,
}
}
// MaxCount ...
func (s Shears) MaxCount() int {
return 1
}
// EncodeItem ...
func (s Shears) EncodeItem() (name string, meta int16) {
return "minecraft:shears", 0
}