ItemInput .java

net.minecraft.commands.arguments.item.ItemInput (record, 31 lines): members: item, components, ERROR_MALFORMED_ITEM, ERROR_STACK_TOO_BIG, createItemStack.

net.minecraft.commands.arguments.itemrecord31 linescommon1.4 KB

API Surface (2)

record ItemInput(Holder<Item> item, DataComponentPatch components)
ItemStack createItemStack(final int count)

Fields & Constants (2)

ERROR_STACK_TOO_BIG
ERROR_MALFORMED_ITEM

String literals (2)

"arguments.item.overstacked"
"arguments.item.malformed"

Code Graph: Dependencies (5)

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

Full Source

ItemInput.java31 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.commands.arguments.item;
2
3
import com.mojang.brigadier.exceptions.CommandSyntaxException;
4
import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType;
5
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
6
import com.mojang.serialization.DataResult;
7
import net.minecraft.core.Holder;
8
import net.minecraft.core.component.DataComponentPatch;
9
import net.minecraft.network.chat.Component;
10
import net.minecraft.world.item.Item;
11
import net.minecraft.world.item.ItemStack;
12
13
public record ItemInput(Holder<Item> item, DataComponentPatch components) {
14
	private static final Dynamic2CommandExceptionType ERROR_STACK_TOO_BIG = new Dynamic2CommandExceptionType(
15
		(item, count) -> Component.translatableEscape("arguments.item.overstacked", item, count)
16
	);
17
	private static final DynamicCommandExceptionType ERROR_MALFORMED_ITEM = new DynamicCommandExceptionType(
18
		error -> Component.translatableEscape("arguments.item.malformed", error)
19
	);
20
21
	public ItemStack createItemStack(final int count) throws CommandSyntaxException {
22
		ItemStack result = new ItemStack(this.item, count, this.components);
23
		if (count > result.getMaxStackSize()) {
24
			throw ERROR_STACK_TOO_BIG.create(this.item.getRegisteredName(), result.getMaxStackSize());
25
		}
26
27
		DataResult<ItemStack> validationResult = ItemStack.validateStrict(result);
28
		return validationResult.getOrThrow(ERROR_MALFORMED_ITEM::create);
29
	}
30
}
31

Decompiled Minecraft 26.3 source of ItemInput (net/minecraft/commands/arguments/item/ItemInput.java) with Mojang official mappings, stored verbatim on the site.