《Minecraft 1.14.4 Forge Mod的制作 第6部分 【新增5种工具】》
首先
参考 – Minecraft 1.14/1.14.3 中的 Modding 教程的工具
?开发环境
在这里,我们将环境设定如下。
Windows 10
JDK 8u211
Minecraft 1.14.4
Minecraft Forge 1.14.4 (28.1.0)
IntelliJ IDEA 2019.2.3
声明物品
package jp.yuyu.biwako_mod.lists;
import net.minecraft.item.Item;
public class ItemList {
public static Item BiwakoIngot;
public static Item BiwakoBlock;
// 5種ツール
public static Item BiwakoAxe;
public static Item BiwakoHoe;
public static Item BiwakoPickaxe;
public static Item BiwakoShovel;
public static Item BiwakoSword;
}
生成工具材料
枚举类型
只需要一个选项,用汉语本地语言释义以下内容:
工具
収穫レベル 木・金(0)、石(1)、鉄(2)、ダイヤ(3) 黒曜石を回収できるものにしたいなら3に設定
耐久力
採掘効率
攻撃力
エンチャント能力 高レベルのエンチャントのつきやすさ
将提供具有参数的材料的信息。
原始材料预计将来会增加很多,
这种情况下我们会创建一个易于管理的Enum类。
解释Enum是很容易理解的[通过使用Enum进行行为控制]。
工具材料清单.java
暂时先将整个源代码都列出来。
package jp.yuyu.biwako_mod.lists;
import net.minecraft.item.IItemTier;
import net.minecraft.item.Item;
import net.minecraft.item.crafting.Ingredient;
public enum ToolMaterialList implements IItemTier {
// Enumの宣言
MATERIAL_BIWAKO(3, 1000, 15.0f, 3.0f,25, ItemList.BiwakoIngot);
// メンバ変数
private float attackDamage, efficiency;
private int maxUses, harvestLevel, enchantability;
private Item repairMaterial;
// コンストラクタ
private ToolMaterialList(int harvestLevelIn, int maxUsesIn, float efficiencyIn, float attackDamageIn, int enchantabilityIn, Item repairMaterialIn) {
this.harvestLevel = harvestLevelIn;
this.maxUses = maxUsesIn;
this.efficiency = efficiencyIn;
this.attackDamage = attackDamageIn;
this.enchantability = enchantabilityIn;
this.repairMaterial = repairMaterialIn;
}
// メソッド
@Override
public float getAttackDamage() {
return attackDamage;
}
@Override
public float getEfficiency() {
return efficiency;
}
@Override
public int getMaxUses() {
return maxUses;
}
@Override
public int getHarvestLevel() {
return harvestLevel;
}
@Override
public int getEnchantability() {
return enchantability;
}
@Override
public Ingredient getRepairMaterial() {
return Ingredient.fromItems(this.repairMaterial);
}
}
構造包含了四个部分:Enum声明、成员变量、构造函数和方法。正如解释文章中所写的那样,
由于成为对象的枚举,可以声明方法和成员变量以及赋予行为。
内部上,枚举的对象被视为常量,因此会预先生成与枚举数量相当的对象。
因此,如果想要增加原始素材,只需在此源代码中新添加Enum的声明即可。这次我尝试添加了MATERIAL_BIWAKO。
添加工具的类。
我会准备每个工具的附加类。
每个类继承并准备构造函数。
到目前为止,铁锹一直继承自ItemSpade类,但从这个版本开始,它的名称似乎变为了ShovelItem。
package jp.yuyu.biwako_mod.items;
import net.minecraft.item.AxeItem;
import net.minecraft.item.IItemTier;
public class ItemCustomAxe extends AxeItem {
public ItemCustomAxe(IItemTier tier, float attackDamageIn, float attackSpeedIn, Properties builder) {
super(tier, attackDamageIn, attackSpeedIn, builder);
}
}
package jp.yuyu.biwako_mod.items;
import net.minecraft.item.HoeItem;
import net.minecraft.item.IItemTier;
public class ItemCustomHoe extends HoeItem {
public ItemCustomHoe(IItemTier tier, float attackSpeedIn, Properties builder) {
super(tier, attackSpeedIn, builder);
}
}
package jp.yuyu.biwako_mod.items;
import net.minecraft.item.PickaxeItem;
import net.minecraft.item.IItemTier;
public class ItemCustomPickaxe extends PickaxeItem {
public ItemCustomPickaxe(IItemTier tier, float attackDamageIn, float attackSpeedIn, Properties builder) {
super(tier, attackDamageIn, attackSpeedIn, builder);
}
}
package jp.yuyu.biwako_mod.items;
import net.minecraft.item.IItemTier;
import net.minecraft.item.ShovelItem;
public class ItemCustomShovel extends ShovelItem {
public ItemCustomShovel(IItemTier tier, float attackDamageIn, float attackSpeedIn, Properties builder) {
super(tier, attackDamageIn, attackSpeedIn, builder);
}
}
package jp.yuyu.biwako_mod.items;
import net.minecraft.item.IItemTier;
import net.minecraft.item.SwordItem;
public class ItemCustomSword extends SwordItem {
public ItemCustomSword(IItemTier tier, int attackDamageIn, float attackSpeedIn, Properties builder) {
super(tier, attackDamageIn, attackSpeedIn, builder);
}
}
IItemTier tier ツールマテリアル
Properties builder クリエイティブタブ
注册物品
我們將像註冊無功能物品時一樣,繼續進行物品的註冊。
這次我們嘗試設定鑽石工具的攻擊力和攻擊速度與之相同。
public static void onItemsRegistry(final RegistryEvent.Register<Item> itemRegistryEvent) {
LOGGER.info("HELLO from Register Item");
itemRegistryEvent.getRegistry().registerAll(
ItemList.BiwakoAxe = new ItemCustomAxe(ToolMaterialList.MATERIAL_BIWAKO,5.0f,-3.0f,new Item.Properties().group(ItemGroup_Biwako))
.setRegistryName(new ResourceLocation(MOD_ID,"biwako_axe")),
ItemList.BiwakoHoe = new ItemCustomHoe(ToolMaterialList.MATERIAL_BIWAKO,0.0f,new Item.Properties().group(ItemGroup_Biwako))
.setRegistryName(new ResourceLocation(MOD_ID,"biwako_hoe")),
ItemList.BiwakoPickaxe = new ItemCustomPickaxe(ToolMaterialList.MATERIAL_BIWAKO,1,-2.8f,new Item.Properties().group(ItemGroup_Biwako))
.setRegistryName(new ResourceLocation(MOD_ID,"biwako_pickaxe")),
ItemList.BiwakoShovel = new ItemCustomShovel(ToolMaterialList.MATERIAL_BIWAKO,1.5f,-3.0f,new Item.Properties().group(ItemGroup_Biwako))
.setRegistryName(new ResourceLocation(MOD_ID,"biwako_shovel")),
ItemList.BiwakoSword = new ItemCustomSword(ToolMaterialList.MATERIAL_BIWAKO,3,-2.4f,new Item.Properties().group(ItemGroup_Biwako))
.setRegistryName(new ResourceLocation(MOD_ID,"biwako_sword"))
);
}
翻译文件
{
"item.biwako_mod.biwako_axe": "Biwako Axe",
"item.biwako_mod.biwako_hoe": "Biwako Hoe",
"item.biwako_mod.biwako_pickaxe": "Biwako Pickaxe",
"item.biwako_mod.biwako_shovel": "Biwako Shovel",
"item.biwako_mod.biwako_sword": "Biwako Sword"
}
{
"item.biwako_mod.biwako_axe": "琵琶湖の斧",
"item.biwako_mod.biwako_hoe": "琵琶湖のクワ",
"item.biwako_mod.biwako_pickaxe": "琵琶湖のピッケル",
"item.biwako_mod.biwako_shovel": "琵琶湖のスコップ",
"item.biwako_mod.biwako_sword": "琵琶湖の剣"
}
模型文件
如果是为工具准备的模型文件,则将parent指定为item/handheld。
其他情况保持不变。
{
"parent": "item/handheld",
"textures": {
"layer0": "biwako_mod:items/biwako_axe"
}
}
{
"parent": "item/handheld",
"textures": {
"layer0": "biwako_mod:items/biwako_hoe"
}
}
{
"parent": "item/handheld",
"textures": {
"layer0": "biwako_mod:items/biwako_pickaxe"
}
}
{
"parent": "item/handheld",
"textures": {
"layer0": "biwako_mod:items/biwako_shovel"
}
}
{
"parent": "item/handheld",
"textures": {
"layer0": "biwako_mod:items/biwako_sword"
}
}
纹理文件
创建并放置纹理。
启动Minecraft
我在Github上公开了项目。

参考 – Minecraft 1.14/1.14.3 中的 Modding 教程的工具
?开发环境
在这里,我们将环境设定如下。
-
Windows 10
JDK 8u211
Minecraft 1.14.4
Minecraft Forge 1.14.4 (28.1.0)
IntelliJ IDEA 2019.2.3
声明物品
package jp.yuyu.biwako_mod.lists;
import net.minecraft.item.Item;
public class ItemList {
public static Item BiwakoIngot;
public static Item BiwakoBlock;
// 5種ツール
public static Item BiwakoAxe;
public static Item BiwakoHoe;
public static Item BiwakoPickaxe;
public static Item BiwakoShovel;
public static Item BiwakoSword;
}
生成工具材料
枚举类型
package jp.yuyu.biwako_mod.lists;
import net.minecraft.item.Item;
public class ItemList {
public static Item BiwakoIngot;
public static Item BiwakoBlock;
// 5種ツール
public static Item BiwakoAxe;
public static Item BiwakoHoe;
public static Item BiwakoPickaxe;
public static Item BiwakoShovel;
public static Item BiwakoSword;
}
枚举类型
只需要一个选项,用汉语本地语言释义以下内容:
工具
-
収穫レベル 木・金(0)、石(1)、鉄(2)、ダイヤ(3) 黒曜石を回収できるものにしたいなら3に設定
耐久力
採掘効率
攻撃力
エンチャント能力 高レベルのエンチャントのつきやすさ
将提供具有参数的材料的信息。
原始材料预计将来会增加很多,
这种情况下我们会创建一个易于管理的Enum类。
解释Enum是很容易理解的[通过使用Enum进行行为控制]。

工具材料清单.java
暂时先将整个源代码都列出来。
package jp.yuyu.biwako_mod.lists;
import net.minecraft.item.IItemTier;
import net.minecraft.item.Item;
import net.minecraft.item.crafting.Ingredient;
public enum ToolMaterialList implements IItemTier {
// Enumの宣言
MATERIAL_BIWAKO(3, 1000, 15.0f, 3.0f,25, ItemList.BiwakoIngot);
// メンバ変数
private float attackDamage, efficiency;
private int maxUses, harvestLevel, enchantability;
private Item repairMaterial;
// コンストラクタ
private ToolMaterialList(int harvestLevelIn, int maxUsesIn, float efficiencyIn, float attackDamageIn, int enchantabilityIn, Item repairMaterialIn) {
this.harvestLevel = harvestLevelIn;
this.maxUses = maxUsesIn;
this.efficiency = efficiencyIn;
this.attackDamage = attackDamageIn;
this.enchantability = enchantabilityIn;
this.repairMaterial = repairMaterialIn;
}
// メソッド
@Override
public float getAttackDamage() {
return attackDamage;
}
@Override
public float getEfficiency() {
return efficiency;
}
@Override
public int getMaxUses() {
return maxUses;
}
@Override
public int getHarvestLevel() {
return harvestLevel;
}
@Override
public int getEnchantability() {
return enchantability;
}
@Override
public Ingredient getRepairMaterial() {
return Ingredient.fromItems(this.repairMaterial);
}
}
構造包含了四个部分:Enum声明、成员变量、构造函数和方法。正如解释文章中所写的那样,
由于成为对象的枚举,可以声明方法和成员变量以及赋予行为。
内部上,枚举的对象被视为常量,因此会预先生成与枚举数量相当的对象。
因此,如果想要增加原始素材,只需在此源代码中新添加Enum的声明即可。这次我尝试添加了MATERIAL_BIWAKO。
添加工具的类。
我会准备每个工具的附加类。

每个类继承并准备构造函数。
到目前为止,铁锹一直继承自ItemSpade类,但从这个版本开始,它的名称似乎变为了ShovelItem。
package jp.yuyu.biwako_mod.items;
import net.minecraft.item.AxeItem;
import net.minecraft.item.IItemTier;
public class ItemCustomAxe extends AxeItem {
public ItemCustomAxe(IItemTier tier, float attackDamageIn, float attackSpeedIn, Properties builder) {
super(tier, attackDamageIn, attackSpeedIn, builder);
}
}
package jp.yuyu.biwako_mod.items;
import net.minecraft.item.HoeItem;
import net.minecraft.item.IItemTier;
public class ItemCustomHoe extends HoeItem {
public ItemCustomHoe(IItemTier tier, float attackSpeedIn, Properties builder) {
super(tier, attackSpeedIn, builder);
}
}
package jp.yuyu.biwako_mod.items;
import net.minecraft.item.PickaxeItem;
import net.minecraft.item.IItemTier;
public class ItemCustomPickaxe extends PickaxeItem {
public ItemCustomPickaxe(IItemTier tier, float attackDamageIn, float attackSpeedIn, Properties builder) {
super(tier, attackDamageIn, attackSpeedIn, builder);
}
}
package jp.yuyu.biwako_mod.items;
import net.minecraft.item.IItemTier;
import net.minecraft.item.ShovelItem;
public class ItemCustomShovel extends ShovelItem {
public ItemCustomShovel(IItemTier tier, float attackDamageIn, float attackSpeedIn, Properties builder) {
super(tier, attackDamageIn, attackSpeedIn, builder);
}
}
package jp.yuyu.biwako_mod.items;
import net.minecraft.item.IItemTier;
import net.minecraft.item.SwordItem;
public class ItemCustomSword extends SwordItem {
public ItemCustomSword(IItemTier tier, int attackDamageIn, float attackSpeedIn, Properties builder) {
super(tier, attackDamageIn, attackSpeedIn, builder);
}
}
-
IItemTier tier ツールマテリアル
Properties builder クリエイティブタブ
注册物品
我們將像註冊無功能物品時一樣,繼續進行物品的註冊。
這次我們嘗試設定鑽石工具的攻擊力和攻擊速度與之相同。
public static void onItemsRegistry(final RegistryEvent.Register<Item> itemRegistryEvent) {
LOGGER.info("HELLO from Register Item");
itemRegistryEvent.getRegistry().registerAll(
ItemList.BiwakoAxe = new ItemCustomAxe(ToolMaterialList.MATERIAL_BIWAKO,5.0f,-3.0f,new Item.Properties().group(ItemGroup_Biwako))
.setRegistryName(new ResourceLocation(MOD_ID,"biwako_axe")),
ItemList.BiwakoHoe = new ItemCustomHoe(ToolMaterialList.MATERIAL_BIWAKO,0.0f,new Item.Properties().group(ItemGroup_Biwako))
.setRegistryName(new ResourceLocation(MOD_ID,"biwako_hoe")),
ItemList.BiwakoPickaxe = new ItemCustomPickaxe(ToolMaterialList.MATERIAL_BIWAKO,1,-2.8f,new Item.Properties().group(ItemGroup_Biwako))
.setRegistryName(new ResourceLocation(MOD_ID,"biwako_pickaxe")),
ItemList.BiwakoShovel = new ItemCustomShovel(ToolMaterialList.MATERIAL_BIWAKO,1.5f,-3.0f,new Item.Properties().group(ItemGroup_Biwako))
.setRegistryName(new ResourceLocation(MOD_ID,"biwako_shovel")),
ItemList.BiwakoSword = new ItemCustomSword(ToolMaterialList.MATERIAL_BIWAKO,3,-2.4f,new Item.Properties().group(ItemGroup_Biwako))
.setRegistryName(new ResourceLocation(MOD_ID,"biwako_sword"))
);
}
翻译文件
{
"item.biwako_mod.biwako_axe": "Biwako Axe",
"item.biwako_mod.biwako_hoe": "Biwako Hoe",
"item.biwako_mod.biwako_pickaxe": "Biwako Pickaxe",
"item.biwako_mod.biwako_shovel": "Biwako Shovel",
"item.biwako_mod.biwako_sword": "Biwako Sword"
}
{
"item.biwako_mod.biwako_axe": "琵琶湖の斧",
"item.biwako_mod.biwako_hoe": "琵琶湖のクワ",
"item.biwako_mod.biwako_pickaxe": "琵琶湖のピッケル",
"item.biwako_mod.biwako_shovel": "琵琶湖のスコップ",
"item.biwako_mod.biwako_sword": "琵琶湖の剣"
}
模型文件
{
"item.biwako_mod.biwako_axe": "Biwako Axe",
"item.biwako_mod.biwako_hoe": "Biwako Hoe",
"item.biwako_mod.biwako_pickaxe": "Biwako Pickaxe",
"item.biwako_mod.biwako_shovel": "Biwako Shovel",
"item.biwako_mod.biwako_sword": "Biwako Sword"
}
{
"item.biwako_mod.biwako_axe": "琵琶湖の斧",
"item.biwako_mod.biwako_hoe": "琵琶湖のクワ",
"item.biwako_mod.biwako_pickaxe": "琵琶湖のピッケル",
"item.biwako_mod.biwako_shovel": "琵琶湖のスコップ",
"item.biwako_mod.biwako_sword": "琵琶湖の剣"
}
如果是为工具准备的模型文件,则将parent指定为item/handheld。
其他情况保持不变。
{
"parent": "item/handheld",
"textures": {
"layer0": "biwako_mod:items/biwako_axe"
}
}
{
"parent": "item/handheld",
"textures": {
"layer0": "biwako_mod:items/biwako_hoe"
}
}
{
"parent": "item/handheld",
"textures": {
"layer0": "biwako_mod:items/biwako_pickaxe"
}
}
{
"parent": "item/handheld",
"textures": {
"layer0": "biwako_mod:items/biwako_shovel"
}
}
{
"parent": "item/handheld",
"textures": {
"layer0": "biwako_mod:items/biwako_sword"
}
}
纹理文件
创建并放置纹理。


启动Minecraft
我在Github上公开了项目。

我在Github上公开了项目。