@minecraft/server-net 1.0.0-beta.1.21.20-preview.22 → 1.0.0-beta.1.21.3-stable
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/README.md +1 -1
- package/index.d.ts +2 -3
- package/package.json +2 -2
- package/tests.ts +139 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@minecraft/server-net`
|
|
2
2
|
|
|
3
|
-
The `@minecraft/server-net` module contains types for executing HTTP-based requests. This module can only be used on Bedrock Dedicated Server.
|
|
3
|
+
The `@minecraft/server-net` module contains types for executing HTTP-based requests. This module can only be used on Bedrock Dedicated Server.
|
|
4
4
|
|
|
5
5
|
## **NOTE: This version of this module is still in pre-release. It may change or it may be removed in future releases.**
|
|
6
6
|
|
package/index.d.ts
CHANGED
|
@@ -11,14 +11,13 @@
|
|
|
11
11
|
* @packageDocumentation
|
|
12
12
|
* The `@minecraft/server-net` module contains types for
|
|
13
13
|
* executing HTTP-based requests. This module can only be used
|
|
14
|
-
* on Bedrock Dedicated Server.
|
|
15
|
-
* within the Minecraft game client or within Minecraft Realms.
|
|
14
|
+
* on Bedrock Dedicated Server.
|
|
16
15
|
*
|
|
17
16
|
* Manifest Details
|
|
18
17
|
* ```json
|
|
19
18
|
* {
|
|
20
19
|
* "module_name": "@minecraft/server-net",
|
|
21
|
-
* "version": "1.0.0-beta"
|
|
20
|
+
* "version": "1.0.0-beta.1.21.3-stable"
|
|
22
21
|
* }
|
|
23
22
|
* ```
|
|
24
23
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minecraft/server-net",
|
|
3
|
-
"version": "1.0.0-beta.1.21.
|
|
3
|
+
"version": "1.0.0-beta.1.21.3-stable",
|
|
4
4
|
"description": "",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@minecraft/common": "^1.0.0",
|
|
17
|
-
"@minecraft/server-admin": "^1.0.0-beta.1.21.
|
|
17
|
+
"@minecraft/server-admin": "^1.0.0-beta.1.21.3-stable"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT"
|
|
20
20
|
}
|
package/tests.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import * as mc from '@minecraft/server';
|
|
3
|
+
|
|
4
|
+
export async function updateScore(log: (message: string, status?: number) => void, targetLocation: mc.Vector3) {
|
|
5
|
+
const req = new mcnet.HttpRequest('http://localhost:3000/updateScore');
|
|
6
|
+
|
|
7
|
+
req.body = JSON.stringify({
|
|
8
|
+
score: 22,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
req.method = mcnet.HttpRequestMethod.POST;
|
|
12
|
+
req.headers = [
|
|
13
|
+
new mcnet.HttpHeader('Content-Type', 'application/json'),
|
|
14
|
+
new mcnet.HttpHeader('auth', 'my-auth-token'),
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
await mcnet.http.request(req);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default class SampleManager {
|
|
21
|
+
tickCount = 0;
|
|
22
|
+
|
|
23
|
+
_availableFuncs: {
|
|
24
|
+
[name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
pendingFuncs: Array<{
|
|
28
|
+
name: string;
|
|
29
|
+
func: (log: (message: string, status?: number) => void, location: mc.Vector3) => void;
|
|
30
|
+
location: mc.Vector3;
|
|
31
|
+
}> = [];
|
|
32
|
+
|
|
33
|
+
gameplayLogger(message: string, status?: number) {
|
|
34
|
+
if (status !== undefined && status > 0) {
|
|
35
|
+
message = 'SUCCESS: ' + message;
|
|
36
|
+
} else if (status !== undefined && status < 0) {
|
|
37
|
+
message = 'FAIL: ' + message;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.say(message);
|
|
41
|
+
}
|
|
42
|
+
say(message: string) {
|
|
43
|
+
mc.world.getDimension('overworld').runCommand('say ' + message);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
newChatMessage(chatEvent: mc.ChatEvent) {
|
|
47
|
+
const message = chatEvent.message.toLowerCase();
|
|
48
|
+
|
|
49
|
+
if (message.startsWith('howto') && chatEvent.sender) {
|
|
50
|
+
const nearbyBlock = chatEvent.sender.getBlockFromViewVector();
|
|
51
|
+
if (!nearbyBlock) {
|
|
52
|
+
this.gameplayLogger('Please look at the block where you want me to run this.');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const nearbyBlockLoc = nearbyBlock.location;
|
|
57
|
+
const nearbyLoc = { x: nearbyBlockLoc.x, y: nearbyBlockLoc.y + 1, z: nearbyBlockLoc.z };
|
|
58
|
+
|
|
59
|
+
const sampleId = message.substring(5).trim();
|
|
60
|
+
|
|
61
|
+
if (sampleId.length < 2) {
|
|
62
|
+
let availableFuncStr = 'Here is my list of available samples:';
|
|
63
|
+
|
|
64
|
+
for (const sampleFuncKey in this._availableFuncs) {
|
|
65
|
+
availableFuncStr += ' ' + sampleFuncKey;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.say(availableFuncStr);
|
|
69
|
+
} else {
|
|
70
|
+
for (const sampleFuncKey in this._availableFuncs) {
|
|
71
|
+
if (sampleFuncKey.toLowerCase() === sampleId) {
|
|
72
|
+
const sampleFunc = this._availableFuncs[sampleFuncKey];
|
|
73
|
+
|
|
74
|
+
this.runSample(sampleFuncKey + this.tickCount, sampleFunc, nearbyLoc);
|
|
75
|
+
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.say(`I couldn't find the sample '${sampleId}"'`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
runSample(
|
|
86
|
+
sampleId: string,
|
|
87
|
+
snippetFunctions: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>,
|
|
88
|
+
targetLocation: mc.Vector3,
|
|
89
|
+
) {
|
|
90
|
+
for (let i = snippetFunctions.length - 1; i >= 0; i--) {
|
|
91
|
+
this.pendingFuncs.push({ name: sampleId, func: snippetFunctions[i], location: targetLocation });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
worldTick() {
|
|
96
|
+
if (this.tickCount % 10 === 0) {
|
|
97
|
+
if (this.pendingFuncs.length > 0) {
|
|
98
|
+
const funcSet = this.pendingFuncs.pop();
|
|
99
|
+
|
|
100
|
+
if (funcSet) {
|
|
101
|
+
funcSet.func(this.gameplayLogger, funcSet.location);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.tickCount++;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
constructor() {
|
|
110
|
+
this._availableFuncs = {};
|
|
111
|
+
|
|
112
|
+
this.gameplayLogger = this.gameplayLogger.bind(this);
|
|
113
|
+
|
|
114
|
+
mc.world.events.tick.subscribe(this.worldTick.bind(this));
|
|
115
|
+
mc.world.events.chat.subscribe(this.newChatMessage.bind(this));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
registerSamples(sampleSet: {
|
|
119
|
+
[name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>;
|
|
120
|
+
}) {
|
|
121
|
+
for (const sampleKey in sampleSet) {
|
|
122
|
+
if (sampleKey.length > 1 && sampleSet[sampleKey]) {
|
|
123
|
+
this._availableFuncs[sampleKey] = sampleSet[sampleKey];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
import * as mcnet from '@minecraft/server-net'; // keep in for net samples
|
|
130
|
+
|
|
131
|
+
const mojangNetAdminTestFuncs: {
|
|
132
|
+
[name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>;
|
|
133
|
+
} = {
|
|
134
|
+
updateScore: [updateScore],
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export function register(sampleManager: SampleManager) {
|
|
138
|
+
sampleManager.registerSamples(mojangNetAdminTestFuncs);
|
|
139
|
+
}
|