Skip to content

Commit

Permalink
Possibility to add NBT data for Anvil recipes output
Browse files Browse the repository at this point in the history
  • Loading branch information
Bulldog83 committed Jun 30, 2021
1 parent 3f225c5 commit e28dcf1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/ru/betterend/recipe/builders/AnvilRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

import com.google.gson.JsonObject;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.TagParser;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
Expand Down Expand Up @@ -276,6 +279,15 @@ public AnvilRecipe fromJson(ResourceLocation id, JsonObject json) {
if (output == null) {
throw new IllegalStateException("Output item does not exists!");
}
if (result.has("nbt")) {
try {
String nbtData = GsonHelper.getAsString(result, "nbt");
CompoundTag nbt = TagParser.parseTag(nbtData);
output.setTag(nbt);
} catch (CommandSyntaxException ex) {
BetterEnd.LOGGER.warning("Error parse nbt data for output.", ex);
}
}
int inputCount = GsonHelper.getAsInt(json, "inputCount", 1);
int toolLevel = GsonHelper.getAsInt(json, "toolLevel", 1);
int anvilLevel = GsonHelper.getAsInt(json, "anvilLevel", 1);
Expand Down

0 comments on commit e28dcf1

Please sign in to comment.