diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-06-23 23:43:14 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-06-23 23:43:14 +0200 |
commit | 0028d1276f042953a4034016815593006d823f6d (patch) | |
tree | c3cea08bad6778e24fc3b7de905069f5c35889ff /index.js | |
parent | fcbea16f2ae86843eb214f64e02a96862e8e3564 (diff) |
generate json files programmatically
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 288 |
1 files changed, 288 insertions, 0 deletions
diff --git a/index.js b/index.js new file mode 100644 index 0000000..5c4c8ca --- /dev/null +++ b/index.js @@ -0,0 +1,288 @@ +const path = require('path'); +const fs = require('fs'); +const { execSync } = require('child_process'); + +const { jigsawConversion } = require('./src/worldgen/structure/index.js'); +const { TemplatePool, JigsawStartHeight } = require('./src/enum.js'); + + +const mcmetaPath = path.resolve(__dirname, 'mcmeta'); +execSync(`cd ${mcmetaPath} && git checkout 1.21-data`); + + +function getMetaData(dataPath) { + return JSON.parse( + fs.readFileSync( + path.resolve(mcmetaPath, `data/minecraft/${dataPath}.json`), + 'utf8' + ) + ); +} + + +function writeData(namespace, dataPath, data) { + // sort keys + const allKeys = new Set(); + JSON.stringify(data, (key, value) => (allKeys.add(key), value)); + const sortedKeys = Array.from(allKeys).sort(); + + // write file + return fs.writeFileSync( + path.resolve(__dirname, `data/${namespace}/${dataPath}.json`), + JSON.stringify(data, sortedKeys, 2) + ); +} + +function overwriteData(dataPath, data) { + return writeData('minecraft', dataPath, data); +} + + + +/* + * worldgen/noise_settings + */ + +function getWorldgenNoiseSettingsMeta(name) { + return getMetaData(`worldgen/noise_settings/${name}`); +} + +function overwriteWorldgenNoiseSettings(name, data) { + return overwriteData(`worldgen/noise_settings/${name}`, data); +} + + +// overworld +const overworld = getWorldgenNoiseSettingsMeta('overworld'); +Object.assign(overworld, { + aquifers_enabled: false, + ore_veins_enabled: false, + default_block: { + ...overworld.default_block, + + Name: 'minecraft:air', + }, + default_fluid: { + ...overworld.default_fluid, + + Name: 'minecraft:air', + }, + noise: { + ...overworld.noise, + + min_y: 0, + height: 320, + }, +}); +overwriteWorldgenNoiseSettings('overworld', overworld); + +// nether +const nether = getWorldgenNoiseSettingsMeta('nether'); +Object.assign(nether, { + default_block: { + ...nether.default_block, + + Name: 'minecraft:air', + }, + default_fluid: { + ...nether.default_fluid, + + Name: 'minecraft:air', + }, +}); +overwriteWorldgenNoiseSettings('nether', nether); + +// end +const end = getWorldgenNoiseSettingsMeta('end'); +Object.assign(end, { + default_block: { + ...end.default_block, + + Name: 'minecraft:air', + }, +}); +overwriteWorldgenNoiseSettings('end', end); + + + +/* + * worldgen/structure + */ + +function getWorldgenStructureMeta(name) { + return getMetaData(`worldgen/structure/${name}`); +} + +function overwriteWorldgenStructure(name, data) { + return overwriteData(`worldgen/structure/${name}`, data); +} + + +// ancient city +const ancientCity = getWorldgenStructureMeta('ancient_city'); +delete ancientCity['start_jigsaw_name']; +overwriteWorldgenStructure('ancient_city', ancientCity); + +// desert pyramid +let desertPyramid = getWorldgenStructureMeta('desert_pyramid'); +desertPyramid = jigsawConversion(desertPyramid, { + start_pool: 'vanilla_skyblock:desert_pyramid', + start_height: JigsawStartHeight.VERY_BIASED_TO_BOTTOM, +}); +overwriteWorldgenStructure('desert_pyramid', desertPyramid); + +// end city +let endCity = getWorldgenStructureMeta('end_city'); +endCity = jigsawConversion(endCity, { + start_pool: 'vanilla_skyblock:end_city', + start_height: JigsawStartHeight.UNIFORM, +}); +overwriteWorldgenStructure('end_city', endCity); + +// fortress +let fortress = getWorldgenStructureMeta('fortress'); +fortress = jigsawConversion(fortress, { + start_pool: TemplatePool.EMPTY_FULL, + start_height: JigsawStartHeight.BIASED_TO_BOTTOM, +}); +overwriteWorldgenStructure('fortress', fortress); + +// igloo +let igloo = getWorldgenStructureMeta('igloo'); +igloo = jigsawConversion(igloo, { + start_pool: TemplatePool.EMPTY_16, + start_height: JigsawStartHeight.UNIFORM, +}); +overwriteWorldgenStructure('igloo', igloo); + +// ocean monument +let monument = getWorldgenStructureMeta('monument'); +monument = jigsawConversion(monument, { + start_pool: TemplatePool.EMPTY_FULL, + start_height: JigsawStartHeight.BIASED_TO_BOTTOM, +}); +overwriteWorldgenStructure('monument', monument); + +// ocean ruin cold +let oceanRuinCold = getWorldgenStructureMeta('ocean_ruin_cold'); +oceanRuinCold = jigsawConversion(oceanRuinCold, { + start_pool: 'vanilla_skyblock:ocean_ruin_cold', + start_height: JigsawStartHeight.VERY_BIASED_TO_BOTTOM, +}); +overwriteWorldgenStructure('ocean_ruin_cold', oceanRuinCold); + +// ocean ruin cold +let oceanRuinWarm = getWorldgenStructureMeta('ocean_ruin_warm'); +oceanRuinWarm = jigsawConversion(oceanRuinWarm, { + start_pool: 'vanilla_skyblock:ocean_ruin_warm', + start_height: JigsawStartHeight.VERY_BIASED_TO_BOTTOM, +}); +overwriteWorldgenStructure('ocean_ruin_warm', oceanRuinWarm); + +// ruined portal +let ruinedPortal = getWorldgenStructureMeta('ruined_portal'); +ruinedPortal = jigsawConversion(ruinedPortal, { + start_pool: TemplatePool.EMPTY_16, + start_height: JigsawStartHeight.UNIFORM, +}); +overwriteWorldgenStructure('ruined_portal', ruinedPortal); + +// ruined portal +const ruinedPortals = [ + 'ruined_portal', + 'ruined_portal_desert', + 'ruined_portal_jungle', + 'ruined_portal_mountain', + 'ruined_portal_nether', + 'ruined_portal_ocean', + 'ruined_portal_swamp', +]; +for (const structure of ruinedPortals) { + let ruinedPortal = getWorldgenStructureMeta(structure); + ruinedPortal = jigsawConversion(ruinedPortal, { + start_pool: TemplatePool.EMPTY_16, + start_height: JigsawStartHeight.UNIFORM, + }); + overwriteWorldgenStructure(structure, ruinedPortal); +} + +// shipwreck +const shipwrecks = [ + 'shipwreck', + 'shipwreck_beached', +]; +for (const structure of shipwrecks) { + let shipwreck = getWorldgenStructureMeta(structure); + shipwreck = jigsawConversion(shipwreck, { + start_pool: TemplatePool.EMPTY_16, + start_height: JigsawStartHeight.UNIFORM, + }); + overwriteWorldgenStructure(structure, shipwreck); +} + +// stronhold +let stronghold = getWorldgenStructureMeta('stronghold'); +stronghold = jigsawConversion(stronghold, { + start_pool: 'vanilla_skyblock:stronghold', + start_height: JigsawStartHeight.VERY_BIASED_TO_BOTTOM, +}); +overwriteWorldgenStructure('stronghold', stronghold); + +// trail ruins +const trailRuins = getWorldgenStructureMeta('trail_ruins'); +delete trailRuins['project_start_to_heightmap']; +overwriteWorldgenStructure('trail_ruins', trailRuins); + + + +/* + * worldgen/noise + */ + +const noisesToSilence = [ + 'iceberg_pillar', + 'iceberg_pillar_roof', + 'iceberg_surface', +]; +for (const noise of noisesToSilence) { + const noiseData = getMetaData(`worldgen/noise/${noise}`); + Object.assign(noiseData, { + firstOctave: 0, + amplitudes: [], + }); + overwriteData(`worldgen/noise/${noise}`, noiseData); +} + + + +/* + * worldgen/configured_feature + */ + +const featuresToRemove = [ + 'end_island', + 'iceberg_blue', + 'iceberg_packed', +]; +for (const feature of featuresToRemove) { + const featureData = getMetaData(`worldgen/configured_feature/${feature}`); + Object.assign(featureData, { + type: 'minecraft:fill_layer', + config: { + state: { + Name: 'minecraft:air' + }, + height: 0, + }, + }); + overwriteData(`worldgen/configured_feature/${feature}`, featureData); +} + + + +/* + * structure/*.nbt + */ + +// TODO if applicable check worldgen/structure.json for pool_start and get location of nbt files. +// write to nbt files accordingly |