From 3d980be724e62921956b2b4ca02661aee79a4365 Mon Sep 17 00:00:00 2001 From: Deviouslrd <63770389+Deviouslrd@users.noreply.github.com> Date: Fri, 22 Jan 2021 22:17:26 -0700 Subject: [PATCH] Added stonecutter functionality. Upgraded save.js massively by adding more localstorage loaders, as well as making it delayed to ensure it loads everything in (revisit). Onload error should also be fixed now. --- functions/blockstates.js | 2 - functions/item_models.js | 2 - functions/loot_tables.js | 2 - functions/recipe_cutter.js | 77 +++++++++++++++++++++++++++++++++++++ functions/recipe_furnace.js | 56 ++++++++++++++++----------- functions/save.js | 49 +++++++++++++++-------- pages/advancement.html | 6 +-- pages/blockstates.html | 3 +- pages/loot_tables.html | 4 +- pages/recipe_cutter.html | 18 +++++---- pages/recipe_furnace.html | 11 ++++-- pages/recipe_table.html | 4 +- 12 files changed, 172 insertions(+), 62 deletions(-) create mode 100644 functions/recipe_cutter.js diff --git a/functions/blockstates.js b/functions/blockstates.js index 084e4c7..79331a0 100644 --- a/functions/blockstates.js +++ b/functions/blockstates.js @@ -48,8 +48,6 @@ document.getElementById("blockstateForm").onsubmit = form => { setTimeout(() => { // Block Creator if (document.getElementById("block").checked === true) { - brickSlice(); - const jsonProduct = { variants: { "": { model: `${modName}:block/${blockName}` }} }; diff --git a/functions/item_models.js b/functions/item_models.js index 9b03ca0..0d57f51 100644 --- a/functions/item_models.js +++ b/functions/item_models.js @@ -47,8 +47,6 @@ document.getElementById("itemModelForm").onsubmit = form => { setTimeout(() => { // Block Creator if (document.getElementById("block").checked === true) { - brickSlice(); - const jsonProduct = { parent: `${modName}:block/${blockName}` }; diff --git a/functions/loot_tables.js b/functions/loot_tables.js index 1130736..d214c34 100644 --- a/functions/loot_tables.js +++ b/functions/loot_tables.js @@ -38,8 +38,6 @@ document.getElementById("lootTableForm").onsubmit = form => { setTimeout(() => { // Block Creator if (document.getElementById("block").checked === true) { - brickSlice(); - const jsonProduct = { type: "minecraft:block", pools: [ diff --git a/functions/recipe_cutter.js b/functions/recipe_cutter.js new file mode 100644 index 0000000..a90e511 --- /dev/null +++ b/functions/recipe_cutter.js @@ -0,0 +1,77 @@ +const fs = require('fs'); + +document.getElementById("recipeForm").onsubmit = form => { + form.preventDefault(); + + const filepath = localStorage.path; + + var blockName = document.getElementById("blockName").value; + var modName = document.getElementById("modName").value; + var result = document.getElementById("result").value; + var textureNamespace = document.getElementById("textureNamespace").value; + var count = document.getElementById("count").value; + + if (document.getElementById("textureNamespace").value === ``) { + textureNamespace = document.getElementById("modName").value; + } else { + textureNamespace = document.getElementById("textureNamespace").value; + } + + localStorage.modName = modName; + localStorage.blockName = blockName; + localStorage.result = result; + localStorage.textureNamespace = textureNamespace; + localStorage.count = count; + + if (document.getElementById("saveLocation").value === 'No Location') { + return document.getElementById("errorholder").innerHTML = `Error: No save location given!`; + } + + blockName = blockName.toLowerCase().split(/ +/).join('_'); + modName = modName.toLowerCase().split(/ +/).join('_'); + result = result.toLowerCase().split(/ +/).join('_'); + textureNamespace = textureNamespace.toLowerCase().split(/ +/).join('_'); + + const blockLength = blockName.length; + const blockLengthStart = blockLength - 6; + const blockSubStr = blockName.substring(blockLengthStart); + + if (blockSubStr === 'bricks') { + blockName = blockName.substring(0, blockName.length - 1); + } + + if (!fs.existsSync(`${filepath}\\data\\${modName}\\recipes`)) { + fs.mkdir(`${filepath}\\data\\${modName}\\recipes`, { recursive: true}, (err) => { + if (err) throw err; + console.log('Made the stonecutting folder structure.'); + }); + } + + setTimeout(() => { + const jsonProduct = { + type: "minecraft:stonecutting", + blockName: { + item: `${textureNamespace}:${blockName}` + }, + result: `${textureNamespace}:${result}`, + count: count + }; + + const jsonContent = JSON.stringify(jsonProduct, null, 4); + + // Note, when writing to a file, include \\assets\\${modName} or \\data\\${modName} to do it correctly + fs.writeFile(`${filepath}\\data\\${modName}\\recipes\\${result}_stonecutter.json`, jsonContent, 'utf8', (err) => { + if (err) throw err; + console.log('Made stonecutter recipe file'); + + }); + + document.getElementById("generateBtn").value = "Generated!"; + document.getElementById("errorholder").innerHTML = ""; + + setTimeout(() => { + document.getElementById("generateBtn").value ="Generate!"; + }, 1000); + + }, 10); +}; \ No newline at end of file diff --git a/functions/recipe_furnace.js b/functions/recipe_furnace.js index eb5353b..6204e9c 100644 --- a/functions/recipe_furnace.js +++ b/functions/recipe_furnace.js @@ -5,21 +5,34 @@ document.getElementById("recipeForm").onsubmit = form => { const filepath = localStorage.path; - var blockName = document.getElementById("blockName").value; + var ingredient = document.getElementById("blockName").value; var modName = document.getElementById("modName").value; var result = document.getElementById("result").value; + var xp = document.getElementById("xpAmount").value; + var cookTime = document.getElementById("cookTime").value; + var textureNamespace = document.getElementById("textureNamespace").value; + + if (document.getElementById("textureNamespace").value === ``) { + textureNamespace = document.getElementById("modName").value; + } else { + textureNamespace = document.getElementById("textureNamespace").value; + } localStorage.modName = modName; - localStorage.blockName = blockName; + localStorage.blockName = ingredient; localStorage.result = result; + localStorage.xp = xp; + localStorage.cookTime = cookTime; + localStorage.textureNamespace = textureNamespace; if (document.getElementById("saveLocation").value === 'No Location') { return document.getElementById("errorholder").innerHTML = `Error: No save location given!`; } - blockName = blockName.toLowerCase().split(/ +/).join('_'); + ingredient = ingredient.toLowerCase().split(/ +/).join('_'); modName = modName.toLowerCase().split(/ +/).join('_'); result = result.toLowerCase().split(/ +/).join('_'); + textureNamespace = result.toLowerCase().split(/ +/).join('_'); const blockLength = blockName.length; const blockLengthStart = blockLength - 6; @@ -29,32 +42,31 @@ document.getElementById("recipeForm").onsubmit = form => { blockName = blockName.substring(0, blockName.length - 1); } - if (!fs.existsSync(`${filepath}\\data\\${modName}\\recipes\\`)) { - fs.mkdir(`${filepath}\\data\\${modName}\\recipes\\`, { recursive: true}, (err) => { + if (!fs.existsSync(`${filepath}\\data\\${modName}\\recipes`)) { + fs.mkdir(`${filepath}\\data\\${modName}\\recipes`, { recursive: true}, (err) => { if (err) throw err; console.log('Made the furnace folder structure.'); }); } setTimeout(() => { - const jsonProduct = { - type: "minecraft:smelting", - ingredient: { - item: `${textureNamespace}:${blockName}` - }, - result: `${modName}:${result}`, - experience: 1, - cooking_time: 200 - }; - - const jsonContent = JSON.stringify(jsonProduct, null, 4); + const jsonProduct = { + type: "minecraft:smelting", + ingredient: { + item: `${textureNamespace}:${ingredient}` + }, + result: `${textureNamespace}:${result}`, + experience: xp, + cooking_time: cookTime + }; + + const jsonContent = JSON.stringify(jsonProduct, null, 4); - // Note, when writing to a file, include \\assets\\${modName} or \\data\\${modName} to do it correctly - fs.writeFile(`${filepath}\\data\\${modName}\\recipes\\${blockName}_furnace.json`, jsonContent, 'utf8', (err) => { - if (err) throw err; - console.log('made file'); - - }); + // Note, when writing to a file, include \\assets\\${modName} or \\data\\${modName} to do it correctly + fs.writeFile(`${filepath}\\data\\${modName}\\recipes\\${blockName}_furnace.json`, jsonContent, 'utf8', (err) => { + if (err) throw err; + console.log('made file'); + }); document.getElementById("generateBtn").value = "Generated!"; document.getElementById("errorholder").innerHTML = ""; diff --git a/functions/save.js b/functions/save.js index e4e10eb..786c7c2 100644 --- a/functions/save.js +++ b/functions/save.js @@ -6,21 +6,40 @@ document.getElementById("savebutton").addEventListener('click', async () => { }); function onLoad() { - if (localStorage.blockName && document.getElementById("blockName")) { - document.getElementById("blockName").value = localStorage.blockName; - } - - if (localStorage.modName && document.getElementById("modName")) { - document.getElementById("modName").value = localStorage.modName; - } - - if (localStorage.textureNamespace && document.getElementById("textureNamespace")) { - document.getElementById("textureNamespace").value = localStorage.textureNamespace; - } - - if (localStorage.path) { - document.getElementById("saveLocation").value = localStorage.path; - } + setTimeout(() => { + if (localStorage.blockName && document.getElementById("blockName")) { + document.getElementById("blockName").value = localStorage.blockName; + } + + if (localStorage.modName && document.getElementById("modName")) { + document.getElementById("modName").value = localStorage.modName; + } + + if (localStorage.textureNamespace && document.getElementById("textureNamespace")) { + document.getElementById("textureNamespace").value = localStorage.textureNamespace; + } + + if (localStorage.path) { + document.getElementById("saveLocation").value = localStorage.path; + } + + if (localStorage.result && document.getElementById("result")) { + document.getElementById("result").value = localStorage.result; + } + + if (localStorage.count && document.getElementById("count")) { + document.getElementById("count").value = localStorage.count; + } + + if (localStorage.xp && document.getElementById("xp")) { + document.getElementById("xp").value = localStorage.xp; + } + + if (localStorage.cookTime && document.getElementById("cookTime")) { + document.getElementById("cookTime").value = localStorage.cookTime; + } + }, 75); + } document.getElementById("generateBtn").addEventListener('click', () => { diff --git a/pages/advancement.html b/pages/advancement.html index db63fde..2c96545 100644 --- a/pages/advancement.html +++ b/pages/advancement.html @@ -1,9 +1,9 @@ -
- + + - +