Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Fixes and additions
Browse files Browse the repository at this point in the history
Fixed stuff, added model support for items, and added Gui feature
  • Loading branch information
Minimine committed Apr 28, 2018
1 parent 0403566 commit 4d82458
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 70 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

package-lock.json
*.bat
test.json
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## Usage

Type **minetem** and add your arguments:
- compile <souce-json\> <dest-folder\> - compile source json
- compile <source-json\> <dest-folder\> - compile source json
- debug - use debug mode (get debug information)
### JSON format
```json
Expand All @@ -37,19 +37,30 @@ Type **minetem** and add your arguments:
"id": 1,
"parent": "diamond_sword",
"texture": "blocks/birch_log"
},
{
"id": 2,
"parent": "diamond_sword",
"model": "block/anvil"
}
],
"guis": [
{
"id": 1,
"texture": "customguis/1"
}
]
}
```
- This is the json structure of the source json. in the first example of a block you define the id of the block (1) and than the texture. The parent of a block is automatically set to a diamond hoe. So to place the first block you habe to execute this command:
- This is the json structure of the source json. in the first example of a block you define the id of the block (1) and then the texture. The parent of a block is automatically set to a diamond hoe. So to place the first block you have to execute this command:
```
/setblock ~ ~ ~ minecraft:mob_spawner{SpawnData:{id:"minecraft:armor_stand",ArmorItems:[{},{},{},{id:"minecraft:diamond_hoe",Count:1b,tag:{Unbreakable:1b,Damage:1}}]}}
```
- The first block is the same as the first, but in this example the block is not the same texture on the first every page of the block. We Also do this with the id, the secound block has also a diamond_hoe as parent like every block, so we mustn't have the same id for it. But this block has for every page side another texture, so we have to write them all manualy, and cant use the short form. To place this block type
- The second block is the same as the first, but in this example the block is not the same texture on the first every page of the block. We also do this with the id, the second block has also a diamond_hoe as parent like every block, so we mustn't have the same id for it. But this block has for every page side another texture, so we have to write them all manually, and cant use the short form. To place this block type
```
/setblock ~ ~ ~ minecraft:mob_spawner{SpawnData:{id:"minecraft:armor_stand",ArmorItems:[{},{},{},{id:"minecraft:diamond_hoe",Count:1b,tag:{Unbreakable:1b,Damage:2}}]}}
```
- For an item we have to manualy define the parent. Becouse it has another parent as the diamond_hoe, we can take an id we already used for the blocks, the 1. Here we can just define one side of the texture, because an item texture has only one side. You can use the following parent types:
- For an item we have to manually define the parent. Because it has another parent as the diamond_hoe, we can take an id we already used for the blocks, the 1. Here we can just define one side of the texture, because an item texture has only one side. You can use the following parent types:
```
wooden_sword
golden_sword
Expand Down Expand Up @@ -104,7 +115,14 @@ To get the Item from the last example just type
```
/give @s minecraft:diamond_sword{Unbreakable:1b,Damage:1}
```

- The second item is nearly the same as the first, but this time it has a custom model, no custom texture. With this model it will look like an anvil. To get it just type
```
/give @s minecraft:diamond_sword{Unbreakable:1b,Damage:2}
```
- The creating of an Inventory is nearly the same as the creating of a block, but we just can use one texture, not 6. As parent it has a diamond_shovel. To place it just type
```
/setblock ~ ~ ~ minecraft:chest{Items:[{Slot:0b,id:"minecraft:diamond_shovel",Count:1b,tag:{Unbreakable:1b,Damage:1}}]} replace
```

## Authors

Expand All @@ -118,8 +136,5 @@ To get the Item from the last example just type

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

## Planned
Model support for the items, **not the block**, with this block generating technology is that not possible!

## Issues
It would be very nice, if you find a issue to report it via the github issue function.
41 changes: 0 additions & 41 deletions example.json

This file was deleted.

Binary file added guitemplate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"description": "An easy way to add blocks and other stuff to minecraft",
"main": "src/index.js",
"scripts": {
"test": "node src/index.js"
"test": "echo error:&echo No test specified"
},
"bin": {
"minetem": "src/index.js"
},
"author": "Minimine",
"license": "ISC",
Expand Down
1 change: 0 additions & 1 deletion src/compiler/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function compile(json, dir) {
if(!value.textures)console.throwException("CompilingError: Can't create a block without a texture");

var textures;
var elements;


if(value.textures instanceof Object) {
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const path = require("path");
const overwriter = require("./overwriter.js");
const blocks = require("./blocks.js");
const items = require("./items.js");
const guis = require("./guis.js");
const data = require("./data.js");
const util = require("./util.js");

Expand Down Expand Up @@ -56,6 +57,7 @@ function compile(src, dest) {

blocks.compile(json, dir);
items.compile(json, dir);
guis.compile(json, dir);
overwriter.generateOverwrites(dir);

console.log("Compiling successfully finished!");
Expand Down
73 changes: 73 additions & 0 deletions src/compiler/guis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
*
* Minetem compiler
* Repository: github.com/MinimineLP/Minetem
* Licensed under MIT, see LICENSE od LICENSE.md file
* Copyright (c) Minimine 2018
*
*/

const fs = require("fs");
const path = require("path");
const data = require("./data.js");
const util = require("./util.js");

module.exports = {
compile: compile
}

function compile(json, dir) {

if(json.guis) {
json.guis.forEach(function(value) {

if(!value.id)console.throwException("CompilingError: Need id for every block");
if(!Number.isInteger(value.id))console.throwException("CompilingError: The id must be a positive number between 1 and 1562");
if(parseInt(value.id)<1 || parseInt(value.id)>1562)console.throwException("CompilingError: The id must be a positive number between 1 and 1562");

if(value.id in data.ids.diamond_shovel) console.throwException("CompilingError: Can't use that id, please try another, it is propably used for another texture.");

if(!value.texture)console.throwException("CompilingError: Can't create a gui without a texture");


var json = util.textureFileLayout.gui
.replaceAll('%path%', value.texture)
.replaceAll('\n', '')
.replaceAll(' ', '')
.replaceAll(' ','');


var path = dir+`\\assets\\minecraft\\models\\custom\\diamond_shovel\\${value.id}.json`;
writeFile(path, json);

// DEBUG:
console.debug(`Compiled gui with id ${value.id} into file `+fixBackslash(path));

data.ids.diamond_shovel.push(value.id);
});
}
}

function fixBackslash(str) {
return str.replaceAll('\\\\', '/')
}

function writeFile(file, content) {
if(fs.existsSync(file)) console.throwException("CompilingError: Can't use that id, please try another, it is propably used for another texture.");

file = file.replaceAll("\\\\", "/");

var parts = file.split("/");
for(var i=1;i<parts.length;i++){

var path = "";

for(var c=0;c<i;c++)
path += parts[c]+"/";

if(!fs.existsSync(path))fs.mkdirSync(path);

}

fs.writeFileSync(file, content);
}
20 changes: 12 additions & 8 deletions src/compiler/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,30 @@ function compile(json, dir) {
if(json.items) {
json.items.forEach(function(value) {

if(!value.id)console.throwException("CompilingError: Need id for every block");
if(!value.id)console.throwException("CompilingError: Need id for every item");

if(!value.parent)console.throwException("CompilingError: Can't create a block without a parent");
if(!util.damage[value.parent])console.throwException(`CompilingError: Parent ${parent} is invalid`)

if(!Number.isInteger(value.id))console.throwException(`CompilingError: The id must be a positive number between 1 and ${util.damage[value.parent]}`);
if(parseInt(value.id)<1 || parseInt(value.id)>util.damage[value.parent])console.throwException(`CompilingError: The id must be a positive number between 1 and ${util.damage[value.parent]}`);

if(!value.texture)console.throwException("CompilingError: Can't create a block without a texture");
if((!value.texture) && (!value.model))console.throwException("CompilingError: Can't create a block without a model or texture");

var json = util.textureFileLayout.onelayer.replaceAll('%path%', value.texture);
if(value.texture) {
var json = util.textureFileLayout.onelayer.replaceAll('%path%', value.texture);

var path = dir+`\\assets\\minecraft\\models\\custom\\${value.parent}\\${value.id}.json`;
var path = dir+`\\assets\\minecraft\\models\\custom\\${value.parent}\\${value.id}.json`;

writeFile(path, json);
writeFile(path, json);

// DEBUG:
console.debug(`Compiled item with id ${value.id} and parent ${value.parent} into file `+fixBackslash(path));
// DEBUG:
console.debug(`Compiled item with id ${value.id} and parent ${value.parent} into file `+fixBackslash(path));

data.ids[value.parent].push(value.id);
data.ids[value.parent].push(value.id);
} else {
data.ids[value.parent].push([value.id,value.model]);
}
});
}
}
Expand Down
27 changes: 17 additions & 10 deletions src/compiler/overwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@ module.exports = {
function generateOverwrites(dir) {
data.ids.forEach(function(key, value) {
if(value.length>0) {
var overwrites = util.overwriteLayout.start
.replaceAll('%type%', key);

value.forEach(function(value) {
overwrites += util.overwriteLayout.overwrite
.replaceAll('%type%', key)
.replaceAll('%id%', value)
.replaceAll('%damage%', value*(1/util.damage[key]));
var overwrites = util.overwriteLayout.start;

value.forEach(function(val) {
var model = null;
if(!Number.isInteger(val)){
model = val[1];
val = val[0];
}
var overwrite = util.overwriteLayout.overwrite
.replaceAll('%damage%', val*(1/util.damage[key]));

if(model != null) overwrite = overwrite.replaceAll('%location%', model);
else overwrite = overwrite.replaceAll('%location%', `custom/${key}/${val}`);

overwrites += overwrite;
});

overwrites+=util.overwriteLayout.end
.replaceAll('%type%', key);
overwrites+=util.overwriteLayout.end;
overwrites = overwrites.replaceAll('%type%', key);

var path = dir+`\\assets\\minecraft\\models\\item\\${key}.json`;
fs.writeFileSync(path, overwrites);
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

const overwriteLayout = {
start: `{"__createdwith": "Minetem Compiler","parent": "item/handheld","textures": {"layer0": "items/%type%"},"overrides": [`,
overwrite: `{ "predicate": {"damaged": 0, "damage": %damage%}, "model": "custom/%type%/%id%"},`,
overwrite: `{ "predicate": {"damaged": 0, "damage": %damage%}, "model": "%location%"},`,
end: `{ "predicate": {"damaged": 1, "damage": 0}, "model": "item/%type%"}]}`,
}

Expand All @@ -18,6 +18,7 @@ const textureFileLayout = {
display: `"display": {"head": {"rotation": [-30, 0, 0],"translation": [ 0, -18.4825, -14.29 ],"scale": [ 1.9845, 1.9845, 1.9845 ]}}`,
elements: `"elements":[{"from":[-16,-16,-16],"to":[32,32,32],"faces":{"up":{"texture":"#up","uv":[0,0,16,16]},"down":{"texture":"#down","uv":[0,0,16,16]},"west":{"texture":"#west","uv":[0,0,16,16]},"east":{"texture":"#east","uv":[0,0,16,16]},"north":{"texture":"#north","uv":[0,0,16,16]},"south":{"texture":"#south","uv":[0,0,16,16]}}}]`,
onelayer: `{"__createdwith": "Minetem Compiler","parent": "item/generated","textures": {"layer0": "%path%"}}}`,
gui: `{"__createdwith": "Minetem Compiler","textures":{"texture":"%path%"},"elements":[{"from":[-16,-16,15.9375],"to":[32,32,16],"faces":{"north":{"uv":[0,0,16,16],"rotation":180,"texture":"#texture"},"south":{"uv":[0,0,16,16],"texture":"#texture"}}}],"display":{"firstperson_lefthand":{"rotation":[0,0,0],"translation":[0,0,0],"scale":[0,0,0]},"gui":{"rotation":[0,0,0],"translation":[72,-62,-80],"scale":[3.66,3.66,3.66]}}}`,
}

const damage = {
Expand Down

0 comments on commit 4d82458

Please sign in to comment.