FridayNightFunkinBoyfriendBot/modules/command_core.js

100 lines
2.9 KiB
JavaScript
Raw Normal View History

2023-12-17 14:55:27 -05:00
const nbt = require('prismarine-nbt');
2024-01-12 12:24:01 -05:00
async function command_core (bot, options) {
2023-12-17 14:55:27 -05:00
bot.core = {
// what you think im doing? look at line 17
area: {
start: options.core?.area.start ?? { x: 0, y: 0, z: 0 },
end: options.core?.area.end ?? { x: 15, y: 0, z: 15 }
},
position: null,
currentBlockRelative: { x: 0, y: 0, z: 0 },
refill () {
const pos = bot.core.position
const { start, end } = bot.core.area
if (!pos) return
2024-01-12 12:24:01 -05:00
bot.command(`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: '{"text":"${bot.options.Core.customName}","color":"#00FFFF","clickEvent":{"action":"open_url","value":"https://chipmunk.land"}}'} destroy`)
2023-12-24 12:20:30 -05:00
2023-12-17 14:55:27 -05:00
},
2023-12-24 12:11:42 -05:00
2023-12-17 14:55:27 -05: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 -1
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 location = bot.core.currentBlock()
if (!location) return
bot._client.write('update_command_block', { command: command.substring(0, 32767), location, mode: 1, flags: 0b100 })
bot.core.incrementCurrentBlock()
// added .substring(0, 32767) so it won't kick the bot if the command is too long.
2023-12-24 12:11:42 -05:00
},
2023-12-17 14:55:27 -05:00
}
2024-01-12 12:24:01 -05:00
/*
bot.on('parsed_message', data => {
if (data.type !== 'minecraft:chat') return
const plainMessage = bot.getMessageAsPrismarine(data.contents)?.toString()
if (plainMessage.startsWith(':3')) {
bot.chat(' :3')
} return
})
*/
2024-01-27 09:44:54 -05:00
if (bot.options.Core.CorelessMode) return
2023-12-17 14:55:27 -05:00
bot.on('move', () => {
bot.core.move(bot.position)
//setTimeout(() => bot.core.run('say hi'), 100)
})
2023-12-24 12:11:42 -05:00
bot.on('packet.login', (data) =>{
const timer = setInterval(() => {
bot.core.refill()
2023-12-29 16:15:50 -05:00
}, bot.options.Core.interval)
2023-12-24 12:11:42 -05:00
bot.on('end', (bot) => {
clearInterval(timer)
2024-01-12 12:24:01 -05:00
2023-12-24 12:11:42 -05:00
})
})
2023-12-17 14:55:27 -05:00
}
2024-01-12 12:24:01 -05:00
module.exports = command_core