Jump to content

Recommended Posts

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).

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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...

×   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.

Announcements



×
×
  • Create New...

Important Information

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