-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addition of scripts for addressing #8
- bb-cli.js for allowing commands to be passed to blockbench - ajexport.js & associated config file to be passed to blockbench for execution - Currently relies on a modified version of animated java which exposes safeExportProject() through the API
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// With thanks to elenterius on discord for troubleshooting ideas | ||
|
||
const consoleLogJson = (args) => { | ||
console.log(JSON.stringify(args)); | ||
} | ||
|
||
if (typeof AnimatedJava === 'undefined') { | ||
throw new Error("Failed to load Animated Java plugin before CLI plugin") | ||
} | ||
let [blockbenchPath, ...ARGV] = electron.getGlobal("process").argv; | ||
const scriptIndicator = ARGV.indexOf("--bb-cli"); | ||
const paths = getConfigPaths('C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\omega-flowey-minecraft-remastered\\scripts\\config.json'); | ||
const dir = paths[3].concat("/"); | ||
console.log("Target paths: ", paths); | ||
const files = fs.readdirSync(dir).filter((file) => file.includes('ajmodel')); | ||
const exportNextFile = () => { | ||
if (Project) { Project.close(); } | ||
const file = files.pop(); | ||
if (typeof file === 'undefined') { | ||
return; | ||
} | ||
consoleLogJson({ file }); | ||
if (file.includes('ajmodel')) { | ||
let content = fs.readFileSync(dir.concat(file), 'utf-8'); | ||
let name = file.split('/').pop(); | ||
let fileObj = { path: file, content: injectModelPackPaths(content, paths), name: name }; | ||
loadModelFile(fileObj); | ||
AnimatedJava.API.safeExportProject(exportNextFile); | ||
} | ||
}; | ||
exportNextFile(); | ||
|
||
|
||
function getModelPackPaths(modelContent) { | ||
var f = JSON.parse(modelContent); | ||
var resourcePackPath = f.animated_java.settings.resource_pack_mcmeta; | ||
var dataPackPath = f.animated_java.exporter_settings["animated_java:datapack_exporter"].datapack_mcmeta; | ||
return [resourcePackPath, dataPackPath]; | ||
} | ||
|
||
function writeModelPackPaths(modelContent, modelFile, paths) { | ||
var f = JSON.parse(modelContent); | ||
f.animated_java.settings.resource_pack_mcmeta = paths[0]; | ||
f.animated_java.exporter_settings["animated_java:datapack_exporter"].datapack_mcmeta = paths[1]; | ||
fs.writeFileSync(modelFile, JSON.stringify(f)); | ||
} | ||
|
||
function injectModelPackPaths(modelContent, paths) { | ||
var f = JSON.parse(modelContent); | ||
f.animated_java.settings.resource_pack_mcmeta = paths[0]; | ||
f.animated_java.exporter_settings["animated_java:datapack_exporter"].datapack_mcmeta = paths[1]; | ||
for (const texture of f.textures) { | ||
texture.path = texture.path.replaceAll('\\', '/'); | ||
// TODO this should maybe be regex? | ||
if (texture.path.includes(".minecraft")) { | ||
const x = texture.path.split("assets")[1]; | ||
const newPath = `${paths[2]}/assets${x}`; | ||
// consoleLogJson({ | ||
// texturePath: texture.path, | ||
// afterAssets: x, | ||
// newPath, | ||
// }); | ||
texture.path = newPath; | ||
} else if (texture.path.includes("resourcepack/assets")) { | ||
const x = texture.path.split("resourcepack/assets")[1]; | ||
const resourcePackBase = paths[0].split("resourcepack")[0]; | ||
const newPath = `${resourcePackBase}resourcepack/assets${x}`; | ||
// consoleLogJson({ | ||
// texturePath: texture.path, | ||
// resourcePackBase, | ||
// afterAssets: x, | ||
// newPath, | ||
// }); | ||
texture.path = newPath; | ||
} | ||
} | ||
return JSON.stringify(f); | ||
} | ||
|
||
function getConfigPaths(configFile) { | ||
const f = JSON.parse(fs.readFileSync(configFile).toString()); | ||
let resourcePackPath = f.resource_pack_mcmeta; | ||
let dataPackPath = f.datapack_mcmeta; | ||
let assetsPath = f.assets_path; | ||
let ajmodelPath = f.ajmodel_folder; | ||
return [resourcePackPath, dataPackPath, assetsPath, ajmodelPath]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// With thanks to fetchbot on discord for the code | ||
|
||
BBPlugin.register('bb-cli', { | ||
title: 'Blockbench CLI', | ||
author: 'aiTan', | ||
icon: 'icon', | ||
description: 'Blockbench CLI plugin (in testing)', | ||
version: '1.0.0', | ||
variant: 'both', | ||
onload() { | ||
console.log("BB-CLI loading..."); | ||
let [blockbenchPath, ...ARGV] = electron.getGlobal("process").argv; | ||
let scriptIndicator = ARGV.indexOf("--bb-cli"); | ||
if (scriptIndicator !== -1) { | ||
const scriptPath = ARGV[scriptIndicator + 1]; | ||
console.log("Importing...", scriptPath); | ||
const script = import(scriptPath); | ||
console.log(script); | ||
script.then(async (module) => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
await module.script(); | ||
window.close(); | ||
}).catch((err) => { | ||
console.log(err); | ||
//window.close(); | ||
}); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"resource_pack_mcmeta": "C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\test\\resourcepack\\pack.mcmeta", | ||
"datapack_mcmeta": "C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\test\\datapacks\\omega-flowey\\pack.mcmeta", | ||
"assets_path": "C:\\Users\\Aidan\\AppData\\Roaming\\.minecraft\\versions\\1.20.4\\1.20.4", | ||
"ajmodel_folder": "C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\test\\resourcepack\\assets\\omega-flowey\\models\\entity\\hostile\\omega-flowey" | ||
} |