From 902e783d8ac4632177861eb7e0738b1d8b4e578d Mon Sep 17 00:00:00 2001 From: Jochen Jacobs Date: Sun, 1 Oct 2023 17:57:48 +0200 Subject: [PATCH] update to mc-datapack-loader 0.3.1, fix exporter --- package-lock.json | 14 +++++++------- package.json | 2 +- src/main/BuilderData/Exporter.ts | 19 ++++++++++--------- src/main/BuilderData/LegacyConfigDatapack.ts | 16 ++++++++-------- src/main/UI/SettingsManager.ts | 4 ++-- src/main/UI/VisualizationManager.ts | 3 ++- src/main/Visualization/BiomeLayer.ts | 12 ++++++------ 7 files changed, 36 insertions(+), 34 deletions(-) diff --git a/package-lock.json b/package-lock.json index f734412..945f762 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "jszip": "^3.10.1", "leaflet": "^1.7.1", "lodash": "^4.17.21", - "mc-datapack-loader": "0.2.2", + "mc-datapack-loader": "0.3.1", "sweetalert2": "^11.4.24", "tilelayer-canvas": "^1.1.3", "uniqid": "^5.4.0" @@ -4482,9 +4482,9 @@ } }, "node_modules/mc-datapack-loader": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/mc-datapack-loader/-/mc-datapack-loader-0.2.2.tgz", - "integrity": "sha512-RHfD9rfbs0fhw0B8tpsuN7WJEfz+h+FQUzpBWvo9riqdEQqUmIJHUn1IegIzHuXUavmvVoEqIzBoTGgY5YD5ig==", + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/mc-datapack-loader/-/mc-datapack-loader-0.3.1.tgz", + "integrity": "sha512-X8n1HPP0vsLvdf81OqsTVmWrgIttzfVeEp/zGHvACbyAFfcFZoHPd5S66SCZzBV3BUF+TP8dCWW5J3lRL2meRw==", "dependencies": { "@fireflysemantics/join": "^1.0.14", "deepslate": "^0.13.2", @@ -9126,9 +9126,9 @@ } }, "mc-datapack-loader": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/mc-datapack-loader/-/mc-datapack-loader-0.2.2.tgz", - "integrity": "sha512-RHfD9rfbs0fhw0B8tpsuN7WJEfz+h+FQUzpBWvo9riqdEQqUmIJHUn1IegIzHuXUavmvVoEqIzBoTGgY5YD5ig==", + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/mc-datapack-loader/-/mc-datapack-loader-0.3.1.tgz", + "integrity": "sha512-X8n1HPP0vsLvdf81OqsTVmWrgIttzfVeEp/zGHvACbyAFfcFZoHPd5S66SCZzBV3BUF+TP8dCWW5J3lRL2meRw==", "requires": { "@fireflysemantics/join": "^1.0.14", "deepslate": "^0.13.2", diff --git a/package.json b/package.json index f7992eb..cd481ef 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "jszip": "^3.10.1", "leaflet": "^1.7.1", "lodash": "^4.17.21", - "mc-datapack-loader": "0.2.2", + "mc-datapack-loader": "0.3.1", "sweetalert2": "^11.4.24", "tilelayer-canvas": "^1.1.3", "uniqid": "^5.4.0" diff --git a/src/main/BuilderData/Exporter.ts b/src/main/BuilderData/Exporter.ts index 27fddd6..319be11 100644 --- a/src/main/BuilderData/Exporter.ts +++ b/src/main/BuilderData/Exporter.ts @@ -1,6 +1,6 @@ import { Climate, Identifier } from "deepslate"; import JSZip from "jszip"; -import { Datapack, PackMcmeta } from "mc-datapack-loader"; +import { Datapack, PackMcmeta, ResourceLocation } from "mc-datapack-loader"; import { MAX_DATAPACK_FORMAT, MIN_DATAPACK_FORMAT } from "../../SharedConstants"; import { UI } from "../UI/UI"; import { VanillaBiomes } from "../Vanilla/VanillaBiomes"; @@ -59,7 +59,7 @@ export class Exporter { for (var i = 0 ; i < folders.length - 1 ; i++){ folder = folder.folder(folders[i]) } - folder.file(filename + ".json", this.getDimensionJSON()) + folder.file(filename + ".json", JSON.stringify(this.getDimensionJSON(), undefined, 2)) if (this.builder.exportSplines){ const densityFunctionFolder = dataFolder.folder("minecraft").folder("worldgen").folder("density_function").folder("overworld") @@ -80,15 +80,15 @@ export class Exporter { throw new Error("Datapack does not support saving") const dimensionIdentifier = Identifier.parse(this.builder.dimensionName) - datapack.save("dimension", dimensionIdentifier, this.getDimensionJSON()) + datapack.save(ResourceLocation.DIMENSION, dimensionIdentifier, this.getDimensionJSON()) if (this.builder.exportSplines){ - datapack.save("worldgen/density_function", new Identifier("minecraft", "offset"), await fetch(`export_presets/${this.builder.targetVersion}/offset.json`).then(s => s.text()).then(s => s.replace("%s", JSON.stringify(this.builder.splines.offset.export())))) - datapack.save("worldgen/density_function", new Identifier("minecraft", "factor"), await fetch(`export_presets/${this.builder.targetVersion}/factor.json`).then(s => s.text()).then(s => s.replace("%s", JSON.stringify(this.builder.splines.factor.export())))) - datapack.save("worldgen/density_function", new Identifier("minecraft", "jaggedness"), await fetch(`export_presets/${this.builder.targetVersion}/jaggedness.json`).then(s => s.text()).then(s => s.replace("%s", JSON.stringify(this.builder.splines.jaggedness.export())))) + datapack.save(ResourceLocation.WORLDGEN_DENSITY_FUNCTION, new Identifier("minecraft", "offset"), JSON.parse(await fetch(`export_presets/${this.builder.targetVersion}/offset.json`).then(s => s.text()).then(s => s.replace("%s", JSON.stringify(this.builder.splines.offset.export()))))) + datapack.save(ResourceLocation.WORLDGEN_DENSITY_FUNCTION, new Identifier("minecraft", "factor"), JSON.parse(await fetch(`export_presets/${this.builder.targetVersion}/factor.json`).then(s => s.text()).then(s => s.replace("%s", JSON.stringify(this.builder.splines.factor.export()))))) + datapack.save(ResourceLocation.WORLDGEN_DENSITY_FUNCTION, new Identifier("minecraft", "jaggedness"), JSON.parse(await fetch(`export_presets/${this.builder.targetVersion}/jaggedness.json`).then(s => s.text()).then(s => s.replace("%s", JSON.stringify(this.builder.splines.jaggedness.export()))))) } if (this.builder.exportBiomeColors){ - datapack.save("", new Identifier("c", "worldgen/biome_colors"), this.getBiomeColorJson()) + datapack.save(ResourceLocation.DATA_FILE, new Identifier("c", "worldgen/biome_colors"), this.getBiomeColorJson()) } } @@ -138,7 +138,7 @@ export class Exporter { }*/ - public getDimensionJSON(): string { + public getDimensionJSON(): unknown { const array: { biome: string, done: boolean }[][][][][][] = [] for (let d_idx = 0; d_idx < this.builder.gridCells.depth.length - 1; d_idx++) { @@ -281,8 +281,9 @@ export class Exporter { } console.log("Emmited " + biomes.length + " Biome settings...") + console.log(dimension) - return (JSON.stringify(dimension)) + return dimension } diff --git a/src/main/BuilderData/LegacyConfigDatapack.ts b/src/main/BuilderData/LegacyConfigDatapack.ts index 8aabdc8..cb33eda 100644 --- a/src/main/BuilderData/LegacyConfigDatapack.ts +++ b/src/main/BuilderData/LegacyConfigDatapack.ts @@ -1,5 +1,5 @@ import { Identifier } from "deepslate"; -import { Datapack, DataType, PackMcmeta, UNKOWN_PACK } from "mc-datapack-loader"; +import { Datapack, ResourceLocation, PackMcmeta, UNKOWN_PACK } from "mc-datapack-loader"; import { MenuManager } from "../UI/MenuManager"; import { BiomeBuilder } from "./BiomeBuilder"; @@ -134,7 +134,7 @@ export class LegacyConfigDatapack implements Datapack { } - async save(_type: DataType.Path, _id: Identifier, _data: unknown | ArrayBuffer): Promise { + async save(_type: ResourceLocation, _id: Identifier, _data: unknown | ArrayBuffer): Promise { throw new Error("Can't write to readonly Datapack") } @@ -155,24 +155,24 @@ export class LegacyConfigDatapack implements Datapack { } } - async has(type: DataType.Path, id: Identifier): Promise { - if (type === "worldgen/density_function" && this.builder.exportSplines) { + async has(type: ResourceLocation, id: Identifier): Promise { + if (type.location === "worldgen/density_function" && this.builder.exportSplines) { return DENSITY_FUNCTIONS.includes(id.toString()) } else { return false } } - async getIds(type: DataType.Path): Promise { - if (type === "worldgen/density_function" && this.builder.exportSplines) { + async getIds(type: ResourceLocation): Promise { + if (type.location === "worldgen/density_function" && this.builder.exportSplines) { return DENSITY_FUNCTIONS.map((str) => Identifier.parse(str)) } else { return [] } } - async get(type: DataType.Path, id: Identifier): Promise { - if (type === "worldgen/density_function" && id.namespace === "minecraft" && this.builder.exportSplines) { + async get(type: ResourceLocation, id: Identifier): Promise { + if (type.location === "worldgen/density_function" && id.namespace === "minecraft" && this.builder.exportSplines) { if (id.path === "overworld/offset") return OFFSET_DF(this.builder.splines["offset"].export()) else if (id.path === "overworld/factor") diff --git a/src/main/UI/SettingsManager.ts b/src/main/UI/SettingsManager.ts index 972e6fa..0f4afec 100644 --- a/src/main/UI/SettingsManager.ts +++ b/src/main/UI/SettingsManager.ts @@ -1,5 +1,5 @@ import * as d3 from "d3"; -import { Datapack } from "mc-datapack-loader" +import { Datapack, ResourceLocation } from "mc-datapack-loader" import { MAX_DATAPACK_FORMAT, MIN_DATAPACK_FORMAT } from "../../SharedConstants"; import { BiomeBuilder } from "../BuilderData/BiomeBuilder" import { Exporter } from "../BuilderData/Exporter"; @@ -39,7 +39,7 @@ export class SettingsManager { const noiseSettingsNameSelect = d3.select("#noise_settings_name") - const noiseSettings = (await this.builder.compositeDatapack.getIds("worldgen/noise_settings")).map(id => id.toString()) + const noiseSettings = (await this.builder.compositeDatapack.getIds(ResourceLocation.WORLDGEN_NOISE_SETTINGS)).map(id => id.toString()) var missingNoiseSetting = false diff --git a/src/main/UI/VisualizationManager.ts b/src/main/UI/VisualizationManager.ts index 51d1164..e93571b 100644 --- a/src/main/UI/VisualizationManager.ts +++ b/src/main/UI/VisualizationManager.ts @@ -1,6 +1,7 @@ import { Climate, Identifier, NoiseSettings } from "deepslate"; import * as L from "leaflet"; import { clamp } from "lodash"; +import { ResourceLocation } from "mc-datapack-loader"; import { BiomeBuilder, MultiNoiseIndexes } from "../BuilderData/BiomeBuilder"; import { GridElementUnassigned } from "../BuilderData/GridElementUnassigned"; import { BiomeLayer } from "../Visualization/BiomeLayer"; @@ -240,7 +241,7 @@ export class VisualizationManger { if (!this.closeContainer.classList.contains("closed")) { if (change.map_display) { - const noise_settings_json = (await this.builder.compositeDatapack.get("worldgen/noise_settings", Identifier.parse(this.builder.noiseSettingsName))) as any + const noise_settings_json = (await this.builder.compositeDatapack.get(ResourceLocation.WORLDGEN_NOISE_SETTINGS, Identifier.parse(this.builder.noiseSettingsName))) as any var noise_settings if (noise_settings_json !== undefined){ noise_settings = NoiseSettings.fromJson(noise_settings_json.noise) diff --git a/src/main/Visualization/BiomeLayer.ts b/src/main/Visualization/BiomeLayer.ts index 7e2d303..6322af8 100644 --- a/src/main/Visualization/BiomeLayer.ts +++ b/src/main/Visualization/BiomeLayer.ts @@ -8,7 +8,7 @@ import { BiomeBuilder, MultiNoiseIndexes } from "../BuilderData/BiomeBuilder"; import { Change, UI } from "../UI/UI"; import { timer } from "d3"; import { getSurfaceDensityFunction, lerp2Climate } from "../util"; -import { AnonymousDatapack, Datapack } from "mc-datapack-loader"; +import { AnonymousDatapack, Datapack, ResourceLocation } from "mc-datapack-loader"; import MultiNoiseWorker from "../../multinoiseworker/worker?worker" const WORKER_COUNT = 4 @@ -165,8 +165,8 @@ export class BiomeLayer extends L.GridLayer { } async loadDatapack(datapack: AnonymousDatapack) { - for (const id of await datapack.getIds("worldgen/density_function")) { - const dfJson = await datapack.get("worldgen/density_function", id) + for (const id of await datapack.getIds(ResourceLocation.WORLDGEN_DENSITY_FUNCTION)) { + const dfJson = await datapack.get(ResourceLocation.WORLDGEN_DENSITY_FUNCTION, id) this.workers.forEach(w => w.postMessage({ task: "addDensityFunction", json: dfJson, @@ -177,8 +177,8 @@ export class BiomeLayer extends L.GridLayer { WorldgenRegistries.DENSITY_FUNCTION.register(id, df) } - for (const id of await datapack.getIds("worldgen/noise")) { - const noiseJson = await datapack.get("worldgen/noise", id) + for (const id of await datapack.getIds(ResourceLocation.WORLDGEN_NOISE)) { + const noiseJson = await datapack.get(ResourceLocation.WORLDGEN_NOISE, id) this.workers.forEach(w => w.postMessage({ task: "addNoise", json: noiseJson, @@ -190,7 +190,7 @@ export class BiomeLayer extends L.GridLayer { } - const noiseSettingsJson = await datapack.get("worldgen/noise_settings", Identifier.parse(this.builder.noiseSettingsName)) + const noiseSettingsJson = await datapack.get(ResourceLocation.WORLDGEN_NOISE_SETTINGS, Identifier.parse(this.builder.noiseSettingsName)) this.workers.forEach(w => w.postMessage({ task: "setNoiseGeneratorSettings", json: noiseSettingsJson,