RecipeCollection .java

net.minecraft.client.gui.screens.recipebook.RecipeCollection (class): members: getSelectedRecipes, CraftableStatus, hasAnySelected, selectRecipes, entries.

net.minecraft.client.gui.screens.recipebookclass83 linesclient2.4 KB

API Surface (6)

void selectRecipes(final StackedItemContents stackedContents, final Predicate<RecipeDisplay> selector)
boolean isCraftable(final RecipeDisplayId recipe)
boolean hasCraftable()
boolean hasAnySelected()
List<RecipeDisplayEntry> getRecipes()
List<RecipeDisplayEntry> getSelectedRecipes(final RecipeCollection.CraftableStatus selector)

Fields & Constants (4)

EMPTY
entries
craftable
selected

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

RecipeCollection.java83 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens.recipebook;
2
3
import java.util.ArrayList;
4
import java.util.HashSet;
5
import java.util.List;
6
import java.util.Set;
7
import java.util.function.Predicate;
8
import net.fabricmc.api.EnvType;
9
import net.fabricmc.api.Environment;
10
import net.minecraft.world.entity.player.StackedItemContents;
11
import net.minecraft.world.item.crafting.display.RecipeDisplay;
12
import net.minecraft.world.item.crafting.display.RecipeDisplayEntry;
13
import net.minecraft.world.item.crafting.display.RecipeDisplayId;
14
15
@Environment(EnvType.CLIENT)
16
public class RecipeCollection {
17
	public static final RecipeCollection EMPTY = new RecipeCollection(List.of());
18
	private final List<RecipeDisplayEntry> entries;
19
	private final Set<RecipeDisplayId> craftable = new HashSet<>();
20
	private final Set<RecipeDisplayId> selected = new HashSet<>();
21
22
	public RecipeCollection(final List<RecipeDisplayEntry> recipes) {
23
		this.entries = recipes;
24
	}
25
26
	public void selectRecipes(final StackedItemContents stackedContents, final Predicate<RecipeDisplay> selector) {
27
		for (RecipeDisplayEntry entry : this.entries) {
28
			boolean isSelected = selector.test(entry.display());
29
			if (isSelected) {
30
				this.selected.add(entry.id());
31
			} else {
32
				this.selected.remove(entry.id());
33
			}
34
35
			if (isSelected && entry.canCraft(stackedContents)) {
36
				this.craftable.add(entry.id());
37
			} else {
38
				this.craftable.remove(entry.id());
39
			}
40
		}
41
	}
42
43
	public boolean isCraftable(final RecipeDisplayId recipe) {
44
		return this.craftable.contains(recipe);
45
	}
46
47
	public boolean hasCraftable() {
48
		return !this.craftable.isEmpty();
49
	}
50
51
	public boolean hasAnySelected() {
52
		return !this.selected.isEmpty();
53
	}
54
55
	public List<RecipeDisplayEntry> getRecipes() {
56
		return this.entries;
57
	}
58
59
	public List<RecipeDisplayEntry> getSelectedRecipes(final RecipeCollection.CraftableStatus selector) {
60
		Predicate<RecipeDisplayId> predicate = switch (selector) {
61
			case ANY -> this.selected::contains;
62
			case CRAFTABLE -> this.craftable::contains;
63
			case NOT_CRAFTABLE -> recipe -> this.selected.contains(recipe) && !this.craftable.contains(recipe);
64
		};
65
		List<RecipeDisplayEntry> result = new ArrayList<>();
66
67
		for (RecipeDisplayEntry entries : this.entries) {
68
			if (predicate.test(entries.id())) {
69
				result.add(entries);
70
			}
71
		}
72
73
		return result;
74
	}
75
76
	@Environment(EnvType.CLIENT)
77
	public enum CraftableStatus {
78
		ANY,
79
		CRAFTABLE,
80
		NOT_CRAFTABLE;
81
	}
82
}
83

Decompiled Minecraft 26.3 source of RecipeCollection (net/minecraft/client/gui/screens/recipebook/RecipeCollection.java) with Mojang official mappings, stored verbatim on the site.