ShapedCraftingRecipeDisplay .java

net.minecraft.world.item.crafting.display.ShapedCraftingRecipeDisplay (record): members: width, height, ingredients, result, craftingStation, isEnabled.

net.minecraft.world.item.crafting.displayrecord55 linescommon2.3 KB

Implements

API Surface (2)

RecipeDisplay.Type<ShapedCraftingRecipeDisplay> type()
boolean isEnabled(final FeatureFlagSet enabledFeatures)

Fields & Constants (3)

MAP_CODEC
STREAM_CODEC
TYPE

String literals (6)

"width"
"height"
"ingredients"
"result"
"crafting_station"
"Invalid shaped recipe display contents"

Code Graph: Dependencies (6)

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

Full Source

ShapedCraftingRecipeDisplay.java55 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item.crafting.display;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import java.util.List;
7
import net.minecraft.network.RegistryFriendlyByteBuf;
8
import net.minecraft.network.codec.ByteBufCodecs;
9
import net.minecraft.network.codec.StreamCodec;
10
import net.minecraft.world.flag.FeatureFlagSet;
11
12
public record ShapedCraftingRecipeDisplay(int width, int height, List<SlotDisplay> ingredients, SlotDisplay result, SlotDisplay craftingStation)
13
	implements RecipeDisplay {
14
	public static final MapCodec<ShapedCraftingRecipeDisplay> MAP_CODEC = RecordCodecBuilder.mapCodec(
15
		i -> i.group(
16
				Codec.INT.fieldOf("width").forGetter(ShapedCraftingRecipeDisplay::width),
17
				Codec.INT.fieldOf("height").forGetter(ShapedCraftingRecipeDisplay::height),
18
				SlotDisplay.CODEC.listOf().fieldOf("ingredients").forGetter(ShapedCraftingRecipeDisplay::ingredients),
19
				SlotDisplay.CODEC.fieldOf("result").forGetter(ShapedCraftingRecipeDisplay::result),
20
				SlotDisplay.CODEC.fieldOf("crafting_station").forGetter(ShapedCraftingRecipeDisplay::craftingStation)
21
			)
22
			.apply(i, ShapedCraftingRecipeDisplay::new)
23
	);
24
	public static final StreamCodec<RegistryFriendlyByteBuf, ShapedCraftingRecipeDisplay> STREAM_CODEC = StreamCodec.composite(
25
		ByteBufCodecs.VAR_INT,
26
		ShapedCraftingRecipeDisplay::width,
27
		ByteBufCodecs.VAR_INT,
28
		ShapedCraftingRecipeDisplay::height,
29
		SlotDisplay.STREAM_CODEC.apply(ByteBufCodecs.list()),
30
		ShapedCraftingRecipeDisplay::ingredients,
31
		SlotDisplay.STREAM_CODEC,
32
		ShapedCraftingRecipeDisplay::result,
33
		SlotDisplay.STREAM_CODEC,
34
		ShapedCraftingRecipeDisplay::craftingStation,
35
		ShapedCraftingRecipeDisplay::new
36
	);
37
	public static final RecipeDisplay.Type<ShapedCraftingRecipeDisplay> TYPE = new RecipeDisplay.Type<>(MAP_CODEC, STREAM_CODEC);
38
39
	public ShapedCraftingRecipeDisplay {
40
		if (ingredients.size() != width * height) {
41
			throw new IllegalArgumentException("Invalid shaped recipe display contents");
42
		}
43
	}
44
45
	@Override
46
	public RecipeDisplay.Type<ShapedCraftingRecipeDisplay> type() {
47
		return TYPE;
48
	}
49
50
	@Override
51
	public boolean isEnabled(final FeatureFlagSet enabledFeatures) {
52
		return this.ingredients.stream().allMatch(e -> e.isEnabled(enabledFeatures)) && RecipeDisplay.super.isEnabled(enabledFeatures);
53
	}
54
}
55

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