The District of Joban Difference between revisions of "MTR:FileGenerator"

Difference between revisions of "MTR:FileGenerator"

From The District of Joban
Line 77: Line 77:


===== But what if it doesn't start with 0? =====
===== But what if it doesn't start with 0? =====
You can also increment a base number, for example:
You can also increment a base number, for example:[[File:File Generator 2.png]]<code>%0.5+16%</code> would make the code start at 16.0, then 16.5, 17.0, 17.5 and so on...
[[File:File Generator 2.png]]
<code>%0.5+16%</code> would make the code start at 16.0, then 16.5, 17.0, 17.5 and so on...


===== The opposite =====
===== The opposite =====
The increment can also be negative. For the door to open the other side, you can switch from <code>%0.5+16%</code> to <code>%-0.5-16%</code>.
The increment can also be negative. For the door to open the other side, you can switch from <code>%0.5+16%</code> to <code>%-0.5-16%</code>.

Revision as of 03:32, 20 August 2022

Draft

This article is a work in progress.
Informations might not be complete and will be improved overtime.

FileGenerator is a class for mass generating model files, specifically Platform Screen Doors and Automatic Platform Gates for the Minecraft Transit Railway Mod.

This file is located under common/src/main/java/FileGenerator.java.

History

Before MTR is migrated to Architectury, it uses Fabric Rendering API to render the APG & PSD.

This however does not work well with Sodium and requires the Indium mod to be installed.

To fix the compatibility issues, these blocks has to be converted to regular Minecraft blockstates.

With the opening state split to 32 parts, we're looking at over 100 files, this could take an enormous amount of time to do each state manually.


As such, a class is made to automatically convert the file name and shift the model.

Executable Download

Note: This version is slightly modified from the original class, of the fact that it's no longer hard coded to %user.home%/desktop.

https://www.joban.tk/misc/FileGenerator.jar

Modified source file:

https://www.joban.tk/misc/FileGenerator.java.

How this works

This is a command line program, and you will need Java 17 to run it.

Let's take a look at the following example:

java -jar FileGenerator.jar "top_left_%i" "33"

java -jar FileGenerator.jar is telling java to run FileGenerator.jar, nothing special.

"top_left_%i" is referring to the exported file name, and %i represents the integer it's looping through.

The end result is bunch of files named:

top_left_0.json

top_left_1.json

top_left_2.json

top_left_3.json

And so on.

"33" is referring to the number of states it exports. (So 0-32, as 0 itself is also a state)

Note: You must name your file input.json on the same directory, so the program can find it.

Where the magic happens

After executing the above command, a generated folder will appear on where you run the jar, these are your outputed files.

But it only exports the files named accordingly, how does this shift the model?

It also replaces the content inside the file with a placeholder.


With a basic understanding of json and Minecraft's model, we can find the coordinates of each model.

To make it automatically shift from 0 to 16 pixels, we need to replace the Z axis with:

%0.5% File Generator 1.png

This simply means the incrementation would be 0.5.

So top_left_0.json would be 0

top_left_1.json would be 0.5

top_left_2.json would be 1, and so on...

But what if it doesn't start with 0?

You can also increment a base number, for example:File Generator 2.png%0.5+16% would make the code start at 16.0, then 16.5, 17.0, 17.5 and so on...

The opposite

The increment can also be negative. For the door to open the other side, you can switch from %0.5+16% to %-0.5-16%.