Skip to content

Commit

Permalink
next release (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Oct 6, 2024
2 parents f13e535 + bd180ef commit f1f4078
Show file tree
Hide file tree
Showing 25 changed files with 311 additions and 176 deletions.
6 changes: 4 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
"defaultHost": "<from-proxy>",
"defaultProxy": "proxy.mcraft.fun",
"mapsProvider": "https://maps.mcraft.fun/",
"peerJsServer": "",
"peerJsServerFallback": "https://p2p.mcraft.fun",
"promoteServers": [
{
"ip": "kaboom.pw",
"version": "1.18.2",
"description": "Chaos and destruction server. Free for everyone."
},
{
"ip": "go.mineberry.org",
"ip": "play.applemc.fun",
"version": "1.18.2",
"description": "One of the best servers here. Join now!"
"description": "Very nice server. Try it now!"
},
{
"ip": "sus.shhnowisnottheti.me",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@floating-ui/react": "^0.26.1",
"@mui/base": "5.0.0-beta.40",
"@nxg-org/mineflayer-auto-jump": "^0.7.12",
"@nxg-org/mineflayer-tracker": "^1.2.3",
"@nxg-org/mineflayer-tracker": "1.2.1",
"@react-oauth/google": "^0.12.1",
"@stylistic/eslint-plugin": "^2.6.1",
"@types/gapi": "^0.0.47",
Expand Down
37 changes: 30 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions prismarine-viewer/viewer/lib/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export class Entities extends EventEmitter {
}

update (entity: import('prismarine-entity').Entity & { delete?; pos }, overrides) {
console.log('entity', entity)
const isPlayerModel = entity.name === 'player'
if (entity.name === 'zombie' || entity.name === 'zombie_villager' || entity.name === 'husk') {
overrides.texture = `textures/1.16.4/entity/${entity.name === 'zombie_villager' ? 'zombie_villager/zombie_villager.png' : `zombie/${entity.name}.png`}`
Expand Down
2 changes: 1 addition & 1 deletion prismarine-viewer/viewer/lib/worldDataEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EventEmitter } from 'events'
import { generateSpiralMatrix, ViewRect } from 'flying-squid/dist/utils'
import { Vec3 } from 'vec3'
import { BotEvents } from 'mineflayer'
import { getItemFromBlock } from '../../../src/botUtils'
import { getItemFromBlock } from '../../../src/chatUtils'
import { chunkPos } from './simpleUtils'

export type ChunkPosKey = string
Expand Down
134 changes: 16 additions & 118 deletions src/botUtils.ts
Original file line number Diff line number Diff line change
@@ -1,122 +1,20 @@
// this should actually be moved to mineflayer / prismarine-viewer
import { versionToNumber } from 'prismarine-viewer/viewer/prepare/utils'

import { fromFormattedString, TextComponent } from '@xmcl/text-component'
import type { IndexedData } from 'minecraft-data'

export type MessageFormatPart = Pick<TextComponent, 'hoverEvent' | 'clickEvent'> & {
text: string
color?: string
bold?: boolean
italic?: boolean
underlined?: boolean
strikethrough?: boolean
obfuscated?: boolean
}

type MessageInput = {
text?: string
translate?: string
with?: Array<MessageInput | string>
color?: string
bold?: boolean
italic?: boolean
underlined?: boolean
strikethrough?: boolean
obfuscated?: boolean
extra?: MessageInput[]
json?: any
}

const global = globalThis as any

// todo move to sign-renderer, replace with prismarine-chat, fix mcData issue!
export const formatMessage = (message: MessageInput, mcData: IndexedData = global.loadedData) => {
let msglist: MessageFormatPart[] = []

const readMsg = (msg: MessageInput) => {
const styles = {
color: msg.color,
bold: !!msg.bold,
italic: !!msg.italic,
underlined: !!msg.underlined,
strikethrough: !!msg.strikethrough,
obfuscated: !!msg.obfuscated
}

if (msg.text) {
msglist.push({
...msg,
text: msg.text,
...styles
})
} else if (msg.translate) {
const tText = mcData?.language[msg.translate] ?? msg.translate

if (msg.with) {
const splitted = tText.split(/%s|%\d+\$s/g)

let i = 0
for (const [j, part] of splitted.entries()) {
msglist.push({ text: part, ...styles })

if (j + 1 < splitted.length) {
if (msg.with[i]) {
const msgWith = msg.with[i]
if (typeof msgWith === 'string') {
readMsg({
...styles,
text: msgWith
})
} else {
readMsg({
...styles,
...msgWith
})
}
}
i++
}
}
} else {
msglist.push({
...msg,
text: tText,
...styles
})
}
}

if (msg.extra) {
for (const ex of msg.extra) {
readMsg({ ...styles, ...ex })
}
}
export const displayClientChat = (text: string) => {
const message = {
text
}

readMsg(message)

const flat = (msg) => {
return [msg, msg.extra?.flatMap(flat) ?? []]
if (versionToNumber(bot.version) >= versionToNumber('1.19')) {
bot._client.emit('systemChat', {
formattedMessage: JSON.stringify(message),
position: 0,
sender: 'minecraft:chat'
})
return
}

msglist = msglist.map(msg => {
// normalize §
if (!msg.text.includes?.('§')) return msg
const newMsg = fromFormattedString(msg.text)
return flat(newMsg)
}).flat(Infinity)

return msglist
}

const blockToItemRemaps = {
water: 'water_bucket',
lava: 'lava_bucket',
redstone_wire: 'redstone',
tripwire: 'tripwire_hook'
}

export const getItemFromBlock = (block: import('prismarine-block').Block) => {
const item = global.loadedData.itemsByName[blockToItemRemaps[block.name] ?? block.name]
return item
bot._client.write('chat', {
message: JSON.stringify(message),
position: 0,
sender: 'minecraft:chat'
})
}
5 changes: 2 additions & 3 deletions src/builtinCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { closeWan, openToWanAndCopyJoinLink } from './localServerMultiplayer'
import { copyFilesAsync, uniqueFileNameFromWorldName } from './browserfs'
import { saveServer } from './flyingSquidUtils'
import { setLoadingScreenStatus } from './utils'
import { displayClientChat } from './botUtils'

const notImplemented = () => {
return 'Not implemented yet'
Expand Down Expand Up @@ -75,9 +76,7 @@ const exportLoadedWorld = async () => {
window.exportWorld = exportLoadedWorld

const writeText = (text) => {
bot._client.emit('chat', {
message: JSON.stringify({ text })
})
displayClientChat(text)
}

const commands: Array<{
Expand Down
2 changes: 1 addition & 1 deletion src/botUtils.test.ts → src/chatUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from 'vitest'
import mcData from 'minecraft-data'
import { formatMessage } from './botUtils'
import { formatMessage } from './chatUtils'

//@ts-expect-error
globalThis.loadedData ??= mcData('1.20.1')
Expand Down
Loading

0 comments on commit f1f4078

Please sign in to comment.