114 lines
4.5 KiB
Java
114 lines
4.5 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 java.util.List;
|
|
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.Items;
|
|
import net.minecraft.world.item.crafting.CraftingBookCategory;
|
|
import net.minecraft.world.item.crafting.CraftingInput;
|
|
import net.minecraft.world.item.crafting.CraftingRecipe;
|
|
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.display.RecipeDisplay;
|
|
import net.minecraft.world.item.crafting.display.ShapelessCraftingRecipeDisplay;
|
|
import net.minecraft.world.item.crafting.display.SlotDisplay;
|
|
import net.minecraft.world.level.Level;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public class ShapelessRecipe
|
|
implements CraftingRecipe {
|
|
private final String group;
|
|
private final CraftingBookCategory category;
|
|
private final ItemStack result;
|
|
private final List<Ingredient> ingredients;
|
|
private @Nullable PlacementInfo placementInfo;
|
|
|
|
public ShapelessRecipe(String group, CraftingBookCategory category, ItemStack result, List<Ingredient> ingredients) {
|
|
this.group = group;
|
|
this.category = category;
|
|
this.result = result;
|
|
this.ingredients = ingredients;
|
|
}
|
|
|
|
@Override
|
|
public RecipeSerializer<ShapelessRecipe> getSerializer() {
|
|
return RecipeSerializer.SHAPELESS_RECIPE;
|
|
}
|
|
|
|
@Override
|
|
public String group() {
|
|
return this.group;
|
|
}
|
|
|
|
@Override
|
|
public CraftingBookCategory category() {
|
|
return this.category;
|
|
}
|
|
|
|
@Override
|
|
public PlacementInfo placementInfo() {
|
|
if (this.placementInfo == null) {
|
|
this.placementInfo = PlacementInfo.create(this.ingredients);
|
|
}
|
|
return this.placementInfo;
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(CraftingInput input, Level level) {
|
|
if (input.ingredientCount() != this.ingredients.size()) {
|
|
return false;
|
|
}
|
|
if (input.size() == 1 && this.ingredients.size() == 1) {
|
|
return this.ingredients.getFirst().test(input.getItem(0));
|
|
}
|
|
return input.stackedContents().canCraft(this, null);
|
|
}
|
|
|
|
@Override
|
|
public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) {
|
|
return this.result.copy();
|
|
}
|
|
|
|
@Override
|
|
public List<RecipeDisplay> display() {
|
|
return List.of(new ShapelessCraftingRecipeDisplay(this.ingredients.stream().map(Ingredient::display).toList(), new SlotDisplay.ItemStackSlotDisplay(this.result), new SlotDisplay.ItemSlotDisplay(Items.CRAFTING_TABLE)));
|
|
}
|
|
|
|
public static class Serializer
|
|
implements RecipeSerializer<ShapelessRecipe> {
|
|
private static final MapCodec<ShapelessRecipe> CODEC = RecordCodecBuilder.mapCodec(r -> r.group((App)Codec.STRING.optionalFieldOf("group", (Object)"").forGetter(o -> o.group), (App)CraftingBookCategory.CODEC.fieldOf("category").orElse((Object)CraftingBookCategory.MISC).forGetter(o -> o.category), (App)ItemStack.STRICT_CODEC.fieldOf("result").forGetter(o -> o.result), (App)Ingredient.CODEC.listOf(1, 9).fieldOf("ingredients").forGetter(o -> o.ingredients)).apply((Applicative)r, ShapelessRecipe::new));
|
|
public static final StreamCodec<RegistryFriendlyByteBuf, ShapelessRecipe> STREAM_CODEC = StreamCodec.composite(ByteBufCodecs.STRING_UTF8, r -> r.group, CraftingBookCategory.STREAM_CODEC, r -> r.category, ItemStack.STREAM_CODEC, r -> r.result, Ingredient.CONTENTS_STREAM_CODEC.apply(ByteBufCodecs.list()), r -> r.ingredients, ShapelessRecipe::new);
|
|
|
|
@Override
|
|
public MapCodec<ShapelessRecipe> codec() {
|
|
return CODEC;
|
|
}
|
|
|
|
@Override
|
|
public StreamCodec<RegistryFriendlyByteBuf, ShapelessRecipe> streamCodec() {
|
|
return STREAM_CODEC;
|
|
}
|
|
}
|
|
}
|
|
|