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

Hi !

I wanted to create a type of recipe that damages a tool you put in the crafting inventory. It's based on ShapelessRecipes. The tool should remain after crafting in the left part, but with -1 damage. For example, a sword and a zombie head gives rotten meat and the sword is damaged.

 

The matches() works, but the getRemainingItems() has a problem.

	public ItemStack[] getRemainingItems(InventoryCrafting inv) {
	ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];

	for (int i = 0; i < aitemstack.length; ++i) {
		ItemStack itemstack = inv.getStackInSlot(i);
		if (isTool(itemstack))
			itemstack.attemptDamageItem(1, new Random());
else
		aitemstack[i] = net.minecraftforge.common.ForgeHooks
				.getContainerItem(itemstack);
	}

	return aitemstack;
}

 

It crashes when trying to take the result.

I know the error is in the lines

		if (isTool(itemstack))
			itemstack.attemptDamageItem(1, new Random());

But I haven't managed to fix it. I think it has something to do with the tool being "consumed" along the recipeItems during the process, but the process itself is fairly magic. I don't know how the games know which items it should consume, there is no explicit method for that, as the getRemainingItems() just returns everything from the left area (except the tool in my method of course but it doesn't work).

Post the

isTool

method and the crash report. I'm guessing you're calling

ItemStack#getItem

on a

null

value.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

The method works when used in matches() but I think you're right, it's probably called on null in getRemainingItems() because the tool is probably already consumed but I don't know how to avoid it. I can avoid the crash by not calling the function when null (easy) but then I don't receive the tool at all, it's just plainly consume like the recipeItems.

 

isTool() method :

	protected boolean isTool(ItemStack itemstack) {
	return ToolClass.isInstance(itemstack.getItem());
}

Crash report : http://hastebin.com/tefukadada.vhdl

 

I think my actual problem can therefore be resumed by : how to NOT consume an item while still keeping it as important in the matches() method.

The actual exception that caused the crash is being hidden by an exception thrown from the crash report code. This is due to Minecraft being rebuilt without debug information by ForgeGradle and has been fixed in ForgeGradle 2.0.2. I'd suggest updating the plugin in your build.gradle, re-running

setupDecompWorkspace

, refreshing your IDE project and posting the new crash report.

 

Edit: The

itemstack

argument of

isTool

will be

null

if there was no item in the slot. Check that it's not

null

before calling

ItemStack#getItem

on it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Yeah it doesn't crash anymore but there is nothing left in the left area. The condition is never satisfied because everything is consumed in the crafting inventory and I don't know how to change that.

In

getRemainingItems

, you're overwriting the damaged tool with the default container item returned by

ForgeHooks.getContainerItem

. This will be

null

unless the item has a container item specified.

 

You should only call

ForgeHooks.getContainerItem

when the item isn't a tool.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

After a few bugfixes, it seems to work, thank you. I have now a generic class allowing me to create shapeless recipes that uses whatever tool I want. Fantastic.

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.