Update util/core.js
This commit is contained in:
parent
f2f1d9b2c3
commit
87a10ab00c
1 changed files with 101 additions and 72 deletions
55
util/core.js
55
util/core.js
|
@ -1,6 +1,8 @@
|
|||
const Vec3 = require('vec3').Vec3;
|
||||
const Vec3 = require("vec3").Vec3;
|
||||
const { MessageBuilder } = require("prismarine-chat")("1.19.4");
|
||||
|
||||
const { Tellraw, Text } = require("./tellrawBuilder.js");
|
||||
|
||||
class CoreClass {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
|
@ -10,17 +12,17 @@ class CoreClass {
|
|||
this.totalCommandsRun = 0;
|
||||
this.startTime = Date.now();
|
||||
this.transaction_id = [];
|
||||
this.coreSize = require('../config.json').core;
|
||||
this.coreSize = require("../config.json").core;
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
refill() {
|
||||
const config = require('../config.json');
|
||||
const config = require("../config.json");
|
||||
const pos = this.client.entity?.position; // Ensure entity exists before accessing position
|
||||
this.commandBlocks = [];
|
||||
|
||||
// Check if the bot's position is defined
|
||||
if (!pos || pos.x === 0 && pos.y === 0 && pos.z === 0) {
|
||||
if (!pos || (pos.x === 0 && pos.y === 0 && pos.z === 0)) {
|
||||
setTimeout(() => this.refill(), 650);
|
||||
return;
|
||||
}
|
||||
|
@ -31,11 +33,13 @@ class CoreClass {
|
|||
z: Math.floor(pos.z - (this.coreSize.depth - 1) / 2),
|
||||
x2: Math.floor(pos.x + (this.coreSize.width - 1) / 2),
|
||||
y2: Math.floor(config.core.y + (this.coreSize.height - 1) / 2),
|
||||
z2: Math.floor(pos.z + (this.coreSize.depth - 1) / 2)
|
||||
z2: Math.floor(pos.z + (this.coreSize.depth - 1) / 2),
|
||||
};
|
||||
|
||||
this.corepos = { x: core.x, y: core.y, z: core.z };
|
||||
this.client.chat(`/fill ${core.x} ${core.y} ${core.z} ${core.x2} ${core.y2} ${core.z2} minecraft:repeating_command_block{CustomName:'{"text":"Ibot core from ImGloriz","color":"cyan"}'} replace`);
|
||||
this.client.chat(
|
||||
`/fill ${core.x} ${core.y} ${core.z} ${core.x2} ${core.y2} ${core.z2} minecraft:repeating_command_block{CustomName:'{"text":"Ibot core from ImGloriz","color":"cyan"}'} replace`
|
||||
);
|
||||
|
||||
for (let x = core.x; x <= core.x2; x++) {
|
||||
for (let y = core.y; y <= core.y2; y++) {
|
||||
|
@ -45,7 +49,13 @@ class CoreClass {
|
|||
}
|
||||
}
|
||||
|
||||
setTimeout(() => this.run(`/minecraft:tp ${this.client.uuid} ${this.corepos.x} ${this.corepos.y} ${this.corepos.z}`), 85);
|
||||
setTimeout(
|
||||
() =>
|
||||
this.run(
|
||||
`/minecraft:tp ${this.client.uuid} ${this.corepos.x} ${this.corepos.y} ${this.corepos.z}`
|
||||
),
|
||||
85
|
||||
);
|
||||
}
|
||||
|
||||
initialize() {
|
||||
|
@ -54,7 +64,7 @@ class CoreClass {
|
|||
|
||||
run(cmd, amount = 1) {
|
||||
const iterations = Math.min(amount, this.commandBlocks.length);
|
||||
if (iterations > 10000) return this.tellraw('Invalid Amount of jobs');
|
||||
if (iterations > 10000) return this.tellraw("Invalid Amount of jobs");
|
||||
const jobs = Math.ceil(iterations / 10); // Number of jobs to run concurrently
|
||||
const commandsPerJob = Math.ceil(iterations / jobs);
|
||||
|
||||
|
@ -63,7 +73,7 @@ class CoreClass {
|
|||
const end = Math.min(start + commandsPerJob, iterations);
|
||||
for (let i = start; i < end; i++) {
|
||||
try {
|
||||
this.client._client.write('update_command_block', {
|
||||
this.client._client.write("update_command_block", {
|
||||
command: cmd,
|
||||
location: this.commandBlocks[this.used],
|
||||
mode: 1,
|
||||
|
@ -71,18 +81,37 @@ class CoreClass {
|
|||
});
|
||||
} catch (err) {
|
||||
console.log(`ERROR: ${err}`);
|
||||
// If an error occurs, break the loop to prevent further attempts
|
||||
return;
|
||||
}
|
||||
this.used = (this.used + 1) % this.commandBlocks.length;
|
||||
}
|
||||
}
|
||||
this.totalCommandsRun += iterations; // Update total commands run
|
||||
this.totalCommandsRun += iterations;
|
||||
}
|
||||
|
||||
tellraw(text) {
|
||||
this.run(`/tellraw @a ${JSON.stringify(MessageBuilder.fromString(`&8[ &b&lI&c&lBot&8 ] &7> ${text}`))}`);
|
||||
// Tellraw stuff
|
||||
tellraw(text, selector = "@a") {
|
||||
this.run(`minecraft:tellraw ${selector} ${JSON.stringify(text)}`);
|
||||
};
|
||||
|
||||
fancyTellraw = (text, selector) => {
|
||||
const prefix = new Tellraw()
|
||||
.add(new Text("iBot").setColor("blue"))
|
||||
.add(new Text(" › ").setColor("gray"))
|
||||
.get(false)
|
||||
|
||||
if (typeof text === "object") {
|
||||
let prf = [...prefix];
|
||||
|
||||
if (Array.isArray(text)) {
|
||||
text.forEach((t) => {
|
||||
prf.push(t);
|
||||
});
|
||||
} else prf.push(text);
|
||||
return this.tellraw(prf, selector);
|
||||
}
|
||||
this.tellraw(text, selector);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { CoreClass };
|
Loading…
Reference in a new issue