1.21.5
This commit is contained in:
parent
38f19ca5d5
commit
ed130373fe
1 changed files with 27 additions and 29 deletions
56
core.js
56
core.js
|
@ -2,10 +2,10 @@ const Afunction = require('../util/function.js');
|
|||
module.exports = {
|
||||
inject: function(bot) {
|
||||
|
||||
const Ypos = Afunction.math.random(-32, 128);
|
||||
const Ypos = Afunction.math.random(-32, -32); // random!
|
||||
bot.task.data.needRefillCore = true;
|
||||
bot.task.data.nbtQueries = {};
|
||||
bot.task.data.commandBlockNeverRepeating = new Map(); // map support object!
|
||||
bot.task.timeout.commandBlockNeverRepeating = new Map();
|
||||
bot.task.timeout.nbtQueries = {};
|
||||
|
||||
if (bot.task.data.serverName === 'Chipmunk25570') bot.task.data.coreConfig.area.end.y = 0;
|
||||
|
@ -43,7 +43,7 @@ module.exports = {
|
|||
bot.on('block_change', (packet) => {
|
||||
if (packet.type === 0 || !isValidBlockType(packet.type)) {
|
||||
const corePos = bot.core.position;
|
||||
if (!corePos) return bot.task.data.needRefillCore === true;
|
||||
if (!corePos) return bot.task.data.needRefillCore = true;
|
||||
if (isCorePosWithinBounds(packet.location, corePos)) {
|
||||
bot.task.data.needRefillCore = true;
|
||||
}
|
||||
|
@ -88,9 +88,7 @@ module.exports = {
|
|||
return count + (isCorePosWithinBounds({ x: blockX, y: blockY, z: blockZ }, corepos) ? 1 : 0);
|
||||
}, 0);
|
||||
|
||||
if (coreCount < coreSize) {
|
||||
bot.task.data.needRefillCore = true;
|
||||
} else bot.task.data.needRefillCore = false;
|
||||
bot.task.data.needRefillCore = coreCount < coreSize;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -299,27 +297,30 @@ module.exports = {
|
|||
bot.write("update_command_block", {
|
||||
command: command,
|
||||
location: CommandBlockLocation,
|
||||
mode: 2,
|
||||
mode: 1,
|
||||
flags: 5
|
||||
});
|
||||
|
||||
bot.task.data.commandBlockNeverRepeating.set(CommandBlockLocation, setTimeout(() => {
|
||||
bot.write("update_command_block", {
|
||||
command: "",
|
||||
location: CommandBlockLocation,
|
||||
mode: 0,
|
||||
flags: 1
|
||||
});
|
||||
bot.task.data.commandBlockNeverRepeating.delete(CommandBlockLocation);
|
||||
}, 500));
|
||||
if (bot.task.timeout.commandBlockNeverRepeating !== undefined) {
|
||||
clearTimeout(bot.task.timeout.commandBlockNeverRepeating.get(CommandBlockLocation));
|
||||
bot.task.timeout.commandBlockNeverRepeating.set(CommandBlockLocation, setTimeout(() => {
|
||||
bot.write("update_command_block", {
|
||||
command: "",
|
||||
location: CommandBlockLocation,
|
||||
mode: 0,
|
||||
flags: 1
|
||||
});
|
||||
bot.task.timeout.commandBlockNeverRepeating.delete(CommandBlockLocation);
|
||||
}, 10000));
|
||||
}
|
||||
|
||||
if (!output) return Promise.resolve(undefined);
|
||||
let outputRelativePosition = JSON.parse(JSON.stringify(CommandBlockLocation)); // prevent relativePosition change pos
|
||||
return new Promise((resolve) => {
|
||||
if (!bot?.task?.data?.nbtQueries) return resolve(undefined);
|
||||
if (!bot?.task?.timeout?.nbtQueries) return resolve(undefined);
|
||||
const secretString = Afunction.generateRandomString(30, 1, 2, 3);
|
||||
bot.task.data.nbtQueries[secretString] = { resolve };
|
||||
bot.core.run(`minecraft:tellraw @a[name="${bot.username}"] {"translate":"NilBot_CommandBlock_Output %s %s","with":["${secretString}",{"nbt":"LastOutput","block":"${CommandBlockLocation.x} ${CommandBlockLocation.y} ${CommandBlockLocation.z}"}]}`);
|
||||
bot.core.run(`minecraft:tellraw @a[name="${bot.username}"] {"translate":"NilBot_CommandBlock_Output %s %s","with":["${secretString}",{"nbt":"LastOutput","block":"${CommandBlockLocation.x} ${CommandBlockLocation.y} ${CommandBlockLocation.z}","interpret":true}]}`);
|
||||
bot.task.timeout.nbtQueries[secretString] = setTimeout(() => {
|
||||
resolve(undefined);
|
||||
delete bot.task.data.nbtQueries[secretString];
|
||||
|
@ -329,22 +330,19 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
bot.task.data.core = bot.core;
|
||||
// bot.task.data.core = bot.core;
|
||||
|
||||
// end core
|
||||
|
||||
bot.on("custom_systemChat", (_, systemChat) => {
|
||||
let jsonMsg = systemChat.jsonMsg.message;
|
||||
if (jsonMsg && jsonMsg.translate === 'NilBot_CommandBlock_Output %s %s' && typeof jsonMsg.with?.[0] === "string" && typeof jsonMsg.with?.[1] === "string") {
|
||||
if (bot?.task?.data?.nbtQueries?.[jsonMsg?.with?.[0]]) {
|
||||
clearTimeout(bot.task.timeout.nbtQueries[jsonMsg.with[0]])
|
||||
delete bot.task.timeout.nbtQueries[jsonMsg.with[0]]
|
||||
try { // possible if jsonMsg.with[1] is empty, not undefined. lazy fix
|
||||
bot.task.data.nbtQueries[jsonMsg.with[0]].resolve(JSON.parse(jsonMsg.with[1]));
|
||||
} catch {
|
||||
bot.task.data.nbtQueries[jsonMsg.with[0]].resolve(undefined);
|
||||
}
|
||||
delete bot.task.data.nbtQueries[jsonMsg.with[0]];
|
||||
if (jsonMsg.translate === 'NilBot_CommandBlock_Output %s %s' && typeof jsonMsg.with?.[0]?.text === "string" && typeof jsonMsg.with?.[1] === "object") {
|
||||
const secretString = jsonMsg.with[0].text;
|
||||
if (bot?.task?.timeout?.nbtQueries?.[secretString]) {
|
||||
clearTimeout(bot.task.timeout.nbtQueries[secretString])
|
||||
delete bot.task.timeout.nbtQueries[secretString]
|
||||
bot.task.data.nbtQueries[secretString].resolve(jsonMsg.with[1]);
|
||||
delete bot.task.data.nbtQueries[secretString];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue