|
本帖最后由 QQ酱199171 于 2023-1-25 23:48 编辑
用CraftTweaker可以修改,只不过有点麻烦,这里我先提供一个示例,写得简略了一些,没看懂可以追问:
首先是修改物品的属性Attribute,这里不包括耐久值。需要用到IIngredient类下的方法addGlobalAttributeModifier,使用之前还要导入两个类IIngredient和AttributeOperation。具体语法如下:- import crafttweaker.api.item.IIngredient;
- import crafttweaker.api.entity.AttributeOperation;
- // 所用到的方法具体语法如下(查询MCwiki有关修饰符的资料即能看明白):
- IIngredient.addGlobalAttributeModifier(
- attribute as Attribute, // 要替换的修饰符对应的属性
- uuid as string, // 要替换的修饰符的唯一标识符
- name as string, // 要替换的修饰符的新名字,个人建议写原名字
- value as double, // 要替换的修饰符的具体修饰值
- operation as AttributeOperation, // 确定修饰符运算模式
- slotTypes as MCEquipmentSlotType[] // 修饰符起作用的物品栏槽位
- ) as void;
复制代码 那这些参数该怎么填?比如我要把铁头盔的护甲值修改为5,IIngredient要写成<item:minecraft:iron_helmet>.anyDamage() (其中anyDamage()的作用就是使得该物品在任何耐久下都能保持属性数值的修改,如果不写,物品一旦损失耐久属性就会恢复成原来的样子),value就是修改后的数值5.0(前提是修饰符运算模式选加法),operation选用加法模式,填AttributeOperation.ADDITION。剩下的参数不知道填的话可以通过游戏内指令获取,主手随便拿个头盔,输入/ct hand attributes可看到聊天栏出现一些信息,如图所示。
最上面的<equipmentslottype:head>就是slotTypes,也就是头部槽位,<attribute:minecraft:generic.armor>就是护甲值属性attribute,其下对应的Name和ID就是方法中的name和uuid参数,记得打上引号。
至此,便可以写出如下代码 (为方便大量调用,写了个ArmorHelmet函数):
- import crafttweaker.api.item.IIngredient;
- import crafttweaker.api.entity.AttributeOperation;
- function ArmorHelmet(item as IIngredient, armor_value as double) as void {
- item.anyDamage().addGlobalAttributeModifier(
- <attribute:minecraft:generic.armor>,
- "2ad3f246-fee1-4e67-b886-69fd380bb150",
- "Armor modifier",
- armor_value,
- AttributeOperation.ADDITION, // 采用加法运算模式,具体参考MCwiki中修饰符页面
- [<equipmentslottype:head>] // 在头部槽位时起作用,可在中括号内添加多个槽位
- );
- }
- ArmorHelmet(<item:minecraft:iron_helmet>, 5.0); // 调用函数ArmorHelmet修改铁头盔护甲值为5.0
复制代码 /reload一下就可以看到铁头盔的护甲值成功修改了(原版数值为2):最后是耐久修改。在导入了IIngredient类的前提下直接写下面的语句即可搞定(也就是说可直接加在上面代码的后面):
- <item:minecraft:iron_helmet>.maxDamage = 2000; // 直接修改耐久值为2000
复制代码 相关链接(有关修饰符的介绍在第三个链接):
IIngredient - CraftTweaker Documentation (blamejared.com)
AttributeOperation - CraftTweaker Documentation (blamejared.com)
属性 - Minecraft Wiki,最详细的我的世界百科 (fandom.com)
自我吐槽→刚刚体验了Potato推荐的Property Modifier,相比我的来说真的是极度简便[笑哭]
|
|