Jump to content

Show recipe items in a string when holding a certain button (item tooltip)


iiBlake

Recommended Posts

hello, I was recently playing a 1.6.4 modpack and saw ICBM has recipes in the lore when holding J (http://prntscr.com/cdkvwq). Is there any way I can do this in my mod? Getting the recipe for an itemStack, I already know how to do the lore based on keys held. I had a look in the CraftingManager class but found nothing that could help. Thanks for any help!

Link to comment
Share on other sites

I think what you're asking for is essentially an uncrafting method, right? Like you want to take an item that was crafted and know what could be used to craft it again?

 

Uncrafting is actually fairly complicated. I did work it out for 1.8 when I made an "uncrafting table" where you can put something in and get the ingredients out.

 

Here is the code repository where I did the deconstructor recipe analysis. Look at all the classes starting with "Deconstructing": https://github.com/jabelar/JadensMod/tree/master/src/main/java/com/blogspot/jabelarminecraft/blocksmith/recipes

 

The idea is that during post initialization of the mod (because I also want recipes from any other mod that is loaded), I use these classes once to go through the various crafting recipes and store their ingredients for future use.

 

If you look into the classes you'll see they require some tricky programming, because there are several different types of recipes.

 

One of the other things is that some crafting recipes produce more than 1 output. So you'll see that I have modes for my table that spread out the ingredients to be fair -- like you wouldn't want game to allow you to get more ingredients back than you used in the first place. In your case, if you just want to display the recipe, you might not care about that.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Okay, i tried using the CraftingDeconstructor class, and I'm doing it like this:

	List<String> d = new ArrayList<String>();
	CraftingDeconstructor decon = new CraftingDeconstructor();

	ItemStack[] ingredients = decon.getDeconstructResults(item);

	for (ItemStack i : ingredients) {
		d.add(i.getUnlocalizedName());
	}

	return d;

But it is throwing a NPE in it:

 

 

[21:43:40] [Client thread/INFO] [sTDOUT]: [me.iiblake.testmod.CraftingDeconstructor:getDeconstructResults:24]: Looking for deconstructing a recipe for item.ballisticsGel

[21:43:40] [Client thread/INFO] [sTDOUT]: [me.iiblake.testmod.CraftingDeconstructor:getCraftingGrid:90]: getCraftingGrid for shapeless ore recipe with input array size = 1

[21:43:41] [server thread/INFO]: Stopping server

[21:43:41] [server thread/INFO]: Saving players

[21:43:41] [server thread/INFO]: Saving worlds

[21:43:41] [server thread/INFO]: Saving chunks for level 'New World'/Overworld

[21:43:41] [server thread/INFO]: Saving chunks for level 'New World'/Nether

[21:43:41] [server thread/INFO]: Saving chunks for level 'New World'/The End

[21:43:42] [server thread/INFO] [FML]: Unloading dimension 0

[21:43:42] [server thread/INFO] [FML]: Unloading dimension -1

[21:43:42] [server thread/INFO] [FML]: Unloading dimension 1

[21:43:42] [server thread/INFO] [FML]: Applying holder lookups

[21:43:42] [server thread/INFO] [FML]: Holder lookups applied

[21:43:42] [Client thread/FATAL]: Reported exception thrown!

net.minecraft.util.ReportedException: Rendering screen

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1168) ~[EntityRenderer.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1068) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_79]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_79]

at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_79]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]

at GradleStart.main(Unknown Source) [start/:?]

Caused by: java.lang.NullPointerException

at me.iiblake.testmod.items.ItemBallisticsGel.getTooltipStrings(ItemBallisticsGel.java:30) ~[itemBallisticsGel.class:?]

at me.iiblake.testmod.items.ItemBase.addInformation(ItemBase.java:17) ~[itemBase.class:?]

at net.minecraft.item.ItemStack.getTooltip(ItemStack.java:641) ~[itemStack.class:?]

at net.minecraft.client.gui.GuiScreen.renderToolTip(GuiScreen.java:124) ~[GuiScreen.class:?]

at net.minecraft.client.gui.inventory.GuiContainerCreative.renderToolTip(GuiContainerCreative.java:769) ~[GuiContainerCreative.class:?]

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:186) ~[GuiContainer.class:?]

at net.minecraft.client.renderer.InventoryEffectRenderer.drawScreen(InventoryEffectRenderer.java:44) ~[inventoryEffectRenderer.class:?]

at net.minecraft.client.gui.inventory.GuiContainerCreative.drawScreen(GuiContainerCreative.java:673) ~[GuiContainerCreative.class:?]

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1137) ~[EntityRenderer.class:?]

... 11 more

[21:43:42] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ----

// This doesn't make any sense!

 

Time: 3/09/16 9:43 PM

Description: Rendering screen

 

java.lang.NullPointerException: Rendering screen

at me.iiblake.testmod.items.ItemBallisticsGel.getTooltipStrings(ItemBallisticsGel.java:30)

at me.iiblake.testmod.items.ItemBase.addInformation(ItemBase.java:17)

at net.minecraft.item.ItemStack.getTooltip(ItemStack.java:641)

at net.minecraft.client.gui.GuiScreen.renderToolTip(GuiScreen.java:124)

at net.minecraft.client.gui.inventory.GuiContainerCreative.renderToolTip(GuiContainerCreative.java:769)

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:186)

at net.minecraft.client.renderer.InventoryEffectRenderer.drawScreen(InventoryEffectRenderer.java:44)

at net.minecraft.client.gui.inventory.GuiContainerCreative.drawScreen(GuiContainerCreative.java:673)

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1137)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1068)

at net.minecraft.client.Minecraft.run(Minecraft.java:962)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at me.iiblake.testmod.items.ItemBallisticsGel.getTooltipStrings(ItemBallisticsGel.java:30)

at me.iiblake.testmod.items.ItemBase.addInformation(ItemBase.java:17)

at net.minecraft.item.ItemStack.getTooltip(ItemStack.java:641)

at net.minecraft.client.gui.GuiScreen.renderToolTip(GuiScreen.java:124)

at net.minecraft.client.gui.inventory.GuiContainerCreative.renderToolTip(GuiContainerCreative.java:769)

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:186)

at net.minecraft.client.renderer.InventoryEffectRenderer.drawScreen(InventoryEffectRenderer.java:44)

at net.minecraft.client.gui.inventory.GuiContainerCreative.drawScreen(GuiContainerCreative.java:673)

 

-- Screen render details --

Details:

Screen name: net.minecraft.client.gui.inventory.GuiContainerCreative

Mouse location: Scaled: (283, 138). Absolute: (567, 202)

Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityClientPlayerMP['Player406'/133, l='MpServer', x=1128.26, y=11.73, z=-82.05]]

Chunk stats: MultiplayerChunkCache: 81, 81

Level seed: 0

Level generator: ID 01 - flat, ver 0. Features enabled: false

Level generator options:

Level spawn location: World: (1140,4,280), Chunk: (at 4,0,8 in 71,17; contains blocks 1136,0,272 to 1151,255,287), Region: (2,0; contains chunks 64,0 to 95,31, blocks 1024,0,0 to 1535,255,511)

Level time: 131385 game time, 147096 day time

Level dimension: 0

Level storage version: 0x00000 - Unknown?

Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 7 total; [EntityItem['item.item.arrow'/137, l='MpServer', x=1145.91, y=4.13, z=-113.56], EntityItem['item.item.rottenFlesh'/136, l='MpServer', x=1140.53, y=4.13, z=-78.91], EntitySpider['Spider'/139, l='MpServer', x=1167.41, y=4.00, z=-32.78], EntityItem['item.item.bone'/138, l='MpServer', x=1145.69, y=4.13, z=-112.91], EntityItem['item.item.rottenFlesh'/135, l='MpServer', x=1137.63, y=4.13, z=-105.00], EntityClientPlayerMP['Player406'/133, l='MpServer', x=1128.26, y=11.73, z=-82.05], EntityItem['item.item.rottenFlesh'/134, l='MpServer', x=1131.00, y=4.13, z=-107.81]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2567)

at net.minecraft.client.Minecraft.run(Minecraft.java:983)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

 

Sorry if this is a basic mistake, I'm not sure what is making the error :/

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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