SetItemFunction .java

net.minecraft.world.level.storage.loot.functions.SetItemFunction (class, 39 lines): members: item, run, MAP_CODEC, codec. strings: "item".

net.minecraft.world.level.storage.loot.functionsclass39 linescommonextends LootItemConditionalFunction1.2 KB

API Surface (2)

MapCodec<SetItemFunction> codec()
ItemStack run(final ItemStack itemStack, final LootContext context)

Fields & Constants (2)

MAP_CODEC
item

String literals (1)

"item"

Code Graph: Dependencies (6)

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

Full Source

SetItemFunction.java39 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.storage.loot.functions;
2
3
import com.mojang.serialization.MapCodec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import java.util.Optional;
6
import net.minecraft.core.Holder;
7
import net.minecraft.world.item.Item;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.level.storage.loot.LootContext;
10
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
11
12
/**
13
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
14
 */
15
public class SetItemFunction extends LootItemConditionalFunction {
16
	public static final MapCodec<SetItemFunction> MAP_CODEC = RecordCodecBuilder.mapCodec(
17
		i -> commonFields(i).and(Item.CODEC.fieldOf("item").forGetter(f -> f.item)).apply(i, SetItemFunction::new)
18
	);
19
	private final Holder<Item> item;
20
21
	/**
22
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
23
	 */
24
	public SetItemFunction(final Optional<Holder<LootItemCondition>> condition, final Holder<Item> item) {
25
		super(condition);
26
		this.item = item;
27
	}
28
29
	@Override
30
	public MapCodec<SetItemFunction> codec() {
31
		return MAP_CODEC;
32
	}
33
34
	@Override
35
	public ItemStack run(final ItemStack itemStack, final LootContext context) {
36
		return itemStack.transmuteCopy(this.item.value());
37
	}
38
}
39

Decompiled Minecraft 26.3 source of SetItemFunction (net/minecraft/world/level/storage/loot/functions/SetItemFunction.java) with Mojang official mappings, stored verbatim on the site.