summaryrefslogtreecommitdiff
path: root/index.js
blob: 116f951798cfaa7ac20b8b0885c1700976bd7a0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
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 getData(namespace, dataPath) {
  let encoding = '';
  if (dataPath.endsWith('json')) {
    encoding = 'utf8';
  }

  return fs.readFileSync(
    path.resolve(__dirname, `data/${namespace}/${dataPath}`),
    encoding
  );
}

function getJsonData(namespace, dataPath) {
  return JSON.parse(
    getData(namespace, `${dataPath}.json`)
  );
}


function writeData(namespace, dataPath, data) {
  return fs.writeFileSync(
    path.resolve(__dirname, `data/${namespace}/${dataPath}`),
    data
  );
}

function overwriteData(dataPath, data) {
  return writeData('minecraft', dataPath, data);
}

function writeJson(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 writeData(
    namespace,
    `${dataPath}.json`,
    JSON.stringify(data, sortedKeys, 2)
  );
}

function overwriteJson(dataPath, data) {
  return writeJson('minecraft', dataPath, data);
}


function replaceData(source, destination) {
  const destinationDirectory = path.resolve(__dirname, `data/minecraft/${path.dirname(destination)}`);
  if (!fs.existsSync(destinationDirectory)) {
    fs.mkdirSync(destinationDirectory, { recursive: true });
  }

  return fs.copyFileSync(
    path.resolve(__dirname, `data/original_skyblock/${source}`),
    path.resolve(__dirname, `data/minecraft/${destination}`)
  );
}



/*
 * worldgen/noise_settings
 */

function getWorldgenNoiseSettingsMeta(name) {
  return getMetaData(`worldgen/noise_settings/${name}`);
}

function overwriteWorldgenNoiseSettings(name, data) {
  return overwriteJson(`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 overwriteJson(`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: TemplatePool.EMPTY_FULL,
  start_height: JigsawStartHeight.VERY_BIASED_TO_BOTTOM,
});
overwriteWorldgenStructure('desert_pyramid', desertPyramid);

// end city
let endCity = getWorldgenStructureMeta('end_city');
endCity = jigsawConversion(endCity, {
	start_pool: TemplatePool.EMPTY_FULL,
  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_FULL,
  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: TemplatePool.EMPTY_FULL,
  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: TemplatePool.EMPTY_FULL,
  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_FULL,
  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_FULL,
    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_FULL,
    start_height: JigsawStartHeight.UNIFORM,
  });
  overwriteWorldgenStructure(structure, shipwreck);
}

// stronhold
let stronghold = getWorldgenStructureMeta('stronghold');
stronghold = jigsawConversion(stronghold, {
  start_pool: 'original_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: [],
  });
  overwriteJson(`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,
    },
  });
  overwriteJson(`worldgen/configured_feature/${feature}`, featureData);
}



/*
 * structure/*.nbt
 */

// ancient city
const ancientCityStartPool = ancientCity.start_pool.replace('minecraft:', '');
const ancientCityTemplatePool = getMetaData(`worldgen/template_pool/${ancientCityStartPool}`);
for (const templatePoolElement of ancientCityTemplatePool.elements) {
  const location = templatePoolElement.element.location.replace('minecraft:', '');
  replaceData('structure/empty_full.nbt', `structure/${location}.nbt`);
}

// bastion
const bastionStartPool = getWorldgenStructureMeta('bastion_remnant').start_pool.replace('minecraft:', '');
const bastionTemplatePool = getMetaData(`worldgen/template_pool/${bastionStartPool}`);
for (const templatePoolElement of bastionTemplatePool.elements) {
  const location = templatePoolElement.element.location.replace('minecraft:', '');
  replaceData('structure/empty_full.nbt', `structure/${location}.nbt`);
}

// pillager outpost
const pillagerOutpostStartPool = getWorldgenStructureMeta('pillager_outpost').start_pool.replace('minecraft:', '');
const pillagerOutpostTemplatePool = getMetaData(`worldgen/template_pool/${pillagerOutpostStartPool}`);
for (const templatePoolElement of pillagerOutpostTemplatePool.elements) {
  const location = templatePoolElement.element.location.replace('minecraft:', '');
  replaceData('structure/empty_full.nbt', `structure/${location}.nbt`);
}

// trail ruins
const trailRuinsStartPool = getWorldgenStructureMeta('trail_ruins').start_pool.replace('minecraft:', '');
const trailRuinsTemplatePool = getMetaData(`worldgen/template_pool/${trailRuinsStartPool}`);
for (const idx in trailRuinsTemplatePool.elements) {
  const templatePoolElement = trailRuinsTemplatePool.elements[idx];
  const location = templatePoolElement.element.location.replace('minecraft:', '');
  replaceData('structure/empty_full.nbt', `structure/${location}.nbt`);
}

// trial chambers
const trialChambersStartPool = getWorldgenStructureMeta('trial_chambers').start_pool.replace('minecraft:', '');
const trialChambersTemplatePool = getMetaData(`worldgen/template_pool/${trialChambersStartPool}`);
for (const templatePoolElement of trialChambersTemplatePool.elements) {
  const location = templatePoolElement.element.location.replace('minecraft:', '');
  replaceData('structure/empty_full.nbt', `structure/${location}.nbt`);
}

// villages
const villages = [
  'village_desert',
  'village_plains',
  'village_savanna',
  'village_snowy',
  'village_taiga',
];
for (const village of villages) {
  const villageStartPool = getWorldgenStructureMeta(village).start_pool.replace('minecraft:', '');
  const villageTemplatePool = getMetaData(`worldgen/template_pool/${villageStartPool}`);
  for (const templatePoolElement of villageTemplatePool.elements) {
    const location = templatePoolElement.element.location.replace('minecraft:', '');
    replaceData('structure/empty_full.nbt', `structure/${location}.nbt`);
  }
}