SelectableRecipe .java

net.minecraft.world.item.crafting.SelectableRecipe (record, 58 lines): members: optionDisplay, recipe, SingleInputEntry, SingleInputSet, noRecipeCodec.

net.minecraft.world.item.craftingrecord58 linescommonextends Recipe<2.2 KB

API Surface (8)

<T extends Recipe<?>> StreamCodec<RegistryFriendlyByteBuf, SelectableRecipe<T>> noRecipeCodec()
<T extends Recipe<?>> StreamCodec<RegistryFriendlyByteBuf, SelectableRecipe.SingleInputEntry<T>> noRecipeCodec()
<T extends Recipe<?>> SelectableRecipe.SingleInputSet<T> empty()
<T extends Recipe<?>> StreamCodec<RegistryFriendlyByteBuf, SelectableRecipe.SingleInputSet<T>> noRecipeCodec()
boolean acceptsInput(final ItemStack input)
SelectableRecipe.SingleInputSet<T> selectByInput(final ItemStack input)
boolean isEmpty()
int size()

Full Source

SelectableRecipe.java58 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item.crafting;
2
3
import java.util.List;
4
import java.util.Optional;
5
import net.minecraft.network.RegistryFriendlyByteBuf;
6
import net.minecraft.network.codec.ByteBufCodecs;
7
import net.minecraft.network.codec.StreamCodec;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.item.crafting.display.SlotDisplay;
10
11
public record SelectableRecipe<T extends Recipe<?>>(SlotDisplay optionDisplay, Optional<RecipeHolder<T>> recipe) {
12
	public static <T extends Recipe<?>> StreamCodec<RegistryFriendlyByteBuf, SelectableRecipe<T>> noRecipeCodec() {
13
		return StreamCodec.composite(SlotDisplay.STREAM_CODEC, SelectableRecipe::optionDisplay, slotDisplay -> new SelectableRecipe<>(slotDisplay, Optional.empty()));
14
	}
15
16
	public record SingleInputEntry<T extends Recipe<?>>(Ingredient input, SelectableRecipe<T> recipe) {
17
		public static <T extends Recipe<?>> StreamCodec<RegistryFriendlyByteBuf, SelectableRecipe.SingleInputEntry<T>> noRecipeCodec() {
18
			return StreamCodec.composite(
19
				Ingredient.CONTENTS_STREAM_CODEC,
20
				SelectableRecipe.SingleInputEntry::input,
21
				SelectableRecipe.noRecipeCodec(),
22
				SelectableRecipe.SingleInputEntry::recipe,
23
				SelectableRecipe.SingleInputEntry::new
24
			);
25
		}
26
	}
27
28
	public record SingleInputSet<T extends Recipe<?>>(List<SelectableRecipe.SingleInputEntry<T>> entries) {
29
		public static <T extends Recipe<?>> SelectableRecipe.SingleInputSet<T> empty() {
30
			return new SelectableRecipe.SingleInputSet<>(List.of());
31
		}
32
33
		public static <T extends Recipe<?>> StreamCodec<RegistryFriendlyByteBuf, SelectableRecipe.SingleInputSet<T>> noRecipeCodec() {
34
			return StreamCodec.composite(
35
				SelectableRecipe.SingleInputEntry.<T>noRecipeCodec().apply(ByteBufCodecs.list()),
36
				SelectableRecipe.SingleInputSet::entries,
37
				SelectableRecipe.SingleInputSet::new
38
			);
39
		}
40
41
		public boolean acceptsInput(final ItemStack input) {
42
			return this.entries.stream().anyMatch(e -> e.input.test(input));
43
		}
44
45
		public SelectableRecipe.SingleInputSet<T> selectByInput(final ItemStack input) {
46
			return new SelectableRecipe.SingleInputSet<>(this.entries.stream().filter(e -> e.input.test(input)).toList());
47
		}
48
49
		public boolean isEmpty() {
50
			return this.entries.isEmpty();
51
		}
52
53
		public int size() {
54
			return this.entries.size();
55
		}
56
	}
57
}
58

Decompiled Minecraft 26.3 source of SelectableRecipe (net/minecraft/world/item/crafting/SelectableRecipe.java) with Mojang official mappings, stored verbatim on the site.