-
Notifications
You must be signed in to change notification settings - Fork 140
/
carpet.go
83 lines (68 loc) · 1.98 KB
/
carpet.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
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"
)
// Carpet is a colourful block that can be obtained by killing/shearing sheep, or crafted using four string.
type Carpet struct {
carpet
transparent
// Colour is the colour of the carpet.
Colour Colour
}
// FlammabilityInfo ...
func (c Carpet) FlammabilityInfo() FlammabilityInfo {
return newFlammabilityInfo(30, 60, true)
}
// CanDisplace ...
func (Carpet) CanDisplace(b world.Liquid) bool {
_, water := b.(Water)
return water
}
// SideClosed ...
func (Carpet) SideClosed(cube.Pos, cube.Pos, *world.World) bool {
return false
}
// BreakInfo ...
func (c Carpet) BreakInfo() BreakInfo {
return newBreakInfo(0.1, alwaysHarvestable, nothingEffective, oneOf(c))
}
// EncodeItem ...
func (c Carpet) EncodeItem() (name string, meta int16) {
return "minecraft:carpet", int16(c.Colour.Uint8())
}
// EncodeBlock ...
func (c Carpet) EncodeBlock() (name string, properties map[string]interface{}) {
return "minecraft:carpet", map[string]interface{}{"color": c.Colour.String()}
}
// HasLiquidDrops ...
func (Carpet) HasLiquidDrops() bool {
return true
}
// NeighbourUpdateTick ...
func (Carpet) NeighbourUpdateTick(pos, _ cube.Pos, w *world.World) {
if _, ok := w.Block(pos.Add(cube.Pos{0, -1})).(Air); ok {
w.BreakBlockWithoutParticles(pos)
}
}
// UseOnBlock handles not placing carpets on top of air blocks.
func (c Carpet) 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, c)
if !used {
return
}
if _, ok := w.Block((cube.Pos{pos.X(), pos.Y() - 1, pos.Z()})).(Air); ok {
return
}
place(w, pos, c, user, ctx)
return placed(ctx)
}
// allCarpet ...
func allCarpet() (carpets []world.Block) {
for _, c := range Colours() {
carpets = append(carpets, Carpet{Colour: c})
}
return
}