[Java] Let's create a mod for Minecraft 1.14.4 [5. Add armor]

(This article is one of a series of commentary articles)

First article: Introduction Previous article: 4. Add Tools Next article: 6. Add Recipes

Add armor

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. キャプチャ.PNG キャプチャ2.PNG ** 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. キャプチャ.PNG ** 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. キャプチャ.PNG 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! ** **

reference

Creating Minecraft 1.14.4 Forge Mod Part 7 [Adding Armor]

Next article

6. Add recipe

[^ 1]: Value related to damage reduction. Reference

Recommended Posts

[Java] Let's create a mod for Minecraft 1.14.4 [5. Add armor]
[Java] Let's create a mod for Minecraft 1.14.4 [7. Add progress]
[Java] Let's create a mod for Minecraft 1.14.4 [6. Add recipe]
[Java] Let's create a mod for Minecraft 1.16.1 [Add item]
[Java] Let's create a mod for Minecraft 1.14.4 [1. Add items]
[Java] Let's create a mod for Minecraft 1.14.4 [2. Add block]
[Java] Let's create a mod for Minecraft 1.16.1 [Add block]
[Java] Let's create a mod for Minecraft 1.14.4 [3. Add creative tab]
[Java] Let's create a mod for Minecraft 1.14.4 [Introduction]
[Java] Let's create a mod for Minecraft 1.16.1 [Introduction]
[Java] Let's create a mod for Minecraft 1.14.4 [99. Mod output]
[Java] Let's create a mod for Minecraft 1.16.1 [Add and generate trees]
[Java] Let's create a mod for Minecraft 1.14.4 [9. Add and generate trees]
[Java] Let's create a mod for Minecraft 1.14.4 [8. Add and generate ore]
[Java] Let's create a mod for Minecraft 1.14.4 [Extra edition]
[Java] Let's create a mod for Minecraft 1.16.1 [Basic file]
Let's create a Java development environment (updating)
Let's create a timed process with Java Timer! !!
Let's create a super-simple web framework in Java
[Java] Create a filter
[Java basics] Let's make a triangle with a for statement
Create a java method [Memo] [java11]
[Java] Create a temporary file
How to create a lightweight container image for Java apps
[Java twig] Create a parser combinator for recursive descent parsing 2
Create a MOB using the Minecraft Java Mythicmobs plugin | Preparation 1
Let's create a TODO application in Java 4 Implementation of posting function
How to sign a Minecraft MOD
Let's create a TODO application in Java 6 Implementation of search function
Let's create a TODO application in Java 8 Implementation of editing function
Create a Java project using Eclipse
[Java] How to create a folder
Let's create a TODO application in Java 1 Brief explanation of MVC
Let's create a TODO application in Java 5 Switch the display of TODO
Create a fluentd server for testing
Let's install Docker on Windows 10 and create a verification environment for CentOS 8!
[Java twig] Create a parser combinator for recursive descent parsing (also memoize)
Let's go with Watson Assistant (formerly Conversation) ⑤ Create a chatbot with Watson + Java + Slack
Create a java web application development environment with docker for mac part2
[Java] Create and apply a slide master
How to create a Maven repository for 2020
Create a TODO app in Java 7 Create Header
[Rails] Let's create a super simple Rails API
[Java] Let's make a DB access library!
Let's make a calculator application with Java ~ Create a display area in the window
Java (add2)
Java (add)
Let's create a versatile file storage (?) Operation library by abstracting file storage / acquisition in Java
[Azure] I tried to create a Java application for free-Web App creation- [Beginner]
How to create a database for H2 Database anywhere
A story about Java 11 support for Web services
Create a CSR with extended information in Java
Create a simple bulletin board with Java + MySQL
Let's create a REST API using WildFly Swarm.
Create a Lambda Container Image based on Java 15
[Java] Create something like a product search API
Let's create a RESTful email sending service + client
Try to create a bulletin board in Java
How to create pagination for a "kaminari" array
Let's create a custom tab view in SwiftUI 2.0
[Java] Create a collection with only one element