本篇教程参考为的NeoForge1.20.4Mod开发的视频,这篇教程是我边学边总结的,与其说是教程更像我的学习笔记,如有不清楚的地方,大家可以在评论区提问。在我力所能及的范围内,我都会解答的。
设计新材料
创建ModItemTiers类
public enum ModItemTiers implements Tier {
RUBY (null, //不限制不可挖掘的方块
3, //挖掘等级
1000,//耐久度
6,//挖掘速度
3,//攻击加成
15,//工具附魔强度
()->Ingredient.of(ModItems.RUBY.get()));//修复材料:Ruby
private final TagKey<Block> incorrectBlockForDrops;//这是一个TagKey<Block>类型的字段,它定义了哪些方块不能使用该工具采集。TagKey 是 Minecraft 用来标记块的一种机制,通常用于定义一个方块类别(如矿石、植物等)
private final int level;//工具的挖掘等级,铁镐的等级为2
private final int uses;//工具的耐久度
private final float speed;//工具的挖掘速度
private final float damage;//工具的攻击伤害加成
private final int enchantmentValue;//工具的附魔值,决定了该工具能够获得的附魔强度
private final LazyLoadedValue<Ingredient> repairIngredient;//工具的修复材料,这是一个 LazyLoadedValue<Ingredient> 对象,表示修复该工具所需的物品(如修复工具的矿石、合成物等)LazyLoadedValue 是一个懒加载容器, 只有在需要时才会加载修复材料
private ModItemTiers(TagKey<Block> incorrectBlockForDrops, int level, int uses, float speed, float damage, int enchantmentValue, Supplier<Ingredient> repairIngredient){
this.incorrectBlockForDrops = incorrectBlockForDrops;
this.level=level;
this.uses=uses;
this.speed =speed;
this.damage=damage;
this.enchantmentValue=enchantmentValue;
this.repairIngredient=new LazyLoadedValue<>(repairIngredient);
}
@Override
public int getUses() {
return this.uses;
}
@Override
public float getSpeed() {
return this.speed;
}
@Override
public float getAttackDamageBonus() {
return this.damage;
}
@Override
public int getLevel() {
return this.level;
}
@Override
public int getEnchantmentValue() {
return this.enchantmentValue;
}
@Override
public @NotNull Ingredient getRepairIngredient() {
return this.repairIngredient.get();
}
@Override
public @Nullable TagKey<Block> getTag() {
return incorrectBlockForDrops;
}
}
创建RubySword类
public class RubySword extends SwordItem {
public RubySword() {
super(ModItemTiers.RUBY,
3,//伤害加成
-2,//攻击速度,越大攻速越快,但要是负数
new Properties());
}
}
武器最终伤害=材料加成+武器加成+空手加成(1)
我们的RubySword的伤害是7
最后不要忘记注册物品,添加到物品栏之类的操作
this.basicItem(ModItems.RUBYSWORD.get());
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END







暂无评论内容