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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • C:\Minecraft Server>java -Xmx4096M -Xms1024M -jar server.jar nogui Starting net.minecraft.server.Main ERROR StatusConsoleListener Unable to delete file C:\Minecraft Server\logs\latest.log: java.nio.file.FileSystemException C:\Minecraft Server\logs\latest.log: The process cannot access the file because it is being used by another process ^CTerminate batch job (Y/N)?
    • I am creating a 1.18.2 server with forge and when I put any mod on it I get something about REM and that I need MODS.TML, what would be the solution?
    • Oke i tried to download a different mod and try that out on my server and i get the same error. Now i know for a fact that my port forwarding and server is working properly, because i can join them without adding any mods into the server file, but then i dont know what i am doing wrong 
    • Salutation to you ladies and gentlemen, i must confidently say a very big thanks to Fastfundrecovery8 AT GMAIL COM for their tremendous action taken over my case immediately brought to their table, i saw how the whole process was going, and i wisperred to myself and said indeed i am previlledge to know such a legitimate recovery company who is very understable and do not stress their client over recovery software tools, Fastfunds Recovery are good in keeping to time, punctuality, I was scammed last year December 18, i realized that my long investment which i inteded to withdraw has long been a scam, got so frustrated, hired 4 recovery hackers which ended up taking money from me and i couldn't contact them anymore, i went through emotional pains and betrayer, wasn't easy for me at that moment, am very greatful for FastFunds Recovery, who was referred to me by a civil engineer who i was opportuned to share part of my story with and he was like i have a cyber friend do reach and say i'm from Pato's, that's how i got in touch with fastfundsrecovery8(@)gmail(.)com, do inform FastFunds recovery for any cyber issues. Fastfundsrecovery8 AT GMAIL WILL ALWAYS HELP GET BACK YOUR FUNDS.
    • Hello everyone i have made a server with forge and have added pixelmon into the server. But for some reason i keep getting "Internal Exception: io.netty.handles.codec.DecoderException: Not enough bytes in buffer, expected 105, byt got 48". I tried upping the ram of the server to 2GB but it didnt solve anything. I have 16 GB of ram on my pc (where i host the server), but i cant seem to get it to work. Pixelmon does work when i try to go into singleplayer, but for some reason just doesnt work online   Edit: server logs sais nothing aswell [18:55:49] [ServerMain/INFO]: Environment: Environment[accountsHost=https://api.mojang.com, sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD] [18:55:50] [ServerMain/INFO]: Loaded 7 recipes [18:55:51] [ServerMain/INFO]: Loaded 1271 advancements [18:55:51] [Server thread/INFO]: Starting minecraft server version 1.20.2 [18:55:51] [Server thread/INFO]: Loading properties [18:55:51] [Server thread/INFO]: Default game type: SURVIVAL [18:55:51] [Server thread/INFO]: Generating keypair [18:55:51] [Server thread/INFO]: Starting Minecraft server on *:xxxx [18:55:51] [Server thread/INFO]: Using default channel type [18:55:51] [Server thread/INFO]: Preparing level "world" [18:55:52] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld [18:55:53] [Worker-Main-8/INFO]: Preparing spawn area: 0% [18:55:53] [Worker-Main-8/INFO]: Preparing spawn area: 0% [18:55:53] [Worker-Main-8/INFO]: Preparing spawn area: 0% [18:55:53] [Worker-Main-12/INFO]: Preparing spawn area: 0% [18:55:54] [Worker-Main-11/INFO]: Preparing spawn area: 31% [18:55:54] [Server thread/INFO]: Time elapsed: 2344 ms [18:55:54] [Server thread/INFO]: Done (2.865s)! For help, type "help" [18:55:56] [User Authenticator #1/INFO]: UUID of player kemal007023 is 9a2a1dff-fa06-4e29-b57d-b1e6afb2db87 [18:55:56] [Server thread/INFO]: kemal007023[/xxxx] logged in with entity id 271 at (9.497695306619189, 68.0, 10.973182362716573) [18:55:56] [Server thread/INFO]: kemal007023 joined the game [18:55:56] [Server thread/INFO]: kemal007023 lost connection: Disconnected [18:55:56] [Server thread/INFO]: kemal007023 left the game [18:56:00] [User Authenticator #2/INFO]: UUID of player kemal007023 is 9a2a1dff-fa06-4e29-b57d-b1e6afb2db87 [18:56:00] [Server thread/INFO]: kemal007023[xxxx] logged in with entity id 272 at (9.497695306619189, 68.0, 10.973182362716573) [18:56:00] [Server thread/INFO]: kemal007023 joined the game [18:56:00] [Server thread/INFO]: kemal007023 lost connection: Disconnected [18:56:00] [Server thread/INFO]: kemal007023 left the game  
  • Topics

×
×
  • Create New...

Important Information

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