2025-11-24 22:52:51 +03:00

108 lines
3.7 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.datafixers.kinds.App
* com.mojang.datafixers.kinds.Applicative
* com.mojang.serialization.Codec
* 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.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.HolderLookup;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.PlacementInfo;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.SingleRecipeInput;
import net.minecraft.world.level.Level;
import org.jspecify.annotations.Nullable;
public abstract class SingleItemRecipe
implements Recipe<SingleRecipeInput> {
private final Ingredient input;
private final ItemStack result;
private final String group;
private @Nullable PlacementInfo placementInfo;
public SingleItemRecipe(String group, Ingredient input, ItemStack result) {
this.group = group;
this.input = input;
this.result = result;
}
@Override
public abstract RecipeSerializer<? extends SingleItemRecipe> getSerializer();
@Override
public abstract RecipeType<? extends SingleItemRecipe> getType();
@Override
public boolean matches(SingleRecipeInput input, Level level) {
return this.input.test(input.item());
}
@Override
public String group() {
return this.group;
}
public Ingredient input() {
return this.input;
}
protected ItemStack result() {
return this.result;
}
@Override
public PlacementInfo placementInfo() {
if (this.placementInfo == null) {
this.placementInfo = PlacementInfo.create(this.input);
}
return this.placementInfo;
}
@Override
public ItemStack assemble(SingleRecipeInput input, HolderLookup.Provider registries) {
return this.result.copy();
}
@FunctionalInterface
public static interface Factory<T extends SingleItemRecipe> {
public T create(String var1, Ingredient var2, ItemStack var3);
}
public static class Serializer<T extends SingleItemRecipe>
implements RecipeSerializer<T> {
private final MapCodec<T> codec = RecordCodecBuilder.mapCodec(r -> r.group((App)Codec.STRING.optionalFieldOf("group", (Object)"").forGetter(SingleItemRecipe::group), (App)Ingredient.CODEC.fieldOf("ingredient").forGetter(SingleItemRecipe::input), (App)ItemStack.STRICT_CODEC.fieldOf("result").forGetter(SingleItemRecipe::result)).apply((Applicative)r, factory::create));
private final StreamCodec<RegistryFriendlyByteBuf, T> streamCodec = StreamCodec.composite(ByteBufCodecs.STRING_UTF8, SingleItemRecipe::group, Ingredient.CONTENTS_STREAM_CODEC, SingleItemRecipe::input, ItemStack.STREAM_CODEC, SingleItemRecipe::result, factory::create);
protected Serializer(Factory<T> factory) {
}
@Override
public MapCodec<T> codec() {
return this.codec;
}
@Override
public StreamCodec<RegistryFriendlyByteBuf, T> streamCodec() {
return this.streamCodec;
}
}
}