Skip to content

Commit feee0b9

Browse files
CopilotDaanV2
andauthored
Add base file support for general data to preserve potion type values across scrapes (#271)
The scraper was overwriting `potion_types.ts` with an empty array on each run because `General` had no base-loading mechanism — unlike BP/RP containers which seed from `src/base/` before scraping. ## Changes - **New base JSON files** in `packages/bedrock-vanilla-data/src/base/general/`: - `potion_types.json` — seeds the known values `["Consume", "ThrownLingering", "ThrownSplash"]` - `potion_modifiers.json` — empty placeholder following the same pattern - **`General.load(folder)`** — new static method on the `General` class that reads base values from JSON files before scraping populates the rest - **`Output.load()`** — updated to call `General.load(baseFolder/general)` alongside the existing `edu`/`vanilla` OutputSet loads - **`loadStringArray(filepath)`** — new helper in `json.ts` for loading plain string arrays; `loadEnsure<string>` silently wraps string items into `{ id }` objects (by design for BP/RP data), which is incorrect for simple string fields on `General` The flow is now consistent with BP/RP containers: base values are loaded first, scraped values are merged on top, and `cleanStrings()` deduplicates before saving. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/Blockception/minecraft-bedrock-language-server/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: DaanV2 <2393905+DaanV2@users.noreply.github.com>
1 parent 15d1ae0 commit feee0b9

5 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["Consume", "ThrownLingering", "ThrownSplash"]

tools/vanilla-scraper/src/classes/general.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import { Container as BPContainer } from '../bp/container';
44
import { cleanStrings, duplicateWithoutNamespace } from '../static/identifier-extension';
5+
import { loadStringArray } from '../static/json';
56
import { saveArray, saveSingle } from '../static/typescript';
67
import { GeneralEntity } from './general-entity';
78
import { Output } from './output';
@@ -23,6 +24,16 @@ export class General {
2324
potionTypes: string[] = [];
2425
features?: string[];
2526

27+
/**
28+
* Load general base data from a folder
29+
*/
30+
static load(folder: string): General {
31+
const out = new General();
32+
out.potionModifiers = loadStringArray(path.join(folder, 'potion_modifiers.json'));
33+
out.potionTypes = loadStringArray(path.join(folder, 'potion_types.json'));
34+
return out;
35+
}
36+
2637
/**
2738
* Scrape from output
2839
*/

tools/vanilla-scraper/src/classes/output.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class Output {
1717
const out = new Output();
1818
out.edu = OutputSet.load(path.join(folder, 'edu'));
1919
out.vanilla = OutputSet.load(path.join(folder, 'vanilla'));
20+
out.general = General.load(path.join(folder, 'general'));
2021

2122
return out;
2223
}

tools/vanilla-scraper/src/static/json.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,36 @@ export function loadEnsure<T>(filepath: string): T[] {
4848
return load<T[]>(filepath) ?? ([] as Array<T>);
4949
}
5050

51+
/**
52+
* Load a JSON file containing a string array, returning an empty array if file doesn't exist.
53+
* Handles both plain string arrays and arrays of objects with an 'id' or 'name' property.
54+
*/
55+
export function loadStringArray(filepath: string): string[] {
56+
if (!fs.existsSync(filepath)) {
57+
return [];
58+
}
59+
60+
try {
61+
const data = fs.readFileSync(filepath, 'utf-8');
62+
const cleaned = removeCommentsAndTrailingCommas(data);
63+
const result = JSON.parse(cleaned);
64+
65+
if (!Array.isArray(result)) return [];
66+
67+
return result.map((item): string => {
68+
if (typeof item === 'string') return item;
69+
if (typeof item === 'object' && item !== null) {
70+
const obj = item as Record<string, unknown>;
71+
return (typeof obj.id === 'string' ? obj.id : null) ?? (typeof obj.name === 'string' ? obj.name : null) ?? '';
72+
}
73+
return '';
74+
}).filter((s) => s.length > 0);
75+
} catch (ex) {
76+
console.error(ex);
77+
return [];
78+
}
79+
}
80+
5181
/**
5282
* Save data to a JSON file
5383
*/

0 commit comments

Comments
 (0)