@minecraft/server-gametest 1.0.0-beta.00001b01
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +23 -0
- package/README.md +9 -0
- package/index.d.ts +2065 -0
- package/package.json +19 -0
- package/tests.ts +140 -0
- package/tsconfig.json +20 -0
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@minecraft/server-gametest",
|
|
3
|
+
"version": "1.0.0-beta.00001b01",
|
|
4
|
+
"description": "",
|
|
5
|
+
"contributors": [
|
|
6
|
+
{
|
|
7
|
+
"name": "Jake Shirley",
|
|
8
|
+
"email": "jake@xbox.com"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "Mike Ammerlaan",
|
|
12
|
+
"email": "mikeam@microsoft.com"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@minecraft/server": "1.0.0-beta.00001b01"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT"
|
|
19
|
+
}
|
package/tests.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as mc from '@minecraft/server';
|
|
2
|
+
|
|
3
|
+
export function simpleMobTest() {
|
|
4
|
+
gt.register('StarterTests', 'simpleMobTest', (test: gt.Test) => {
|
|
5
|
+
const attackerId = 'fox';
|
|
6
|
+
const victimId = 'chicken';
|
|
7
|
+
|
|
8
|
+
test.spawn(attackerId, new mc.BlockLocation(5, 2, 5));
|
|
9
|
+
test.spawn(victimId, new mc.BlockLocation(2, 2, 2));
|
|
10
|
+
|
|
11
|
+
test.assertEntityPresentInArea(victimId, true);
|
|
12
|
+
|
|
13
|
+
test.succeedWhen(() => {
|
|
14
|
+
test.assertEntityPresentInArea(victimId, false);
|
|
15
|
+
});
|
|
16
|
+
})
|
|
17
|
+
.maxTicks(400)
|
|
18
|
+
.structureName('gametests:mediumglass');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default class SampleManager {
|
|
22
|
+
tickCount = 0;
|
|
23
|
+
|
|
24
|
+
_availableFuncs: {
|
|
25
|
+
[name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Location) => void>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
pendingFuncs: Array<{
|
|
29
|
+
name: string;
|
|
30
|
+
func: (log: (message: string, status?: number) => void, location: mc.Location) => void;
|
|
31
|
+
location: mc.Location;
|
|
32
|
+
}> = [];
|
|
33
|
+
|
|
34
|
+
gameplayLogger(message: string, status?: number) {
|
|
35
|
+
if (status !== undefined && status > 0) {
|
|
36
|
+
message = 'SUCCESS: ' + message;
|
|
37
|
+
} else if (status !== undefined && status < 0) {
|
|
38
|
+
message = 'FAIL: ' + message;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.say(message);
|
|
42
|
+
}
|
|
43
|
+
say(message: string) {
|
|
44
|
+
mc.world.getDimension('overworld').runCommand('say ' + message);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
newChatMessage(chatEvent: mc.ChatEvent) {
|
|
48
|
+
const message = chatEvent.message.toLowerCase();
|
|
49
|
+
|
|
50
|
+
if (message.startsWith('howto') && chatEvent.sender) {
|
|
51
|
+
const nearbyBlock = chatEvent.sender.getBlockFromViewVector();
|
|
52
|
+
if (!nearbyBlock) {
|
|
53
|
+
this.gameplayLogger('Please look at the block where you want me to run this.');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const nearbyBlockLoc = nearbyBlock.location;
|
|
58
|
+
const nearbyLoc = new mc.Location(nearbyBlockLoc.x, nearbyBlockLoc.y + 1, nearbyBlockLoc.z);
|
|
59
|
+
|
|
60
|
+
const sampleId = message.substring(5).trim();
|
|
61
|
+
|
|
62
|
+
if (sampleId.length < 2) {
|
|
63
|
+
let availableFuncStr = 'Here is my list of available samples:';
|
|
64
|
+
|
|
65
|
+
for (const sampleFuncKey in this._availableFuncs) {
|
|
66
|
+
availableFuncStr += ' ' + sampleFuncKey;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.say(availableFuncStr);
|
|
70
|
+
} else {
|
|
71
|
+
for (const sampleFuncKey in this._availableFuncs) {
|
|
72
|
+
if (sampleFuncKey.toLowerCase() === sampleId) {
|
|
73
|
+
const sampleFunc = this._availableFuncs[sampleFuncKey];
|
|
74
|
+
|
|
75
|
+
this.runSample(sampleFuncKey + this.tickCount, sampleFunc, nearbyLoc);
|
|
76
|
+
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.say(`I couldn't find the sample '${sampleId}"'`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
runSample(
|
|
87
|
+
sampleId: string,
|
|
88
|
+
snippetFunctions: Array<(log: (message: string, status?: number) => void, location: mc.Location) => void>,
|
|
89
|
+
targetLocation: mc.Location,
|
|
90
|
+
) {
|
|
91
|
+
for (let i = snippetFunctions.length - 1; i >= 0; i--) {
|
|
92
|
+
this.pendingFuncs.push({ name: sampleId, func: snippetFunctions[i], location: targetLocation });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
worldTick() {
|
|
97
|
+
if (this.tickCount % 10 === 0) {
|
|
98
|
+
if (this.pendingFuncs.length > 0) {
|
|
99
|
+
const funcSet = this.pendingFuncs.pop();
|
|
100
|
+
|
|
101
|
+
if (funcSet) {
|
|
102
|
+
funcSet.func(this.gameplayLogger, funcSet.location);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.tickCount++;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
constructor() {
|
|
111
|
+
this._availableFuncs = {};
|
|
112
|
+
|
|
113
|
+
this.gameplayLogger = this.gameplayLogger.bind(this);
|
|
114
|
+
|
|
115
|
+
mc.world.events.tick.subscribe(this.worldTick.bind(this));
|
|
116
|
+
mc.world.events.chat.subscribe(this.newChatMessage.bind(this));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
registerSamples(sampleSet: {
|
|
120
|
+
[name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Location) => void>;
|
|
121
|
+
}) {
|
|
122
|
+
for (const sampleKey in sampleSet) {
|
|
123
|
+
if (sampleKey.length > 1 && sampleSet[sampleKey]) {
|
|
124
|
+
this._availableFuncs[sampleKey] = sampleSet[sampleKey];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
import * as gt from '@minecraft/server-gametest';
|
|
131
|
+
|
|
132
|
+
const mojangGameTestFuncs: {
|
|
133
|
+
[name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Location) => void>;
|
|
134
|
+
} = {
|
|
135
|
+
simpleMobTest: [simpleMobTest],
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export function register(sampleManager: SampleManager) {
|
|
139
|
+
sampleManager.registerSamples(mojangGameTestFuncs);
|
|
140
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"lib": ["es6"],
|
|
5
|
+
"target": "es6",
|
|
6
|
+
"forceConsistentCasingInFileNames": true,
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"noImplicitAny": true,
|
|
9
|
+
"noImplicitThis": true,
|
|
10
|
+
"strictFunctionTypes": true,
|
|
11
|
+
"strictNullChecks": true,
|
|
12
|
+
"baseUrl": "../",
|
|
13
|
+
"typeRoots": ["../"],
|
|
14
|
+
"types": []
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.d.ts",
|
|
18
|
+
"tests.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|