Fix server crash by using JsonUtils (client only)
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package com.raoulvdberge.refinedstorage.recipe;
|
package com.raoulvdberge.refinedstorage.recipe;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.mojang.realmsclient.util.JsonUtils;
|
|
||||||
import net.minecraft.enchantment.Enchantment;
|
import net.minecraft.enchantment.Enchantment;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||||
@@ -15,9 +14,15 @@ import javax.annotation.Nullable;
|
|||||||
public class UpgradeWithEnchantedBookRecipeSerializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<UpgradeWithEnchantedBookRecipe> {
|
public class UpgradeWithEnchantedBookRecipeSerializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<UpgradeWithEnchantedBookRecipe> {
|
||||||
@Override
|
@Override
|
||||||
public UpgradeWithEnchantedBookRecipe read(ResourceLocation recipeId, JsonObject json) {
|
public UpgradeWithEnchantedBookRecipe read(ResourceLocation recipeId, JsonObject json) {
|
||||||
|
JsonObject enchantmentInfo = json.getAsJsonObject("enchantment");
|
||||||
|
|
||||||
ItemStack result = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(json.getAsJsonPrimitive("result").getAsString())));
|
ItemStack result = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(json.getAsJsonPrimitive("result").getAsString())));
|
||||||
Enchantment enchantment = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(json.getAsJsonObject("enchantment").getAsJsonPrimitive("id").getAsString()));
|
Enchantment enchantment = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(enchantmentInfo.getAsJsonPrimitive("id").getAsString()));
|
||||||
int level = JsonUtils.func_225172_a("level", json.getAsJsonObject("enchantment"), 1);
|
|
||||||
|
int level = 1;
|
||||||
|
if (enchantmentInfo.has("level")) {
|
||||||
|
level = enchantmentInfo.getAsJsonPrimitive("level").getAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
return new UpgradeWithEnchantedBookRecipe(recipeId, enchantment, level, result);
|
return new UpgradeWithEnchantedBookRecipe(recipeId, enchantment, level, result);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user