Skip to content

Commit

Permalink
Fix server crash by using JsonUtils (client only)
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Oct 15, 2019
1 parent caa7392 commit 34ca584
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.raoulvdberge.refinedstorage.recipe;

import com.google.gson.JsonObject;
import com.mojang.realmsclient.util.JsonUtils;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipeSerializer;
Expand All @@ -15,9 +14,15 @@
public class UpgradeWithEnchantedBookRecipeSerializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<UpgradeWithEnchantedBookRecipe> {
@Override
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())));
Enchantment enchantment = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(json.getAsJsonObject("enchantment").getAsJsonPrimitive("id").getAsString()));
int level = JsonUtils.func_225172_a("level", json.getAsJsonObject("enchantment"), 1);
Enchantment enchantment = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(enchantmentInfo.getAsJsonPrimitive("id").getAsString()));

int level = 1;
if (enchantmentInfo.has("level")) {
level = enchantmentInfo.getAsJsonPrimitive("level").getAsInt();
}

return new UpgradeWithEnchantedBookRecipe(recipeId, enchantment, level, result);
}
Expand Down

0 comments on commit 34ca584

Please sign in to comment.