Jump to content

[1.9.4] Recipe that takes any item as an input


DARKHAWX

Recommended Posts

Hi there, I want to make a normal shaped recipe that can take any item/block as one input in its recipe... Does anyone know how I could achieve this?

 

The item also has a field that stores an associated itemstack, which I would like to set upon item creation (once I craft it from the recipe), but I'm not sure how to achieve this when registering the registry... Does anyone have ideas?

 

Any help would be appreciated.

No signature for you!

Link to comment
Share on other sites

Thanks!

 

After a bit of work I've reached another roadblock. I'm still a little rusty on my NBT knowledge and am having trouble with the getCraftingResult() method. I've gotten the code to the point where I can 'craft' the item (the game recognises the recipe) but will crash each time getCraftingResult() is called.

 

The way the item works is it stores, through an nbt tag, the item put in the middle of the crafting matrix for later use.

 

The following is the code used for getCraftingResult.

 

/**
     * Returns an Item that is the result of this recipe
     */
    @Nullable
    @Override
    public ItemStack getCraftingResult(InventoryCrafting inv)
    {
        ItemStack itemstack = this.getRecipeOutput().copy();

        ItemStack inputStack = inv.getStackInRowAndColumn(1, 1);
        if (inputStack != null) {
            NBTTagCompound inputNBT = new NBTTagCompound();
            inputStack.writeToNBT(inputNBT);

            System.out.println("Itemstack: " + itemstack + " InputItemstack: " + inputNBT);

            itemstack.getTagCompound().setTag("Present", inputNBT);
        }

        return itemstack;
    }

 

Crash Report:

 

---- Minecraft Crash Report ----
// Oops.

Time: 7/24/16 6:12 PM
Description: Updating screen events

java.lang.NullPointerException: Updating screen events
at com.darkhawx.planck.api.crafting.RecipePresent.getCraftingResult(RecipePresent.java:79)
at net.minecraft.item.crafting.CraftingManager.findMatchingRecipe(CraftingManager.java:333)
at net.minecraft.inventory.ContainerWorkbench.onCraftMatrixChanged(ContainerWorkbench.java:56)
at net.minecraft.inventory.InventoryCrafting.setInventorySlotContents(InventoryCrafting.java:110)
at net.minecraft.inventory.Slot.putStack(Slot.java:99)
at net.minecraft.inventory.Container.slotClick(Container.java:319)
at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:584)
at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:685)
at net.minecraft.client.gui.inventory.GuiContainer.mouseReleased(GuiContainer.java:641)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:619)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:575)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1796)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1119)
at net.minecraft.client.Minecraft.run(Minecraft.java:404)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)


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

-- Head --
Thread: Client thread
Stacktrace:
at com.darkhawx.planck.api.crafting.RecipePresent.getCraftingResult(RecipePresent.java:79)
at net.minecraft.item.crafting.CraftingManager.findMatchingRecipe(CraftingManager.java:333)
at net.minecraft.inventory.ContainerWorkbench.onCraftMatrixChanged(ContainerWorkbench.java:56)
at net.minecraft.inventory.InventoryCrafting.setInventorySlotContents(InventoryCrafting.java:110)
at net.minecraft.inventory.Slot.putStack(Slot.java:99)
at net.minecraft.inventory.Container.slotClick(Container.java:319)
at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:584)
at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:685)
at net.minecraft.client.gui.inventory.GuiContainer.mouseReleased(GuiContainer.java:641)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:619)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:575)

-- Affected screen --
Details:
Screen name: net.minecraft.client.gui.inventory.GuiCrafting

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityPlayerSP['Player309'/9, l='MpServer', x=952.87, y=10.00, z=-203.50]]
Chunk stats: MultiplayerChunkCache: 625, 625
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: World: (969,4,-190), Chunk: (at 9,0,2 in 60,-12; contains blocks 960,0,-192 to 975,255,-177), Region: (1,-1; contains chunks 32,-32 to 63,-1, blocks 512,0,-512 to 1023,255,-1)
Level time: 1220544 game time, 6153 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: 1 total; [EntityPlayerSP['Player309'/9, l='MpServer', x=952.87, y=10.00, z=-203.50]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:448)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2770)
at net.minecraft.client.Minecraft.run(Minecraft.java:425)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

-- System Details --
Details:
Minecraft Version: 1.9.4
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_73, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 516615360 bytes (492 MB) / 1796734976 bytes (1713 MB) up to 3808428032 bytes (3632 MB)
JVM Flags: 0 total; 
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP 9.28 Powered by Forge 12.17.0.1954 4 mods loaded, 4 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHIJAAAA	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAAAA	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.9.4-12.17.0.1954.jar) 
UCHIJAAAA	Forge{12.17.0.1954} [Minecraft Forge] (forgeSrc-1.9.4-12.17.0.1954.jar) 
UCHIJAAAA	planck{0.0.1} [Planck] (Planck 1.9) 
Loaded coremods (and transformers): 
GL info: ' Vendor: 'ATI Technologies Inc.' Version: '4.5.13431 Compatibility Profile Context 16.150.2211.0' Renderer: 'AMD Radeon (TM) R9 390 Series'
Launched Version: 1.9.4
LWJGL: 2.9.4
OpenGL: AMD Radeon (TM) R9 390 Series GL version 4.5.13431 Compatibility Profile Context 16.150.2211.0, ATI Technologies Inc.
GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

Using VBOs: No
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: 
Current Language: English (US)
Profiler Position: N/A (disabled)
CPU: net.minecraft.client.Minecraft$15@78b79e3

 

 

The crash occurs whenever

            itemstack.getTagCompound().setTag("Present", inputNBT);

is called.

 

I know its because I'm probably doing the whole NBT thing wrong. Can someone point me the right way of doing this? If another method should be used for storing the itemstack used in the middle of the recipe (remember I need to access this information from the itemstack somehow in another piece of code), let me know.

No signature for you!

Link to comment
Share on other sites

You should first check if the stack has compound or not, using ItemStack#hasTagCompound(). (It is null by default) Create one if it is null.

Or make the recipe output has the tag compound by default. (You can set the compound using ItemStack#setTagCompound)

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Don't know if this helps but it could. X being where your put the item in the crafting grid, to craft such stuff.

 

public class Guru
{
@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
public static CommonProxy proxy;
@Instance(Reference.MOD_ID)
private static Guru instance;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	ModCreativeTabs.load();
	proxy.preInit();
	GuruItems.init();
	GuruItems.register();
	GuruEntities.registerEntities();
	initRecipes();
}
    @EventHandler
    public void init(FMLInitializationEvent event)
    { 
	proxy.registerRenders();
        proxy.registerKeybindings();
        NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
    }	
private static void initRecipes()
{
	GameRegistry.addRecipe(new ItemStack(GuruItems.AirOrb), new Object[] {" X ", "X X", " X ", 'X', Items.FEATHER});
	GameRegistry.addRecipe(new ItemStack(GuruItems.WaterOrb), new Object[] {" X ",  "X X", " X ", 'X', Items.WATER_BUCKET});
	GameRegistry.addRecipe(new ItemStack(GuruItems.EarthOrb), new Object[] {" X ",  "X X", " X ", 'X', Item.getItemFromBlock(Blocks.DIRT)});
	GameRegistry.addRecipe(new ItemStack(GuruItems.FireOrb), new Object[] {" X ",  "X X", " X ", 'X', Items.LAVA_BUCKET});
	GameRegistry.addRecipe(new ItemStack(GuruItems.NetherOrb), new Object[] {" X ",  "X X", " X ", 'X', Item.getItemFromBlock(Blocks.OBSIDIAN)});
}
public static Guru getInstance()
{
	return instance;
}
}

Link to comment
Share on other sites

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.