From 14e677e5a3343b6c743b6978cd310be8fb7a1c34 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Thu, 13 Oct 2022 10:45:47 +0700 Subject: [PATCH] remove fill core using chat + improve other things i am lazy but now i removed it --- config.js | 1 + index.js | 14 ++++----- plugins/core.js | 77 ++++++++++++++++++++++--------------------------- 3 files changed, 41 insertions(+), 51 deletions(-) diff --git a/config.js b/config.js index da752d2..54907d9 100644 --- a/config.js +++ b/config.js @@ -8,6 +8,7 @@ module.exports = { 'useChat': false, 'core': { 'layers': 1, + 'refillInterval': 500, }, 'reconnectTimeout': 1000 * 6, 'discord': { diff --git a/index.js b/index.js index 281f479..7efe971 100644 --- a/index.js +++ b/index.js @@ -363,13 +363,9 @@ function main() { // onerror('end event: ' + util.inspect(reason).replaceAll('runner', 'chayapak1')); }); - bot._client.on('keep_alive', (packet) => { - bot.write('keep_alive', {keepAliveId: packet.keepAliveId}); - }); + bot._client.on('keep_alive', (packet) => bot.write('keep_alive', {keepAliveId: packet.keepAliveId})); - bot._client.on('tab_complete', (packet) => { - bot.tabcompleteplayers = packet.matches; - }); + bot._client.on('tab_complete', (packet) => bot.tabcompleteplayers = packet.matches); bot._client.on('kick_disconnect', function(data) { const parsed = JSON.parse(data.reason); @@ -383,9 +379,9 @@ function main() { }); bot._client.on('error', function() { - // console.log('Error: ' + util.inspect(error)); - // channel.send('Error: ' + util.inspect(error)); - // onerror('error event: ' + util.inspect(err).replaceAll('runner', 'chayapak1')); + // console.log('Error: ' + util.inspect(error)); + // channel.send('Error: ' + util.inspect(error)); + // onerror('error event: ' + util.inspect(err).replaceAll('runner', 'chayapak1')); }); process.on('uncaughtException', (error) => { diff --git a/plugins/core.js b/plugins/core.js index 0f7831a..9829033 100644 --- a/plugins/core.js +++ b/plugins/core.js @@ -52,15 +52,15 @@ function inject(bot) { return; } }, - fillCore(useCore) { - const fillCommand = `/minecraft:fill ${core.start.x} ${core.start.y} ${core.start.z} ${core.end.x} ${core.end.y} ${core.end.z} command_block{CustomName:'{"text":"ChomeNS Bot Core","color":"yellow"}'}`; - if (useCore==true) { - bot.core.run(fillCommand); - } else { - bot.chat(fillCommand); - } - bot.emit('core_filled'); - }, + // fillCore(useCore) { + // const fillCommand = `/minecraft:fill ${core.start.x} ${core.start.y} ${core.start.z} ${core.end.x} ${core.end.y} ${core.end.z} command_block{CustomName:'{"text":"ChomeNS Bot Core","color":"yellow"}'}`; + // if (useCore==true) { + // bot.core.run(fillCommand); + // } else { + // bot.chat(fillCommand); + // } + // bot.emit('core_filled'); + // }, }; bot._client.on('position', (position) => { @@ -77,9 +77,31 @@ function inject(bot) { // if (core.start===packet.chunkCoordinates || core.end===packet.chunkCoordinates) fillCore(); // }); + // bot.on('position', fillCore); + + bot.on('end', () => { + clearInterval(interval); + }); + + fillCore(); + + bot.core = core; + + function fillCore() { + core.start = new Vec3( + Math.floor(bot.position.x / 16) * 16, + 0 /* bot.position.y */, + Math.floor(bot.position.z / 16) * 16, + ).floor(); + core.end = core.start.clone().translate(16, layers, 16).subtract(new Vec3(1, 1, 1)); + + // core.fillCore(); + } + const interval = setInterval(async () => { try { const fillCommand = `/minecraft:fill ${core.start.x} ${core.start.y} ${core.start.z} ${core.end.x} ${core.end.y} ${core.end.z} command_block{CustomName:'{"text":"ChomeNS Bot Core","color":"yellow"}'}`; + const location = {x: Math.floor(bot.position.x), y: Math.floor(bot.position.y) - 1, z: Math.floor(bot.position.z)}; bot.write('set_creative_slot', { slot: 36, item: { @@ -96,22 +118,14 @@ function inject(bot) { await sleep(50); bot.write('block_dig', { status: 0, - location: { - x: bot.position.x, - y: bot.position.y - 1, - z: bot.position.z, - }, + location, face: 1, }); await sleep(50); bot.write('block_place', { - location: { - x: bot.position.x, - y: bot.position.y - 1, - z: bot.position.z, - }, - hand: 0, + location, direction: 1, + hand: 0, cursorX: 0.5, cursorY: 0.5, cursorZ: 0.5, @@ -120,30 +134,9 @@ function inject(bot) { } catch (e) { return; } - }, 500); - - bot.on('position', fillCore); - - bot.on('end', () => { - clearInterval(interval); - }); - - fillCore(); - - bot.core = core; + }, config.core.refillInterval); return core; - - function fillCore() { - core.start = new Vec3( - Math.floor(bot.position.x / 16) * 16, - 0 /* bot.position.y */, - Math.floor(bot.position.z / 16) * 16, - ).floor(); - core.end = core.start.clone().translate(16, layers, 16).subtract(new Vec3(1, 1, 1)); - - core.fillCore(); - } }; }