I found it pretty tedious to make tons of JSON files when making simple new blocks and items. Therefore, I made a snippet of Groovy code you can add to build.gradle in your project that will let you automatically generate default JSON files for blocks and items. I documented the procedure of making this script here. It's part of an ongoing documentation of converting Gases Framework from 1.7.10 to 1.9.4.
Generating JSON for an item: Open a command prompt in your project root directory and run the following
./gradlew generateItemModel itemName=item_name
item_name: the registry name of your item. The script also assumes this is the name of a texture that will be used for the item.
The following files will be created with default content, and will also override any existing files.
Installation:Download the templates here, and copy the templates folder into your project's root directory. Look through the folders and rename the modid folders according to your assets.
The final step is to add the following snippet to the bottom of your build.gradle
ext.args = [:]
ext.requireArgument = {String property, String displayValue ->
def value = args[property]
if (value == null) {
throw new InvalidUserDataException("$property must be set with \'$property=$displayValue\'")
}
return value
}
tasks.addRule("Pattern: <property>=<value>: Passes arguments to the scripts") { String taskName ->
def match = taskName =~ /(.*?)=(.*?$)/
if (match) {
def property = match[0][1]
def value = match[0][2]
ext.args[property] = value;
task(taskName) << {
println "Passes value \'$value\' to args[\'$property\']"
}
}
}
import org.apache.tools.ant.filters.FixCrLfFilter
class CopyJsonTemplate extends DefaultTask {
@Input
def template
@Input
def arguments
@Input
def jsonRename
@TaskAction
def build() {
def args = arguments()
project.copy {
from("templates/${template}") {
expand(args)
filter(FixCrLfFilter, eol: FixCrLfFilter.CrLf.newInstance('crlf'))
}
into 'src/main/resources'
rename { String filename ->
def match = filename =~ /(.*)\.json/
if (match) {
def prevFilename = match[0][1]
def newFilename = jsonRename.call(prevFilename)
return "${newFilename}.json"
}
else {
return filename
}
}
}
}
}
task generateBlockModel(type: CopyJsonTemplate) {
template 'block'
arguments {
def blockName = requireArgument('blockName', 'block_name')
return ['modid':archivesBaseName, 'block_name':blockName]
}
jsonRename {
return args['blockName']
}
}
task generateItemModel(type: CopyJsonTemplate) {
template 'item'
arguments {
def itemName = requireArgument('itemName', 'item_name')
return ['modid':archivesBaseName, 'item_name':itemName]
}
jsonRename {
return args['itemName']
}
}
Customization: It's a build script, so you can do whatever you want! Simply change the JSON files in the templates if you want different indentation or something else.
You don't need to create a json for the block and item model, just specify variants in the blockstates file and use the Forge-provided blockstates format. like this:
I also find making the json files tedious. However, one disadvantage of doing this at build-time is that you are just going to see the black/purple null texture when running in the dev enviornment. So if you forgot to write the Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(...) or ModelLoader.setCustomModelResourceLocation(...) you may not know until after you build and run outside the dev enviornment.
So I don't have that problem, I plan on writing code to generate all the json files at run-time, like I have done with the en_us.lang file. It just requires you creating a default folder resource pack that can be read by minecraft (requires reflection as Minecraft.defaultResourcePacks field is private) and using basic java.io classes. However, a problem of doing this at run-time is that the mod will take longer to load.
I found it pretty tedious to make tons of JSON files when making simple new blocks and items. Therefore, I made a snippet of Groovy code you can add to build.gradle in your project that will let you automatically generate default JSON files for blocks and items. I documented the procedure of making this script here. It's part of an ongoing documentation of converting Gases Framework from 1.7.10 to 1.9.4.
Generating JSON for an item: Open a command prompt in your project root directory and run the following
./gradlew generateItemModel itemName=item_name
item_name: the registry name of your item. The script also assumes this is the name of a texture that will be used for the item.
The following files will be created with default content, and will also override any existing files.
Generating JSON for a block: Open a command prompt in your project root directory and run the following
./gradlew generateBlockModel blockName=block_name
block_name: the registry name of your block. The script also assumes this is the name of a texture that will be used for the block.
The following files will be created with default content, and will also override any existing files.
Installation: Download the templates here, and copy the templates folder into your project's root directory. Look through the folders and rename the modid folders according to your assets.
The final step is to add the following snippet to the bottom of your build.gradle
Customization: It's a build script, so you can do whatever you want! Simply change the JSON files in the templates if you want different indentation or something else.
The .JSON files were what was keeping my interest away from 1.7.10 <. Definitely will be using this. Thanks
Thanks, very helpful!
Techguns Mod
You don't need to create a json for the block and item model, just specify variants in the blockstates file and use the Forge-provided blockstates format. like this:
I also find making the json files tedious. However, one disadvantage of doing this at build-time is that you are just going to see the black/purple null texture when running in the dev enviornment. So if you forgot to write the Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(...) or ModelLoader.setCustomModelResourceLocation(...) you may not know until after you build and run outside the dev enviornment.
So I don't have that problem, I plan on writing code to generate all the json files at run-time, like I have done with the en_us.lang file. It just requires you creating a default folder resource pack that can be read by minecraft (requires reflection as Minecraft.defaultResourcePacks field is private) and using basic java.io classes. However, a problem of doing this at run-time is that the mod will take longer to load.
Is the templates-folder still somehow existent?
Looking for testers, translators and sounds for