Files
NitoriBot/src/modules/command_core.js
T

185 lines
5.3 KiB
JavaScript
Raw Normal View History

const mcData = require('minecraft-data')('1.20.2');
2024-11-22 12:49:22 -05:00
function core (context) {
const bot = context.bot;
const config = context.config;
const options = context.options;
2024-07-07 15:44:16 -04:00
bot.core = {
area: {
2024-07-20 20:27:17 -04:00
start: config.core?.area.start ?? { x: 0, y: 0, z: 0 },
end: config.core?.area.end ?? { x: 15, y: 0, z: 15 }
2024-07-07 15:44:16 -04:00
},
2024-07-07 15:44:16 -04:00
position: null,
2024-07-07 15:44:16 -04:00
currentBlockRelative: { x: 0, y: 0, z: 0 },
2024-07-07 15:44:16 -04:00
refill () {
const pos = bot.core.position
const { start, end } = bot.core.area
if (!pos) return
2024-09-19 11:30:06 -04:00
if (bot.options.useChat || bot.options.isCreayun || bot.options.isSavage) return
if (isNaN(pos.x + start.x)) {
bot.chat.command('spawn');
return
}
/*^^^
for checking is the core pos is null and if so
it will not refill core until the pos is not NaN
instead of tping to a set cords cuz fuck you im not doing that
*/
2024-11-22 12:49:22 -05:00
const command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} repeating_command_block{CustomName:'${JSON.stringify(config.core.name)}'} destroy`
if (config.core.method === 'chat') {
2024-11-22 12:49:22 -05:00
bot.chat.command(`${command}`)
} else if (config.core.method === 'item') {
bot._client.write('set_creative_slot', {
slot: 36,
item: {
present: true,
itemId: mcData.itemsByName.command_block.id,
itemCount: 1,
2024-11-22 12:49:22 -05:00
nbtData: { }
}
});
bot._client.write('block_dig', {
status: 0,
location: {
x: bot.position.x,
y: bot.position.y,
z: bot.position.z
},
face: 0
});
bot._client.write('block_place', {
hand: 0,
location: {
x: bot.position.x,
y: bot.position.y,
z: bot.position.z
},
direction: 0,
cursorX: 0.1,
cursorY: 0,
cursorZ: 0.1,
insideBlock: false
});
bot._client.write('update_command_block', {
location: bot.position,
2024-11-22 12:49:22 -05:00
command,
flags: 5,
mode: 1
})
}
2024-07-07 15:44:16 -04:00
},
move (pos = bot.position) {
bot.core.position = {
x: Math.floor(pos.x / 16) * 16,
y: 0,
z: Math.floor(pos.z / 16) * 16
}
bot.core.refill()
},
currentBlock () {
const relativePosition = bot.core.currentBlockRelative
const corePosition = bot.core.position
if (!corePosition) return null
return { x: relativePosition.x + corePosition.x, y: relativePosition.y + corePosition.y, z: relativePosition.z + corePosition.z }
},
incrementCurrentBlock () {
const relativePosition = bot.core.currentBlockRelative
const { start, end } = bot.core.area
relativePosition.x++
if (relativePosition.x > end.x) {
relativePosition.x = start.x
relativePosition.z++
}
if (relativePosition.z > end.z) {
relativePosition.z = start.z
relativePosition.y++
}
if (relativePosition.y > end.y) {
relativePosition.x = start.x
relativePosition.y = start.y
relativePosition.z = start.z
}
},
run (command) {
const eee = Math.floor(Math.random() * 10000)
2024-07-07 15:44:16 -04:00
const location = bot.core.currentBlock()
if (!location) return
if (bot.options.isSavage || bot.options.isCreayun || bot.options.useChat) {
return
2024-07-20 20:27:17 -04:00
} else {
bot._client.write('update_command_block', { command: command.substring(0, 32767), location, mode: 1, flags: 0b100 });
bot._client.write('query_block_nbt', ({ location: location, transactionId: eee}));
bot.core.incrementCurrentBlock();
2024-07-20 20:27:17 -04:00
}
},
2024-11-22 12:49:22 -05:00
runTracked (command) {
const transactionId = Math.floor(Math.random() * 1000);
const location = bot.core.currentBlock();
if (!location) return;
if (bot.position.y !== bot.core.position.y) {
bot.chat.command(`minecraft:tp ${bot.core.position.x} ${bot.core.position.y} ${bot.core.position.z}`)
}
bot._client.write('update_command_block', {
command: command.substring(0, 32767),
location,
flags: 5,
mode: 1,
// LastOutput: true,
});
bot.core.incrementCurrentBlock();
bot._client.write('query_block_nbt', {
location,
transactionId
});
bot.on('packet.nbt_query_response', (data) => {
// transactionId,
try {
if (data.transactionId === transactionId) {
bot.tellraw("@a", require('util').inspect(data.value))
bot.tellraw("@a", JSON.stringify(data.value))
}
} catch (e) {
bot.tellraw("@a", require("util").inspect(e.stack));
}
})
}
2024-07-07 15:44:16 -04:00
}
2024-09-19 11:30:06 -04:00
if (bot.options.isSavage || bot.options.isCreayun) return
2024-07-07 15:44:16 -04:00
bot.on('move', () => {
bot.core.move(bot.position)
})
bot.on('packet.block_change', (data) => {
// console.log('data pos ' + JSON.stringify(data.location))
// console.log('core pos ' +JSON.stringify(bot.core.position));
if (data.type === 0) {
// console.log('data pos ' + JSON.stringify(data.location));
// console.log('core position ' + JSON.stringify(bot.core.position));
// bot.core.refill();
}
})
}
2024-07-07 15:44:16 -04:00
module.exports = core;