forked from microsoft/pxt-minecraft-HOC2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.ts
108 lines (101 loc) · 3.58 KB
/
extension.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
/**
* Writing data for hacking stem experiments
*/
//% weight=94 color=#EC7505 icon="\uf1b3"
namespace hourOfCode {
let targetsL4 = 5
let targetsL5 = 8
let targetsL6 = 12
let hazardA = 31 // fern for HoC (variants: tallgrass)
let hazardB = 175 // double tallgrass for HoC (variants: peony, rose bush, large fern, lilac, sunflower)
let airBlock = Block.Air
let completionBlockA = Block.DiamondBlock
let completionBlockB = Block.GoldBlock
let completionPosition = [positions.createWorld(-75, 65, -122), positions.createWorld(-57, 57, -63), positions.createWorld(-4, 32, 199)]
let brokeNonHazard = false
//% block="agent detect dry fern %dir"
//% weight=80
export function agentDetectDryFern(dir: SixDirection) {
return agent.inspect(AgentInspection.Block, dir) == hazardA
}
//% block="agent detect dry grass %dir"
//% weight=80
export function agentDetectDryGrass(dir: SixDirection) {
return agent.inspect(AgentInspection.Block, dir) == hazardB
}
//% block="agent analyze %dir"
//% weight=70
export function agentAnalyze(dir: SixDirection) {
let targetBlock = agent.inspect(AgentInspection.Block, dir)
if (targetBlock == hazardA || targetBlock == hazardB) {
mobs.execute(
mobs.target(TargetSelectorKind.NearestPlayer),
positions.create(0, 0, 0),
"playsound random.levelup @p"
)
if (targetBlock == hazardA) {
blocks.place(completionBlockA, completionPosition[0])
} else {
blocks.place(completionBlockB, completionPosition[0])
}
}
}
//% block="hazards remain"
//% weight=45
export function hazardsRemainL4() {
if (targetsL4 == 0 && !brokeNonHazard) {
blocks.place(completionBlockA, completionPosition[1])
}
return targetsL4 > 0
}
//% block="agent destroy %dir"
//% weight=40
export function agentDestroyL4(dir: SixDirection) {
loops.pause(500)
let targetBlock4 = agent.inspect(AgentInspection.Block, dir)
if (targetBlock4 == hazardA || targetBlock4 == hazardB) {
targetsL4 -= 1
} else if (targetBlock4 != airBlock) {
brokeNonHazard = true
}
agent.destroy(dir)
}
//% block="hazards remain"
//% weight=55
export function hazardsRemainL5() {
if (targetsL5 == 0 && !brokeNonHazard) {
blocks.place(completionBlockA, completionPosition[2])
}
return targetsL5 > 0
}
//% block="agent destroy %dir"
//% weight=50
export function agentDestroyL5(dir: SixDirection) {
let targetBlock5 = agent.inspect(AgentInspection.Block, dir)
if (targetBlock5 == hazardA || targetBlock5 == hazardB) {
targetsL5 -= 1
} else if (targetBlock5 != airBlock) {
brokeNonHazard = true
}
agent.destroy(dir)
}
//% block="hazards remain"
//% weight=65
export function hazardsRemainL6() {
if (targetsL6 == 0 && !brokeNonHazard) {
blocks.place(completionBlockB, completionPosition[2])
}
return targetsL6 > 0
}
//% block="agent destroy %dir"
//% weight=60
export function agentDestroyL6(dir: SixDirection) {
let targetBlock6 = agent.inspect(AgentInspection.Block, dir)
if (targetBlock6 == hazardA || targetBlock6 == hazardB) {
targetsL6 -= 1
} else if (targetBlock6 != airBlock) {
brokeNonHazard = true
}
agent.destroy(dir)
}
}