Why does Minecraft Forge have these strange variable names?

Viewed 382

I have been frustrated about my Minecraft Forge Project being wonkey.

Why? Because most of the code have weird arguments and with it, I cant understand. Before this, my other projects didn't have this craziness. Here is an example:

public WoodFurnaceBlock(Properties p_49795_) {
    super(p_49795_);
}

In this example, the argument looks like a weird id, and this might have been an import error. Is there a website to search what the argument means or do I have to live with it in a Bad way.

Remember in my project, most of the arguments are broken.

1 Answers

The reason the weird id is because Mojang obfuscates their code.

The people behind forge use a mapper to translate method, class and property names to human readable names. They use MCP mappings to translate method calls to Minecraft code to the calls the obfucated code understands.

That's also the reason why it always takes a little time after a new version is released before forge releases their version, as they need to check and improve their mappings and naming.

That also explains why the same method can have different names in different Forge versions for different Minecraft versions, as they can decide on a better or different naming scheme.

The variable in your case, is still the obfuscated value, which hasn't gotten a mapping appointed yet, or nobody had found it worthwhile to think up a name and add the mapping to it, or pushed it down on the queue, focusing on the more important class and method names first, instead of the relatively unimportant property names.

Try to infer the use of the property by it's type name. Copy the entire class in your own namespace and use refactor to give the variables and arguments proper names so you can read the code better.

Don't forget Forge is maintained by volunteers, and it takes a lot of time and effort to make these mappings.

You can also volunteer some effort https://github.com/MinecraftForge/MCPConfig

Usually when a version is around longer, more and more of these weird mappings get resolved to proper names. When you work with newer versions, you'll have more instances where your IDE will generate these methods with these weird property names.

Just give them proper names. Your example I would refactor to:

class WoodFurnaceBlock {
  public WoodFurnaceBlock(Properties properties) {
    super(properties);
  }
}

I once spend half a year to figure out how to do proper structure generation like nether temples in 1.7.10, working solely with obfuscated code, having to think of names and then refactor to better names as I understood the code better as to how Mojang did it.

When modding with Forge, this will always be part of the development experience.

If you prefer doing things on easy mode I'd suggest doing bukkit/spigot plugins. It's harder to do fancy things like custom mobs and blocks, but it's easier and more consistent to code.

Related