forked from ReWrite-Media/hoc2020-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.ts
137 lines (116 loc) · 2.7 KB
/
custom.ts
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// global variables
const directions = [
FORWARD,
BACK,
LEFT,
RIGHT,
UP,
DOWN
];
const turns = [
LEFT_TURN,
RIGHT_TURN
]
//% block="HOC 2020" weight=200 color=#d83b01
namespace hoc2020 {
/**
* Agent Interact Forward
*/
//% block="toggle lever"
export function flipLever() {
agent.interact(FORWARD)
}
/**
* Agent Place Fence
*/
//% block="place fence behind"
export function placeFence() {
agent.setItem(OAK_FENCE, 1, 1)
agent.place(BACK)
}
/**
* Agent place soil
*/
//% block="till and move forward %n times"
//% n.defl=1
export function tillSoil(n: number): void{
for (let i = 0; i < n; i++){
agent.till(UP)
player.execute(
"execute @c ~ ~ ~ detect ~ ~-1 ~ dirt 0 setblock ~ ~-1 ~ farmland"
)
agent.move(FORWARD,1)
}
}
/**
* Agent place wood down
*/
//% block="move and place wood %n times"
//% n.defl=1
export function placePlanks(n: number): void{
for (let i = 0; i < n; i++){
agent.move(FORWARD, 1)
agent.setItem(PLANKS_OAK, 1, 1)
agent.place(DOWN)
}
}
/**
* Agent place rail down
*/
//% block="place rail below"
export function placeRails(){
agent.setItem(RAIL, 1, 1)
agent.place(DOWN)
}
/**
* Agent move forward with pause
*/
//% block="lead ravager %n forward"
//% n.defl=1
export function leadRavager(n: number): void{
for (let i = 0; i < n; i++){
agent.move(FORWARD,1)
loops.pause(100)
}
}
/**
* Agent move
*/
//% block="agent move %d by %n"
//% n.defl=1
export function moveAgent(d: SixDirection, n: number): void{
for (let i = 0; i < n; i++){
const direction = directions[d];
agent.move(direction,1)
}
}
/**
* Agent move up
*/
//% block="agent climb %n up"
//% n.defl=1
export function agentClimb(n: number): void{
for (let i = 0; i < n; i++){
agent.move(UP,1)
}
}
/**
* Give player sappling
*/
//% block="accept gift"
export function acceptGift(){
mobs.give(
mobs.target(LOCAL_PLAYER),
OAK_SAPLING,
1
)
}
/**
* Give player sappling
*/
//% block="turn agent %t"
export function turnAgent(t: TurnDirection): void{
const turn = turns[t];
agent.turn(turn);
}
}