EquipmentSlot .java

net.minecraft.world.entity.EquipmentSlot (enum, 102 lines): members: MAINHAND, OFFHAND, FEET, LEGS, CHEST, HEAD, BODY, SADDLE, canIncreaseExperience, Type.

net.minecraft.world.entityenum102 linescommon2.9 KB

Implements

API Surface (11)

EquipmentSlot.Type getType()
int getIndex()
int getIndex(final int base)
ItemStack limit(final ItemStack toEquip)
int getId()
int getFilterBit(final int offset)
String getName()
boolean isArmor()
String getSerializedName()
boolean canIncreaseExperience()
EquipmentSlot byName(final String name)

Fields & Constants (10)

NO_COUNT_LIMIT
VALUES
BY_ID
CODEC
STREAM_CODEC
type
index
countLimit
id
name

String literals (9)

"mainhand"
"offhand"
"feet"
"legs"
"chest"
"head"
"body"
"saddle"
"Invalid slot '"

Code Graph: Dependencies (5)

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

Full Source

EquipmentSlot.java102 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity;
2
3
import io.netty.buffer.ByteBuf;
4
import java.util.List;
5
import java.util.function.IntFunction;
6
import net.minecraft.network.codec.ByteBufCodecs;
7
import net.minecraft.network.codec.StreamCodec;
8
import net.minecraft.util.ByIdMap;
9
import net.minecraft.util.StringRepresentable;
10
import net.minecraft.world.item.ItemStack;
11
12
public enum EquipmentSlot implements StringRepresentable {
13
	MAINHAND(EquipmentSlot.Type.HAND, 0, 0, "mainhand"),
14
	OFFHAND(EquipmentSlot.Type.HAND, 1, 5, "offhand"),
15
	FEET(EquipmentSlot.Type.HUMANOID_ARMOR, 0, 1, 1, "feet"),
16
	LEGS(EquipmentSlot.Type.HUMANOID_ARMOR, 1, 1, 2, "legs"),
17
	CHEST(EquipmentSlot.Type.HUMANOID_ARMOR, 2, 1, 3, "chest"),
18
	HEAD(EquipmentSlot.Type.HUMANOID_ARMOR, 3, 1, 4, "head"),
19
	BODY(EquipmentSlot.Type.ANIMAL_ARMOR, 0, 1, 6, "body"),
20
	SADDLE(EquipmentSlot.Type.SADDLE, 0, 1, 7, "saddle");
21
22
	public static final int NO_COUNT_LIMIT = 0;
23
	public static final List<EquipmentSlot> VALUES = List.of(values());
24
	public static final IntFunction<EquipmentSlot> BY_ID = ByIdMap.continuous(s -> s.id, values(), ByIdMap.OutOfBoundsStrategy.ZERO);
25
	public static final StringRepresentable.EnumCodec<EquipmentSlot> CODEC = StringRepresentable.fromEnum(EquipmentSlot::values);
26
	public static final StreamCodec<ByteBuf, EquipmentSlot> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, s -> s.id);
27
	private final EquipmentSlot.Type type;
28
	private final int index;
29
	private final int countLimit;
30
	private final int id;
31
	private final String name;
32
33
	EquipmentSlot(final EquipmentSlot.Type type, final int index, final int countLimit, final int id, final String name) {
34
		this.type = type;
35
		this.index = index;
36
		this.countLimit = countLimit;
37
		this.id = id;
38
		this.name = name;
39
	}
40
41
	EquipmentSlot(final EquipmentSlot.Type type, final int index, final int filterFlag, final String name) {
42
		this(type, index, 0, filterFlag, name);
43
	}
44
45
	public EquipmentSlot.Type getType() {
46
		return this.type;
47
	}
48
49
	public int getIndex() {
50
		return this.index;
51
	}
52
53
	public int getIndex(final int base) {
54
		return base + this.index;
55
	}
56
57
	public ItemStack limit(final ItemStack toEquip) {
58
		return this.countLimit > 0 ? toEquip.split(this.countLimit) : toEquip;
59
	}
60
61
	public int getId() {
62
		return this.id;
63
	}
64
65
	public int getFilterBit(final int offset) {
66
		return this.id + offset;
67
	}
68
69
	public String getName() {
70
		return this.name;
71
	}
72
73
	public boolean isArmor() {
74
		return this.type == EquipmentSlot.Type.HUMANOID_ARMOR || this.type == EquipmentSlot.Type.ANIMAL_ARMOR;
75
	}
76
77
	@Override
78
	public String getSerializedName() {
79
		return this.name;
80
	}
81
82
	public boolean canIncreaseExperience() {
83
		return this.type != EquipmentSlot.Type.SADDLE;
84
	}
85
86
	public static EquipmentSlot byName(final String name) {
87
		EquipmentSlot slot = CODEC.byName(name);
88
		if (slot != null) {
89
			return slot;
90
		} else {
91
			throw new IllegalArgumentException("Invalid slot '" + name + "'");
92
		}
93
	}
94
95
	public enum Type {
96
		HAND,
97
		HUMANOID_ARMOR,
98
		ANIMAL_ARMOR,
99
		SADDLE;
100
	}
101
}
102

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