Update util/core.js
This commit is contained in:
parent
f2f1d9b2c3
commit
87a10ab00c
1 changed files with 101 additions and 72 deletions
173
util/core.js
173
util/core.js
|
@ -1,88 +1,117 @@
|
|||
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;
|
||||
this.commandBlocks = [];
|
||||
this.used = 0;
|
||||
this.corepos = { x: 0, y: 0, z: 0 };
|
||||
this.totalCommandsRun = 0;
|
||||
this.startTime = Date.now();
|
||||
this.transaction_id = [];
|
||||
this.coreSize = require('../config.json').core;
|
||||
this.initialize();
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
this.commandBlocks = [];
|
||||
this.used = 0;
|
||||
this.corepos = { x: 0, y: 0, z: 0 };
|
||||
this.totalCommandsRun = 0;
|
||||
this.startTime = Date.now();
|
||||
this.transaction_id = [];
|
||||
this.coreSize = require("../config.json").core;
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
refill() {
|
||||
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)) {
|
||||
setTimeout(() => this.refill(), 650);
|
||||
return;
|
||||
}
|
||||
|
||||
refill() {
|
||||
const config = require('../config.json');
|
||||
const pos = this.client.entity?.position; // Ensure entity exists before accessing position
|
||||
this.commandBlocks = [];
|
||||
const core = {
|
||||
x: Math.floor(pos.x - (this.coreSize.width - 1) / 2),
|
||||
y: Math.floor(config.core.y - (this.coreSize.height - 1) / 2),
|
||||
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),
|
||||
};
|
||||
|
||||
// Check if the bot's position is defined
|
||||
if (!pos || pos.x === 0 && pos.y === 0 && pos.z === 0) {
|
||||
setTimeout(() => this.refill(), 650);
|
||||
return;
|
||||
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`
|
||||
);
|
||||
|
||||
for (let x = core.x; x <= core.x2; x++) {
|
||||
for (let y = core.y; y <= core.y2; y++) {
|
||||
for (let z = core.z; z <= core.z2; z++) {
|
||||
this.commandBlocks.push(new Vec3(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const core = {
|
||||
x: Math.floor(pos.x - (this.coreSize.width - 1) / 2),
|
||||
y: Math.floor(config.core.y - (this.coreSize.height - 1) / 2),
|
||||
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)
|
||||
};
|
||||
setTimeout(
|
||||
() =>
|
||||
this.run(
|
||||
`/minecraft:tp ${this.client.uuid} ${this.corepos.x} ${this.corepos.y} ${this.corepos.z}`
|
||||
),
|
||||
85
|
||||
);
|
||||
}
|
||||
|
||||
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`);
|
||||
initialize() {
|
||||
this.refill(); // Start the refill process
|
||||
}
|
||||
|
||||
for (let x = core.x; x <= core.x2; x++) {
|
||||
for (let y = core.y; y <= core.y2; y++) {
|
||||
for (let z = core.z; z <= core.z2; z++) {
|
||||
this.commandBlocks.push(new Vec3(x, y, z));
|
||||
}
|
||||
}
|
||||
run(cmd, amount = 1) {
|
||||
const iterations = Math.min(amount, this.commandBlocks.length);
|
||||
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);
|
||||
|
||||
for (let job = 0; job < jobs; job++) {
|
||||
const start = job * commandsPerJob;
|
||||
const end = Math.min(start + commandsPerJob, iterations);
|
||||
for (let i = start; i < end; i++) {
|
||||
try {
|
||||
this.client._client.write("update_command_block", {
|
||||
command: cmd,
|
||||
location: this.commandBlocks[this.used],
|
||||
mode: 1,
|
||||
flags: 4,
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(`ERROR: ${err}`);
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout(() => this.run(`/minecraft:tp ${this.client.uuid} ${this.corepos.x} ${this.corepos.y} ${this.corepos.z}`), 85);
|
||||
this.used = (this.used + 1) % this.commandBlocks.length;
|
||||
}
|
||||
}
|
||||
this.totalCommandsRun += iterations;
|
||||
}
|
||||
|
||||
initialize() {
|
||||
this.refill(); // Start the refill process
|
||||
}
|
||||
|
||||
run(cmd, amount = 1) {
|
||||
const iterations = Math.min(amount, this.commandBlocks.length);
|
||||
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);
|
||||
|
||||
for (let job = 0; job < jobs; job++) {
|
||||
const start = job * commandsPerJob;
|
||||
const end = Math.min(start + commandsPerJob, iterations);
|
||||
for (let i = start; i < end; i++) {
|
||||
try {
|
||||
this.client._client.write('update_command_block', {
|
||||
command: cmd,
|
||||
location: this.commandBlocks[this.used],
|
||||
mode: 1,
|
||||
flags: 4,
|
||||
});
|
||||
} 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
|
||||
}
|
||||
|
||||
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 };
|
||||
module.exports = { CoreClass };
|
Loading…
Reference in a new issue