ArmorSlot .java

net.minecraft.world.inventory.ArmorSlot (class): members: emptyIcon, getNoItemIcon, setByPlayer, slotIndex, mayPickup, getMaxStackSize, mayPlace, isActive.

net.minecraft.world.inventoryclass67 linescommonextends Slot1.8 KB

API Surface (5)

void setByPlayer(final ItemStack itemStack, final ItemStack previous)
int getMaxStackSize()
boolean mayPlace(final ItemStack itemStack)
boolean isActive()
boolean mayPickup(final Player player)

Fields & Constants (7)

owner
slot
emptyIcon
inventory
slotIndex
x
y

Full Source

ArmorSlot.java67 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.inventory;
2
3
import net.minecraft.resources.Identifier;
4
import net.minecraft.world.Container;
5
import net.minecraft.world.entity.EquipmentSlot;
6
import net.minecraft.world.entity.LivingEntity;
7
import net.minecraft.world.entity.player.Player;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
10
import net.minecraft.world.item.enchantment.EnchantmentHelper;
11
import org.jspecify.annotations.Nullable;
12
13
public class ArmorSlot extends Slot {
14
	private final LivingEntity owner;
15
	private final EquipmentSlot slot;
16
	private final @Nullable Identifier emptyIcon;
17
18
	public ArmorSlot(
19
		final Container inventory,
20
		final LivingEntity owner,
21
		final EquipmentSlot slot,
22
		final int slotIndex,
23
		final int x,
24
		final int y,
25
		final @Nullable Identifier emptyIcon
26
	) {
27
		super(inventory, slotIndex, x, y);
28
		this.owner = owner;
29
		this.slot = slot;
30
		this.emptyIcon = emptyIcon;
31
	}
32
33
	@Override
34
	public void setByPlayer(final ItemStack itemStack, final ItemStack previous) {
35
		this.owner.onEquipItem(this.slot, previous, itemStack);
36
		super.setByPlayer(itemStack, previous);
37
	}
38
39
	@Override
40
	public int getMaxStackSize() {
41
		return 1;
42
	}
43
44
	@Override
45
	public boolean mayPlace(final ItemStack itemStack) {
46
		return this.owner.isEquippableInSlot(itemStack, this.slot);
47
	}
48
49
	@Override
50
	public boolean isActive() {
51
		return this.owner.canUseSlot(this.slot);
52
	}
53
54
	@Override
55
	public boolean mayPickup(final Player player) {
56
		ItemStack itemStack = this.getItem();
57
		return !itemStack.isEmpty() && !player.isCreative() && EnchantmentHelper.has(itemStack, EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE)
58
			? false
59
			: super.mayPickup(player);
60
	}
61
62
	@Override
63
	public @Nullable Identifier getNoItemIcon() {
64
		return this.emptyIcon;
65
	}
66
}
67

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