ArmorMaterial .java

net.minecraft.world.item.equipment.ArmorMaterial (record, 39 lines): members: durability, defense, enchantmentValue, equipSound, toughness, assetId.

net.minecraft.world.item.equipmentrecord39 linescommon1.6 KB

API Surface (2)

record ArmorMaterial(int durability, Map<ArmorType, Integer> defense, int enchantmentValue, Holder<SoundEvent> equipSound, float toughness, float knockbackResistance, TagKey<Item> repairIngredient, ResourceKey<EquipmentAsset> assetId)
ItemAttributeModifiers createAttributes(final ArmorType type)

String literals (1)

"armor."

Full Source

ArmorMaterial.java39 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item.equipment;
2
3
import java.util.Map;
4
import net.minecraft.core.Holder;
5
import net.minecraft.resources.Identifier;
6
import net.minecraft.resources.ResourceKey;
7
import net.minecraft.sounds.SoundEvent;
8
import net.minecraft.tags.TagKey;
9
import net.minecraft.world.entity.EquipmentSlotGroup;
10
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
11
import net.minecraft.world.entity.ai.attributes.Attributes;
12
import net.minecraft.world.item.Item;
13
import net.minecraft.world.item.component.ItemAttributeModifiers;
14
15
public record ArmorMaterial(
16
	int durability,
17
	Map<ArmorType, Integer> defense,
18
	int enchantmentValue,
19
	Holder<SoundEvent> equipSound,
20
	float toughness,
21
	float knockbackResistance,
22
	TagKey<Item> repairIngredient,
23
	ResourceKey<EquipmentAsset> assetId
24
) {
25
	public ItemAttributeModifiers createAttributes(final ArmorType type) {
26
		int defense = this.defense.getOrDefault(type, 0);
27
		ItemAttributeModifiers.Builder modifiers = ItemAttributeModifiers.builder();
28
		EquipmentSlotGroup slotGroup = EquipmentSlotGroup.bySlot(type.getSlot());
29
		Identifier modifierId = Identifier.withDefaultNamespace("armor." + type.getName());
30
		modifiers.add(Attributes.ARMOR, new AttributeModifier(modifierId, defense, AttributeModifier.Operation.ADD_VALUE), slotGroup);
31
		modifiers.add(Attributes.ARMOR_TOUGHNESS, new AttributeModifier(modifierId, this.toughness, AttributeModifier.Operation.ADD_VALUE), slotGroup);
32
		if (this.knockbackResistance > 0.0F) {
33
			modifiers.add(Attributes.KNOCKBACK_RESISTANCE, new AttributeModifier(modifierId, this.knockbackResistance, AttributeModifier.Operation.ADD_VALUE), slotGroup);
34
		}
35
36
		return modifiers.build();
37
	}
38
}
39

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