mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-27 17:45:34 -05:00
0acd7861de
(repeating command block placing method)
150 lines
4.6 KiB
JavaScript
150 lines
4.6 KiB
JavaScript
/* 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');
|
|
|
|
const relativePosition = new Vec3(0, 0, 0);
|
|
|
|
function inject(bot) {
|
|
bot.createCore = (layers = config.core.layers) => {
|
|
const core = {
|
|
isCore(position) {
|
|
return position.x >= core.start.x && position.x <= core.end.x && position.y >= core.start.y && position.y <= core.end.y && position.z >= core.start.z && position.z <= core.end.z;
|
|
},
|
|
run(command) {
|
|
try {
|
|
if (config.useChat && command.startsWith('minecraft:tellraw @a ') && !command.includes('Console') && !command.includes('Discord')) {
|
|
bot.chat(chatMessage.fromNotch(command.replace('minecraft:tellraw @a ', '')).toMotd().replaceAll('\xa7', '&'));
|
|
return;
|
|
}
|
|
|
|
relativePosition.x++;
|
|
|
|
if (relativePosition.x >= 16) {
|
|
relativePosition.x = 0;
|
|
relativePosition.y++;
|
|
}
|
|
|
|
if (relativePosition.y >= layers) {
|
|
relativePosition.y = 0;
|
|
relativePosition.z++;
|
|
}
|
|
|
|
if (relativePosition.z >= 16) {
|
|
relativePosition.z = 0;
|
|
}
|
|
|
|
const impulseMode = bot.options.host === '0.tcp.ap.ngrok.io';
|
|
|
|
const location = {
|
|
x: core.start.x + relativePosition.x,
|
|
y: core.start.y + relativePosition.y,
|
|
z: core.start.z + relativePosition.z,
|
|
};
|
|
|
|
if (impulseMode) bot.write('update_command_block', {location, command: command.substring(0, 32767), mode: 0, flags: 0});
|
|
bot.write('update_command_block', {location, command: command.substring(0, 32767), mode: impulseMode ? 2 : 1, flags: 0b100});
|
|
} catch (e) {
|
|
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');
|
|
},
|
|
};
|
|
|
|
bot._client.on('position', (position) => {
|
|
bot.position = position;
|
|
|
|
bot.emit('position', position);
|
|
});
|
|
|
|
// 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();
|
|
// });
|
|
|
|
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;
|
|
|
|
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();
|
|
}
|
|
};
|
|
}
|
|
|
|
module.exports = {inject};
|