0
\$\begingroup\$

I'm designing a robust system for resolving item dependencies in Minecraft and to do so, I need to maintain a database of items and recipes. Right now, this database has to be hand-crafted (no pun intended); I would like to know if it is possible to somehow query the Minecraft jars (or perhaps more realistically, grep through them) to extract this data automatically.

How can this be done? The project is currently in Python, but it can still be ported to Java without much fuss at this stage. (For the curious.)

\$\endgroup\$
10
  • 1
    \$\begingroup\$ Just an initial observation, you may be better off getting the source code (the code the modders use) and parsing those files. I'm sure you can set up scripts to download the latest source and then parse the object lists to keep your database up to date. It has been a while since I went through that code so I don't remember how easy it would be. \$\endgroup\$ Jun 24 '13 at 18:11
  • \$\begingroup\$ @UnderscoreZero I thought about that; the issue is that everyone uses a different set of mods. Some mods are incompatible (clashing item IDs, I imagine) which would throw the database into self-contradiction. \$\endgroup\$ Jun 24 '13 at 18:13
  • 1
    \$\begingroup\$ The vanilla source code the modders use would not have clashing item IDs. \$\endgroup\$
    – House
    Jun 24 '13 at 18:14
  • \$\begingroup\$ @Byte56 But so many mods add item IDs. If it was just a one-time thing, I really wouldn't care to automate the process to begin with. \$\endgroup\$ Jun 24 '13 at 18:15
  • \$\begingroup\$ Are you interested in adding items and recipes that were added with mods? \$\endgroup\$
    – House
    Jun 24 '13 at 18:16
1
\$\begingroup\$

Minecraft's item and crafting recipes are defined in code, not in data. So you'll have to decompile the .jar files to do any useful analysis. To include mods in this analysis, you'd need to decompile them as well.

The main Minecraft server contains an Item.java file that lists all items along with their item IDs. The format of the calls that insert items into the registry is pretty simple and amenable to extraction via grep and some regular expressions. For example, on a not-necessarily-very-recent copy of the file, they look like:

REGISTRY.a(325, "bucket", item);
REGISTRY.a(326, "water_bucket", (new ItemBucket(Blocks.WATER)).c("bucketWater").c(item).f("bucket_water"));
REGISTRY.a(327, "lava_bucket", (new ItemBucket(Blocks.LAVA)).c("bucketLava").c(item).f("bucket_lava"));

Similarly, you can find recipes defined in CraftingManager.java:

this.registerShapelessRecipe(new ItemStack(Items.BOOK_AND_QUILL, 1), new Object[] { Items.BOOK, new ItemStack(Items.INK_SACK, 1, 0), Items.FEATHER});
this.registerShapedRecipe(new ItemStack(Blocks.FENCE, 2), new Object[] { "###", "###", Character.valueOf('#'), Items.STICK});

By exploiting these patterns, you can parse out a set of items and recipes for the main Minecraft application easily enough. However, because you're relying on source code parsing this technique is subject to being trivially broken in the likely event that the code structure changes (it may already be broken, I am looking at an old copy of the decompiled code to find these examples).

Worse still, mods may not use the same patterns and you are certainly likely to see different patterns across mods. You may be able to build a system that uses a unique, slightly-modified set of parse rules for each mod (and the main application), and this may be less work in the long run than manually adding every item and recipe to your database... but it's unfortunately still subject to being trivially broken by new version of the mods or the main executable.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ It may be best to introduce a new meta-mod that will expose these recipes as data on server start; decompilation is a bit... ugly. \$\endgroup\$ Dec 15 '14 at 19:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .