progwml6 / HungerOverhaul

23 stars 35 forks source link

Custom Blacklist JSON is not working #202

Closed paulgb434 closed 5 years ago

paulgb434 commented 6 years ago

In my config/hungeroverhaul folder, I created a file titled 'blacklist.json' and put the following into it to test the functionality of foodsBlacklist (following the Wiki)

But when I check the hunger and saturation values of Steak with Appleskin in JEI, the Hunger Overhaul values are still there instead of the vanilla values.

I am running the latest versions of Hunger Overhaul, Apple Core, and Mantle, and I'm on Forge 14.23.4.2748.

paulgb434 commented 6 years ago

In the latest.log, I get this error but it seems that JSON formatting is right:

Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 4 column 13 path $.foodsBlacklist[0].name
    at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385) ~[JsonReader.class:?]
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:213) ~[ReflectiveTypeAdapterFactory$Adapter.class:?]
    ... 51 more
[20:40:03] [main/INFO] [hungeroverhaul]: Loading data from json
[20:40:03] [main/INFO] [hungeroverhaul]: Loaded all data from JSON
paulgb434 commented 6 years ago

To add to this, copy-pasting the default JSON example for "Custom Blacklists" from the wiki generates an identical error in latest.log:

Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 7 column 13 path $.foodsBlacklist[0].name
    at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385) ~[JsonReader.class:?]
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:213) ~[ReflectiveTypeAdapterFactory$Adapter.class:?]

I've tried running Forge 2768, and only the following mods (latest versions): -Applecore -Appleskin -Hunger Overhaul -JEI

And the same error occurs.

bolehan commented 6 years ago

According to the code, field name in GameObject.java must be of type ResourceLocation instead of String as written on the wiki — this causes an exception, although ResourceLocation has it's own (de)serializer from String (which for some reason does not work in this case).

toktoktheeo commented 5 years ago

Hi,

Is there a work around this? I would like to blacklist the sandwiches from Culinary Construct since if they're not blacklisted they are useless.

They are supposed to restore the sum of all the ingredients used to make them but with Hunger Overhaul they only restore one unit of hunger.

When I try to blacklist the sandwiches I got the same java error as above and I'm running Forge 2768. (The recommended version.)

Trinsdar commented 5 years ago

@squeek502 do you have any ideas what needs to be changed to fix it? As I'm not really sure how, though I know this line has something to do with it, which probably means the resource location has something to do with it. Unless it's just an error in the wiki example, though I don't think it is. P.S. I'm pinging you because I wasn't sure who to ping, and you seemed to be the most active.

squeek502 commented 5 years ago

Don't know, haven't worked on this mod since 1.7.10. My guess would be there's some breaking change in the GSON library that hasn't been accounted for. It looks like the code here is pretty much identical to the same code (that worked) in the 1.7.10 verion.

squeek502 commented 5 years ago

Oh, it's almost certainly this line: https://github.com/progwml6/HungerOverhaul/blob/1.12/src/main/java/iguanaman/hungeroverhaul/module/json/GameObject.java#L13

GSON doesn't know how to read a ResourceLocation from JSON, so some special handling needs to be added for that. @alexbegt

Trinsdar commented 5 years ago

Yah I figured that was the culprit. I don't know if it's possible to do something kinda like this: public String stringName; public ResourceLocation name = new ResourceLocation(stringName); that itself didn't work but there might be some other way of doing it.

squeek502 commented 5 years ago

Change name to String and then every place it's used do new ResourceLocation(name) (or whatever is actually necessary to transform the string into a ResourceLocation).

EDIT: This is how it works in Food.java: https://github.com/progwml6/HungerOverhaul/blob/1.12/src/main/java/iguanaman/hungeroverhaul/module/json/Food.java#L39-L41