Enchantable .java

net.minecraft.world.item.enchantment.Enchantable (record, 22 lines): record with 1 component. members: value, STREAM_CODEC, CODEC. imports: ExtraCodecs.

net.minecraft.world.item.enchantmentrecord22 linescommon849 B

API Surface (1)

record Enchantable(int value)

Fields & Constants (2)

CODEC
STREAM_CODEC

String literals (1)

"Enchantment value must be positive, but was "

Code Graph: Dependencies (3)

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

Full Source

Enchantable.java22 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item.enchantment;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import io.netty.buffer.ByteBuf;
6
import net.minecraft.network.codec.ByteBufCodecs;
7
import net.minecraft.network.codec.StreamCodec;
8
import net.minecraft.util.ExtraCodecs;
9
10
public record Enchantable(int value) {
11
	public static final Codec<Enchantable> CODEC = RecordCodecBuilder.create(
12
		i -> i.group(ExtraCodecs.POSITIVE_INT.fieldOf("value").forGetter(Enchantable::value)).apply(i, Enchantable::new)
13
	);
14
	public static final StreamCodec<ByteBuf, Enchantable> STREAM_CODEC = StreamCodec.composite(ByteBufCodecs.VAR_INT, Enchantable::value, Enchantable::new);
15
16
	public Enchantable {
17
		if (value <= 0) {
18
			throw new IllegalArgumentException("Enchantment value must be positive, but was " + value);
19
		}
20
	}
21
}
22

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