Files
NitoriBot/src/modules/command_core.js
T

188 lines
5.0 KiB
JavaScript
Raw Normal View History

const mcData = require('minecraft-data')('1.20.2');
2024-12-06 11:04:23 -05:00
const nbt = require('prismarine-nbt');
2024-11-22 12:49:22 -05:00
2025-01-15 11:32:27 -05:00
function inject (context) {
2024-11-22 12:49:22 -05:00
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-12-06 11:04:23 -05:00
itemPosition: null,
2024-07-07 15:44:16 -04:00
currentBlockRelative: { x: 0, y: 0, z: 0 },
2024-12-06 11:04:23 -05:00
usePlacedCommandBlock: false,
chatRefill () {
2024-07-07 15:44:16 -04:00
const pos = bot.core.position
const { start, end } = bot.core.area
if (!pos) return
2025-02-03 09:15:29 -06:00
if (bot.options.mode === "creayun" || bot.options.mode === "savageFriends") return;
2024-09-19 11:30:06 -04:00
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`
2024-12-06 11:04:23 -05:00
bot.chat.command(`${command}`)
},
itemRefill () {
const pos = bot.core.position;
const { start, end } = bot.core.area;
const itemPosition = bot.core.itemPosition;
if (!pos) return;
2025-02-03 09:15:29 -06:00
if (bot.options.mode === "creayun" || bot.options.mode === "savageFriends") return;
2024-12-06 11:04:23 -05:00
if (isNaN(pos.x + pos.x)) {
bot.chat.command('spawn');
return
}
2024-12-16 13:48:50 -05:00
2024-12-06 11:04:23 -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`
bot._client.write('set_creative_slot', {
slot: 36,
item: {
present: true,
itemId: mcData.itemsByName.repeating_command_block.id,
itemCount: 1,
nbtData: nbt.comp({
BlockEntityTag: nbt.comp({
CustomName: nbt.string(JSON.stringify(config.core.itemName))
})
})
}
});
2024-12-06 11:04:23 -05:00
bot._client.write('block_dig', {
status: 0,
location: itemPosition,
face: 0
});
bot._client.write('block_place', {
hand: 0,
location: itemPosition,
direction: 0,
cursorX: 0.1,
cursorY: 0,
cursorZ: 0.1,
insideBlock: false
});
if (bot.core.usePlacedCommandBlock) {
return
} else {
bot._client.write('update_command_block', {
2024-12-06 11:04:23 -05:00
location: itemPosition,
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
2024-12-06 11:04:23 -05:00
};
bot.core.itemPosition = {
x: pos.x,
y: pos.y -1,
z: pos.z
}
if (config.core.itemRefill === true) {
bot.core.itemRefill();
} else {
bot.core.chatRefill();
2024-07-07 15:44:16 -04:00
}
},
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) {
2024-12-06 11:04:23 -05:00
const location = bot.core.currentBlock();
const itemPosition = bot.core.itemPosition;
if (!location) return;
2025-02-03 09:15:29 -06:00
if (bot.options.mode === "creayun" || bot.options.mode === "savageFriends") {
return
2024-07-20 20:27:17 -04:00
} else {
2024-12-06 11:04:23 -05:00
if (bot.core.usePlacedCommandBlock) {
bot._client.write('update_command_block', {
command: command.substring(0, 32767),
location: itemPosition,
mode: 1,
flags: 5,
});
bot.core.incrementCurrentBlock();
} else {
bot._client.write('update_command_block', {
command: command.substring(0, 32767),
location,
mode: 1,
flags: 5
});
bot.core.incrementCurrentBlock();
}
2024-07-20 20:27:17 -04:00
}
},
2024-07-07 15:44:16 -04:00
}
2025-01-24 10:00:06 -05:00
require('../util/core_util')(bot, config, options);
}
2025-01-15 11:32:27 -05:00
module.exports = {
data: {
enabled: true,
name: "core",
type: "extras"
},
inject
};