StackedItemContents .java

net.minecraft.world.entity.player.StackedItemContents (class): members: getBiggestCraftableStack, accountSimpleStack, accountStack, canCraft, raw, amount.

net.minecraft.world.entity.playerclass64 linescommon2.3 KB

API Surface (9)

void accountSimpleStack(final ItemStack itemStack)
void accountStack(final ItemStack itemStack)
void accountStack(final ItemStack itemStack, final int maxCount)
boolean canCraft(final Recipe<?> recipe, final StackedContents.@Nullable Output<Holder<Item>> output)
boolean canCraft(final Recipe<?> recipe, final int amount, final StackedContents.@Nullable Output<Holder<Item>> output)
boolean canCraft(final List<? extends StackedContents.IngredientInfo<Holder<Item>>> contents, final StackedContents.@Nullable Output<Holder<Item>> output)
int getBiggestCraftableStack(final Recipe<?> recipe, final StackedContents.@Nullable Output<Holder<Item>> output)
int getBiggestCraftableStack(final Recipe<?> recipe, final int maxSize, final StackedContents.@Nullable Output<Holder<Item>> output)
void clear()

Fields & Constants (3)

raw
contents
amount

Code Graph: Dependencies (7)

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

Full Source

StackedItemContents.java64 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.player;
2
3
import java.util.List;
4
import net.minecraft.core.Holder;
5
import net.minecraft.world.item.Item;
6
import net.minecraft.world.item.ItemStack;
7
import net.minecraft.world.item.crafting.PlacementInfo;
8
import net.minecraft.world.item.crafting.Recipe;
9
import org.jspecify.annotations.Nullable;
10
11
public class StackedItemContents {
12
	private final StackedContents<Holder<Item>> raw = new StackedContents<>();
13
14
	public void accountSimpleStack(final ItemStack itemStack) {
15
		if (Inventory.isUsableForCrafting(itemStack)) {
16
			this.accountStack(itemStack);
17
		}
18
	}
19
20
	public void accountStack(final ItemStack itemStack) {
21
		this.accountStack(itemStack, itemStack.getMaxStackSize());
22
	}
23
24
	public void accountStack(final ItemStack itemStack, final int maxCount) {
25
		if (!itemStack.isEmpty()) {
26
			int count = Math.min(maxCount, itemStack.getCount());
27
			this.raw.account(itemStack.typeHolder(), count);
28
		}
29
	}
30
31
	public boolean canCraft(final Recipe<?> recipe, final StackedContents.@Nullable Output<Holder<Item>> output) {
32
		return this.canCraft(recipe, 1, output);
33
	}
34
35
	public boolean canCraft(final Recipe<?> recipe, final int amount, final StackedContents.@Nullable Output<Holder<Item>> output) {
36
		PlacementInfo placementInfo = recipe.placementInfo();
37
		return placementInfo.isImpossibleToPlace() ? false : this.canCraft(placementInfo.ingredients(), amount, output);
38
	}
39
40
	public boolean canCraft(
41
		final List<? extends StackedContents.IngredientInfo<Holder<Item>>> contents, final StackedContents.@Nullable Output<Holder<Item>> output
42
	) {
43
		return this.canCraft(contents, 1, output);
44
	}
45
46
	private boolean canCraft(
47
		final List<? extends StackedContents.IngredientInfo<Holder<Item>>> contents, final int amount, final StackedContents.@Nullable Output<Holder<Item>> output
48
	) {
49
		return this.raw.tryPick(contents, amount, output);
50
	}
51
52
	public int getBiggestCraftableStack(final Recipe<?> recipe, final StackedContents.@Nullable Output<Holder<Item>> output) {
53
		return this.getBiggestCraftableStack(recipe, Integer.MAX_VALUE, output);
54
	}
55
56
	public int getBiggestCraftableStack(final Recipe<?> recipe, final int maxSize, final StackedContents.@Nullable Output<Holder<Item>> output) {
57
		return this.raw.tryPickAll(recipe.placementInfo().ingredients(), maxSize, output);
58
	}
59
60
	public void clear() {
61
		this.raw.clear();
62
	}
63
}
64

Decompiled Minecraft 26.3 source of StackedItemContents (net/minecraft/world/entity/player/StackedItemContents.java) with Mojang official mappings, stored verbatim on the site.