chomens-bot-js/plugins/core.js

113 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-11-27 02:35:28 -05:00
const nbt = require('prismarine-nbt')
const Vec3 = require('vec3')
2022-08-14 05:51:45 -04:00
2022-11-27 02:35:28 -05:00
const relativePosition = new Vec3(0, 0, 0)
2022-08-14 05:51:45 -04:00
2022-11-27 02:35:28 -05:00
function inject (bot, dcclient, config) {
const mcData = require('minecraft-data')(bot.version)
2023-01-13 23:01:36 -05:00
const impulseMode = !bot.options.kaboom
2022-11-14 05:45:49 -05:00
const core = {
start: new Vec3(null, null, null),
end: new Vec3(null, null, null),
2022-11-27 02:35:28 -05:00
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
2022-11-14 05:45:49 -05:00
},
2022-11-27 02:35:28 -05:00
run (command) {
2022-11-14 05:45:49 -05:00
try {
2022-11-27 02:35:28 -05:00
relativePosition.x++
2022-11-14 05:45:49 -05:00
if (relativePosition.x >= 16) {
2022-11-27 02:35:28 -05:00
relativePosition.x = 0
2023-03-16 10:03:26 -04:00
relativePosition.z++
2022-11-14 05:45:49 -05:00
}
2023-03-16 03:57:12 -04:00
if (relativePosition.z >= 16) {
relativePosition.z = 0
relativePosition.y++
2022-11-14 05:45:49 -05:00
}
2023-03-16 03:57:12 -04:00
if (relativePosition.y >= config.core.layers) {
relativePosition.x = 0
relativePosition.y = config.core.layers
2022-11-27 02:35:28 -05:00
relativePosition.z = 0
2022-11-14 05:45:49 -05:00
}
2022-08-14 05:51:45 -04:00
2022-11-14 05:45:49 -05:00
const location = {
x: core.start.x + relativePosition.x,
y: core.start.y + relativePosition.y,
2022-11-27 02:35:28 -05:00
z: core.start.z + relativePosition.z
}
2022-11-14 05:45:49 -05:00
2022-11-27 02:35:28 -05:00
if (impulseMode) bot.write('update_command_block', { location, command: '', mode: 0, flags: 0 })
2022-12-18 01:49:08 -05:00
bot.write('update_command_block', { location, command: String(command).substring(0, 32767), mode: impulseMode ? 2 : 1, flags: 0b101 })
2022-11-14 05:45:49 -05:00
} catch (e) {
2022-11-27 02:35:28 -05:00
bot.console.error(e)
2022-11-14 05:45:49 -05:00
}
},
2022-11-29 04:46:22 -05:00
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, config.core.layers, 16).subtract(new Vec3(1, 1, 1))
placeCore()
2022-11-27 02:35:28 -05:00
}
}
2022-11-14 05:45:49 -05:00
2022-11-29 04:46:22 -05:00
bot.core = core
2022-11-14 05:45:49 -05:00
2022-11-29 04:46:22 -05:00
function placeCore () {
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:'${JSON.stringify(config.core.customName)}'}`
2022-11-29 04:46:22 -05:00
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: {
present: true,
2023-01-13 23:01:36 -05:00
itemId: impulseMode ? mcData.itemsByName.command_block.id : mcData.itemsByName.repeating_command_block.id,
2022-11-29 04:46:22 -05:00
itemCount: 64,
nbtData: nbt.comp({
BlockEntityTag: nbt.comp({
Command: nbt.string(fillCommand),
auto: nbt.byte(1),
TrackOutput: nbt.byte(0)
})
})
}
})
bot.write('block_dig', {
status: 0,
location,
face: 1
})
bot.write('block_place', {
location,
direction: 1,
hand: 0,
cursorX: 0.5,
cursorY: 0.5,
cursorZ: 0.5,
insideBlock: false
})
} catch (e) {
bot.console.error(e)
}
2022-11-14 05:45:49 -05:00
}
2022-11-29 04:46:22 -05:00
bot.on('position', bot.core.fillCore)
2022-11-14 05:45:49 -05:00
2022-11-29 04:46:22 -05:00
const interval = setInterval(bot.core.fillCore, config.core.refillInterval)
2022-11-15 05:52:33 -05:00
2022-11-30 04:45:20 -05:00
bot.on('end', () => {
2022-11-27 02:35:28 -05:00
clearInterval(interval)
})
2022-08-14 05:51:45 -04:00
}
2022-11-27 02:35:28 -05:00
module.exports = { inject }