greentext & fixes
This commit is contained in:
parent
9de7b08cee
commit
f139c0b417
4 changed files with 94 additions and 51 deletions
5
bot.js
5
bot.js
|
@ -94,7 +94,10 @@ function createBot (options = {}) {
|
|||
|
||||
// position code
|
||||
bot.position = { x: null, y: null, z: null } // to prevent errors i guess
|
||||
bot._client.on('position', (position) => (bot.position = position))
|
||||
bot._client.on('position', (packet) => {
|
||||
bot.position = packet
|
||||
bot._client.write('teleport_confirm', { teleportId: packet.teleportId })
|
||||
})
|
||||
|
||||
// plugin injection
|
||||
bot.plugins.forEach((plugin) => {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -8,7 +8,7 @@ function inject (bot) {
|
|||
// const { id } = mcData.itemsByName.cod
|
||||
bot.chatFilter = {
|
||||
enabled: false,
|
||||
_lines: [],
|
||||
_lines: Array(100).fill(''),
|
||||
_filter
|
||||
}
|
||||
bot.on('chat', ({ raw }) => {
|
||||
|
@ -40,6 +40,18 @@ function inject (bot) {
|
|||
function _filter (message) {
|
||||
let filtered = message
|
||||
filtered = filtered.replace(/geese/g, censor)
|
||||
|
||||
let separatorIndex = filtered.indexOf('\xa7r:\xa7r \xa7')
|
||||
if (separatorIndex !== -1) {
|
||||
separatorIndex += '\xa7r:\xa7r \xa7'.length + 1
|
||||
const sender = filtered.substring(0, separatorIndex)
|
||||
let msg = filtered.substring(separatorIndex)
|
||||
let modified
|
||||
|
||||
if (msg[0] === '>') { msg = '\xa7a' + msg; modified = true }
|
||||
if (modified) filtered = sender + msg
|
||||
}
|
||||
|
||||
return filtered
|
||||
}
|
||||
|
||||
|
|
124
plugins/core.js
124
plugins/core.js
|
@ -1,60 +1,88 @@
|
|||
const nbt = require('prismarine-nbt')
|
||||
const SNBT = require('../util/snbt')
|
||||
const mcNamespace = 'minecraft:'
|
||||
|
||||
function inject (bot) {
|
||||
// const mcData = require('minecraft-data')(bot._client.version)
|
||||
// const commandBlocks = [ mcData.blocksByName.command_block.id, mcData.blocksByName.chain_command_block.id, mcData.blocksByName.repeating_command_block.id ]
|
||||
function bot (bot) {
|
||||
let mcData = require('minecraft-data')('1.17.1')
|
||||
bot.on('login', () => (mcData = require('minecraft-data')(bot._client.version)))
|
||||
|
||||
const core = {}
|
||||
bot.core = {
|
||||
size: { from: { x: -8, y: 0, z: -8 }, to: { x: 8, y: 0, z: 8 } },
|
||||
|
||||
core.pos = { x: null, y: null, z: null }
|
||||
core.size = { fromX: -8, fromY: 0, fromZ: -8, toX: 8, toY: 0, toZ: 8 }
|
||||
core.block = { x: core.size.fromX, y: core.size.fromY, z: core.size.fromZ }
|
||||
core.refill = () => bot.chat.queue.push(`/fill ${core.pos.x + core.size.fromX} ${core.pos.y + core.size.fromY} ${core.pos.z + core.size.fromZ} ${core.pos.x + core.size.toX} ${core.pos.y + core.size.toY} ${core.size.toZ + core.pos.z} repeating_command_block${SNBT.stringify(nbt.comp({ CustomName: nbt.string(JSON.stringify('')) }))} destroy`)
|
||||
core.reset = (position = bot.position) => {
|
||||
core.pos = { x: Math.round(position.x), y: 0, z: Math.round(position.z) }
|
||||
core.block = { x: core.size.fromX, y: core.size.fromY, z: core.size.fromZ }
|
||||
core.refill()
|
||||
}
|
||||
core.run = async (command) => {
|
||||
if (!bot.loggedIn || !command) return
|
||||
from: { x: null, y: null, z: null },
|
||||
to: { x: null, y: null, z: null },
|
||||
|
||||
core.block.x++
|
||||
if (core.block.x > core.size.toX) {
|
||||
core.block.x = core.size.fromX
|
||||
core.block.z++
|
||||
if (core.block.z > core.size.toZ) {
|
||||
core.block.z = core.size.fromZ
|
||||
core.block.y++
|
||||
if (core.block.y > core.size.toY) {
|
||||
core.block.x = core.size.fromX
|
||||
core.block.y = core.size.fromY
|
||||
core.block.z = core.size.fromZ
|
||||
block: { x: null, y: null, z: null },
|
||||
|
||||
refill () {
|
||||
const refillCommand = `/fill ${this.from.x} ${this.from.y} ${this.from.z} ${this.to.x} ${this.to.y} ${this.to.z} repeating_command_block{CustomName:'""'}`
|
||||
const location = { x: Math.floor(bot.position.x), y: Math.floor(bot.position.y) - 1, z: Math.floor(bot.position.z) }
|
||||
const commandBlockId = mcData?.itemsByName.command_block.id
|
||||
|
||||
bot._client.write('set_creative_slot', {
|
||||
slot: 36,
|
||||
item: {
|
||||
present: true,
|
||||
itemId: commandBlockId,
|
||||
itemCount: 1,
|
||||
nbtData: nbt.comp({
|
||||
BlockEntityTag: nbt.comp({
|
||||
auto: nbt.byte(1),
|
||||
Command: nbt.string(refillCommand)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
bot._client.write('block_dig', {
|
||||
status: 0,
|
||||
location,
|
||||
face: 1
|
||||
})
|
||||
|
||||
bot._client.write('block_place', {
|
||||
location,
|
||||
direction: 1,
|
||||
hand: 0,
|
||||
cursorX: 0.5,
|
||||
cursorY: 0.5,
|
||||
cursorZ: 0.5,
|
||||
insideBlock: false
|
||||
})
|
||||
},
|
||||
run (command) {
|
||||
if (!bot.loggedIn) return
|
||||
// if (!bot.server.isBukkit && command.startsWith(mcNamespace)) command = command.substring(mcNamespace.length)
|
||||
const isKaboom = bot.brand === 'kaboom'
|
||||
if (isKaboom) bot._client.write('update_command_block', { location: this.block, command: '', mode: 0, flags: 0b000 })
|
||||
bot._client.write('update_command_block', { location: this.block, command: String(command).substring(0, 32767), mode: isKaboom ? 1 : 2, flags: 0b100 })
|
||||
|
||||
this.block.x++
|
||||
if (this.block.x > this.to.x) {
|
||||
this.block.x = this.from.x
|
||||
this.block.z++
|
||||
if (this.block.z > this.to.z) {
|
||||
this.block.z = this.from.z
|
||||
this.block.y++
|
||||
if (this.block.y > this.to.y) {
|
||||
this.block.x = this.from.x
|
||||
this.block.y = this.from.y
|
||||
this.block.z = this.from.z
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const location = { x: core.pos.x + core.block.x, y: core.pos.y + core.block.y, z: core.pos.z + core.block.z }
|
||||
bot._client.write('update_command_block', { location, command, mode: 1, flags: 0b100 })
|
||||
|
||||
if (bot.brand !== 'kaboom') {
|
||||
setTimeout(() =>
|
||||
bot._client.write('update_command_block', { location, command: '', mode: 1, flags: 0b100 }
|
||||
), 50)
|
||||
},
|
||||
reset () {
|
||||
this.from = { x: Math.floor(this.size.from.x + bot.position.x), y: 0, z: Math.floor(this.size.from.z + bot.position.z) }
|
||||
this.to = { x: Math.floor(this.size.to.x + bot.position.x), y: Math.floor(this.size.to.y), z: Math.floor(this.size.to.z + bot.position.z) }
|
||||
this.block = { ...this.from }
|
||||
this.refill()
|
||||
}
|
||||
}
|
||||
// bot._client.on('block_change', (packet) => {
|
||||
// if (packet.location.x >= (core.pos.x + core.size.fromX) && packet.location.x <= (core.pos.x + core.size.toX)
|
||||
// && packet.location.y >= (core.pos.y + core.size.fromY) && packet.location.y <= (core.pos.y + core.size.toY)
|
||||
// && packet.location.z >= (core.pos.z + core.size.fromZ) && packet.location.z <= (core.pos.z + core.size.toZ)
|
||||
// && !commandBlocks.includes(packet.type))
|
||||
// bot.core.refill()
|
||||
// })
|
||||
|
||||
bot.core = core
|
||||
bot._client.on('position', (position) => {
|
||||
bot.core.reset(position)
|
||||
bot.on('move', oldPos => {
|
||||
bot.core.run(`minecraft:setblock ${Math.floor(oldPos.x)} ${Math.floor(oldPos.y - 1)} ${Math.floor(oldPos.z)} minecraft:air replace mincecraft:command:block`) // Clean up after refills
|
||||
bot.core.reset()
|
||||
})
|
||||
setInterval(bot.core.reset, 60 * 1000)
|
||||
setInterval(() => bot.core.refill(), 60 * 1000)
|
||||
}
|
||||
|
||||
module.exports.bot = inject
|
||||
module.exports = { bot }
|
||||
|
|
Loading…
Reference in a new issue