Allow advancement icons to have nbt (#4114)

This commit is contained in:
Vincent Lee authored and LexManos committed 2017-07-08 15:14:29 -05:00
1 parent 80da39d4e3
commit 4df20daf41
2 files changed
+38

No files matched your search

@@ -31,9 +31,16 @@ import com.google.common.reflect.TypeToken;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonSyntaxException;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nullable;
public class JsonUtils
{
@@ -88,6 +95,24 @@ public class JsonUtils
}
}
@Nullable
public static NBTTagCompound readNBT(JsonObject json, String key)
{
if (net.minecraft.util.JsonUtils.hasField(json, key))
{
try
{
return JsonToNBT.getTagFromJson(net.minecraft.util.JsonUtils.getString(json, key));
} catch (NBTException e)
{
throw new JsonSyntaxException("Malformed NBT tag", e);
}
} else
{
return null;
}
}
@SuppressWarnings({ "serial", "unchecked" })
private static <E> TypeToken<Map<String, E>> mapOf(final Type arg)
{