Minecraft – How to get a Minecraft texture from the id

minecraft-java-edition

This is my first question on any forum, so any advice would be helpful; down voting doesn't count as advice 🙂
Also, I am not sure if this is the right forum, or if Stack Overflow is better … any pointers are very helpful!

I am creating a world viewing and editing software for Minecraft in Java as MC Edit has been broken for a long time. Currently, I am able to get the Minecraft id of the top block in every x and z coordinate pair. Now, I need to get the texture of these blocks. (Just to be clear, the id I am talking about is like this: minecraft:bedrock, not the number) Is there an easy way to get the file name of the texture from the id? I plan to then create a BufferedImage and render the texture onto the screen, to get a realistic overview of the world.

This would need to account for the blocks with different textures on the sides, blocks with only one texture, and so on. If possible, I would like to be able to show the tops of chests, item frames, and more, accurately, but that might be more difficult. So far, the only idea I have gotten is to map all the file names to the id, which could take a while.

Thank You!

Best Answer

Most blocks use a "normal cube" model, meaning six sides, following a standard naming scheme. But some blocks are much more complex, like redstone wire (whose connection directions were not even saved to file until 1.13), lecterns (with a diagonal "top" face), plants (which are basically invisible from the top) and so on.

If you want to display them from any angle, including the top, you will always need to parse that block's block model (archive). This is done in four main steps:

  1. Find the default resources: The path of the default .minecraft folder (archive) depends on the operating system, but not on launcher profiles. In there you can find (archive) the file versions/<version>/<version>.jar, which you can unpack as an archive. The file structure inside is explained here (archive) and in more detail the resource pack structure here (archive).
  2. Parse the <id>.json file (with <id> being the ID you know) in the assets/minecraft/blockstates folder, which references the different block states this block can have and the blockstate files that they use.
  3. Parse the <blockstate>.json model files in assets/minecraft/models/block that the block state file referenced. Either decide somehow what you consider the "top" or make a full 3D render, both using …
  4. … the <texture>.png image files in assets/minecraft/textures/block that the model file referenced.

This will certainly not be a small project …