285 words
1 minutes
02 面包剑
02 面包剑
public class BreadSwordHotItem extends SwordItem {
public BreadSwordHotItem(){
super(Tiers.STONE,new Properties().food(ModFoods.BREAD_SWORD_HOT));
}
}
public class BreadSwordItem extends SwordItem {
public BreadSwordItem() {
super(Tiers.STONE, new Properties().food(ModFoods.BREAD_SWORD));
}
@Override
public void onUseTick(Level level, LivingEntity livingEntity, ItemStack stack, int remainingUseDuration) {
if (remainingUseDuration%20==0){
livingEntity.addEffect(new MobEffectInstance(MobEffects.HARM,10,0)); // 使用添加一个瞬间伤害的效果。
}
super.onUseTick(level, livingEntity, stack, remainingUseDuration);
}
}
public class BreadSwordVeryHotItem extends SwordItem {
public BreadSwordVeryHotItem() {
super(Tiers.STONE,new Properties().food(ModFoods.BREAD_SWORD_VERY_HOT));
}
@Override
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
super.inventoryTick(stack, level, entity, slotId, isSelected);
ItemEnchantments itemenchantments = stack.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY);
Set<Object2IntMap.Entry<Holder<Enchantment>>> enchantments = itemenchantments.entrySet();
if (enchantments.isEmpty()){ // 添加火焰附加的附魔
RegistryAccess registryAccess = level.registryAccess();
Optional<HolderLookup.RegistryLookup<Enchantment>> enchantmentGetter = registryAccess.lookup(Registries.ENCHANTMENT);
Optional<Holder.Reference<Enchantment>> enchantmentReference = enchantmentGetter.get().get(Enchantments.FIRE_ASPECT);
stack.enchant(enchantmentReference.get(),2);
}
}
@Override
public void onUseTick(Level level, LivingEntity livingEntity, ItemStack stack, int remainingUseDuration) {
if (remainingUseDuration % 20==0){
livingEntity.setRemainingFireTicks(100); //使用时候着火。
}
}
@Override
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
tooltipComponents.add(Component.translatable("tooltip.neomafishmod.fire_happy")); // 添加额外的描述信息。
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
}
}
// 物品注册。
public static final DeferredItem<Item> BREAD_SWORD = registerItem("bread_sword", BreadSwordItem::new);
public static final DeferredItem<Item> BREAD_SWORD_HOT = registerItem("bread_sword_hot", BreadSwordHotItem::new);
public static final DeferredItem<Item> BREAD_SWORD_VERY_HOT = registerItem("bread_sword_very_hot", BreadSwordVeryHotItem::new);
模型
贴图
语言文件
至少得加一个英文的。
resources/assets/neomafishmod/lang/en_us.json
"item.neomafishmod.bread_sword": "bread_sword",
"item.neomafishmod.bread_sword_hot": "bread_sword_hot",
"item.neomafishmod.bread_sword_very_hot": "bread_sword_very_hot",
resources/assets/neomafishmod/lang/zh_cn.json
"item.neomafishmod.bread_sword": "法棍剑",
"item.neomafishmod.bread_sword_hot": "热的法棍剑",
"item.neomafishmod.bread_sword_very_hot": "火热♂的法棍剑",
还有那个”tooltip.neomafishmod.fire_happy”
"tooltip.neomafishmod.fire_happy": "Fire Happy",
// 其他需要国际化处理的内容同理。