Jump to content

[Solved][1.12.2] Json number value as byte


Recommended Posts

Posted (edited)

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
Posted

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);
    }
}
Posted

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

  Reveal hidden contents

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)

Posted
  On 9/23/2018 at 3:35 PM, 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).

Expand  

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. 

Posted
  On 9/23/2018 at 3:53 PM, 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. 

Expand  

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.

Posted

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/

Posted
  On 9/23/2018 at 4:10 PM, 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.

Expand  

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. 

Posted
  On 9/23/2018 at 4:19 PM, 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. 

Expand  
  On 9/23/2018 at 3:59 PM, Animefan8888 said:

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

Expand  

 

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.

Posted
  On 9/23/2018 at 4:20 PM, Animefan8888 said:

 

Expand  
 

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. 

Posted
  On 9/23/2018 at 4:24 PM, 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. 
Expand  

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.

Posted
  On 9/23/2018 at 4:29 PM, Animefan8888 said:

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

Expand  

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. 

Posted
  On 9/23/2018 at 4:30 PM, 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. 

Expand  

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.

Posted
  On 9/23/2018 at 4:32 PM, 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.

Expand  

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. 

Posted
  On 9/23/2018 at 4:36 PM, 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. 

Expand  

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.

Posted
  On 9/23/2018 at 4:24 PM, 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. 

Expand  

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.

Posted
  On 9/23/2018 at 5:27 PM, 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

Expand  

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. 

Posted

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

About Me

  Reveal hidden contents

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)

Posted
  On 9/23/2018 at 10:06 PM, Cadiboo said:

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

Expand  

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. 

Posted

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.

  Reveal hidden contents

 

Posted (edited)
  On 9/23/2018 at 11:26 PM, 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.

Expand  

0b without quotes won't pass Json validation.

Edit:

failing Json validation fails loading as a recipe. 

Edited by lehjr
Posted (edited)

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

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.