Skip to content

Commit

Permalink
json optimiser minecraft: prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanhowell5195 committed Aug 16, 2024
1 parent c1bb4ff commit caa274d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions plugins/resource_pack_utilities/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
"date": "2024-08-16",
"author": "Ewan Howell",
"categories": [
{
"title": "New Features",
"list": [
"JSON Optimiser now has an option to remove \"minecraft:\" prefixes"
]
},
{
"title": "Changes",
"list": [
Expand Down
12 changes: 10 additions & 2 deletions plugins/resource_pack_utilities/resource_pack_utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,7 @@
<li>Minifies <code>.json</code>, <code>.mcmeta</code>, <code>.jem</code>, and <code>.jpm</code> files</li>
<li>Removes default credits. Custom credits are kept</li>
<li>Removes unnecessary keys</li>
<li>Removes <code>minecraft:</code> prefixes</li>
<li>For block/item model <code>.json</code> files
<ul>
<li>Removes the <code>groups</code> object</li>
Expand Down Expand Up @@ -2155,6 +2156,7 @@
jem: true,
jpm: true
},
prefixes: true,
minify: true,
ignoreList: [],
outputLog,
Expand Down Expand Up @@ -2382,11 +2384,16 @@
if (this.types.jpm && file.endsWith(".jpm")) {
processPart(data)
}
let output
if (this.minify) {
await fs.promises.writeFile(file, JSON.stringify(data), "utf-8")
output = JSON.stringify(data)
} else {
await fs.promises.writeFile(file, compileJSON(data, { indentation: " " }), "utf-8")
output = compileJSON(data, { indentation: " " })
}
if (this.prefixes) {
output = output.replace(/(?<![a-z0-9])minecraft:/g, "")
}
await fs.promises.writeFile(file, output, "utf-8")
const after = (await fs.promises.stat(file)).size
afterTotal += after
output.log(`\`${shortened}\`\nBefore: ${formatBytes(before)}\nAfter: ${formatBytes(after)}`)
Expand All @@ -2408,6 +2415,7 @@
<checkbox-row v-model="types.mcmeta">Optimise <code>.mcmeta</code> files</checkbox-row>
<checkbox-row v-model="types.jem">Optimise <code>.jem</code> files</checkbox-row>
<checkbox-row v-model="types.jpm">Optimise <code>.jpm</code> files</checkbox-row>
<checkbox-row v-model="prefixes" style="margin-top: 0;">Remove <code>minecraft:</code> prefixes</checkbox-row>
<checkbox-row v-model="minify" style="margin-top: 0;">Minify output</checkbox-row>
</div>
<ignore-list v-model="ignoreList" />
Expand Down

0 comments on commit caa274d

Please sign in to comment.