(This article is one of a series of commentary articles)
First article: Introduction Previous article: 4. Add Tools Next article: 6. Add Recipes
In 4. Addition of tools, tools including swords have been added. The next thing I want after getting a weapon is armor! Let's add armor this time.
ItemList.java
//...
public class ItemList {
public static Item ExampleHelmet = new ArmorItem(ArmorMaterial.IRON, EquipmentSlotType.HEAD, new Item.Properties().group(ExampleItemGroup.DEFAULT))
.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_helmet"));
public static Item ExampleChestplate = new ArmorItem(ArmorMaterial.IRON, EquipmentSlotType.CHEST, new Item.Properties().group(ExampleItemGroup.DEFAULT))
.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_chestplate"));
public static Item ExampleLeggings = new ArmorItem(ArmorMaterial.IRON, EquipmentSlotType.LEGS, new Item.Properties().group(ExampleItemGroup.DEFAULT))
.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_leggings"));
public static Item ExampleBoots = new ArmorItem(ArmorMaterial.IRON, EquipmentSlotType.FEET, new Item.Properties().group(ExampleItemGroup.DEFAULT))
.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_boots"));
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
event.getRegistry().registerAll(
ExampleHelmet,
ExampleChestplate,
ExampleLeggings,
ExampleBoots
);
}
}
This time, instead of creating a separate class, declare the ʻArmorItem class directly in ʻItemList
.
The arguments are, in order, material, slot location, and item properties.
I will make detailed settings.
\src\main\resources\assets\example_mod
├ blockstates
├ lang
│ └ en_us.json
│ └ ja_jp.json
├ models
│ ├ block
│ └ item
│ ├ example_helmet.json
│ ├ example_chestplate.json
│ ├ example_leggings.json
│ └ example_boots.json
└ textures
├ blocks
└ items
├ example_helmet.png
├ example_chestplate.png
├ example_leggings.png
└ example_boots.png
en_us.json
{
"item.example_mod.example_helmet": "Example Helmet",
"item.example_mod.example_chestplate": "Example Chestplate",
"item.example_mod.example_leggings": "Example Leggings",
"item.example_mod.example_boots": "Example Boots"
}
ja_jp.json
{
"item.example_mod.example_helmet": "Example helmet",
"item.example_mod.example_chestplate": "Example chest plate",
"item.example_mod.example_leggings": "Example leggings",
"item.example_mod.example_boots": "Example boots"
}
example_helmet.json
{
"parent": "item/generated",
"textures": {
"layer0": "example_mod:items/example_helmet"
}
}
example_chestplate.json
{
"parent": "item/generated",
"textures": {
"layer0": "example_mod:items/example_chestplate"
}
}
example_leggings.json
{
"parent": "item/generated",
"textures": {
"layer0": "example_mod:items/example_leggings"
}
}
example_boots.json
{
"parent": "item/generated",
"textures": {
"layer0": "example_mod:items/example_boots"
}
}
Let's start the game.
** I can't add armor ... I can't! !! ** **
When I put it on, it looked like iron armor (in addition to that, the status and repair materials are actually like iron armor). This is because ʻArmorMaterial.IRON is passed as the material of ʻArmorItem
.
Let's define a new and unique material, as we did with the tool.
\src\main\java\jp\koteko\example_mod\
├ items
│ └ ExampleArmorMaterial.java
├ lists
├ ExampleItemGroup.java
└ ExampleMod.java
ExampleArmorMaterial.java
package jp.koteko.example_mod.items;
import jp.koteko.example_mod.ExampleMod;
import jp.koteko.example_mod.lists.ItemList;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.LazyLoadBase;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.function.Supplier;
public enum ExampleArmorMaterial implements IArmorMaterial {
EXAMPLE("example", 66, new int[]{3, 6, 8, 3}, 30, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 3.0F, () -> {
return Ingredient.fromItems(ItemList.ExampleIngot);
});
private static final int[] MAX_DAMAGE_ARRAY = new int[]{13, 15, 16, 11};
private final String name;
private final int maxDamageFactor;
private final int[] damageReductionAmountArray;
private final int enchantability;
private final SoundEvent soundEvent;
private final float toughness;
private final LazyLoadBase<Ingredient> repairMaterial;
private ExampleArmorMaterial(String nameIn, int maxDamageFactorIn, int[] damageReductionAmountsIn, int enchantabilityIn, SoundEvent equipSoundIn, float toughnessIn, Supplier<Ingredient> repairMaterialSupplier) {
this.name = nameIn;
this.maxDamageFactor = maxDamageFactorIn;
this.damageReductionAmountArray = damageReductionAmountsIn;
this.enchantability = enchantabilityIn;
this.soundEvent = equipSoundIn;
this.toughness = toughnessIn;
this.repairMaterial = new LazyLoadBase<>(repairMaterialSupplier);
}
public int getDurability(EquipmentSlotType slotIn) {
return MAX_DAMAGE_ARRAY[slotIn.getIndex()] * this.maxDamageFactor;
}
public int getDamageReductionAmount(EquipmentSlotType slotIn) {
return this.damageReductionAmountArray[slotIn.getIndex()];
}
public int getEnchantability() {
return this.enchantability;
}
public SoundEvent getSoundEvent() {
return this.soundEvent;
}
public Ingredient getRepairMaterial() {
return this.repairMaterial.getValue();
}
@OnlyIn(Dist.CLIENT)
public String getName() {
return ExampleMod.MOD_ID + ":" + this.name;
}
public float getToughness() {
return this.toughness;
}
}
name
: Internal name
maxDamageFactor
: Basic endurance coefficient
MAX_DAMAGE_ARRAY
: Durability value for each part
damageReductionAmountArray
: Defensive power for each part
ʻEnchantability: Enchantment efficiency
soundEvent: Sound when attached
toughness: Armor strength [^ 1]
repairMaterial`: Repair material
** [Durability value of each part] = [maxDamageFactor] × [MAX_DAMAGE_ARRAY [Part]] **
I tried to make it stronger than diamond. Change the armor material to this.
ItemList.java
//...
public class ItemList {
public static Item ExampleHelmet = new ArmorItem(ExampleArmorMaterial.EXAMPLE, EquipmentSlotType.HEAD, new Item.Properties().group(ExampleItemGroup.DEFAULT))
.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_helmet"));
public static Item ExampleChestplate = new ArmorItem(ExampleArmorMaterial.EXAMPLE, EquipmentSlotType.CHEST, new Item.Properties().group(ExampleItemGroup.DEFAULT))
.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_chestplate"));
public static Item ExampleLeggings = new ArmorItem(ExampleArmorMaterial.EXAMPLE, EquipmentSlotType.LEGS, new Item.Properties().group(ExampleItemGroup.DEFAULT))
.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_leggings"));
public static Item ExampleBoots = new ArmorItem(ExampleArmorMaterial.EXAMPLE, EquipmentSlotType.FEET, new Item.Properties().group(ExampleItemGroup.DEFAULT))
.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_boots"));
//...
}
Start the game. ** A monster was born. ** The texture is not set.
\src\main\resources\assets\example_mod
├ blockstates
├ lang
├ models
└ textures
├ blocks
├ items
└ models
└ armor
├ example_layer_1.png
└ example_layer_2.png
Create a folder called \ assets \ example_mod \ textures \ models \ armor
and place [material internal name] _layer_1.png
and [material internal name] _layer_2.png
. Let's refer to the texture of vanilla armor.
It is a little difficult to understand because of the diamond-like color, but the texture is reflected properly. You can also see that the durability value is 66 * 13 = 858.
This time ** armor has been added! ** **
Creating Minecraft 1.14.4 Forge Mod Part 7 [Adding Armor]
[^ 1]: Value related to damage reduction. Reference