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

    • I want to play minecraft modded with CurseForge but every time i start my mincraft its crash with the report:  This crash may be caused by an invalid java runtime configuration. Check any custom configuration settings. Exite Code:1 and i dont now what it mean i already reinstalled minecraft and curseforge i dont have mods loaded or installed when i start the game. i just start forge 1.18.2 but its crash. This is the Game output: 17:01:53.866 launcher main Preparing to launch minecraft client for forge-40.1.0 17:01:53.867 launcher main Prepared asset index 17:01:54.226 launcher main Have 3120 total files to check or download 17:01:54.235 launcher main Local file C:\Users\User\curseforge\minecraft\Install\versions\forge-40.1.0\forge-40.1.0.jar is incomplete 17:01:55.968 launcher main Minecraft client forge-40.1.0 requires 1521781 bytes to download. 17:01:55.968 launcher main Starting! 17:01:55.968 launcher main Downloading 1 files 17:01:56.177 launcher main Download from https://piston-data.mojang.com/v1/objects/2e9a3e3107cca00d6bc9c97bf7d149cae163ef21/client.jar had invalid checksum! Expected: 2e9a3e3107cca00d6bc9c97bf7d149cae163ef21 got: 04292004f7145d1d991b8808d2976f9dc8db5cba 17:01:56.741 launcher main Download from https://piston-data.mojang.com/v1/objects/2e9a3e3107cca00d6bc9c97bf7d149cae163ef21/client.jar passed checksum check. 17:01:56.741 launcher main Downloaded https://piston-data.mojang.com/v1/objects/2e9a3e3107cca00d6bc9c97bf7d149cae163ef21/client.jar to C:\Users\User\curseforge\minecraft\Install\versions\forge-40.1.0\forge-40.1.0.jar 17:01:56.741 launcher main Downloads successful 17:01:56.741 launcher main TIMER: Downloads took 0 seconds. 17:01:56.741 launcher main Downloading Java Runtime java-runtime-beta:17.0.1.12.1 17:01:57.506 launcher main Extracting 8 files! 17:01:58.159 launcher main Using default game log configuration client-1.12.xml (outputs XML) 17:02:00.387 cpw.mods.modlauncher.Launcher main ModLauncher running: args [--username, Pixelcaft, --version, forge-40.1.0, --gameDir, C:\Users\User\curseforge\minecraft\Instances\test (3), --assetsDir, C:\Users\User\curseforge\minecraft\Install\assets, --assetIndex, 1.18, --uuid, d5bb472870874443847c9b99c9bf273f, --accessToken, ❄❄❄❄❄❄❄❄, --clientId, NDdmNzk3ZjctMzZmMS00YWI0LTkyNzktNGYyMDQwYjUwYmRl, --xuid, 2535455300377521, --userType, msa, --versionType, release, --width, 1024, --height, 768, --launchTarget, forgeclient, --fml.forgeVersion, 40.1.0, --fml.mcVersion, 1.18.2, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20220404.173914] 17:02:00.393 cpw.mods.modlauncher.Launcher main ModLauncher 9.1.3+9.1.3+main.9b69c82a starting: java version 17.0.1 by Microsoft 17:02:00.537 mixin main SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/User/curseforge/minecraft/Install/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2314!/ Service=ModLauncher Env=CLIENT 17:02:00.603 net.minecraftforge.fml.loading.FMLConfig main Configuration file C:\Users\User\curseforge\minecraft\Instances\test (3)\config\fml.toml is not correct. Correcting 17:02:00.612 net.minecraftforge.fml.loading.FMLConfig main Incorrect key [defaultConfigPath] was corrected from null to defaultconfigs 17:02:01.245 launcher main Exception in thread "main" java.io.UncheckedIOException: java.io.IOException: Invalid paths argument, contained no existing paths: [C:\Users\User\curseforge\minecraft\Install\libraries\net\minecraft\client\1.18.2-20220404.173914\client-1.18.2-20220404.173914-srg.jar, C:\Users\User\curseforge\minecraft\Install\libraries\net\minecraft\client\1.18.2-20220404.173914\client-1.18.2-20220404.173914-extra.jar, C:\Users\User\curseforge\minecraft\Install\libraries\net\minecraftforge\forge\1.18.2-40.1.0\forge-1.18.2-40.1.0-client.jar] at cpw.mods.securejarhandler@1.0.3/cpw.mods.jarhandling.impl.Jar.<init>(Jar.java:74) at cpw.mods.securejarhandler@1.0.3/cpw.mods.jarhandling.SecureJar.from(SecureJar.java:58) at MC-BOOTSTRAP/fmlloader@1.18.2-40.1.0/net.minecraftforge.fml.loading.moddiscovery.ModJarMetadata.buildFile(ModJarMetadata.java:41) at MC-BOOTSTRAP/fmlloader@1.18.2-40.1.0/net.minecraftforge.fml.loading.moddiscovery.MinecraftLocator.scanMods(MinecraftLocator.java:33) at MC-BOOTSTRAP/fmlloader@1.18.2-40.1.0/net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer.discoverMods(ModDiscoverer.java:50) at MC-BOOTSTRAP/fmlloader@1.18.2-40.1.0/net.minecraftforge.fml.loading.FMLLoader.beginModScan(FMLLoader.java:166) at MC-BOOTSTRAP/fmlloader@1.18.2-40.1.0/net.minecraftforge.fml.loading.FMLServiceProvider.beginScanning(FMLServiceProvider.java:86) at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.TransformationServiceDecorator.runScan(TransformationServiceDecorator.java:112) at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.TransformationServicesHandler.lambda$runScanningTransformationServices$8(TransformationServicesHandler.java:100) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1779) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575) at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260) at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616) at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622) at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627) at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.TransformationServicesHandler.runScanningTransformationServices(TransformationServicesHandler.java:102) at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:55) at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.Launcher.run(Launcher.java:87) at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.Launcher.main(Launcher.java:77) at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) at cpw.mods.bootstraplauncher@1.0.0/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) Caused by: java.io.IOException: Invalid paths argument, contained no existing paths: [C:\Users\User\curseforge\minecraft\Install\libraries\net\minecraft\client\1.18.2-20220404.173914\client-1.18.2-20220404.173914-srg.jar, C:\Users\User\curseforge\minecraft\Install\libraries\net\minecraft\client\1.18.2-20220404.173914\client-1.18.2-20220404.173914-extra.jar, C:\Users\User\curseforge\minecraft\Install\libraries\net\minecraftforge\forge\1.18.2-40.1.0\forge-1.18.2-40.1.0-client.jar] ... 25 more 17:02:01.245 monitor Process Monitor Process crashed with exit code 1
    • why do you work with .schematic file? From what I know are .schematic files a community creation and not used by vanilla you can take a look how they are written
    • I did look at vanilla code, but I don't understand how it works. For example, what does the PoseStack do? How should I use the buffers? And how does it "attach" to the model?
    • I've got a problem with schematics generation. So actually after reading .schematic file I'm getting two arrays of bytes (blockid and blockdata). The problem is I dont know how to obtain a BlockState for Level#setBlock (2nd parameter), because I dont know what kind of block I'm going to place, just id and data, and I see no static plug for this parameter (Like BlockState.WHATEVER).  So how can I deal with it? 
  • Topics

×
×
  • Create New...

Important Information

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