Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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)
   break;
   
   return i;
}

 

1.8 version:

private static int findFreeEnchantID() {
   int i;
   for (i = 0; i < 256; ++i)
   if (Enchantment.getEnchantmentById(i) == null)
   break;
   
   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()) {
            recipes.remove(scan);
            --scan;
         }
      }
   }
}

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.

  • Author

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.

  • Author

I've added another tutorial: how to remove crafting recipes

Maker of the Craft++ mod.

  • Author

Again, in principle it is correct, but not great.

a) Why are you casting to ArrayList?

b) Use an Iterator, it is much safer against off-by-one errors.

I've revised the method

Maker of the Craft++ mod.

  • 2 months later...

Thank you! This is a quite useful idea; using it now and in future :D

  • 2 weeks later...
  • Author

Thank you! This is a quite useful idea; using it now and in future :D

No problem ;)

Maker of the Craft++ mod.

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.