2024-07-27 02:39:18 -04:00
|
|
|
const uuidToInt = require('../util/uuidtoint.js')
|
2024-09-11 23:38:34 -04:00
|
|
|
const plainParser = require('../util/chatparse_plain.js')
|
|
|
|
const mcParser = require('../util/chatparse_mc.js')
|
2024-09-12 01:18:23 -04:00
|
|
|
const protover = require("../util/getProtocolVersion.js")
|
2024-08-12 05:13:32 -04:00
|
|
|
const cs = {
|
|
|
|
x: 4,
|
|
|
|
y: 6,
|
|
|
|
z: 4
|
|
|
|
}
|
2024-07-27 02:39:18 -04:00
|
|
|
module.exports = {
|
2024-08-12 05:13:32 -04:00
|
|
|
load: function (b) {
|
2024-09-12 01:18:23 -04:00
|
|
|
if(protover(b._client.version) < 386){ // 1.13-pre4
|
|
|
|
b.host.options.useChat = true // This does not support command blocks below 1.13
|
|
|
|
}
|
2024-08-12 05:13:32 -04:00
|
|
|
b.interval.commandFill = setInterval(() => { if (b.sc_tasks.cc) b.sc_tasks.cc.failed = 1 }, 150000)
|
2024-07-28 02:37:31 -04:00
|
|
|
b.ccq = []
|
|
|
|
b.blocknoX = 0
|
|
|
|
b.blocknoZ = 0
|
2024-08-12 05:13:32 -04:00
|
|
|
b.ccStarted = false
|
2024-07-28 02:37:31 -04:00
|
|
|
b.blocknoY = 0
|
2024-08-12 05:13:32 -04:00
|
|
|
b.pos = { x: 0, y: 0, z: 0 }
|
|
|
|
|
|
|
|
b.refillCoreCmd = `/fill ~ 55 ~ ~${cs.x - 1} ${54 + cs.y} ~${cs.z - 1} command_block{CustomName:'{"translate":"%s %s","with":[{"translate":"entity.minecraft.ender_dragon"},{"translate":"language.region"}],"color":"#FFAAEE"}'}`
|
2024-07-27 02:39:18 -04:00
|
|
|
|
2024-07-28 02:37:31 -04:00
|
|
|
b.advanceccq = function () {
|
2024-09-12 00:26:36 -04:00
|
|
|
if (b.host.options.useChat) return
|
2024-07-28 02:37:31 -04:00
|
|
|
if (b.ccq[0] && b.ccq[0].length !== 0) {
|
|
|
|
b._client.write('update_command_block', {
|
2024-08-22 07:34:39 -04:00
|
|
|
command: '/',
|
2024-07-28 02:37:31 -04:00
|
|
|
location: {
|
2024-08-12 05:13:32 -04:00
|
|
|
x: b.commandPos.x + b.blocknoX,
|
|
|
|
y: b.commandPos.y + b.blocknoY,
|
|
|
|
z: b.commandPos.z + b.blocknoZ
|
2024-07-28 02:37:31 -04:00
|
|
|
},
|
|
|
|
mode: 2,
|
|
|
|
flags: 1
|
2024-07-27 02:39:18 -04:00
|
|
|
})
|
2024-07-28 02:37:31 -04:00
|
|
|
b._client.write('update_command_block', {
|
2024-08-22 07:34:39 -04:00
|
|
|
command: b.ccq[0].substr(0, 32767),
|
2024-07-28 02:37:31 -04:00
|
|
|
location: {
|
2024-08-12 05:13:32 -04:00
|
|
|
x: b.commandPos.x + b.blocknoX,
|
|
|
|
y: b.commandPos.y + b.blocknoY,
|
|
|
|
z: b.commandPos.z + b.blocknoZ
|
2024-07-28 02:37:31 -04:00
|
|
|
},
|
|
|
|
mode: 2,
|
|
|
|
flags: 5
|
2024-07-27 02:39:18 -04:00
|
|
|
})
|
2024-07-28 02:37:31 -04:00
|
|
|
b.blocknoX++
|
2024-08-12 05:13:32 -04:00
|
|
|
if (b.blocknoX === cs.x) {
|
2024-07-28 02:37:31 -04:00
|
|
|
b.blocknoY++
|
|
|
|
b.blocknoX = 0
|
2024-08-12 05:13:32 -04:00
|
|
|
if (b.blocknoY === cs.y) {
|
2024-07-28 02:37:31 -04:00
|
|
|
b.blocknoZ++
|
|
|
|
b.blocknoY = 0
|
2024-08-12 05:13:32 -04:00
|
|
|
if (b.blocknoZ === cs.z) {
|
2024-07-28 02:37:31 -04:00
|
|
|
b.blocknoZ = 0
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b.ccq.splice(0, 1)
|
|
|
|
}
|
2024-08-12 05:13:32 -04:00
|
|
|
|
2024-07-28 02:37:31 -04:00
|
|
|
b._client.on('login', () => {
|
2024-08-22 07:34:39 -04:00
|
|
|
b._client.write('settings', {
|
|
|
|
locale: 'ru_RU',
|
|
|
|
viewDistance: 4,
|
|
|
|
chatFlags: 0, // Enable full chat functionality
|
|
|
|
chatColors: true,
|
|
|
|
skinParts: 127, // Allow the second layer of the skin, when the bot is sudoed to do /skin
|
|
|
|
mainHand: 1 // Right hand
|
|
|
|
})
|
2024-09-12 00:26:36 -04:00
|
|
|
if (!b.host.options.useChat) {
|
2024-09-11 23:38:34 -04:00
|
|
|
b.add_sc_task('cc', () => {
|
|
|
|
b.chat(b.refillCoreCmd)
|
|
|
|
}, true)
|
|
|
|
b.add_sc_task('cc_size', () => {
|
|
|
|
b.chat('/gamerule commandModificationBlockLimit 32768')
|
|
|
|
})
|
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
})
|
|
|
|
b.on('ccstart', () => {
|
2024-08-22 07:34:39 -04:00
|
|
|
setTimeout(() => { b.interval.ccqi = setInterval(b.advanceccq, 2) }, 1000)
|
2024-07-28 02:37:31 -04:00
|
|
|
b.ccStarted = true
|
|
|
|
})
|
2024-09-19 00:31:15 -04:00
|
|
|
b.on('chat_unparsed', (data) => {
|
2024-07-28 02:37:31 -04:00
|
|
|
if (data.json.translate === 'commands.fill.failed' || (data.json.extra && data.json.extra[0] && data.json.extra[0].translate === 'commands.fill.failed') ||
|
|
|
|
data.json.translate === 'commands.fill.success' || (data.json.extra && data.json.extra[0] && data.json.extra[0].translate === 'commands.fill.success')) {
|
|
|
|
if (!b.ccStarted) {
|
|
|
|
b.emit('ccstart')
|
|
|
|
}
|
|
|
|
b.sc_tasks.cc.failed = 0
|
|
|
|
b.sc_tasks.cc_size.failed = 0
|
|
|
|
} else if (data.json.translate === 'commands.fill.toobig' || (data.json.extra && data.json.extra[0] && data.json.extra[0].translate === 'commands.fill.toobig')) {
|
|
|
|
b.sc_tasks.cc_size.failed = 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
b._client.on('position', function (a) {
|
|
|
|
if (!b.ccStarted) {
|
|
|
|
b.original_pos = { x: a.x, y: a.y, z: a.z }
|
2024-08-12 05:13:32 -04:00
|
|
|
b.pos = { x: a.x, y: a.y, z: a.z }
|
2024-07-28 02:37:31 -04:00
|
|
|
} else {
|
2024-08-12 05:13:32 -04:00
|
|
|
b.pos = { x: a.x, y: a.y, z: a.z }
|
2024-07-28 02:37:31 -04:00
|
|
|
if (a.x !== b.original_pos.x || a.z !== b.original_pos.z) {
|
|
|
|
b.original_pos = { x: a.x, y: a.y, z: a.z }
|
|
|
|
b.sc_tasks.cc.failed = 1
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
}
|
|
|
|
b.commandPos = {
|
2024-08-12 05:13:32 -04:00
|
|
|
x: Math.floor(a.x),
|
|
|
|
z: Math.floor(a.z),
|
|
|
|
y: 55
|
2024-07-28 02:37:31 -04:00
|
|
|
}
|
|
|
|
b._client.write('teleport_confirm', { teleportId: a.teleportId })
|
|
|
|
})
|
2024-08-12 05:13:32 -04:00
|
|
|
|
2024-07-28 02:37:31 -04:00
|
|
|
b.tellraw = (uuid, message) => {
|
|
|
|
let finalname = ''
|
2024-09-12 00:26:36 -04:00
|
|
|
if (b.host.options.useChat) {
|
|
|
|
if (b.host.options.useAmpersandColorCodes) {
|
|
|
|
b.chat(mcParser(message).replaceAll('§', '&'))
|
2024-09-11 23:38:34 -04:00
|
|
|
} else {
|
|
|
|
b.chat(plainParser(message))
|
|
|
|
}
|
2024-08-12 05:13:32 -04:00
|
|
|
} else {
|
2024-09-11 23:38:34 -04:00
|
|
|
if (uuid === '@a') {
|
|
|
|
finalname = '@a'
|
|
|
|
} else if (uuid.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)) {
|
|
|
|
finalname = `@a[nbt={UUID:[I;${uuidToInt(uuid)}]}]`
|
|
|
|
} else {
|
|
|
|
finalname = uuid
|
|
|
|
}
|
|
|
|
let tellrawCommand
|
|
|
|
if (b.host.options.isVanilla) {
|
|
|
|
tellrawCommand = 'tellraw'
|
|
|
|
} else {
|
|
|
|
tellrawCommand = 'minecraft:tellraw'
|
|
|
|
}
|
|
|
|
b.ccq.push(`/${tellrawCommand} ${finalname} ${JSON.stringify(message)}`)
|
2024-08-12 05:13:32 -04:00
|
|
|
}
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
}
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|