-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.ts
118 lines (86 loc) · 2.24 KB
/
local.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
109
110
111
112
113
114
115
116
117
118
import { Vec3 } from 'vec3';
import chat from '../ddg.chat/local.js';
import { pose } from '../ddg.pose/local.js';
import proxy from '../internal.proxy/local.js';
export class Core {
public position: Vec3;
public size: Vec3;
constructor(position: Vec3, size: Vec3) {
this.position = position;
this.size = size;
}
public fill(): void {
const size = this.size;
const start = this.position;
const end = start.plus(size);
chat.toServer(
`/fill ${start.toArray().join(' ')} ${end.toArray().join(' ')} command_block`,
);
}
private readonly offset = new Vec3(0, 0, 0);
public run(command: string): void {
const offset = this.offset;
const size = this.size;
offset.x++;
if (offset.x > size.x) {
offset.x = 0;
offset.y++;
}
if (offset.y > size.y) {
offset.y = 0;
offset.z++;
}
if (offset.z > size.z) {
offset.z = 0;
}
const position = this.position.plus(offset);
proxy.writeUpstream('update_command_block', {
location: position,
command,
// 0 = Chain
// 1 = Repeat
// 2 = Impulse
mode: 1,
// 0bXX1 = Track Output
// 0bX1X = Conditional
// 0b1XX = Automatic
flags: 0b100,
});
}
}
export const core = new Core(new Vec3(NaN, 0, NaN), new Vec3(16, 16, 16));
export default core;
pose.bi.on('position', () => {
const position = pose.position.clone();
// no scalar division 😭
position.scale(1 / 16);
position.floor();
position.scale(16);
if (
Math.abs(core.position.x - position.x) < 256 &&
Math.abs(core.position.z - position.z) < 256
)
return;
core.position.x = position.x;
core.position.z = position.z;
core.fill();
});
proxy.downstream.on('respawn', (packet) => {
if (packet.canceled) return;
core.fill();
});
chat.downstream.on('system', (data, packet) => {
if (packet === undefined) return;
if (data.positionId !== 1) return;
let message;
try {
message = JSON.parse(data.formattedMessage);
} catch {
return;
}
if (!('translate' in message)) return;
const translate = message.translate;
if (typeof translate !== 'string') return;
if (translate !== 'advMode.setCommand.success') return;
packet.canceled = true;
});