1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-27 16:02:17 +00:00

fix: recipes with nbt

it looks like the recipes need to be regenerated
This commit is contained in:
Nikita Savyolov 2021-10-11 10:06:15 +03:00
parent ebe847c04b
commit fb274e2ed6
No known key found for this signature in database
GPG Key ID: 32C1EF023AFC184B
3 changed files with 29 additions and 9 deletions

View File

@ -29,8 +29,10 @@ public final class ImpostorRecipe extends ShapedRecipe
{
String group = JsonHelper.getString( json, "group", "" );
ShapedRecipe recipe = RecipeSerializer.SHAPED.read( identifier, json );
ItemStack result = ShapedRecipe.outputFromJson( JsonHelper.getObject( json, "result" ) );
return new ImpostorRecipe( identifier, group, recipe.getWidth(), recipe.getHeight(), recipe.getIngredients(), result );
JsonObject resultObject = JsonHelper.getObject( json, "result" );
ItemStack itemStack = ShapedRecipe.outputFromJson( resultObject );
RecipeUtil.setNbt( itemStack, resultObject );
return new ImpostorRecipe( identifier, group, recipe.getWidth(), recipe.getHeight(), recipe.getIngredients(), itemStack );
}
@Override

View File

@ -41,9 +41,10 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe
{
throw new JsonParseException( "Too many ingredients for shapeless recipe the max is 9" );
}
ItemStack itemstack = ShapedRecipe.outputFromJson( JsonHelper.getObject( json, "result" ) );
return new ImpostorShapelessRecipe( id, s, itemstack, ingredients );
JsonObject resultObject = JsonHelper.getObject( json, "result" );
ItemStack itemStack = ShapedRecipe.outputFromJson( resultObject );
RecipeUtil.setNbt( itemStack, resultObject );
return new ImpostorShapelessRecipe( id, s, itemStack, ingredients );
}
private DefaultedList<Ingredient> readIngredients( JsonArray arrays )

View File

@ -8,11 +8,11 @@ package dan200.computercraft.shared.util;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.google.gson.*;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.recipe.Ingredient;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.collection.DefaultedList;
@ -24,6 +24,7 @@ import java.util.Set;
public final class RecipeUtil
{
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
private RecipeUtil() {}
public static ShapedTemplate getTemplate( JsonObject json )
@ -111,6 +112,22 @@ public final class RecipeUtil
throw new JsonSyntaxException( "Unknown computer family '" + familyName + "' for field " + name );
}
public static void setNbt( ItemStack itemStack, JsonObject result )
{
JsonElement nbtElement = result.get( "nbt" );
if ( nbtElement != null )
{
try
{
itemStack.setNbt( NbtHelper.method_32260( nbtElement.isJsonObject() ? GSON.toJson( nbtElement ) : nbtElement.getAsString() ) );
}
catch( CommandSyntaxException e )
{
throw new JsonSyntaxException( "Invalid NBT entry: " + e.getMessage() );
}
}
}
public static class ShapedTemplate
{
public final int width;