Advertisement
DePhoegon

Modded MC Fence & Gates JSON Aid - NodeJS

May 29th, 2022 (edited)
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // NodeJS Javascript
  2. // Assumes Custom Registered blocks  (Modded only currently)
  3. // Assumes template files are already made beforehand
  4. // Modifying variable for custom ModID, Manditory (Your namespace)
  5. // Modifying variable for base folder (temp storage for files) recomended
  6. // Modifying variables for custom template files, Manditory if you plan to use template json that aren't standard
  7. // Number of textures used, is limited to one for built in templates.
  8. // Custom locations can be used with built in templates.  Suggest to keep orginization the same throughout your mod.
  9. // Follows MC naming scheme. type_material_block_blockSubtype   ( example oak_plank_stairs_outter )
  10. // Will take on _fence & _fence_gate to provided variant_material provided.
  11. // Fixed typo rendering 2nd texture useless
  12.  
  13. var fs = require('fs');
  14. const { resolve } = require('path');
  15. const path = require('path');
  16.  
  17. // setup to use MC naming convention of using _ as the spaces
  18.  
  19. var baseDrive = 'G:/';
  20. var baseFolder = baseDrive+'MC_JSONS';
  21. var customModID = 'delbase';
  22. var baseModID = 'minecraft';
  23. var textureModID;
  24. var textureUseCount;
  25.  
  26. // Folder structure
  27. var blockState = '/assets/blockstates';
  28. var models = '/assets/models';
  29. var baseModelFiles = 'block';
  30. var customModelFiles = baseModelFiles+'/fence';
  31. var itemModelFiles = models+'/items';
  32. var lootTableFiles = '/loot_tables/blocks';
  33. var useCustomTemplate = false;
  34. var useCustomModelFolders = false;
  35.  
  36.  
  37. // Hard coded Normal Minecraft
  38. // Useful for single textured fences
  39. var templateFencePost = 'block/fence_post';
  40. var templateFenceSide = 'block/fence_side';
  41. var templateFenceGate = 'block/template_fence_gate';
  42. var templateFenceGateOpen = 'block/template_fence_gate_open';
  43. var templateFenceGateWall = 'block/template_fence_gate_wall';
  44. var templateFenceGateWallOpen = 'block/template_fence_gate_wall_open';
  45. var templateFenceInventory = 'block/fence_inventory';
  46.  
  47. // Custom Templates.  Set before use.
  48. // useful for log like textures (with a side/top)
  49. var customFencePost = 'block/template/fence_post';
  50. var customFenceSide = 'block/template/fence_side';
  51. var customFenceGate = 'block/template/fence_gate';
  52. var customFenceGateOpen = 'block/template/fence_gate_open';
  53. var customFenceGateWall = 'block/template/fence_gate_wall';
  54. var customFenceGateWallOpen = 'block/template/fence_gate_wall_open';
  55. var customFenceInventory = 'block/template/fence_inventory';
  56.  
  57. // Texture tags in use.  Base is the Minecraft one.
  58. var baseTextureTag = 'texture';
  59. // Add variables as needed for templates, name as needed
  60. var customTextureUpDownTag = baseTextureTag;
  61. var customTextureSideTag = 'postside';
  62.  
  63. // One used for the base Texture Tag & available for custom
  64. // assigned in code
  65. var textureOne;
  66. var textureTwo;
  67.  
  68. //misc texturnames
  69. var colorName;
  70. var typeName;
  71. var blockName;
  72.  
  73. const myArgs = process.argv.slice(2);
  74. keystart(myArgs);
  75. /*
  76. [0] 1. color / Variant name (text)
  77. [1] 2. Material type (sand, terracotta, etc) (text)
  78. [2] 3. Built in template or custom template ( 0 -base / 1 -custom)
  79. [3] 4. normal model file location or custom ( 0 -normal / 1 -custom)
  80. [4] 5. number of textures for the file
  81. [5] 6. modID for texture (0 -Minecraft built in/ 1- Custom modID
  82. [6] 7. Texture 1 Name  ||  /block is included in the first texture assuming it's under the block folder
  83. [7] 8. Texture 2 Name [if used]
  84.  
  85. // 0 color/variant name, 1 material type, 2 base/custom templates (base/custom == 0 / 1)
  86. // 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 )
  87. // 6 texture one name (up/down), 7+ add as many texture used per one,
  88. // comes setup for 2 textures per block, must adjust for 3+
  89. */
  90.  
  91. async function setVariables(Args) {
  92.     colorName = Args[0];
  93.     typeName = Args[1];
  94.     blockName = colorName;
  95.     if (typeName != 0) { blockName = blockName + '_' + typeName; }
  96.     if (Args[2] == 0 || Args[2] == 1) {
  97.         if (Args[2] == 0) { useCustomTemplate = false; } else { useCustomTemplate = true; }
  98.     } else {
  99.         errorout('wrong selection of custom or built in templates for model files.')
  100.     }
  101.     if (Args[3] == 0 || Args[3] == 1) {
  102.         if (Args[3] == 0) { useCustomModelFolders = false; } else { useCustomModelFolders = true; }
  103.     } else {
  104.         errorout('Invalid selection of custom or built in(For Minecraft) folder structure')
  105.     }
  106.     textureUseCount = Args[4];
  107.     if (textureUseCount < 1) { errorout('number of textures claimed less than 1') }
  108.     if (Args[5] == 0 || Args[5] == 1){
  109.         if (Args[5] == 1) { textureModID = customModID } else { textureModID = baseModID }
  110.     } else { errorout('missing/invalid selection for texture modID') }
  111.     if (Args[6] != null){ textureOne = Args[6]; } else { errorout('no valid texture given') }
  112.     if (Args[7] != null){
  113.         if (textureUseCount > 1) { textureTwo = Args[7] }
  114.     }
  115. }
  116. function errorout(extmsg) {
  117.     console.log(extmsg);
  118.     process.exit();
  119. }
  120. function fileOut(fileOut, message, newfile) {
  121.     if (newfile) { fs.openSync(fileOut, 'w'); }
  122.     fs.appendFileSync(fileOut, message+'\n');
  123. }
  124. function keystart(argums){
  125.     setVariables(argums).then(blockStates(useCustomModelFolders)).then(fenceModels(useCustomTemplate, useCustomModelFolders)).then(lootTable());
  126. }
  127. function blockStates(useCustomtmpath) {
  128.     let blockPath;
  129.     let foldPath = path.join(baseFolder, blockState)
  130.     fs.mkdirSync(foldPath, { recursive: true });
  131.     if (useCustomtmpath) { blockPath = customModelFiles; } else { blockPath = baseModelFiles; }
  132.     bsFence(path.join(foldPath, blockName+'_fence.json'), blockPath)
  133.     bsFenceGate(path.join(foldPath, blockName+'_fence_gate.json'), blockPath)
  134. }
  135. function bsFence(fileLocation, filePath) {
  136.     let post = filePath+'/'+blockName+'_fence_post';
  137.     let side = filePath+'/'+blockName+'_fence_side';
  138.     let uvlock = '\"uvlock\": true';
  139.     fileOut(fileLocation, '{', true);
  140.     fileOut(fileLocation, '\"multipart\": [', false);
  141.     fileOut(fileLocation, '{', false);
  142.     fileOut(fileLocation, '\"apply\": {', false);
  143.     fileOut(fileLocation, '\"model\": \"'+customModID+':'+post+'\"', false);
  144.     fileOut(fileLocation, '}', false);
  145.     fileOut(fileLocation, '},', false);
  146.     bsFenceAid(fileLocation, customModID, side, 'north', uvlock, 0, false);
  147.     bsFenceAid(fileLocation, customModID, side, 'east', uvlock, 90, false);
  148.     bsFenceAid(fileLocation, customModID, side, 'south', uvlock, 180, false);
  149.     bsFenceAid(fileLocation, customModID, side, 'west', uvlock, 270, true);
  150.     fileOut(fileLocation, ']', false);
  151.     fileOut(fileLocation, '}', false);
  152. }
  153. function bsFenceAid(fLocation, modID, model, direct, uv, y, last) {
  154.     let bracket;
  155.     if(last) { bracket = '}' } else { bracket = '},' }
  156.     fileOut(fLocation, '{', false);
  157.     fileOut(fLocation, '\"when\": {', false);
  158.     fileOut(fLocation, '\"'+direct+'\": \"true\"', false);
  159.     fileOut(fLocation, '},', false);
  160.     fileOut(fLocation, '\"apply\": {', false);
  161.     fileOut(fLocation, '\"model\": \"'+modID+':'+model+'\",', false);
  162.     if(y != 0) { fileOut(fLocation, '\"y\": '+y+',', false); }
  163.     fileOut(fLocation, uv, false);
  164.     fileOut(fLocation, '}', false);
  165.     fileOut(fLocation, bracket, false);
  166. }
  167. function bsFenceGate(fileLocation, filePath) {
  168.     let gate = filePath+'/'+blockName+'_fence_gate';
  169.     let gateOpen = gate+'_open';
  170.     let gateWall = gate+'_wall';
  171.     let gateWallOpen = gateWall+'_open';
  172.     let fEast = 'facing=east';
  173.     let fWest = 'facing=west';
  174.     let fNorth = 'facing=north';
  175.     let fSouth = 'facing=south';
  176.     let iWall = 'in_wall=true';
  177.     let oWall = 'in_wall=false';
  178.     let wOpen = 'open=true';
  179.     let wClose = 'open=false';
  180.     let uvlock = '\"uvlock\": true,';
  181.     fileOut(fileLocation, '{', true);
  182.     fileOut(fileLocation, '\"variants\": {', false);
  183.     fileOut(fileLocation, '\"'+fEast+','+oWall+','+wClose+'\": {', false);
  184.     bsFenceGateAid(fileLocation, customModID, gate, uvlock, 270, false);
  185.     fileOut(fileLocation, '\"'+fEast+','+oWall+','+wOpen+'\": {', false);
  186.     bsFenceGateAid(fileLocation, customModID, gateOpen, uvlock, 270, false);
  187.     fileOut(fileLocation, '\"'+fEast+','+iWall+','+wClose+'\": {', false);
  188.     bsFenceGateAid(fileLocation, customModID, gateWall, uvlock, 270, false);
  189.     fileOut(fileLocation, '\"'+fEast+','+iWall+','+wOpen+'\": {', false);
  190.     bsFenceGateAid(fileLocation, customModID, gateWallOpen, uvlock, 270, false);
  191.     fileOut(fileLocation, '\"'+fNorth+','+oWall+','+wClose+'\": {', false);
  192.     bsFenceGateAid(fileLocation, customModID, gate, uvlock, 180, false);
  193.     fileOut(fileLocation, '\"'+fNorth+','+oWall+','+wOpen+'\": {', false);
  194.     bsFenceGateAid(fileLocation, customModID, gateOpen, uvlock, 180, false);
  195.     fileOut(fileLocation, '\"'+fNorth+','+iWall+','+wClose+'\": {', false);
  196.     bsFenceGateAid(fileLocation, customModID, gateWall, uvlock, 180, false);
  197.     fileOut(fileLocation, '\"'+fNorth+','+iWall+','+wOpen+'\": {', false);
  198.     bsFenceGateAid(fileLocation, customModID, gateWallOpen, uvlock, 180, false);
  199.     fileOut(fileLocation, '\"'+fSouth+','+oWall+','+wClose+'\": {', false);
  200.     bsFenceGateAid(fileLocation, customModID, gate, uvlock, 0, false);
  201.     fileOut(fileLocation, '\"'+fSouth+','+oWall+','+wOpen+'\": {', false);
  202.     bsFenceGateAid(fileLocation, customModID, gateOpen, uvlock, 0, false);
  203.     fileOut(fileLocation, '\"'+fSouth+','+iWall+','+wClose+'\": {', false);
  204.     bsFenceGateAid(fileLocation, customModID, gateWall, uvlock, 0, false);
  205.     fileOut(fileLocation, '\"'+fSouth+','+iWall+','+wOpen+'\": {', false);
  206.     bsFenceGateAid(fileLocation, customModID, gateWallOpen, uvlock, 0, false);
  207.     fileOut(fileLocation, '\"'+fWest+','+oWall+','+wClose+'\": {', false);
  208.     bsFenceGateAid(fileLocation, customModID, gate, uvlock, 90, false);
  209.     fileOut(fileLocation, '\"'+fWest+','+oWall+','+wOpen+'\": {', false);
  210.     bsFenceGateAid(fileLocation, customModID, gateOpen, uvlock, 90, false);
  211.     fileOut(fileLocation, '\"'+fWest+','+iWall+','+wClose+'\": {', false);
  212.     bsFenceGateAid(fileLocation, customModID, gateWall, uvlock, 90, false);
  213.     fileOut(fileLocation, '\"'+fWest+','+iWall+','+wOpen+'\": {', false);
  214.     bsFenceGateAid(fileLocation, customModID, gateWallOpen, uvlock, 90, true);
  215.     fileOut(fileLocation, '}', false);
  216.     fileOut(fileLocation, '}', false);
  217. }
  218. function bsFenceGateAid(fLocation, modID, model, uv, y, last) {
  219.     let bracket;
  220.     if (last) { bracket = '}' } else { bracket = '},'  }
  221.     fileOut(fLocation, uv, false);
  222.     if (y != 0) { fileOut(fLocation, '\"y\": '+y+',', false); }
  223.     fileOut(fLocation, '\"model\": \"'+modID+':'+model+'\"', false);
  224.     fileOut(fLocation, bracket, false);
  225. }
  226. function fenceModels(customTemplateLocation, customModelLocation){
  227.     let fold;
  228.     if (customModelLocation) { fold = path.join(baseFolder, models, customModelFiles) } else { fold = path.join(baseFolder, models, baseModelFiles) }
  229.     fs.mkdirSync(fold, { recursive: true });
  230.     let iFold = path.join(baseFolder, itemModelFiles);
  231.     fs.mkdirSync(iFold, { recursive: true });
  232.     fmFencePost(fold, customTemplateLocation);
  233.     fmFenceSide(fold, customTemplateLocation);
  234.     fmFenceInventory(fold, customTemplateLocation);
  235.     fmFenceGate(fold, customTemplateLocation);
  236.     fmFenceGateOpen(fold, customTemplateLocation);
  237.     fmFenceGateWall(fold, customTemplateLocation);
  238.     fmFenceGateWallOpen(fold, customTemplateLocation);    
  239.     fmFenceItems(iFold, customModelLocation);
  240. }
  241. function fmFencePost(folder, iscustomtemplate){
  242.     let template;
  243.     let templatemod;
  244.     let json = path.join(folder, blockName+'_fence_post.json')
  245.     if (iscustomtemplate) {
  246.         template = customFencePost;
  247.         templatemod = customModID;
  248.     } else {
  249.         template = templateFencePost;
  250.         templatemod = baseModID;
  251.     }
  252.     fileOut(json, '{', true);
  253.     fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
  254.     fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
  255. }
  256. function fmFenceSide(folder, iscustomtemplate) {
  257.     let template;
  258.     let templatemod;
  259.     let json = path.join(folder, blockName+'_fence_side.json')
  260.     if (iscustomtemplate) {
  261.         template = customFenceSide;
  262.         templatemod = customModID;
  263.     } else {
  264.         template = templateFenceSide;
  265.         templatemod = baseModID;
  266.     }
  267.     fileOut(json, '{', true);
  268.     fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
  269.     fmFenceAid(1, iscustomtemplate, json, textureModID);
  270. }
  271. function fmFenceInventory(folder, iscustomtemplate) {
  272.     let template;
  273.     let templatemod;
  274.     let json = path.join(folder, blockName+'_fence_inventory.json')
  275.     if (iscustomtemplate) {
  276.         template = customFenceInventory;
  277.         templatemod = customModID;
  278.     } else {
  279.         template = templateFenceInventory;
  280.         templatemod = baseModID;
  281.     }
  282.     fileOut(json, '{', true);
  283.     fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
  284.     fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
  285. }
  286. function fmFenceGate(folder, iscustomtemplate) {
  287.     let template;
  288.     let templatemod;
  289.     let json = path.join(folder, blockName+'_fence_gate.json')
  290.     if (iscustomtemplate) {
  291.         template = customFenceGate;
  292.         templatemod =customModID;
  293.     } else {
  294.         template = templateFenceGate;
  295.         templatemod = baseModID;
  296.     }
  297.     fileOut(json, '{', true);
  298.     fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
  299.     fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
  300. }
  301. function fmFenceGateOpen(folder, iscustomtemplate) {
  302.     let template;
  303.     let templatemod;
  304.     let json = path.join(folder, blockName+'_fence_gate_open.json')
  305.     if (iscustomtemplate) {
  306.         template = customFenceGateOpen;
  307.         templatemod = customModID;
  308.     } else {
  309.         template = templateFenceGateOpen;
  310.         templatemod = baseModID;
  311.     }
  312.     fileOut(json, '{', true);
  313.     fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
  314.     fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
  315. }
  316. function fmFenceGateWall(folder, iscustomtemplate) {
  317.     let template;
  318.     let templatemod;
  319.     let json = path.join(folder, blockName+'_fence_gate_wall.json')
  320.     if (iscustomtemplate) {
  321.         template = customFenceGateWall;
  322.         templatemod =customModID;
  323.     } else {
  324.         template = templateFenceGateWall;
  325.         templatemod = baseModID;
  326.     }
  327.     fileOut(json, '{', true);
  328.     fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
  329.     fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
  330. }
  331. function fmFenceGateWallOpen(folder, iscustomtemplate) {
  332.     let template;
  333.     let templatemod;
  334.     let json = path.join(folder, blockName+'_fence_gate_wall_open.json')
  335.     if (iscustomtemplate) {
  336.         template = customFenceGateWallOpen;
  337.         templatemod = customModID;
  338.     } else {
  339.         template = templateFenceGateWallOpen;
  340.         templatemod = baseModID;
  341.     }
  342.     fileOut(json, '{', true);
  343.     fileOut(json, '\"parent\": \"'+templatemod+':'+template+'\",');
  344.     fmFenceAid(textureUseCount, iscustomtemplate, json, textureModID);
  345. }
  346. function fmFenceItems(folder, iscustomLocation) {
  347.     let modelLocation;
  348.     if (iscustomLocation) { modelLocation = customModelFiles } else { modelLocation = baseModelFiles }
  349.     fmFenceItemAid(path.join(folder, blockName+'_fence.json'), modelLocation, 'fence_inventory');
  350.     fmFenceItemAid(path.join(folder, blockName+'_fence_gate.json'), modelLocation, 'fence_gate');
  351. }
  352. function fmFenceItemAid(file, modelLocation, type) {
  353.     fileOut(file, '{', true);
  354.     fileOut(file, '\"parent\": \"'+customModID+':'+modelLocation+'/'+blockName+'_'+type+'\"', false);
  355.     fileOut(file, '}', false);
  356. }
  357. function fmFenceAid(texturecount, isCustom, file, mod) {
  358.     fileOut(file, '\"textures\": {', false)
  359.     if (isCustom) {
  360.         if (texturecount > 1) {
  361.             fileOut(file, '\"'+customTextureUpDownTag+'\": \"'+mod+':'+'block/'+textureOne+'\",', false)
  362.             fileOut(file, '\"'+customTextureSideTag+'\": \"'+mod+':'+'block/'+textureTwo+'\"', false)
  363.         } else {
  364.             fileOut(file, '\"'+customTextureUpDownTag+'\": \"'+mod+':'+'block/'+textureOne+'\"', false)
  365.         }
  366.     } else {
  367.         fileOut(file, '\"'+baseTextureTag+'\": \"'+mod+':'+'block/'+textureOne+'\"', false)
  368.     }
  369.     fileOut(file, '}\n}', false)
  370. }
  371. function lootTable(){
  372.     let fold = path.join(baseFolder, lootTableFiles);
  373.     fs.mkdirSync(fold, { recursive: true })
  374.     ltFenceAid(path.join(fold, blockName+'_fence.json'), blockName+'_fence');
  375.     ltFenceAid(path.join(fold, blockName+'_fence_gate.json'), blockName+'_fence_gate');
  376. }
  377. function ltFenceAid(file, block) {
  378.     fileOut(file, '{', true);
  379.     fileOut(file, '\"type\": \"minecraft:block\",', false);
  380.     fileOut(file, '\"pools\": [', false);
  381.     fileOut(file, '{', false);
  382.     fileOut(file, '\"rolls\": 1.0,', false);
  383.     fileOut(file, '\"bonus_rolls\": 0.0,', false);
  384.     fileOut(file, '\"entries\": [', false);
  385.     fileOut(file, '{', false);
  386.     fileOut(file, '\"type\": \"minecraft:item\",', false);
  387.     fileOut(file, '\"name\": \"'+customModID+':'+block+'\"', false);
  388.     fileOut(file, '}', false);
  389.     fileOut(file, '],', false);
  390.     fileOut(file, '\"conditions\": [', false);
  391.     fileOut(file, '{', false);
  392.     fileOut(file, '\"condition\": \"minecraft:survives_explosion\"', false);
  393.     fileOut(file, '}\n]\n\}\n]\n}', false);
  394. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement