From 0acd7861de7f2a366382d0b151b37097eb8badce Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Sun, 11 Sep 2022 11:21:18 +0700 Subject: [PATCH] new fill core method (repeating command block placing method) --- plugins/core.js | 65 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/plugins/core.js b/plugins/core.js index c5ffa41..0f7831a 100644 --- a/plugins/core.js +++ b/plugins/core.js @@ -1,6 +1,9 @@ /* eslint-disable max-len */ /* eslint-disable require-jsdoc */ const config = require('../config'); +const nbt = require('prismarine-nbt'); +const mcData = require('minecraft-data')('1.18.2'); +const sleep = require('sleep-promise'); const chatMessage = require('prismarine-chat')('1.18.2'); const Vec3 = require('vec3'); @@ -56,7 +59,6 @@ function inject(bot) { } else { bot.chat(fillCommand); } - bot.emit('core_filled'); }, }; @@ -67,16 +69,65 @@ function inject(bot) { bot.emit('position', position); }); - bot._client.on('block_change', (packet) => { - if (core.isCore(packet.location) && packet.type===0) fillCore(); - }); + // bot._client.on('block_change', (packet) => { + // if (core.isCore(packet.location) && packet.type===0) fillCore(); + // }); - bot._client.on('multi_block_change', (packet) => { - if (core.start===packet.chunkCoordinates || core.end===packet.chunkCoordinates) fillCore(); - }); + // bot._client.on('multi_block_change', (packet) => { + // if (core.start===packet.chunkCoordinates || core.end===packet.chunkCoordinates) 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"}'}`; + bot.write('set_creative_slot', { + slot: 36, + item: { + present: true, + itemId: mcData.itemsByName['repeating_command_block'].id, + itemCount: 64, + nbtData: nbt.comp({BlockEntityTag: nbt.comp({ + Command: nbt.string(fillCommand), + auto: nbt.byte(1), + TrackOutput: nbt.byte(0), + })}), + }, + }); + await sleep(50); + bot.write('block_dig', { + status: 0, + location: { + x: bot.position.x, + y: bot.position.y - 1, + z: bot.position.z, + }, + 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, + direction: 1, + cursorX: 0.5, + cursorY: 0.5, + cursorZ: 0.5, + insideBlock: false, + }); + } catch (e) { + return; + } + }, 500); bot.on('position', fillCore); + bot.on('end', () => { + clearInterval(interval); + }); + fillCore(); bot.core = core;