Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Item crafted does not persist, but when taken from creative it persists


ctbe
 Share

Recommended Posts

I hope this is not a silly question. For a staff I created in my mod, I added a crafting recipe using GameRegistry.addShapedRecipe(). I passed it a new ItemStack with the item, as well as the other parameters to build the recipe. The recipe works. It gets registered and you can craft the staff in a crafting table, but when you close the world, or the whole minecraft game, and open it again, the staff disappears!

 

The staff is added to the creative tab and you can get the item from creative. When you do get the item from creative, it persists across world closes and opening. But when you craft it, you get the item only for the time the world is open. If you close the world with Save and quit to title, or close the whole minecraft game, the item disapears from your inventory. It does not persist.

 

Is there anything else one has to do for when items are crafted in a crafting table to be saved?

Link to comment
Share on other sites

Sure.

 

 GameRegistry.addShapedRecipe(new ItemStack(modItems.itemStaff),
      "XRX",
      "XSX",
      "XSX",
      'R'.asInstanceOf[Character], Items.REDSTONE, 'S'.asInstanceOf[Character], Items.STICK)

 

modItems contains the staff item in a variable called itemStaff. I debugged and the item is present and initialized at the moment the crafting recipe is added.

Link to comment
Share on other sites

Yes, I can craft it. And use it. My staff does what I programmed it to do.

 

Is there any way I can test if the item the player is holding on hand is registered? Like a method that gives you information about the item the user is holding or something similar. I ask to see if I can somehow debug it.

 

While debugging in the IDE I can see the item modItems.itemStaff has been registered using events as per the documentation recommendations, and exists. It is properly initialized and it has the unlocalized and registry names registered too.

 

Edit: To add more information, I am looking through the logs and when I reopen the world, it says nothing about a missing item or an item being deleted. It just reopens the world without the item in the inventory. When I close it doesn't say anything either about an item failing to save or something similar. Nor when I craft the item. No message is thrown whatsoever.

Edited by ctbe
Adding information
Link to comment
Share on other sites

1 hour ago, ctbe said:

.asInstanceOf[Character]

The class that implements these recipes, is it made in Scala?

Because that's Scala casting, and I believe the objects has to be pure Java to work properly. JsonTweaker (Scala mod, is on GitHub) faces this issue, and solved it by invoking a custom Java method that took the ItemStack & object[] and returned the recipe.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

1 hour ago, Matryoshika said:

The class that implements these recipes, is it made in Scala?

 

Yes, my mod is made in Scala.

 

But it's okay. I got it working. The object I was passing to it (modItems.itemStaff) did exist, was initialized and everything was correct, but it wasn't the same object instance I used in the RegistryEvent (RegistryEvent.Register[Item]) to register the item before preInit. The instance of the Item you must pass to new ItemStack when adding a recipe must be the same instance used in the RegistryEvent for the item. If you create a new instance just for the sake of registering a recipe, it will give the impression it works, you will be able to craft and use the item, etc., but it will not persist when you close the world. When you open the world again, the item will disappear from your inventory.

 

I ran into this because I was trying to avoid the use of statics as much as possible. But it's fixed now.

 

For those who might face the same problem, make sure the instance of the item you pass to the ItemStack when registering the recipe with

 GameRegistry.addShapedRecipe

or similar methods from GameRegistry, is the same instance used to register the item in the RegistryEvent before preInit.

 

Thanks for your prompt replies, everyone.

Edited by ctbe
Formatting the text
Link to comment
Share on other sites

5 hours ago, ctbe said:

For those who might face the same problem, make sure the instance of the item you pass to the ItemStack when registering the recipe with GameRegistry.addShapedRecipe or similar methods from GameRegistry, is the same instance used to register the item in the RegistryEvent before preInit.

Uh. Yes.  That's....kind of how things work.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Nice. I report your post on your dim mockery and nothing happens. I love it. That certainly leaves a lot to say.

 

I faced a problem here and you didn't even try to help. When the problem was solved and the thread could have died with the conclusion of a solution, you reply. Not to help, but to make dim mockery and try to make yourself look like you have so much common sense knowledge on the forge platform. Your reply contributes nothing, but dim mockery and helps no one. The problem was already solved, your reply is out of place. I'd love to see anyone pointing out how your reply is helpful in any aspect and/or helps solve the problem. For it to be so evident, I didn't see you pointing out the so evident solution. I had more to say about some observations I have seen that are meretricious at best, but I'll leave it at that. After all humans like that tend to be described by society with certain words. The behavior has been already studied, well documented, and is somewhat predictable on certain levels.

Link to comment
Share on other sites

3 minutes ago, ctbe said:

I faced a problem here and you didn't even try to help.

With the amount of code you posted it was impossible for anyone here to have spotted your error.  All you posted was your crafting recipe line. That's it.

 

It's an obvious error to literally everyone that you have to pass in the same object to the recipe as to the game registry because if you don't how is the game supposed to know they're the same object? You created two different objects.

 

So yeah, you'll get undefined behavior when you try to do something that was never intended to be done.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Look, I modestly (without arrogance) tell you that I will not argue anymore past this reply. The problem is solved and the thread can fall into forgotten. Here's the thing. That is exactly one of the many kinds of behavior I talk that has been already studied and well documented in texts and academic text books. That last reply was predictable. Try to look for a loophole in what one person has said, then paint the person in bad light with that mistake to justify your actions. The rest of the arguments of the person that committed the mistake will disappear in the eyes of the others. Like they never existed. Nothing they say after will be listened to. The action is very old and documented in newspapers and probably history books. Humans have been doing that for centuries. One person makes fun of another, the other person says "hey, please, stop making fun of me, I don't like it", and the person may stop it, but not before trying to justify its past actions by telling the other person that he/she did wrong first. "But look what this person did first." or "But it's true. Look at this..." That's the kind of arguments.

That it was impossible for anyone to help doesn't justify the reply. I am not going to use sarcasm, insult or even make fun of you. Nor will I try to paint you in bad light or try to make it look like I'm better. I'll simply not do it. I'll just say that when I don't understand the question of another person and need more information to help, I query by telling them to provide more information instead of making a statement of "obviousness" that dimly makes fun of the person. I am not telling you to do the same. I'm just saying what I do when I face similar situations and it's not to make you look bad or make it look like I'm better. That's not the point.

Since the problem was solved and I am not going to argue past this post about that reply I'd like to lastly make emphasis that I did mentioned above that they were not two different objects. They were the same and contained the exact bytes in memory. 22 bytes to be precise according to the heap dump. They were different instances, which is a different concept. If I compare the objects with the equals() methods, the JVM will return true. Making them not two different objects. Just different instances.

Link to comment
Share on other sites

@ctbeTurn signatures on and read Draco18s' signature. You will then understand.

 

In case you are lazy, here it is:

"

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

"

 
Draco18s i hope you do not have any objections to this.

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Link to comment
Share on other sites

I am not going to comment on the wall of text of "i studied psychology" or whatever. But:

5 hours ago, ctbe said:

Since the problem was solved and I am not going to argue past this post about that reply I'd like to lastly make emphasis that I did mentioned above that they were not two different objects. They were the same and contained the exact bytes in memory. 22 bytes to be precise according to the heap dump. They were different instances, which is a different concept. If I compare the objects with the equals() methods, the JVM will return true. Making them not two different objects. Just different instances.

This is false. equals has nothing to do with the JVM. It is a method in the Object class that by default checks if the two objects are the same. You can override it (in tandem with hashCode) to define a custom equality relationship, like e.g. String does. And yes, they are still different objects. They may have the same contents, but they are most certainly not the same.

Link to comment
Share on other sites

7 hours ago, Leomelonseeds said:
Draco18s i hope you do not have any objections to this.

Hardly. :)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • thank you very much, the problem was in the path to the model.  
    • The version you are using is no longer supported on this forum. Please update to a modern version of Minecraft to receive support. Currently supported versions are 1.18.1/1.18.2 (Latest) and 1.16.5 (LTS).
    • The version of WorldEdit that you have is for 1.18.1 and not compatible with 1.18.2. Use the 1.18.2 version.
    • Having probems with a server i have at home it crashes when loading up   ---- Minecraft Crash Report ---- // Daisy, daisy... Time: 25/05/2022, 14:03 Description: Exception in server tick loop java.lang.NoSuchMethodError: 'net.minecraft.core.RegistryAccess net.minecraft.server.MinecraftServer.m_129911_()'     at com.sk89q.worldedit.forge.ForgeWorldEdit.setupRegistries(ForgeWorldEdit.java:197) ~[worldedit-mod-7.2.8.jar%2355!/:?] {re:classloading}     at com.sk89q.worldedit.forge.ForgeWorldEdit.serverStarted(ForgeWorldEdit.java:256) ~[worldedit-mod-7.2.8.jar%2355!/:?] {re:classloading}     at net.minecraftforge.eventbus.ASMEventHandler_9_ForgeWorldEdit_serverStarted_ServerStartedEvent.invoke(.dynamic) ~[?:?] {}     at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-5.0.3.jar%232!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-5.0.3.jar%232!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-5.0.3.jar%232!/:?] {}     at net.minecraftforge.server.ServerLifecycleHooks.handleServerStarted(ServerLifecycleHooks.java:99) ~[forge-1.18.2-40.1.25-universal.jar%2361!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:662) ~[server-1.18.2-20220404.173914-srg.jar%2357!/:?] {re:classloading,pl:accesstransformer:B}     at net.minecraft.server.MinecraftServer.m_177918_(MinecraftServer.java:261) ~[server-1.18.2-20220404.173914-srg.jar%2357!/:?] {re:classloading,pl:accesstransformer:B}     at java.lang.Thread.run(Thread.java:833) [?:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details:     Minecraft Version: 1.18.2     Minecraft Version ID: 1.18.2     Operating System: Windows 11 (amd64) version 10.0     Java Version: 17.0.2, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode, sharing), Oracle Corporation     Memory: 1172062448 bytes (1117 MiB) / 2105540608 bytes (2008 MiB) up to 2105540608 bytes (2008 MiB)     CPUs: 4     Processor Vendor: GenuineIntel     Processor Name: Intel(R) Core(TM) i3-8100T CPU @ 3.10GHz     Identifier: Intel64 Family 6 Model 158 Stepping 11     Microarchitecture: Coffee Lake     Frequency (GHz): 3.10     Number of physical packages: 1     Number of physical CPUs: 4     Number of logical CPUs: 4     Graphics card #0 name: Intel(R) UHD Graphics 630     Graphics card #0 vendor: Intel Corporation (0x8086)     Graphics card #0 VRAM (MB): 1024.00     Graphics card #0 deviceId: 0x3e91     Graphics card #0 versionInfo: DriverVersion=26.20.100.7757     Memory slot #0 capacity (MB): 8192.00     Memory slot #0 clockSpeed (GHz): 2.67     Memory slot #0 type: DDR4     Virtual memory max (MB): 9310.78     Virtual memory used (MB): 5713.56     Swap memory total (MB): 1280.00     Swap memory used (MB): 10.88     JVM Flags: 0 total;     Server Running: true     Player Count: 0 / 20; []     Data Packs: vanilla, mod:charginggadgets (incompatible), mod:supermartijn642configlib (incompatible), mod:worldedit (incompatible), mod:buildinggadgets (incompatible), mod:buildhelper (incompatible), mod:mcjtylib (incompatible), mod:supermartijn642corelib (incompatible), mod:chunkloaders (incompatible), mod:mininggadgets (incompatible), mod:forge (incompatible), mod:rftoolsbase (incompatible), mod:rftoolsbuilder (incompatible), mod:refinedstorage, mod:journeymap (incompatible), mod:cyclic, mod:jamd (incompatible), mod:jei (incompatible), mod:patchouli (incompatible), mod:laserio     World Generation: Experimental     Is Modded: Definitely; Server brand changed to 'forge'     Type: Dedicated Server (map_server.txt)     ModLauncher: 9.1.3+9.1.3+main.9b69c82a     ModLauncher launch target: forgeserver     ModLauncher naming: srg     ModLauncher services:          mixin PLUGINSERVICE          eventbus PLUGINSERVICE          slf4jfixer PLUGINSERVICE          object_holder_definalize PLUGINSERVICE          runtime_enum_extender PLUGINSERVICE          capability_token_subclass PLUGINSERVICE          accesstransformer PLUGINSERVICE          runtimedistcleaner PLUGINSERVICE          mixin TRANSFORMATIONSERVICE          fml TRANSFORMATIONSERVICE     FML Language Providers:         minecraft@1.0         javafml@null     Mod List:         server-1.18.2-20220404.173914-srg.jar             |Minecraft                     |minecraft                     |1.18.2              |DONE      |Manifest: NOSIGNATURE         charginggadgets-1.5.0.jar                         |Charging Gadgets              |charginggadgets               |1.5.0               |DONE      |Manifest: NOSIGNATURE         supermartijn642configlib-1.0.9-mc1.18.jar         |SuperMartijn642's Config Lib  |supermartijn642configlib      |1.0.9               |DONE      |Manifest: NOSIGNATURE         worldedit-mod-7.2.8.jar                           |WorldEdit                     |worldedit                     |7.2.8+6008-1246d61  |DONE      |Manifest: NOSIGNATURE         buildinggadgets-3.13.0-build.5+mc1.18.2.jar       |Building Gadgets              |buildinggadgets               |3.13.0-build.5+mc1.1|DONE      |Manifest: NOSIGNATURE         torojimaBuildHelper-3.5.0.0.jar                   |Torojima's Buildhelper        |buildhelper                   |3.5.0.0             |DONE      |Manifest: NOSIGNATURE         mcjtylib-1.18-6.0.13.jar                          |McJtyLib                      |mcjtylib                      |1.18-6.0.13         |DONE      |Manifest: NOSIGNATURE         jei-1.18.1-9.2.1.69.jar                           |Just Enough Items             |jei                           |9.2.1.69            |DONE      |Manifest: NOSIGNATURE         supermartijn642corelib-1.0.16-mc1.18.jar          |SuperMartijn642's Core Lib    |supermartijn642corelib        |1.0.16              |DONE      |Manifest: NOSIGNATURE         chunkloaders-1.1.8-mc1.18.jar                     |Chunk Loaders                 |chunkloaders                  |1.1.8               |DONE      |Manifest: NOSIGNATURE         mininggadgets-1.11.0.jar                          |Mining Gadgets                |mininggadgets                 |1.11.0              |DONE      |Manifest: NOSIGNATURE         forge-1.18.2-40.1.25-universal.jar                |Forge                         |forge                         |40.1.25             |DONE      |Manifest: 84:ce:76:e8:45:35:e4:0e:63:86:df:47:59:80:0f:67:6c:c1:5f:6e:5f:4d:b3:54:47:1a:9f:7f:ed:5e:f2:90         rftoolsbase-1.18-3.0.7.jar                        |RFToolsBase                   |rftoolsbase                   |1.18-3.0.7          |DONE      |Manifest: NOSIGNATURE         rftoolsbuilder-1.18-4.0.10.jar                    |RFToolsBuilder                |rftoolsbuilder                |1.18-4.0.10         |DONE      |Manifest: NOSIGNATURE         Patchouli-1.18.2-67.jar                           |Patchouli                     |patchouli                     |1.18.2-67           |DONE      |Manifest: NOSIGNATURE         refinedstorage-1.10.2.jar                         |Refined Storage               |refinedstorage                |1.10.2              |DONE      |Manifest: NOSIGNATURE         laserio-1.0.1.jar                                 |LaserIO                       |laserio                       |1.0.1               |DONE      |Manifest: NOSIGNATURE         journeymap-1.18-5.8.0alpha4.jar                   |Journeymap                    |journeymap                    |5.8.0alpha4         |DONE      |Manifest: NOSIGNATURE         Cyclic-1.18.2-1.7.0.jar                           |Cyclic                        |cyclic                        |1.18.2-1.7.0        |DONE      |Manifest: 1f:47:ac:b1:61:82:96:b8:47:19:16:d2:61:81:11:60:3a:06:4b:61:31:56:7d:44:31:1e:0c:6f:22:5b:4c:ed         JAMD-1.7.0-build.24+mc1.18.2.jar                  |Just Another Mining Dimension |jamd                          |1.7.0-build.24+mc1.1|DONE      |Manifest: NOSIGNATURE     Crash Report UUID: a4b30830-b80e-4601-9aec-8e6451729eed     FML: 40.1     Forge: net.minecraftforge:40.1.25
    • This means the version of Configured is not for 1.18, you need a version of the Mod for 1.18.2
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.