First we'll need to create a tool material for our new tools to use. We'll use Forge's `EnumHelper` class to add a value to the Minecraft `Item.ToolMaterial` enum.
```java
// ...
public class TutorialMod {
// ...
public static final Item.ToolMaterial copperToolMaterial = EnumHelper.addToolMaterial("COPPER", 2, 500, 6, 2, 14);
// ...
}
```
Each tool is going to be quite similar, so feel free to skip ahead to the one you want.
- [Sword](#sword)
- [Pickaxe](#pickaxe)
- [Axe](#axe)
- [Shovel](#shovel)
- [Hoe](#hoe)
## Sword
First we'll create an `ItemSword` class in the `item.tool` package inside our mod package. This class will extend the vanilla `ItemSword` class
In the constructor, we'll:
- Call the `super` constructor with the tool material
- Set the unlocalized and registry names
- Store the name for use in item model registration
We'll also implement `registerItemModel` and use the stored `name` to register our item model.
```java
package net.shadowfacts.tutorial.item.tool;
import net.minecraft.item.Item;
import net.shadowfacts.tutorial.TutorialMod;
public class ItemSword extends net.minecraft.item.ItemSword {
private String name;
public ItemSword(ToolMaterial material, String name) {
Next, we'll add our copper sword to our `ModItems` class.
```java
// ...
public class ModItems {
// ...
public static ItemSword copperSword = new ItemSword(TutorialMod.copperToolMaterial, "copper_sword");
public static void register(IForgeRegistry<Item> registry) {
registry.registerAll(
// ...
copperSword
);
}
public static void registerModels() {
// ...
copperSword.registerItemModel();
}
}
```
We'll also create our JSON item model at `assets/tutorial/models/item/copper_sword.json`. Unlike our other item models, the parent for the model will be `item/handheld` instead of `item/generated`. `item/handheld` provides the transformations used by handheld items, such as tools.
```json
{
"parent": "item/handheld",
"textures": {
"layer0": "tutorial:items/copper_sword"
}
}
```
We'll also need the texture, which you can download [here](https://raw.githubusercontent.com/shadowfacts/TutorialMod/1.12/src/main/resources/assets/tutorial/textures/items/copper_sword.png).
And lastly, we'll add a localization entry for the sword.
Next, we'll add our copper pickaxe to our `ModItems` class.
```java
// ...
public class ModItems {
// ...
public static ItemPickaxe copperPickaxe = new ItemPickaxe(TutorialMod.copperToolMaterial, "copper_pickaxe");
public static void register(IForgeRegistry<Item> registry) {
registry.registerAll(
// ...
copperPickaxe
);
}
public static void registerModels() {
// ...
copperPickaxe.registerItemModel();
}
}
```
We'll create a JSON model for our item at `assets/tutorial/models/item/copper_pickaxe.json`. This model will have a parent of `item/handheld` instead of `item/generated` so it inherits the transformations for handheld models.
```json
{
"parent": "item/handheld",
"textures": {
"layer0": "tutorial:items/copper_pickaxe"
}
}
```
You can download the texture for the copper pickaxe [here](https://raw.githubusercontent.com/shadowfacts/TutorialMod/1.12/src/main/resources/assets/tutorial/textures/items/copper_pickaxe.png).
Lastly, we'll need a localization entry for the pick.
First off, we'll need an `ItemAxe` class that extends the vanilla `ItemAxe` class.
If you look at the vanilla `ItemAxe` class, you'll notice that it has two constructors. One of them takes only a `ToolMaterial` whereas the other takes a `ToolMaterial` and two `float`s. Only vanilla `ToolMaterial`s will work with the `ToolMaterial` only constructor, any modded materials will cause an `ArrayIndexOutOfBoundsException` because of the hardcoded values in the `float` arrays in the `ItemAxe` class. Forge provides the secondary constructor that accepts the two `float`s as well, allowing modders to add axes with their own tool materials.
In the `ItemPickaxe` constructor, we will:
- Call the `super` constructor with the tool material and the damage and attack speeds used by the vanilla iron axe.
- Set the unlocalized and registry names
- Store the name for use in the item model registration
Additionally, we'll implement `registerItemModel` and use the stored `name` to register our model.
```java
package net.shadowfacts.tutorial.item.tool;
import net.minecraft.item.Item;
import net.shadowfacts.tutorial.TutorialMod;
public class ItemAxe extends net.minecraft.item.ItemAxe {
private String name;
public ItemAxe(ToolMaterial material, String name) {
Next, we'll add our copper axe to our `ModItems` class.
```java
// ...
public class ModItems {
// ...
public static ItemAxe copperAxe = new ItemAxe(TutorialMod.copperToolMaterial, "copper_axe");
public static void register(IForgeRegistry<Item> registry) {
registry.registerAll(
// ...
copperAxe
);
}
public static void registerModels() {
// ...
copperAxe.registerItemModel();
}
}
```
Additionally, we'll need a JSON item model. We'll create it at `assets/tutorials/models/item/copper_axe.json`.
Our model will have a parent of `item/handheld` instead of `item/generated` so it has the same transformations used by other hand-held items.
```json
{
"parent": "item/handheld",
"textures": {
"layer0": "tutorial:items/copper_axe"
}
}
```
You can download the texture for the copper axe [here](https://raw.githubusercontent.com/shadowfacts/TutorialMod/1.12/src/main/resources/assets/tutorial/textures/items/copper_axe.png).
Lastly, we'll need a localization entry for our axe.
Next, we'll add our copper shovel to our `ModItems` class.
```java
// ...
public class ModItems {
// ...
public static ItemShovel copperShovel = new ItemShovel(TutorialMod.copperToolMaterial, "copper_shovel");
public static void register(IForgeRegistry<Item> registry) {
registry.registerAll(
// ...
copperShovel
);
}
public static void registerModels() {
// ...
copperShovel.registerItemModel();
}
}
```
Next, we'll create a JSON item model for our shovel at `assets/tutorial/models/item/copper_shovel.json`. This model will have a parent of `item/handheld`, unlike our previous item models, so it inherits the transformations used by handheld items.
```json
{
"parent": "item/handheld",
"textures": {
"layer0": "tutorial:items/copper_shovel"
}
}
```
You can download the texture for our shovel [here](https://raw.githubusercontent.com/shadowfacts/TutorialMod/1.12/src/main/resources/assets/tutorial/textures/items/copper_shovel.png).
We'll also need a localization entry for our shovel.
public static ItemSword copperHoe = new ItemSword(TutorialMod.copperToolMaterial, "copper_hoe");
public static void register(IForgeRegistry<Item> registry) {
registry.registerAll(
// ...
copperHoe
);
}
// ...
}
```
Next, we'll create a JSON item model for our hoe at `assets/tutorial/models/item/copper_hoe.json`. This model will have a parent of `item/handheld` instead of `item/generated` so it inherits the transformations used by vanilla handheld items.
```json
{
"parent": "item/handheld",
"textures": {
"layer0": "tutorial:items/copper_hoe"
}
}
```
You can download the copper hoe texture [here](https://raw.githubusercontent.com/shadowfacts/TutorialMod/1.12/src/main/resources/assets/tutorial/textures/items/copper_hoe.png).
Lastly, we'll need a localization entry for our hoe.