ApplyExhaustion .java

net.minecraft.world.item.enchantment.effects.ApplyExhaustion (record, 29 lines): members: amount, apply, codec, CODEC. strings: "amount". imports: Player.

net.minecraft.world.item.enchantment.effectsrecord29 linescommon1.1 KB

Implements

API Surface (2)

void apply(final ServerLevel serverLevel, final int enchantmentLevel, final EnchantedItemInUse item, final Entity entity, final Vec3 position)
MapCodec<ApplyExhaustion> codec()

Fields & Constants (1)

CODEC

String literals (1)

"amount"

Code Graph: Dependencies (7)

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

Full Source

ApplyExhaustion.java29 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item.enchantment.effects;
2
3
import com.mojang.serialization.MapCodec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import net.minecraft.server.level.ServerLevel;
6
import net.minecraft.world.entity.Entity;
7
import net.minecraft.world.entity.player.Player;
8
import net.minecraft.world.item.enchantment.EnchantedItemInUse;
9
import net.minecraft.world.item.enchantment.LevelBasedValue;
10
import net.minecraft.world.phys.Vec3;
11
12
public record ApplyExhaustion(LevelBasedValue amount) implements EnchantmentEntityEffect {
13
	public static final MapCodec<ApplyExhaustion> CODEC = RecordCodecBuilder.mapCodec(
14
		i -> i.group(LevelBasedValue.CODEC.fieldOf("amount").forGetter(ApplyExhaustion::amount)).apply(i, ApplyExhaustion::new)
15
	);
16
17
	@Override
18
	public void apply(final ServerLevel serverLevel, final int enchantmentLevel, final EnchantedItemInUse item, final Entity entity, final Vec3 position) {
19
		if (entity instanceof Player livingEntity) {
20
			livingEntity.causeFoodExhaustion(this.amount.calculate(enchantmentLevel));
21
		}
22
	}
23
24
	@Override
25
	public MapCodec<ApplyExhaustion> codec() {
26
		return CODEC;
27
	}
28
}
29

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