Skip to content

Commit

Permalink
Added stonecutter functionality. Upgraded save.js massively by adding…
Browse files Browse the repository at this point in the history
… more localstorage loaders, as well as making it delayed to ensure it loads everything in (revisit). Onload error should also be fixed now.
  • Loading branch information
Deviouslrd committed Jan 23, 2021
1 parent c6a50a7 commit 3d980be
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 62 deletions.
2 changes: 0 additions & 2 deletions functions/blockstates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}` }}
};
Expand Down
2 changes: 0 additions & 2 deletions functions/item_models.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
};
Expand Down
2 changes: 0 additions & 2 deletions functions/loot_tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
77 changes: 77 additions & 0 deletions functions/recipe_cutter.js
Original file line number Diff line number Diff line change
@@ -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);
};
56 changes: 34 additions & 22 deletions functions/recipe_furnace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = "";
Expand Down
49 changes: 34 additions & 15 deletions functions/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
6 changes: 3 additions & 3 deletions pages/advancement.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../assets/styles.css" onload="onLoad()">
<head>
<link rel="stylesheet" href="../assets/styles.css">
</head>
<body style="background: rgb(71, 71, 71);">
<body style="background: rgb(71, 71, 71);" onload="onLoad()">
<div style="text-align: center;">
<a class="button" href="./main.html">Home Page</a>
<a class="button" href="./block_models.html" onclick="return switchPage()">Block Models</a>
Expand Down
3 changes: 1 addition & 2 deletions pages/blockstates.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ <h1 class="header1">Minecraft Mod JSON Creation Tool</h1>
<input type="text" id="modName" required="true" class="textinput"><br>
</div>

<div name="Texture Namespace">
<div name="Texture Namespace">
<label for="textureNamespace" class="textbold">Texture Namespace:</label>
<input type="text" id="textureNamespace" class="textinput"><br>
</div>


<div name="Block Name">
<label for="blockName" class="textbold">Block Name:</label>
<div class="tooltip">?
Expand Down
4 changes: 2 additions & 2 deletions pages/loot_tables.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../assets/styles.css" onload="onLoad()">
<link rel="stylesheet" href="../assets/styles.css">
</head>
<body style="background: rgb(71, 71, 71);">
<body style="background: rgb(71, 71, 71);" onload="onLoad()">
<div style="text-align: center;">
<a class="button" href="./main.html" id="menuButton">Home Page</a>
<a class="button" href="./block_models.html" id="menuButton">Block Models</a>
Expand Down
18 changes: 11 additions & 7 deletions pages/recipe_cutter.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../assets/styles.css" onload="onLoad()">
<link rel="stylesheet" href="../assets/styles.css">
</head>
<body style="background: rgb(71, 71, 71);">
<body style="background: rgb(71, 71, 71);" onload="onLoad()">
<div style="text-align: center;">
<a class="button" href="./main.html" id="menuButton">Home Page</a>
<a class="button" href="./block_models.html" id="menuButton">Block Models</a>
Expand Down Expand Up @@ -33,8 +33,13 @@ <h1 class="header1">Minecraft Mod JSON Creation Tool</h1>
<input type="text" id="modName" required="true" class="textinput"><br>
</div>

<div name="Texture Namespace">
<label for="textureNamespace" class="textbold">Texture Namespace:</label>
<input type="text" id="textureNamespace" class="textinput"><br>
</div>

<div name="Ingredient Name">
<label for="blockName" class="textbold">Block Name:</label>
<label for="blockName" class="textbold">Ingredient:</label>
<div class="tooltip">?
<span class="tooltiptext">Input the name of the block you want to make, as you might see it in the inventory, i.e. Birch Logs. Capitals are not necessary.</span>
</div>
Expand All @@ -44,8 +49,8 @@ <h1 class="header1">Minecraft Mod JSON Creation Tool</h1>
<div>
<label for="result" class="textbold">Result:</label>
<input type="text" id="result" required="true" class="textinput"><br>
<label for="resultCount" class="textbold">Count:</label>
<input type="number" id="resultCount" required="true" class="textinput" style="width: 50px">
<label for="count" class="textbold">Count:</label>
<input type="number" id="count" required="true" class="textinput" style="width: 50px">
</div>

<div name="bottomButtons">
Expand All @@ -61,8 +66,7 @@ <h1 class="header1">Minecraft Mod JSON Creation Tool</h1>
<input type="image" id="savebutton" class="button" src='../assets/folder.png' onclick="saveLocation()" style="vertical-align: bottom;">
<input disabled type="text" id="saveLocation" class="savelocation" value="No location">
</div>

<script type="text/javascript" src="../functions/recipes.js"></script>
<script type="text/javascript" src="../functions/save.js"></script>
<script type="text/javascript" src="../functions/recipe_cutter.js"></script>
</body>
</html>
11 changes: 8 additions & 3 deletions pages/recipe_furnace.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../assets/styles.css" onload="onLoad()">
<link rel="stylesheet" href="../assets/styles.css">
</head>
<body style="background: rgb(71, 71, 71);">
<body style="background: rgb(71, 71, 71);" onload="onLoad()">
<div style="text-align: center;">
<a class="button" href="./main.html" id="menuButton">Home Page</a>
<a class="button" href="./block_models.html" id="menuButton">Block Models</a>
Expand Down Expand Up @@ -33,8 +33,13 @@ <h1 class="header1">Minecraft Mod JSON Creation Tool</h1>
<input type="text" id="modName" required="true" class="textinput"><br>
</div>

<div name="Texture Namespace">
<label for="textureNamespace" class="textbold">Texture Namespace:</label>
<input type="text" id="textureNamespace" class="textinput"><br>
</div>

<div name="Ingredient Name">
<label for="blockName" class="textbold">Block Name:</label>
<label for="blockName" class="textbold">Ingredient:</label>
<div class="tooltip">?
<span class="tooltiptext">Input the name of the block you want to make, as you might see it in the inventory, i.e. Birch Logs. Capitals are not necessary.</span>
</div>
Expand Down
4 changes: 2 additions & 2 deletions pages/recipe_table.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../assets/styles.css" onload="onLoad()">
<link rel="stylesheet" href="../assets/styles.css">
</head>
<body style="background: rgb(71, 71, 71);">
<body style="background: rgb(71, 71, 71);" onload="onLoad()">
<div style="text-align: center;">
<a class="button" href="./main.html" id="menuButton">Home Page</a>
<a class="button" href="./block_models.html" id="menuButton">Block Models</a>
Expand Down

0 comments on commit 3d980be

Please sign in to comment.