-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
166 lines (157 loc) · 5.15 KB
/
index.js
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
let x, y, z, viewDistance, minDistance, maxDistance, player, tpDelay, /*typeDelay,*/ chatKey //inputs
//let stepSize, startStep, endStep //derived from input
let generator, done //globals
let robot = require("robotjs")
let sendKeys = require("sendKeys-js")
let prompt = require("prompts")
let iohook = require("iohook")
//let clipboardy = require("clipboardy")
let question = [{
type: "text",
name: "input",
//message: "x y z minDistance maxDistance viewDistance player tpDelay typeDelay chatKey",
message: "x y z minDistance maxDistance viewDistance player tpDelay chatKey",
initial: "0 200 0 0 2048 8 @s 10000 t"
}]
let inputRegex = /^(-?\d+) (\d+) (-?\d+) (\d+) (\d+) (\d+) ([\.\S]+) (\d+) ([\.\S]+)$/
let stop = 1
let typeDelay = 100
setup()
function handler() {
//console.log("handled");
stop *= -1
if (stop != 1) {
run()
}
}
function sleep(delay) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(delay)
}, delay)
})
}
async function setup() {
while (true) {
console.log("")
console.log("To get started, choose a starting position (Center)")
console.log("Make sure that you can see all the corners in your render distance (Even at a 45° angle x-rotation)")
console.log("If not, increase your FOV, or increase your height")
console.log("Recommended: max FOV, height 200, render distance 10")
console.log("If you're using this on a website or server console, I recommend setting the chatKey option to \"null\" (Without \")");
console.log("All options must be entered with a single space separating them")
console.log("")
let input = await prompt(question)
input = input.input.match(inputRegex)
if (input != null) {
input = input.map((x) => {
let y = parseInt(x, 10)
if (y * 1 == y * 1) {
return y
} else {
return x
}
});
[input, x, y, z, minDistance, maxDistance, viewDistance, player, tpDelay, /*typeDelay,*/ chatKey] = input
break;
}
console.log("")
console.log("")
console.log("It seems like you've missed something there... could you please try again?")
}
generator = CommandGenerator(x, y, z, minDistance, maxDistance, viewDistance, player)
done = false
iohook.registerShortcut([52, 29], () => handler())
iohook.start()
console.log("")
console.log("Ready, enter your minecraft world, open the debug-menu (F3), go into flight mode and press Ctrl+. (Control + Dot)")
console.log("Your x-rotation (Penultimate number in the command) will show you the progress in percent (0%-100%)")
console.log("You can pause and continue by pressing Ctrl+.")
console.log("If you don't want to pause but cancel, you can just pause the process and close this window")
console.log("")
}
async function run() {
let time
while (stop != 1 && done == false) {
let command = generator.next()
done = command.done
if (!command.done) {
time = new Date().getTime()
command = command.value
//console.log(command)
await sendCommand(command, chatKey, typeDelay)
time = new Date().getTime() - time
//console.log(time)
//await sendCommand(`/say Progress: ${progress}`, chatKey, typeDelay)
await sleep(tpDelay - time)
}
}
if (done == true) {
iohook.unregisterAllShortcuts()
iohook.stop()
console.log("Done 100%")
console.log("You can close this window now")
process.exit()
}
}
async function sendCommand(command, chatKey, typeDelay) {
robot.setKeyboardDelay(typeDelay)
if (chatKey != "null") {
await robot.keyTap(chatKey)
}
sendKeys.send(command)
//await sleep(typeDelay)
//await sendKeys.send(command)
await sleep(typeDelay)
//sendKeys.sendKeys("{enter}")
await robot.keyTap("enter")
}
function command(x, y, z, player, progress) {
//progress = 360 / progress
return `/execute as ${player} at @s run tp @s ${x} ${y} ${z} ${progress} 90`
}
function* CommandGenerator(x, y, z, minDistance, maxDistance, viewDistance, player) {
function makeCommand(curX, curZ) {
counter++
progress = round(counter / totalCommands * 100, 1)
let realX = x + curX * stepSize
let realZ = z + curZ * stepSize
return command(realX, y, realZ, player, progress)
}
let counter = 0
let progress = 0
let stepSize = viewDistance * 16 * 2
let startStep = Math.round(minDistance / stepSize)
let endStep = -Math.round(-(maxDistance / stepSize))
let totalCommands = ((endStep * 2 + 1) ** 2)
if (startStep != 0) {
totalCommands -= ((startStep - 1) * 2 + 1) ** 2
}
for (let curStep = startStep; curStep <= endStep; curStep++) {
let curX = -curStep
let curZ = -curStep
if (curStep == 0) {
yield makeCommand(curX, curZ)
}
while (curX < curStep) {
yield makeCommand(curX, curZ)
curX += 1
}
while (curZ < curStep) {
yield makeCommand(curX, curZ)
curZ += 1
}
while (curX > -curStep) {
yield makeCommand(curX, curZ)
curX -= 1
}
while (curZ > -curStep) {
yield makeCommand(curX, curZ)
curZ -= 1
}
}
}
function round(number, decimalPlaces) {
let multiplier = Math.pow(10, decimalPlaces || 0)
return Math.round(number * multiplier) / multiplier
}