Skip to content

Commit 38e9e50

Browse files
WaitToMove (JaylyDev#261)
I think this could be done in easier way, but i will marge it OK?
1 parent d6e66b5 commit 38e9e50

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

scripts/wait-move/index.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
* @author defowler2005#4812
1111
12-
* @version 1.0.0
12+
* @version 2.0.0
1313
1414
* ---------------------------------------------------------------------------
1515
@@ -34,26 +34,30 @@ import { world, system, Entity } from '@minecraft/server';
3434
*/
3535
export function waitMove(target, x, y, z, callback) {
3636

37-
const t = new Map();
37+
const t = new Map();
3838

39-
t.set(target, [x, y, z]);
39+
t.set(target, [x, y, z]);
4040

41-
system.runInterval(() => {
41+
system.runInterval(() => {
4242

43-
for (const [target, [xOld, yOld, zOld]] of t) {
43+
for (const [target, [xOld, yOld, zOld]] of t) {
4444

45-
const { x: xc, y: yc, z: zc } = target.location;
45+
const { x: xc, y: yc, z: zc } = target.location;
4646

47-
if (xOld !== xc || yOld !== yc || zOld !== zc) {
47+
if (xOld !== xc || yOld !== yc || zOld !== zc) {
4848

49-
t.delete(target);
49+
t.delete(target);
5050

51-
callback(target);
51+
system.run(() => {
5252

53-
}
53+
callback(target);
5454

55-
}
55+
})
5656

57-
})
57+
}
58+
59+
}
60+
61+
})
5862

5963
};

0 commit comments

Comments
 (0)