新建ItemVoidSword
ItemVoidSword.java
package com.example.items; public class ItemVoidSword extends SwordItem { public ItemVoidSword() { super(toolMaterial, 232, -2.4F, new Settings().group(GroupLoader.GROUPHAHA)); } }
我们可以看到4个参数,第一个是工具的属性,第二个是攻击力,第三个是攻击速度,最后一个是这个物品的一些设置。
其中武器的属性需要我们创建一个枚举类MItemTier
MItemTier.java
package com.example.items; public enum MItemTier implements ToolMaterial { VOID(3, 1000, 4.0F, 0.0F, 15, () -> { return Ingredient.ofItems(ItemLoader.VOID_INGOT); }); private final int miningLevel; private final int itemDurability; private final float miningSpeed; private final float attackDamage; private final int enchantability; private final SupplierrepairIngredient; MItemTier(int miningLevel, int itemDurability, float miningSpeed, float attackDamage, int enchantability, Supplier repairIngredient) { this.miningLevel = miningLevel; this.itemDurability = itemDurability; this.miningSpeed = miningSpeed; this.attackDamage = attackDamage; this.enchantability = enchantability; this.repairIngredient = repairIngredient; } public int getDurability() { return this.itemDurability; } public float getMiningSpeedMultiplier() { return this.miningSpeed; } public float getAttackDamage() { return this.attackDamage; } public int getMiningLevel() { return this.miningLevel; } public int getEnchantability() { return this.enchantability; } public Ingredient getRepairIngredient() { return (Ingredient) this.repairIngredient.get(); } }
其中有6个参数,依次是挖掘等级,耐久值,挖掘速度,攻击伤害,附魔能力,以及维修需要的材料。
我们回到我们的虚空剑里将工具属性设置为我们刚刚创建的。
ItemVoidSword.java
public class ItemVoidSword extends SwordItem { public ItemVoidSword() { super(MItemTier.VOID, 232, -2.4F, new Settings().group(GroupLoader.GROUPHAHA)); } }
注册物品
ItemLoader.java
public class ItemLoader { public static final Item VOID_INGOT = new ItemVoidIngot(); public static final Item VOID_SWORD = new ItemVoidSword(); public ItemLoader() { register("void_ingot", VOID_INGOT); register("void_sword",VOID_SWORD); } private void register(String name, Item item) { Registry.register(Registry.ITEM, new Identifier("haha", name), item); } }
创建材质
void_sword.json
{ "parent": "item/handheld", "textures": { "layer0": "haha:item/void_sword" } }
void_sword.png
检查文件的位置都正确
运行游戏看看效果。
看着欢迎分享,转载请注明来源:内存溢出
评论列表(0条)