1+ const fs = require ( 'fs' ) ;
2+
3+ document . getElementById ( "recipeForm" ) . onsubmit = form => {
4+ form . preventDefault ( ) ;
5+
6+ const filepath = localStorage . path ;
7+
8+ var blockName = document . getElementById ( "blockName" ) . value ;
9+ var modName = document . getElementById ( "modName" ) . value ;
10+ var result = document . getElementById ( "result" ) . value ;
11+
12+ localStorage . modName = modName ;
13+ localStorage . blockName = blockName ;
14+ localStorage . result = result ;
15+
16+ if ( document . getElementById ( "saveLocation" ) . value === 'No Location' ) {
17+ return document . getElementById ( "errorholder" ) . innerHTML = `Error: No save location given!` ;
18+ }
19+
20+ blockName = blockName . toLowerCase ( ) . split ( / + / ) . join ( '_' ) ;
21+ modName = modName . toLowerCase ( ) . split ( / + / ) . join ( '_' ) ;
22+ result = result . toLowerCase ( ) . split ( / + / ) . join ( '_' ) ;
23+
24+ const blockLength = blockName . length ;
25+ const blockLengthStart = blockLength - 6 ;
26+ const blockSubStr = blockName . substring ( blockLengthStart ) ;
27+
28+ if ( blockSubStr === 'bricks' ) {
29+ blockName = blockName . substring ( 0 , blockName . length - 1 ) ;
30+ }
31+
32+ if ( ! fs . existsSync ( `${ filepath } \\data\\${ modName } \\recipes\\` ) ) {
33+ fs . mkdir ( `${ filepath } \\data\\${ modName } \\recipes\\` , { recursive : true } , ( err ) => {
34+ if ( err ) throw err ;
35+ console . log ( 'Made the furnace folder structure.' ) ;
36+ } ) ;
37+ }
38+
39+ setTimeout ( ( ) => {
40+ const jsonProduct = {
41+ type : "minecraft:smelting" ,
42+ ingredient : {
43+ item : `${ textureNamespace } :${ blockName } `
44+ } ,
45+ result : `${ modName } :${ result } ` ,
46+ experience : 1 ,
47+ cooking_time : 200
48+ } ;
49+
50+ const jsonContent = JSON . stringify ( jsonProduct , null , 4 ) ;
51+
52+ // Note, when writing to a file, include \\assets\\${modName} or \\data\\${modName} to do it correctly
53+ fs . writeFile ( `${ filepath } \\data\\${ modName } \\recipes\\${ blockName } _furnace.json` , jsonContent , 'utf8' , ( err ) => {
54+ if ( err ) throw err ;
55+ console . log ( 'made file' ) ;
56+
57+ } ) ;
58+
59+ document . getElementById ( "generateBtn" ) . value = "Generated!" ;
60+ document . getElementById ( "errorholder" ) . innerHTML = "" ;
61+
62+ setTimeout ( ( ) => {
63+ document . getElementById ( "generateBtn" ) . value = "Generate!" ;
64+ } , 1000 ) ;
65+
66+ } , 10 ) ;
67+ } ;
0 commit comments