InteractionHand .java

net.minecraft.world.InteractionHand (enum): members: MAIN_HAND, OFF_HAND, asEquipmentSlot, asArm, BY_ID, STREAM_CODEC. imports: HumanoidArm, ByIdMap.

net.minecraft.worldenum34 linescommon1004 B

API Surface (2)

HumanoidArm asArm(final HumanoidArm mainArm)
EquipmentSlot asEquipmentSlot()

Fields & Constants (3)

BY_ID
STREAM_CODEC
id

Code Graph: Dependencies (5)

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

Full Source

InteractionHand.java34 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world;
2
3
import io.netty.buffer.ByteBuf;
4
import java.util.function.IntFunction;
5
import net.minecraft.network.codec.ByteBufCodecs;
6
import net.minecraft.network.codec.StreamCodec;
7
import net.minecraft.util.ByIdMap;
8
import net.minecraft.world.entity.EquipmentSlot;
9
import net.minecraft.world.entity.HumanoidArm;
10
11
public enum InteractionHand {
12
	MAIN_HAND(0),
13
	OFF_HAND(1);
14
15
	private static final IntFunction<InteractionHand> BY_ID = ByIdMap.continuous(h -> h.id, values(), ByIdMap.OutOfBoundsStrategy.ZERO);
16
	public static final StreamCodec<ByteBuf, InteractionHand> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, h -> h.id);
17
	private final int id;
18
19
	InteractionHand(final int id) {
20
		this.id = id;
21
	}
22
23
	public HumanoidArm asArm(final HumanoidArm mainArm) {
24
		return switch (this) {
25
			case MAIN_HAND -> mainArm;
26
			case OFF_HAND -> mainArm.getOpposite();
27
		};
28
	}
29
30
	public EquipmentSlot asEquipmentSlot() {
31
		return this == MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND;
32
	}
33
}
34

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