Jump to content

[Solved][1.12.2] Json number value as byte


lehjr

Recommended Posts

I have a couple of Json recipes that use Industrialcraft cables as ingredients. The cables nbt values use bytes instead of integers. JsonToNBT (net.minecraft.nbt.JsonToNBT) has a regex for byte values, but I can't get the values to show up as a byte. Setting the values to 0 sets them as integers, but "0b" sets them as strings. I confirmed this with an IIngredientFactory where I was able to check the data types on the tags produced, and changed them to bytes and was able to get a working recipe instead of one with a blank output when trying to craft the item. While this is a possible workaround, I'd like to see if it's possible to do this without resorting to such a method. 

Example recipe:

(values in question are "type" and "insulation")

https://github.com/MachineMuse/MachineMusePowersuits/blob/1.12.2-experimental/src/main/resources/assets/powersuits/recipes/ic2/components/component_computer_chip.json 

Edited by lehjr
Solutions provided by fantastic community :D
Link to comment
Share on other sites

So basically, from what I can see, this is an issue in Minecraft's JsonToNBT, specifically in readTypedValue(); The way it's currently written requires illegal characters to pass the "if clause" checking for quotes, since the Json standard does not allow for alpha numeric strings, such as 0b or 1f without quotes. 

 

protected NBTBase readTypedValue() throws NBTException
{
    this.skipWhitespace();

    if (this.peek() == '"')
    {
        return new NBTTagString(this.readQuotedString());
    }
    else
    {
        String s = this.readString();

        if (s.isEmpty())
        {
            throw this.exception("Expected value");
        }
        else
        {
            return this.type(s);
        }
    }
}

 

It could have been written something like this and it would have worked (actually tested before posting), since type() actually defaults to a string anyway. This would have opened up more data types available to recipes: 

protected NBTBase readTypedValue() throws NBTException
{
    this.skipWhitespace();
    String s;

    if (this.peek() == '"')
    {
        s = this.readQuotedString();
    }
    else {
        s = this.readString();
    }

    if (s.isEmpty())
    {
        throw this.exception("Expected value");
    }
    else
    {
        return this.type(s);
    }
}
Link to comment
Share on other sites

Consider making a PR to forge or submitting a bug report to Minecraft.

A PR probably won't be accepted because of how much work is being done because of 1.13 & forge doesn't like to (unnecessarily) tamper with Minecraft's code and submitting a bug report will probably go no-where because they have like 5 people, it works for them and they still have game-breaking bugs that haven't been fixed for many years to deal with. Of the two, I think a PR is the better option.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

9 minutes ago, jabelar said:

While it does seem like a bug, can't you just work around it by converting through an integer? Read into an integer and then cast into a byte (you can validate the value first if you want and throw error if the int value doesn't fit into a byte).

Can you elaborate? Remember, this is a crafting recipe being loaded from a Json. And while I do have a condition factory for which recipes are loaded, I was trying to not use workarounds like a custom IIngredientFactory because these recipes are intended to be allowed to be overridden, which means accounting for additional edge cases that do not yet exist. 

Link to comment
Share on other sites

5 minutes ago, lehjr said:

Can you elaborate? Remember, this is a crafting recipe being loaded from a Json. And while I do have a condition factory for which recipes are loaded, I was trying to not use workarounds like a custom IIngredientFactory because these recipes are intended to be allowed to be overridden, which means accounting for additional edge cases that do not yet exist. 

Create your own IRecipeFactory, this is what actually parses the JSON.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I just reread your original post and realize you're trying to use another mod's items. If it was your own item you can convert the integers to bytes and back since you can control the NBT.

 

Does an integer value actually fail? It's possible that the NBT creation code can handle casting to byte.

 

Have you contacted the industrialcraft authors? Maybe they know a solution, or if not they will probably appreciate being aware of the bug and maybe could fix their mod to accommodate integers.

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

Link to comment
Share on other sites

Just now, jabelar said:

I just reread your original post and realize you're trying to use another mod's items. If it was your own item you can convert the integers to bytes and back since you can control the NBT.

 

Does an integer value actually fail? It's possible that the NBT creation code can handle casting to byte.

 

Have you contacted the industrialcraft authors? Maybe they know a solution, or if not they will probably appreciate being aware of the bug and maybe could fix their mod to accommodate integers.

Yes, it fails silently, meaning the recipe passes as valid and shows up as valid, but upon trying to use it on a crafting table, it shows a blank output. Using a custom IIngredient factory and changing the tags to bytes fixes it, but it's a hard coded work around for a soft coded issue that may change depending on the user, being the point of Json recipes is to allow them to be overridden. Strangely, Industrialcraft doesn't even use Jsons, they have some type if INI system. But I have seen the question asked before, but without an answer. 

 

I could use true/false to work around this (since it produces a byte tag instead of boolean) , except one of the cables actually uses a byte value of 2 for it's insulation. 

Link to comment
Share on other sites

1 minute ago, lehjr said:

Yes, it fails silently, meaning the recipe passes as valid and shows up as valid, but upon trying to use it on a crafting table, it shows a blank output. Using a custom IIngredient factory and changing the tags to bytes fixes it, but it's a hard coded work around for a soft coded issue that may change depending on the user, being the point of Json recipes is to allow them to be overridden. Strangely, Industrialcraft doesn't even use Jsons, they have some type if INI system. But I have seen the question asked before, but without an answer. 

 

I could use true/false to work around this (since it produces a byte tag instead of boolean) , except one of the cables actually uses a byte value of 2 for it's insulation. 

20 minutes ago, Animefan8888 said:

Create your own IRecipeFactory, this is what actually parses the JSON.

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 minute ago, Animefan8888 said:

 

 

Again, I was trying to avoid that, mainly because I don't want to write a Json parser as a hard coded work around to handle a soft coded edge case that may change and be replaced with another soft coded edge case. 

Link to comment
Share on other sites

4 minutes ago, lehjr said:
Again, I was trying to avoid that, mainly because I don't want to write a Json parser as a hard coded work around to handle a soft coded edge case that may change and be replaced with another soft coded edge case. 

You realize that even if you do make a custom IRecipeFactory you can still override it with another json, right?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Just now, Animefan8888 said:

You realize that even if you do make a custom IRecipeFactory you can still override it with another json, right?

Yes, which is the point that I am making, that another recipe with another edge case requiring another hard coded work around is more than likely. 

Link to comment
Share on other sites

1 minute ago, lehjr said:

Yes, which is the point that I am making, that another recipe with another edge case requiring another hard coded work around is more than likely. 

If I'm understanding you correctly, here is my solution. Instead of making an IRecipeFactory that only works for this specific recipe/nbt data. Make a IRecipeFactory that handles all NBT data.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Just now, Animefan8888 said:

If I'm understanding you correctly, here is my solution. Instead of making an IRecipeFactory that only works for this specific recipe/nbt data. Make a IRecipeFactory that handles all NBT data.

Basically this, which is already there in vanilla code, but broken. So it would be pretty much recreating that. The only difference between doing it there vs doing in an IIngredient factory is that both input and output could be handled, which probably isn't so awful. 

Link to comment
Share on other sites

1 minute ago, lehjr said:

Basically this, which is already there in vanilla code, but broken. So it would be pretty much recreating that. The only difference between doing it there vs doing in an IIngredient factory is that both input and output could be handled, which probably isn't so awful. 

Exactly my point, there are things the Mojang has done that could have been done better. This is one of those scenarios.

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 hour ago, lehjr said:
 

Again, I was trying to avoid that, mainly because I don't want to write a Json parser as a hard coded work around to handle a soft coded edge case that may change and be replaced with another soft coded edge case. 

You don't have to write a JSON parser. All you have to do is ask the existing JSON parser to get the values you want.

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/api/recipes/RecipeToolMold.java#L248-L265

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

3 minutes ago, Draco18s said:

You don't have to write a JSON parser. All you have to do is ask the existing JSON parser to get the values you want.

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/api/recipes/RecipeToolMold.java#L248-L265

That looks simpler than what I was looking at. Thanks everyone. I appreciate the help. 

Link to comment
Share on other sites

57 minutes ago, Draco18s said:

You don't have to write a JSON parser. All you have to do is ask the existing JSON parser to get the values you want.

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/api/recipes/RecipeToolMold.java#L248-L265

Wait, since the problem IS the existing parser, specifically the JsonToNBT parser called by CraftingHelper.getItemStack, doesn't that make the existing parser useless? That's what I'm already working around with the IRecipeFactory because JsonToNBT cannot properly parse NBT values from Json. 

Link to comment
Share on other sites

Just replace the call to that method with a call to your own improved method

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

15 minutes ago, Cadiboo said:

Just replace the call to that method with a call to your own improved method

Except that method is called by other methods that parse the ingredients. So you have to implement that code as well, which results in implementing your own parser. Remember, I'm not trying to limit functionality or catch special edge cases, but rather make the code work as it was intended to so that those edge case work as they were supposed to. 

Link to comment
Share on other sites

I'm not sure I understand this issue in its entirety,

from the code I'm looking at 0b without quotes should get you 0 as a byte, yes this messes up syntax highlighting and Json verification as it's not 100% pure Json, but from what I'm seeing that should be what works.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

Link to comment
Share on other sites

5 minutes ago, DaemonUmbra said:

I'm not sure I understand this issue in its entirety,

from the code I'm looking at 0b without quotes should get you 0 as a byte, yes this messes up syntax highlighting and Json verification as it's not 100% pure Json, but from what I'm seeing that should be what works.

0b without quotes won't pass Json validation.

Edit:

failing Json validation fails loading as a recipe. 

Edited by lehjr
Link to comment
Share on other sites

I'll probably just copy/edit one of the existing recipe setups, maybe something like ShapedRecipes

 

Edit:

... because that has a builtin parser. It's not perfect and will need some work, but it doesn't need much.

Edited by lehjr
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.