/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.kinds.App * com.mojang.datafixers.kinds.Applicative * com.mojang.serialization.MapCodec * com.mojang.serialization.codecs.RecordCodecBuilder * org.jspecify.annotations.Nullable */ package net.minecraft.world.item.crafting; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.Applicative; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.List; import java.util.Objects; import java.util.Optional; import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.core.component.DataComponents; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.PlacementInfo; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.SmithingRecipe; import net.minecraft.world.item.crafting.SmithingRecipeInput; import net.minecraft.world.item.crafting.display.RecipeDisplay; import net.minecraft.world.item.crafting.display.SlotDisplay; import net.minecraft.world.item.crafting.display.SmithingRecipeDisplay; import net.minecraft.world.item.equipment.trim.ArmorTrim; import net.minecraft.world.item.equipment.trim.TrimMaterial; import net.minecraft.world.item.equipment.trim.TrimMaterials; import net.minecraft.world.item.equipment.trim.TrimPattern; import org.jspecify.annotations.Nullable; public class SmithingTrimRecipe implements SmithingRecipe { private final Ingredient template; private final Ingredient base; private final Ingredient addition; private final Holder pattern; private @Nullable PlacementInfo placementInfo; public SmithingTrimRecipe(Ingredient template, Ingredient base, Ingredient addition, Holder pattern) { this.template = template; this.base = base; this.addition = addition; this.pattern = pattern; } @Override public ItemStack assemble(SmithingRecipeInput input, HolderLookup.Provider registries) { return SmithingTrimRecipe.applyTrim(registries, input.base(), input.addition(), this.pattern); } public static ItemStack applyTrim(HolderLookup.Provider registries, ItemStack baseItem, ItemStack materialItem, Holder pattern) { Optional> material = TrimMaterials.getFromIngredient(registries, materialItem); if (material.isPresent()) { ArmorTrim newTrim; ArmorTrim existingTrim = baseItem.get(DataComponents.TRIM); if (Objects.equals(existingTrim, newTrim = new ArmorTrim(material.get(), pattern))) { return ItemStack.EMPTY; } ItemStack trimmedItem = baseItem.copyWithCount(1); trimmedItem.set(DataComponents.TRIM, newTrim); return trimmedItem; } return ItemStack.EMPTY; } @Override public Optional templateIngredient() { return Optional.of(this.template); } @Override public Ingredient baseIngredient() { return this.base; } @Override public Optional additionIngredient() { return Optional.of(this.addition); } @Override public RecipeSerializer getSerializer() { return RecipeSerializer.SMITHING_TRIM; } @Override public PlacementInfo placementInfo() { if (this.placementInfo == null) { this.placementInfo = PlacementInfo.create(List.of(this.template, this.base, this.addition)); } return this.placementInfo; } @Override public List display() { SlotDisplay base = this.base.display(); SlotDisplay material = this.addition.display(); SlotDisplay template = this.template.display(); return List.of(new SmithingRecipeDisplay(template, base, material, new SlotDisplay.SmithingTrimDemoSlotDisplay(base, material, this.pattern), new SlotDisplay.ItemSlotDisplay(Items.SMITHING_TABLE))); } public static class Serializer implements RecipeSerializer { private static final MapCodec CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)Ingredient.CODEC.fieldOf("template").forGetter(r -> r.template), (App)Ingredient.CODEC.fieldOf("base").forGetter(r -> r.base), (App)Ingredient.CODEC.fieldOf("addition").forGetter(r -> r.addition), (App)TrimPattern.CODEC.fieldOf("pattern").forGetter(r -> r.pattern)).apply((Applicative)i, SmithingTrimRecipe::new)); public static final StreamCodec STREAM_CODEC = StreamCodec.composite(Ingredient.CONTENTS_STREAM_CODEC, r -> r.template, Ingredient.CONTENTS_STREAM_CODEC, r -> r.base, Ingredient.CONTENTS_STREAM_CODEC, r -> r.addition, TrimPattern.STREAM_CODEC, r -> r.pattern, SmithingTrimRecipe::new); @Override public MapCodec codec() { return CODEC; } @Override public StreamCodec streamCodec() { return STREAM_CODEC; } } }