Refactor furnace input, fuel, and output handling: stringify on save and parse on load

This commit is contained in:
MayaTheShy
2026-03-21 18:21:23 -04:00
parent 80338d1973
commit 4af91235e1

View File

@@ -158,9 +158,9 @@ const saveFurnacesBatch = db.transaction((furnaces, now) => {
name, name,
type: f.type || 'minecraft:furnace', type: f.type || 'minecraft:furnace',
active: f.active ? 1 : 0, active: f.active ? 1 : 0,
input: f.input || null, input: f.input ? JSON.stringify(f.input) : null,
fuel: f.fuel || null, fuel: f.fuel ? JSON.stringify(f.fuel) : null,
output: f.output || null, output: f.output ? JSON.stringify(f.output) : null,
updatedAt: now, updatedAt: now,
}); });
} }
@@ -260,12 +260,16 @@ export function loadFurnaces() {
const rows = getAllFurnaces.all(); const rows = getAllFurnaces.all();
const result = {}; const result = {};
for (const row of rows) { for (const row of rows) {
let input = null, fuel = null, output = null;
try { input = row.input ? JSON.parse(row.input) : null; } catch { input = row.input; }
try { fuel = row.fuel ? JSON.parse(row.fuel) : null; } catch { fuel = row.fuel; }
try { output = row.output ? JSON.parse(row.output) : null; } catch { output = row.output; }
result[row.name] = { result[row.name] = {
active: !!row.active, active: !!row.active,
type: row.type, type: row.type,
input: row.input, input,
fuel: row.fuel, fuel,
output: row.output, output,
}; };
} }
return result; return result;
@@ -362,9 +366,9 @@ const _saveFullStateTransaction = db.transaction((state, now) => {
name, name,
type: f.type || 'minecraft:furnace', type: f.type || 'minecraft:furnace',
active: f.active ? 1 : 0, active: f.active ? 1 : 0,
input: f.input || null, input: f.input ? JSON.stringify(f.input) : null,
fuel: f.fuel || null, fuel: f.fuel ? JSON.stringify(f.fuel) : null,
output: f.output || null, output: f.output ? JSON.stringify(f.output) : null,
updatedAt: now, updatedAt: now,
}); });
} }