Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional minecraft: prefix #39

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions lib/pc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ nbt.float = value => ({ type: 'float', value })

const { networkBiomesToMcDataSchema, mcDataSchemaToNetworkBiomes } = require('./transforms')

const getEntry = (obj, key) => obj?.[key] ?? obj?.['minecraft:' + key]
// TODO depending on the MC version, entries need to be prefixed with "minecraft:" or not
const setEntry = (obj, key, val) => {
obj[key] = val
}

module.exports = (data, staticData) => {
let hasDynamicDimensionData = false

return {
loadDimensionCodec (codec) {
const dimensionCodec = nbt.simplify(codec)

const chat = dimensionCodec['minecraft:chat_type']?.value
const chat = getEntry(dimensionCodec, 'chat_type')?.value
if (chat) {
data.chatFormattingById = {}
data.chatFormattingByName = {}
Expand All @@ -22,15 +28,14 @@ module.exports = (data, staticData) => {
id: chatType.id,
name: chatType.name,
formatString: staticData.language[d.translation_key] || d.translation_key /* chat type minecraft:raw has the formatString given directly by the translation key */,
parameters: d.parameters,
style: d.style
parameters: d.parameters
}
data.chatFormattingById[chatType.id] = n
data.chatFormattingByName[chatType.name] = n
}
}

const dimensions = dimensionCodec['minecraft:dimension_type']?.value
const dimensions = getEntry(dimensionCodec, 'dimension_type')?.value
if (dimensions) {
data.dimensionsById = {}
data.dimensionsByName = {}
Expand All @@ -46,7 +51,7 @@ module.exports = (data, staticData) => {
}
}

const biomes = dimensionCodec['minecraft:worldgen/biome']?.value
const biomes = getEntry(dimensionCodec, 'worldgen/biome')?.value
if (!biomes) {
return // no biome data
}
Expand Down Expand Up @@ -78,7 +83,7 @@ module.exports = (data, staticData) => {
// Keep the old dimension codec data if it exists (re-encoding)
// We don't have this data statically, should probably be added to mcData
if (data.dimensionsArray) {
codec['minecraft:dimension_type'] = nbt.comp({
setEntry(codec, 'dimension_type', nbt.comp({
type: nbt.string('minecraft:dimension_type'),
value: nbt.list(nbt.comp(
data.dimensionsArray.map(dimension => ({
Expand All @@ -87,19 +92,19 @@ module.exports = (data, staticData) => {
element: dimension.element
}))
))
})
}))
} else {
codec['minecraft:dimension_type'] = staticData.loginPacket.dimensionCodec.value['minecraft:dimension_type']
setEntry(codec, 'dimension_type', getEntry(staticData.loginPacket.dimensionCodec.value, 'dimension_type'))
}

// if we have dynamic biome data (re-encoding), we can count on biome.effects
// being in place. Otherwise, we need to use static data exclusively, e.g. flying squid.
codec['minecraft:worldgen/biome'] = nbt.comp({
setEntry(codec, 'worldgen/biome', nbt.comp({
type: nbt.string('minecraft:worldgen/biome'),
value: nbt.list(nbt.comp(mcDataSchemaToNetworkBiomes(hasDynamicDimensionData ? data.biomesArray : null, staticData)))
})
}))
// 1.19
codec['minecraft:chat_type'] = staticData.loginPacket.dimensionCodec?.value?.['minecraft:chat_type']
setEntry(codec, 'chat_type', getEntry(staticData.loginPacket.dimensionCodec?.value, 'chat_type'))
}

return nbt.comp(codec)
Expand Down
Loading