Jump to content

Anon10W1z's tutorials


Recommended Posts

Hello, my name is Anon10W1z. I have been modding for just under a year and want to enlighten some of the modders here with the information I have gathered through my experience.


1. How to avoid enchantment ID conflicts


In 1.7, Forge had dropped the need to specify the ID of your item or block in its constructor. That was great! However, enchantment IDs still need to be specified in the constructor. I have developed a simple algorithm to combat this. Behold!


private static int findFreeEnchantID() {
   int i;
   for (i = 0; i < Enchantment.enchantmentsList.length; ++i)
   if (Enchantment.enchantmentsList[i] == null)
   return i;


1.8 version:

private static int findFreeEnchantID() {
   int i;
   for (i = 0; i < 256; ++i)
   if (Enchantment.getEnchantmentById(i) == null)
   return i;


It is a very simple yet effective algorithm that will only fail if there is no room for an enchantment at all, which is a problem that can only be solved by deleting the enchantment itself. It simply checks for an open space for an enchantment with the lowest enchantment ID it can find. All that is left to do is call findFreeEnchantID() in the enchantment's constructor.

Some other ideas to think about:

Give a reasonable crash report if no free enchantment ID is found.

Allow the user to pick whether or not to have the enchantment ID automatically selected for them. If not, allow them to pick the ID.


2. Remove a crafting recipe from the game


It is pretty simple to add a crafting recipe to Minecraft, but what if you want to remove a crafting recipe from Minecraft? Let me direct your attention to the following method:


private static void removeRecipe(ItemStack result) {
   ItemStack recipeResult = null;
   List recipes = craftingmanager.getRecipeList();
   for (int scan = 0; scan < recipes.size(); scan++) {
      IRecipe tmpRecipe = (IRecipe) recipes.get(scan);
      recipeResult = tmpRecipe.getRecipeOutput();
      if (recipeResult != null) {
         if (recipeResult.getItem() == resultItem.getItem() && recipeResult.getItemDamage() == resultItem.getItemDamage()) {

Call this method with whatever ItemStack you wish. It is another simple method that will search through all recipes for results that match the given ItemStack. If it finds the desired item to remove, then it checks for matching metadata values. If that also matches, then the recipe is removed from the list of recipes.

More tutorials will come soon!

Maker of the Craft++ mod.

Link to comment
Share on other sites

That's a good idea, I have two suggestions though:

a) You should fail and crash with a reasonable message when there are no IDs left.

b) You should have a Configuration fallback like this:

  - If there is an ID specified in the config, always try to use that, if it is taken then fail

  - If there is no ID in the config, try to find a free one like you proposed here and put it in the config

That way the user who just wants to throw a bunch of mods together most likely doesn't need to configure anything and someone who is designing a big modpack can still set the ID to what they want it to be. The 2nd step also makes sure that you get the same ID every time.

I think I should leave those features for the user to implement, instead of spoon-feeding them that much, but I'll leave those as ideas in the OP. Thanks!

Maker of the Craft++ mod.

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.