@minecraft/server 1.0.0-internal.00001b39 → 1.0.0-preview.1.19.50.21
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/index.d.ts +116 -13824
- package/package.json +1 -1
- package/tests.ts +65 -49
package/package.json
CHANGED
package/tests.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1
2
|
import * as mc from '@minecraft/server';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
export function createExplosion(log: (message: string, status?: number) => void, targetLocation: mc.Location) {
|
|
5
|
+
const overworld = mc.world.getDimension('overworld');
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
overworld.createExplosion(targetLocation, 10
|
|
7
|
+
log('Creating an explosion of radius 10.');
|
|
8
|
+
overworld.createExplosion(targetLocation, 10);
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
export function createNoBlockExplosion(targetLocation: mc.Location) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
// Start by exploding without breaking blocks
|
|
13
|
-
explosionOptions.breaksBlocks = false;
|
|
11
|
+
export function createNoBlockExplosion(log: (message: string, status?: number) => void, targetLocation: mc.Location) {
|
|
12
|
+
const overworld = mc.world.getDimension('overworld');
|
|
14
13
|
|
|
15
14
|
const explodeNoBlocksLoc = new mc.Location(
|
|
16
15
|
Math.floor(targetLocation.x + 1),
|
|
@@ -18,43 +17,51 @@ export function createNoBlockExplosion(targetLocation: mc.Location) {
|
|
|
18
17
|
Math.floor(targetLocation.z + 1),
|
|
19
18
|
);
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
log('Creating an explosion of radius 15 that does not break blocks.');
|
|
21
|
+
overworld.createExplosion(explodeNoBlocksLoc, 15, { breaksBlocks: false });
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function createFireAndWaterExplosions(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
export function createFireAndWaterExplosions(
|
|
25
|
+
log: (message: string, status?: number) => void,
|
|
26
|
+
targetLocation: mc.Location,
|
|
27
|
+
) {
|
|
28
|
+
const overworld = mc.world.getDimension('overworld');
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
fireExplosionOptions.causesFire = true;
|
|
31
|
-
|
|
32
|
-
overworld.createExplosion(explosionLoc, 15, fireExplosionOptions);
|
|
33
|
-
const waterExplosionOptions = new mc.ExplosionOptions();
|
|
30
|
+
const explosionLoc = new mc.Location(targetLocation.x + 0.5, targetLocation.y + 0.5, targetLocation.z + 0.5);
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
log('Creating an explosion of radius 15 that causes fire.');
|
|
33
|
+
overworld.createExplosion(explosionLoc, 15, { causesFire: true });
|
|
37
34
|
|
|
38
35
|
const belowWaterLoc = new mc.Location(targetLocation.x + 3, targetLocation.y + 1, targetLocation.z + 3);
|
|
39
36
|
|
|
40
|
-
|
|
37
|
+
log('Creating an explosion of radius 10 that can go underwater.');
|
|
38
|
+
overworld.createExplosion(belowWaterLoc, 10, { allowUnderwater: true });
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
export function itemStacks() {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
41
|
+
export function itemStacks(log: (message: string, status?: number) => void, targetLocation: mc.Location) {
|
|
42
|
+
const overworld = mc.world.getDimension('overworld');
|
|
43
|
+
|
|
44
|
+
const oneItemLoc = new mc.BlockLocation(targetLocation.x + targetLocation.y + 3, 2, targetLocation.z + 1);
|
|
45
|
+
const fiveItemsLoc = new mc.BlockLocation(targetLocation.x + 1, targetLocation.y + 2, targetLocation.z + 1);
|
|
46
|
+
const diamondPickaxeLoc = new mc.BlockLocation(targetLocation.x + 2, targetLocation.y + 2, targetLocation.z + 4);
|
|
47
47
|
|
|
48
48
|
const oneEmerald = new mc.ItemStack(mc.MinecraftItemTypes.emerald, 1, 0);
|
|
49
49
|
const onePickaxe = new mc.ItemStack(mc.MinecraftItemTypes.diamondPickaxe, 1, 0);
|
|
50
50
|
const fiveEmeralds = new mc.ItemStack(mc.MinecraftItemTypes.emerald, 5, 0);
|
|
51
51
|
|
|
52
|
+
log(`Spawning an emerald at (${oneItemLoc.x}, ${oneItemLoc.y}, ${oneItemLoc.z})`);
|
|
52
53
|
overworld.spawnItem(oneEmerald, oneItemLoc);
|
|
54
|
+
|
|
55
|
+
log(`Spawning five emeralds at (${fiveItemsLoc.x}, ${fiveItemsLoc.y}, ${fiveItemsLoc.z})`);
|
|
53
56
|
overworld.spawnItem(fiveEmeralds, fiveItemsLoc);
|
|
57
|
+
|
|
58
|
+
log(`Spawning a diamond pickaxe at (${diamondPickaxeLoc.x}, ${diamondPickaxeLoc.y}, ${diamondPickaxeLoc.z})`);
|
|
54
59
|
overworld.spawnItem(onePickaxe, diamondPickaxeLoc);
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
export function quickFoxLazyDog(log: (message: string, status?: number) => void, targetLocation: mc.Location) {
|
|
63
|
+
const overworld = mc.world.getDimension('overworld');
|
|
64
|
+
|
|
58
65
|
const fox = overworld.spawnEntity(
|
|
59
66
|
'minecraft:fox',
|
|
60
67
|
new mc.BlockLocation(targetLocation.x + 1, targetLocation.y + 2, targetLocation.z + 3),
|
|
@@ -71,20 +78,21 @@ export function quickFoxLazyDog(log: (message: string, status?: number) => void,
|
|
|
71
78
|
log('Created a sneaking wolf.', 1);
|
|
72
79
|
}
|
|
73
80
|
|
|
74
|
-
export function runEntityCreatedEvent(log: (message: string, status?: number) => void) {
|
|
81
|
+
export function runEntityCreatedEvent(log: (message: string, status?: number) => void, targetLocation: mc.Location) {
|
|
75
82
|
// register a new function that is called when a new entity is created.
|
|
76
|
-
|
|
83
|
+
mc.world.events.entityCreate.subscribe((entityEvent: mc.EntityCreateEvent) => {
|
|
77
84
|
if (entityEvent && entityEvent.entity) {
|
|
78
85
|
log(`New entity of type '${entityEvent.entity}' created!`, 1);
|
|
79
86
|
} else {
|
|
80
87
|
log(`The entity event didn't work as expected.`, -1);
|
|
81
88
|
}
|
|
82
89
|
});
|
|
83
|
-
mc.world.events.entityCreate.unsubscribe(entityCreatedCallback);
|
|
84
90
|
}
|
|
85
91
|
|
|
86
|
-
export function createOldHorse(targetLocation: mc.Location) {
|
|
87
|
-
|
|
92
|
+
export function createOldHorse(log: (message: string, status?: number) => void, targetLocation: mc.Location) {
|
|
93
|
+
const overworld = mc.world.getDimension('overworld');
|
|
94
|
+
|
|
95
|
+
log("Create a horse and triggering the 'ageable_grow_up' event, ensuring the horse is created as an adult");
|
|
88
96
|
overworld.spawnEntity('minecraft:horse<minecraft:ageable_grow_up>', targetLocation);
|
|
89
97
|
}
|
|
90
98
|
|
|
@@ -95,27 +103,31 @@ export function pistonEvent(log: (message: string, status?: number) => void, tar
|
|
|
95
103
|
Math.floor(targetLocation.z) + 1,
|
|
96
104
|
);
|
|
97
105
|
|
|
98
|
-
|
|
99
|
-
(pistonEvent
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
mc.world.events.beforePistonActivate.unsubscribe(pistonCallback);
|
|
106
|
+
mc.world.events.beforePistonActivate.subscribe((pistonEvent: mc.BeforePistonActivateEvent) => {
|
|
107
|
+
if (pistonEvent.piston.location.equals(pistonLoc)) {
|
|
108
|
+
log('Cancelling piston event');
|
|
109
|
+
pistonEvent.cancel = true;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
export function spawnItem(log: (message: string, status?: number) => void, targetLocation: mc.Location) {
|
|
111
115
|
const featherItem = new mc.ItemStack(mc.MinecraftItemTypes.feather, 1, 0);
|
|
112
116
|
|
|
113
117
|
overworld.spawnItem(featherItem, targetLocation);
|
|
114
|
-
log(
|
|
118
|
+
log(`New feather created at ${targetLocation.x}, ${targetLocation.y}, ${targetLocation.z}!`);
|
|
115
119
|
}
|
|
116
120
|
|
|
117
|
-
export function testThatEntityIsFeatherItem(
|
|
118
|
-
|
|
121
|
+
export function testThatEntityIsFeatherItem(
|
|
122
|
+
log: (message: string, status?: number) => void,
|
|
123
|
+
targetLocation: mc.Location,
|
|
124
|
+
) {
|
|
125
|
+
const overworld = mc.world.getDimension('overworld');
|
|
126
|
+
|
|
127
|
+
const items = overworld.getEntities({
|
|
128
|
+
location: targetLocation,
|
|
129
|
+
maxDistance: 20,
|
|
130
|
+
});
|
|
119
131
|
|
|
120
132
|
for (const item of items) {
|
|
121
133
|
const itemComp = item.getComponent('item') as any;
|
|
@@ -129,16 +141,20 @@ export function testThatEntityIsFeatherItem(log: (message: string, status?: numb
|
|
|
129
141
|
}
|
|
130
142
|
|
|
131
143
|
export function trapTick() {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
mc.world.events.tick.subscribe(() => {
|
|
135
|
-
ticks++;
|
|
144
|
+
const overworld = mc.world.getDimension('overworld');
|
|
136
145
|
|
|
146
|
+
try {
|
|
137
147
|
// Minecraft runs at 20 ticks per second
|
|
138
148
|
if (ticks % 1200 === 0) {
|
|
139
|
-
overworld.
|
|
149
|
+
overworld.runCommandAsync('say Another minute passes...');
|
|
140
150
|
}
|
|
141
|
-
|
|
151
|
+
|
|
152
|
+
ticks++;
|
|
153
|
+
} catch (e) {
|
|
154
|
+
console.warn('Error: ' + e);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
mc.system.run(trapTick);
|
|
142
158
|
}
|
|
143
159
|
|
|
144
160
|
export default class SampleManager {
|