From 3f225c59a172447f327245fa80e591c59342c5a9 Mon Sep 17 00:00:00 2001 From: Aleksey Date: Wed, 30 Jun 2021 16:20:16 +0300 Subject: [PATCH] Possibility to add NBT data for Infusion recipes output (#215) --- build.gradle | 26 +++++++++---------- gradle.properties | 8 +++--- .../mixin/common/LivingEntityMixin.java | 2 +- .../particle/InfusionParticleType.java | 13 +++++----- .../recipe/builders/InfusionRecipe.java | 14 ++++++++++ 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index ce8b39950..9a618e8be 100644 --- a/build.gradle +++ b/build.gradle @@ -43,30 +43,30 @@ dependencies { def useOptional(String dep) { dependencies.modRuntime (dep) { - exclude group: "net.fabricmc.fabric-api" - exclude group: "net.fabricmc" + exclude group: 'net.fabricmc.fabric-api' + exclude group: 'net.fabricmc' if (!dep.contains("me.shedaniel")) { - exclude group: "me.shedaniel.cloth" - exclude group: "me.shedaniel" + exclude group: 'me.shedaniel.cloth' + exclude group: 'me.shedaniel' } } dependencies.modCompileOnly (dep) { - exclude group: "net.fabricmc.fabric-api" - exclude group: "net.fabricmc" + exclude group: 'net.fabricmc.fabric-api' + exclude group: 'net.fabricmc' if (!dep.contains("me.shedaniel")) { - exclude group: "me.shedaniel.cloth" - exclude group: "me.shedaniel" + exclude group: 'me.shedaniel.cloth' + exclude group: 'me.shedaniel' } } } def useApi(String dep) { dependencies.modApi (dep) { - exclude group: "net.fabricmc.fabric-api" - exclude group: "net.fabricmc" + exclude group: 'net.fabricmc.fabric-api' + exclude group: 'net.fabricmc' if (!dep.contains("me.shedaniel")) { - exclude group: "me.shedaniel.cloth" - exclude group: "me.shedaniel" + exclude group: 'me.shedaniel.cloth' + exclude group: 'me.shedaniel' } } } @@ -162,4 +162,4 @@ task release(dependsOn: [remapJar, sourcesJar, javadocJar]) { // // uncomment to publish to the local maven // // mavenLocal() // } -//} +//} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 5f798ac21..a0581cf98 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,8 +14,8 @@ archives_base_name = better-end # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api -patchouli_version = 50-FABRIC -fabric_version = 0.32.9+1.16 -canvas_version = 1.0.+ +patchouli_version = 53-FABRIC +fabric_version = 0.36.0+1.16 bclib_version = 0.1.44 -rei_version = 5.8.10 \ No newline at end of file +rei_version = 5.12.248 +canvas_version = 1.0.+ \ No newline at end of file diff --git a/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java b/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java index 93c281748..565976a89 100644 --- a/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java +++ b/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java @@ -95,7 +95,7 @@ public void be_canBeAffected(MobEffectInstance mobEffectInstance, CallbackInfoRe info.setReturnValue(false); } } catch (Exception ex) { - BetterEnd.LOGGER.warning("Blindness resistance attribute haven't registered."); + BetterEnd.LOGGER.warning("Blindness resistance attribute haven't been registered."); } } diff --git a/src/main/java/ru/betterend/particle/InfusionParticleType.java b/src/main/java/ru/betterend/particle/InfusionParticleType.java index 672f3ab9a..bda8fe131 100644 --- a/src/main/java/ru/betterend/particle/InfusionParticleType.java +++ b/src/main/java/ru/betterend/particle/InfusionParticleType.java @@ -17,11 +17,10 @@ import ru.betterend.registry.EndParticles; public class InfusionParticleType extends ParticleType implements ParticleOptions { - public static final Codec CODEC = ItemStack.CODEC.xmap(itemStack -> { - return new InfusionParticleType(EndParticles.INFUSION, itemStack); - }, infusionParticleType -> { - return infusionParticleType.itemStack; - }); + public static final Codec CODEC = ItemStack.CODEC.xmap( + itemStack -> new InfusionParticleType(EndParticles.INFUSION, itemStack), + infusionParticleType -> infusionParticleType.itemStack); + public static final ParticleOptions.Deserializer PARAMETERS_FACTORY = new ParticleOptions.Deserializer() { public InfusionParticleType fromCommand(ParticleType particleType, StringReader stringReader) throws CommandSyntaxException { stringReader.expect(' '); @@ -35,8 +34,8 @@ public InfusionParticleType fromNetwork(ParticleType parti } }; - private ParticleType type; - private ItemStack itemStack; + private final ParticleType type; + private final ItemStack itemStack; public InfusionParticleType(ParticleType particleType, ItemStack stack) { super(true, PARAMETERS_FACTORY); diff --git a/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java b/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java index b05b2f37a..f1186d59b 100644 --- a/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java @@ -4,11 +4,15 @@ import com.google.gson.JsonObject; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.util.NbtType; import net.minecraft.core.NonNullList; +import net.minecraft.nbt.*; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagLoader; import net.minecraft.util.GsonHelper; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; @@ -17,6 +21,7 @@ import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; +import net.minecraft.world.level.storage.loot.GsonAdapterFactory; import ru.bclib.recipes.BCLRecipeManager; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; @@ -209,6 +214,15 @@ public InfusionRecipe fromJson(ResourceLocation id, JsonObject json) { if (recipe.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); + recipe.output.setTag(nbt); + } catch (CommandSyntaxException ex) { + BetterEnd.LOGGER.warning("Error parse nbt data for output.", ex); + } + } recipe.group = GsonHelper.getAsString(json, "group", GROUP); recipe.time = GsonHelper.getAsInt(json, "time", 1);