Skip to content

Commit

Permalink
update to mc-datapack-loader 0.3.1, fix exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsjo committed Oct 1, 2023
1 parent aa3aa0c commit 902e783
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 10 additions & 9 deletions src/main/BuilderData/Exporter.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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")
Expand All @@ -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())
}
}

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -281,8 +281,9 @@ export class Exporter {
}

console.log("Emmited " + biomes.length + " Biome settings...")
console.log(dimension)

return (JSON.stringify(dimension))
return dimension
}


Expand Down
16 changes: 8 additions & 8 deletions src/main/BuilderData/LegacyConfigDatapack.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -134,7 +134,7 @@ export class LegacyConfigDatapack implements Datapack {

}

async save(_type: DataType.Path, _id: Identifier, _data: unknown | ArrayBuffer): Promise<boolean> {
async save(_type: ResourceLocation, _id: Identifier, _data: unknown | ArrayBuffer): Promise<boolean> {
throw new Error("Can't write to readonly Datapack")
}

Expand All @@ -155,24 +155,24 @@ export class LegacyConfigDatapack implements Datapack {
}
}

async has(type: DataType.Path, id: Identifier): Promise<boolean> {
if (type === "worldgen/density_function" && this.builder.exportSplines) {
async has(type: ResourceLocation, id: Identifier): Promise<boolean> {
if (type.location === "worldgen/density_function" && this.builder.exportSplines) {
return DENSITY_FUNCTIONS.includes(id.toString())
} else {
return false
}
}

async getIds(type: DataType.Path): Promise<Identifier[]> {
if (type === "worldgen/density_function" && this.builder.exportSplines) {
async getIds(type: ResourceLocation): Promise<Identifier[]> {
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<unknown> {
if (type === "worldgen/density_function" && id.namespace === "minecraft" && this.builder.exportSplines) {
async get(type: ResourceLocation, id: Identifier): Promise<unknown> {
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")
Expand Down
4 changes: 2 additions & 2 deletions src/main/UI/SettingsManager.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/main/UI/VisualizationManager.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/main/Visualization/BiomeLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 902e783

Please sign in to comment.