diff --git a/plugins/core.js b/plugins/core.js new file mode 100644 index 0000000..1cd1eeb --- /dev/null +++ b/plugins/core.js @@ -0,0 +1,58 @@ +const conf = require("../config.json"); +const vec3 = require("vec3"); +const sleep = require("system-sleep"); +const relativePos = new vec3(0, 0, 0); +function inject(client) { + const cmdCore = { + isCmdCore(pos) { + return pos.x >= cmdCore.S.x && pos.x <= cmdCore.E.x && pos.y >= cmdCore.S.y && pos.y <= cmdCore.E.y && pos.z >= cmdCore.S.z && pos.z <= cmdCore.E.z; + }, + run(cmd) { + relativePos.x++; + if(relativePos.x >= 16) { + relativePos.x = 0; + relativePos.y++; + } + if(relativePos.y >= conf.cmdCore.layers) { + relativePos.y = 0; + relativePos.z++; + } + if(relativePos.z >= 16) { + relativePos.z = 0; + } + client.write("update_command_block", { + location: {x: cmdCore.S.x+relativePos.x, y: cmdCore.S.y+relativePos.y, z: cmdCore.S.z+relativePos.z}, + command: cmd, + mode: 1, + flags: 0b100 + }); + client.cmdCore.xpos = cmdCore.S.x+relativePos.x; + client.cmdCore.ypos = cmdCore.S.y+relativePos.y; + client.cmdCore.zpos = cmdCore.S.z+relativePos.z; + }, + refillCmdCore() { + client.chat(`/minecraft:fill ${cmdCore.S.x} ${cmdCore.S.y} ${cmdCore.S.z} ${cmdCore.E.x} ${cmdCore.E.y} ${cmdCore.E.z} minecraft:repeating_command_block replace`); + client.emit("cmdCore_refilled"); + } + } + client.on("position", (pos) => { + client.pos = pos; + client.emit("pos", pos); + }); + client.once("pos", async () => { + client.chat("/essentials:vanish on"); + sleep(100); + refillCmdCore(); + }); + + client.cmdCore = cmdCore; + return cmdCore; + + function refillCmdCore() { + cmdCore.S = new vec3(Math.floor(client.pos.x / 16) * 16, 0, Math.floor(client.pos.z / 16) * 16).floor(); + cmdCore.E = cmdCore.S.clone().translate(16, conf.cmdCore.layers, 16).subtract(new vec3(1, 1, 1)); + cmdCore.refillCmdCore(); + } +} + +module.exports = { inject }; \ No newline at end of file