Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NodeJS Javascript
- // Assumes Custom Registered blocks (Modded only currently)
- // Assumes template files are already made beforehand
- // Modifying variable for custom ModID, Manditory (Your namespace)
- // Modifying variable for base folder (temp storage for files) recomended
- // Modifying variables for custom template files, Manditory if you plan to use template json that aren't standard
- // Number of textures used, is limited to one for built in templates.
- // Custom locations can be used with built in templates. Suggest to keep orginization the same throughout your mod.
- // Follows MC naming scheme. type_material_block_blockSubtype ( example oak_plank_stairs_outter )
- // Will take on _fence & _fence_gate to provided variant_material provided.
- // Fixed typo rendering 2nd texture useless
- var fs = require('fs');
- const { resolve } = require('path');
- const path = require('path');
- // setup to use MC naming convention of using _ as the spaces
- var baseDrive = 'G:/';
- var baseFolder = baseDrive+'MC_JSONS';
- var customModID = 'delbase';
- var baseModID = 'minecraft';
- var textureModID;
- var textureUseCount;
- // Folder structure
- var blockState = '/assets/blockstates';
- var models = '/assets/models';
- var baseModelFiles = 'block';
- var customModelFiles = baseModelFiles+'/fence';
- var itemModelFiles = models+'/items';
- var lootTableFiles = '/loot_tables/blocks';
- var useCustomTemplate = false;
- var useCustomModelFolders = false;
- // Hard coded Normal Minecraft
- // Useful for single textured fences
- var templateFencePost = 'block/fence_post';
- var templateFenceSide = 'block/fence_side';
- var templateFenceGate = 'block/template_fence_gate';
- var templateFenceGateOpen = 'block/template_fence_gate_open';
- var templateFenceGateWall = 'block/template_fence_gate_wall';
- var templateFenceGateWallOpen = 'block/template_fence_gate_wall_open';
- var templateFenceInventory = 'block/fence_inventory';
- // Custom Templates. Set before use.
- // useful for log like textures (with a side/top)
- var customFencePost = 'block/template/fence_post';
- var customFenceSide = 'block/template/fence_side';
- var customFenceGate = 'block/template/fence_gate';
- var customFenceGateOpen = 'block/template/fence_gate_open';
- var customFenceGateWall = 'block/template/fence_gate_wall';
- var customFenceGateWallOpen = 'block/template/fence_gate_wall_open';
- var customFenceInventory = 'block/template/fence_inventory';
- // Texture tags in use. Base is the Minecraft one.
- var baseTextureTag = 'texture';
- // Add variables as needed for templates, name as needed
- var customTextureUpDownTag = baseTextureTag;
- var customTextureSideTag = 'postside';
- // One used for the base Texture Tag & available for custom
- // assigned in code
- var textureOne;
- var textureTwo;
- //misc texturnames
- var colorName;
- var typeName;
- var blockName;
- const myArgs = process.argv.slice(2);
- keystart(myArgs);
- /*
- [0] 1. color / Variant name (text)
- [1] 2. Material type (sand, terracotta, etc) (text)
- [2] 3. Built in template or custom template ( 0 -base / 1 -custom)
- [3] 4. normal model file location or custom ( 0 -normal / 1 -custom)
- [4] 5. number of textures for the file
- [5] 6. modID for texture (0 -Minecraft built in/ 1- Custom modID
- [6] 7. Texture 1 Name || /block is included in the first texture assuming it's under the block folder
- [7] 8. Texture 2 Name [if used]
- // 0 color/variant name, 1 material type, 2 base/custom templates (base/custom == 0 / 1)
- // 3 base/custom model file location (base/custom), 4 number of textures used per file, 5 texture modID, custom or built in Minecraft ( base/custom == 0/1 )
- // 6 texture one name (up/down), 7+ add as many texture used per one,
- // comes setup for 2 textures per block, must adjust for 3+
- */
- async function setVariables(Args) {
- colorName = Args[0];
- typeName = Args[1];
- blockName = colorName;
- if (typeName != 0) { blockName = blockName + '_' + typeName; }
- if (Args[2] == 0 || Args[2] == 1) {
- if (Args[2] == 0) { useCustomTemplate = false; } else { useCustomTemplate = true; }
- } else {
- errorout('wrong selection of custom or built in templates for model files.')
- }
- if (Args[3] == 0 || Args[3] == 1) {
- if (Args[3] == 0) { useCustomModelFolders = false; } else { useCustomModelFolders = true; }
- } else {
- errorout('Invalid selection of custom or built in(For Minecraft) folder structure')
- }
- textureUseCount = Args[4];
- if (textureUseCount < 1) { errorout('number of textures claimed less than 1') }
- if (Args[5] == 0 || Args[5] == 1){
- if (Args[5] == 1) { textureModID = customModID } else { textureModID = baseModID }
- } else { errorout('missing/invalid selection for texture modID') }
- if (Args[6] != null){ textureOne = Args[6]; } else { errorout('no valid texture given') }
- if (Args[7] != null){
- if (textureUseCount > 1) { textureTwo = Args[7] }
- }
- }
- function errorout(extmsg) {
- console.log(extmsg);
- process.exit();
- }
- function fileOut(fileOut, message, newfile) {
- if (newfile) { fs.openSync(fileOut, 'w'); }
- fs.appendFileSync(fileOut, message+'\n');
- }
- function keystart(argums){
- setVariables(argums).then(blockStates(useCustomModelFolders)).then(fenceModels(useCustomTemplate, useCustomModelFolders)).then(lootTable());
- }
- function blockStates(useCustomtmpath) {
- let blockPath;
- let foldPath = path.join(baseFolder, blockState)
- fs.mkdirSync(foldPath, { recursive: true });
- if (useCustomtmpath) { blockPath = customModelFiles; } else { blockPath = baseModelFiles; }
- bsFence(path.join(foldPath, blockName+'_fence.json'), blockPath)
- bsFenceGate(path.join(foldPath, blockName+'_fence_gate.json'), blockPath)
- }
- function bsFence(fileLocation, filePath) {
- let post = filePath+'/'+blockName+'_fence_post';
- let side = filePath+'/'+blockName+'_fence_side';
- let uvlock = '\"uvlock\": true';
- fileOut(fileLocation, '{', true);
- fileOut(fileLocation, '\"multipart\": [', false);
- fileOut(fileLocation, '{', false);
- fileOut(fileLocation, '\"apply\": {', false);
- fileOut(fileLocation, '\"model\": \"'+customModID+':'+post+'\"', false);
- fileOut(fileLocation, '}', false);
- fileOut(fileLocation, '},', false);
- bsFenceAid(fileLocation, customModID, side, 'north', uvlock, 0, false);
- bsFenceAid(fileLocation, customModID, side, 'east', uvlock, 90, false);
- bsFenceAid(fileLocation, customModID, side, 'south', uvlock, 180, false);
- bsFenceAid(fileLocation, customModID, side, 'west', uvlock, 270, true);
- fileOut(fileLocation, ']', false);
- fileOut(fileLocation, '}', false);
- }
- function bsFenceAid(fLocation, modID, model, direct, uv, y, last) {
- let bracket;
- if(last) { bracket = '}' } else { bracket = '},' }
- fileOut(fLocation, '{', false);
- fileOut(fLocation, '\"when\": {', false);
- fileOut(fLocation, '\"'+direct+'\": \"true\"', false);
- fileOut(fLocation, '},', false);
- fileOut(fLocation, '\"apply\": {', false);
- fileOut(fLocation, '\"model\": \"'+modID+':'+model+'\",', false);
- if(y != 0) { fileOut(fLocation, '\"y\": '+y+',', false); }
- fileOut(fLocation, uv, false);
- fileOut(fLocation, '}', false);
- fileOut(fLocation, bracket, false);
- }
- function bsFenceGate(fileLocation, filePath) {
- let gate = filePath+'/'+blockName+'_fence_gate';
- let gateOpen = gate+'_open';
- let gateWall = gate+'_wall';
- let gateWallOpen = gateWall+'_open';
- let fEast = 'facing=east';
- let fWest = 'facing=west';
- let fNorth = 'facing=north';
- let fSouth = 'facing=south';
- let iWall = 'in_wall=true';
- let oWall = 'in_wall=false';
- let wOpen = 'open=true';
- let wClose = 'open=false';
- let uvlock = '\"uvlock\": true,';
- fileOut(fileLocation, '{', true);
- fileOut(fileLocation, '\"variants\": {', false);
- fileOut(fileLocation, '\"'+fEast+','+oWall+','+wClose+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gate, uvlock, 270, false);
- fileOut(fileLocation, '\"'+fEast+','+oWall+','+wOpen+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateOpen, uvlock, 270, false);
- fileOut(fileLocation, '\"'+fEast+','+iWall+','+wClose+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateWall, uvlock, 270, false);
- fileOut(fileLocation, '\"'+fEast+','+iWall+','+wOpen+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateWallOpen, uvlock, 270, false);
- fileOut(fileLocation, '\"'+fNorth+','+oWall+','+wClose+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gate, uvlock, 180, false);
- fileOut(fileLocation, '\"'+fNorth+','+oWall+','+wOpen+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateOpen, uvlock, 180, false);
- fileOut(fileLocation, '\"'+fNorth+','+iWall+','+wClose+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateWall, uvlock, 180, false);
- fileOut(fileLocation, '\"'+fNorth+','+iWall+','+wOpen+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateWallOpen, uvlock, 180, false);
- fileOut(fileLocation, '\"'+fSouth+','+oWall+','+wClose+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gate, uvlock, 0, false);
- fileOut(fileLocation, '\"'+fSouth+','+oWall+','+wOpen+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateOpen, uvlock, 0, false);
- fileOut(fileLocation, '\"'+fSouth+','+iWall+','+wClose+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateWall, uvlock, 0, false);
- fileOut(fileLocation, '\"'+fSouth+','+iWall+','+wOpen+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateWallOpen, uvlock, 0, false);
- fileOut(fileLocation, '\"'+fWest+','+oWall+','+wClose+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gate, uvlock, 90, false);
- fileOut(fileLocation, '\"'+fWest+','+oWall+','+wOpen+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateOpen, uvlock, 90, false);
- fileOut(fileLocation, '\"'+fWest+','+iWall+','+wClose+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateWall, uvlock, 90, false);
- fileOut(fileLocation, '\"'+fWest+','+iWall+','+wOpen+'\": {', false);
- bsFenceGateAid(fileLocation, customModID, gateWallOpen, uvlock, 90, true);
- fileOut(fileLocation, '}', false);
- fileOut(fileLocation, '}', false);
- }
- function bsFenceGateAid(fLocation, modID, model, uv, y, last) {
- let bracket;
- if (last) { bracket = '}' } else { bracket = '},' }
- fileOut(fLocation, uv, false);
- if (y != 0) { fileOut(fLocation, '\"y\": '+y+',', false); }
- fileOut(fLocation, '\"model\": \"'+modID+':'+model+'\"', false);
- fileOut(fLocation, bracket, false);
- }
- function fenceModels(customTemplateLocation, customModelLocation){
- let fold;
- if (customModelLocation) { fold = path.join(baseFolder, models, customModelFiles) } else { fold = path.join(baseFolder, models, baseModelFiles) }
- fs.mkdirSync(fold, { recursive: true });
- let iFold = path.join(baseFolder, itemModelFiles);
- fs.mkdirSync(iFold, { recursive: true });
- fmFencePost(fold, customTemplateLocation);
- fmFenceSide(fold, customTemplateLocation);
- fmFenceInventory(fold, customTemplateLocation);
- fmFenceGate(fold, customTemplateLocation);
- fmFenceGateOpen(fold, customTemplateLocation);
- fmFenceGateWall(fold, customTemplateLocation);
- fmFenceGateWallOpen(fold, customTemplateLocation);
- fmFenceItems(iFold, customModelLocation);
- }
- function fmFencePost(folder, iscustomtemplate){
- let template;
- let templatemod;
- let json = path.join(folder, blockName+'_fence_post.json')
- if (iscustomtemplate) {
- template = customFencePost;
- templatemod = customModID;
- } else {
- template = templateFencePost;
- templatemod = baseModID;
- }
- fileOut(json, '{', true);
- fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
- fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
- }
- function fmFenceSide(folder, iscustomtemplate) {
- let template;
- let templatemod;
- let json = path.join(folder, blockName+'_fence_side.json')
- if (iscustomtemplate) {
- template = customFenceSide;
- templatemod = customModID;
- } else {
- template = templateFenceSide;
- templatemod = baseModID;
- }
- fileOut(json, '{', true);
- fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
- fmFenceAid(1, iscustomtemplate, json, textureModID);
- }
- function fmFenceInventory(folder, iscustomtemplate) {
- let template;
- let templatemod;
- let json = path.join(folder, blockName+'_fence_inventory.json')
- if (iscustomtemplate) {
- template = customFenceInventory;
- templatemod = customModID;
- } else {
- template = templateFenceInventory;
- templatemod = baseModID;
- }
- fileOut(json, '{', true);
- fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
- fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
- }
- function fmFenceGate(folder, iscustomtemplate) {
- let template;
- let templatemod;
- let json = path.join(folder, blockName+'_fence_gate.json')
- if (iscustomtemplate) {
- template = customFenceGate;
- templatemod =customModID;
- } else {
- template = templateFenceGate;
- templatemod = baseModID;
- }
- fileOut(json, '{', true);
- fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
- fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
- }
- function fmFenceGateOpen(folder, iscustomtemplate) {
- let template;
- let templatemod;
- let json = path.join(folder, blockName+'_fence_gate_open.json')
- if (iscustomtemplate) {
- template = customFenceGateOpen;
- templatemod = customModID;
- } else {
- template = templateFenceGateOpen;
- templatemod = baseModID;
- }
- fileOut(json, '{', true);
- fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
- fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
- }
- function fmFenceGateWall(folder, iscustomtemplate) {
- let template;
- let templatemod;
- let json = path.join(folder, blockName+'_fence_gate_wall.json')
- if (iscustomtemplate) {
- template = customFenceGateWall;
- templatemod =customModID;
- } else {
- template = templateFenceGateWall;
- templatemod = baseModID;
- }
- fileOut(json, '{', true);
- fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
- fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
- }
- function fmFenceGateWallOpen(folder, iscustomtemplate) {
- let template;
- let templatemod;
- let json = path.join(folder, blockName+'_fence_gate_wall_open.json')
- if (iscustomtemplate) {
- template = customFenceGateWallOpen;
- templatemod = customModID;
- } else {
- template = templateFenceGateWallOpen;
- templatemod = baseModID;
- }
- fileOut(json, '{', true);
- fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
- fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
- }
- function fmFenceItems(folder, iscustomLocation) {
- let modelLocation;
- if (iscustomLocation) { modelLocation = customModelFiles } else { modelLocation = baseModelFiles }
- fmFenceItemAid(path.join(folder, blockName+'_fence.json'), modelLocation, 'fence_inventory');
- fmFenceItemAid(path.join(folder, blockName+'_fence_gate.json'), modelLocation, 'fence_gate');
- }
- function fmFenceItemAid(file, modelLocation, type) {
- fileOut(file, '{', true);
- fileOut(file, '\"parent\": \"'+customModID+':'+modelLocation+'/'+blockName+'_'+type+'\"', false);
- fileOut(file, '}', false);
- }
- function fmFenceAid(texturecount, isCustom, file, mod) {
- fileOut(file, '\"textures\": {', false)
- if (isCustom) {
- if (texturecount > 1) {
- fileOut(file, '\"'+customTextureUpDownTag+'\": \"'+mod+':'+'block/'+textureOne+'\",', false)
- fileOut(file, '\"'+customTextureSideTag+'\": \"'+mod+':'+'block/'+textureTwo+'\"', false)
- } else {
- fileOut(file, '\"'+customTextureUpDownTag+'\": \"'+mod+':'+'block/'+textureOne+'\"', false)
- }
- } else {
- fileOut(file, '\"'+baseTextureTag+'\": \"'+mod+':'+'block/'+textureOne+'\"', false)
- }
- fileOut(file, '}\n}', false)
- }
- function lootTable(){
- let fold = path.join(baseFolder, lootTableFiles);
- fs.mkdirSync(fold, { recursive: true })
- ltFenceAid(path.join(fold, blockName+'_fence.json'), blockName+'_fence');
- ltFenceAid(path.join(fold, blockName+'_fence_gate.json'), blockName+'_fence_gate');
- }
- function ltFenceAid(file, block) {
- fileOut(file, '{', true);
- fileOut(file, '\"type\": \"minecraft:block\",', false);
- fileOut(file, '\"pools\": [', false);
- fileOut(file, '{', false);
- fileOut(file, '\"rolls\": 1.0,', false);
- fileOut(file, '\"bonus_rolls\": 0.0,', false);
- fileOut(file, '\"entries\": [', false);
- fileOut(file, '{', false);
- fileOut(file, '\"type\": \"minecraft:item\",', false);
- fileOut(file, '\"name\": \"'+customModID+':'+block+'\"', false);
- fileOut(file, '}', false);
- fileOut(file, '],', false);
- fileOut(file, '\"conditions\": [', false);
- fileOut(file, '{', false);
- fileOut(file, '\"condition\": \"minecraft:survives_explosion\"', false);
- fileOut(file, '}\n]\n\}\n]\n}', false);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement