2024-10-27 05:11:51 -04:00
|
|
|
|
const Vec3 = require("vec3").Vec3;
|
2024-10-26 15:29:53 -04:00
|
|
|
|
const { MessageBuilder } = require("prismarine-chat")("1.19.4");
|
|
|
|
|
|
2024-10-27 05:11:51 -04:00
|
|
|
|
const { Tellraw, Text } = require("./tellrawBuilder.js");
|
|
|
|
|
|
2024-10-26 15:29:53 -04:00
|
|
|
|
class CoreClass {
|
2024-10-27 05:11:51 -04:00
|
|
|
|
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;
|
2024-10-26 15:29:53 -04:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-27 05:11:51 -04:00
|
|
|
|
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),
|
|
|
|
|
};
|
2024-10-26 15:29:53 -04:00
|
|
|
|
|
2024-10-27 05:11:51 -04:00
|
|
|
|
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`
|
|
|
|
|
);
|
2024-10-26 15:29:53 -04:00
|
|
|
|
|
2024-10-27 05:11:51 -04:00
|
|
|
|
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));
|
2024-10-26 15:29:53 -04:00
|
|
|
|
}
|
2024-10-27 05:11:51 -04:00
|
|
|
|
}
|
2024-10-26 15:29:53 -04:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-27 05:11:51 -04:00
|
|
|
|
setTimeout(
|
|
|
|
|
() =>
|
|
|
|
|
this.run(
|
|
|
|
|
`/minecraft:tp ${this.client.uuid} ${this.corepos.x} ${this.corepos.y} ${this.corepos.z}`
|
|
|
|
|
),
|
|
|
|
|
85
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-10-26 15:29:53 -04:00
|
|
|
|
|
2024-10-27 05:11:51 -04:00
|
|
|
|
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}`);
|
|
|
|
|
return;
|
2024-10-26 15:29:53 -04:00
|
|
|
|
}
|
2024-10-27 05:11:51 -04:00
|
|
|
|
this.used = (this.used + 1) % this.commandBlocks.length;
|
|
|
|
|
}
|
2024-10-26 15:29:53 -04:00
|
|
|
|
}
|
2024-10-27 05:11:51 -04:00
|
|
|
|
this.totalCommandsRun += iterations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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];
|
2024-10-26 15:29:53 -04:00
|
|
|
|
|
2024-10-27 05:11:51 -04:00
|
|
|
|
if (Array.isArray(text)) {
|
|
|
|
|
text.forEach((t) => {
|
|
|
|
|
prf.push(t);
|
|
|
|
|
});
|
|
|
|
|
} else prf.push(text);
|
|
|
|
|
return this.tellraw(prf, selector);
|
2024-10-26 15:29:53 -04:00
|
|
|
|
}
|
2024-10-27 05:11:51 -04:00
|
|
|
|
this.tellraw(text, selector);
|
|
|
|
|
};
|
2024-10-26 15:29:53 -04:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-27 05:11:51 -04:00
|
|
|
|
module.exports = { CoreClass };
|