原理:
Random前置的内容不再赘述。
计分板设置:customdamage v1.2\data\customdamage\functions\load:
- scoreboard objectives add Customdamage dummy
- scoreboard objectives add Duriable dummy
- scoreboard objectives add Unbreaking dummy
- scoreboard objectives add DamageMax dummy
复制代码 共4个计分板,均为虚拟型。
分别将储存的信息:
Customdamage:要消耗的耐久;
Duriable:损害值;
Unbreaking:耐久等级;
DamageMax:该物品耐久的最大值。
超频执行函数:customdamage v1.2\data\customdamage\functions\tick:
- #对造成伤害的玩家执行“function”
- execute as @a[scores={Customdamage=1..},gamemode= !creative] run function customdamage:function
复制代码 检测有相应计分板数据,手上拿有对应物品,且不处于创造模式的玩家执行损耗命令。
执行函数:customdamage v1.2\data\customdamage\functions\function:
- #初始化数据
- scoreboard players set @s Unbreaking 0
- #放置潜影盒并获取玩家手中物品信息
- setblock ~ 255 ~ shulker_box{Items:[{Slot:0b,id:"minecraft:stone",Count:1b}]}
- data modify block ~ 255 ~ Items[0].id set from entity @s SelectedItem.id
- data modify block ~ 255 ~ Items[0].tag set from entity @s SelectedItem.tag
- function customdamage:max
- #耐久附魔模块
- execute as @s store result score @s Unbreaking run data get entity @s SelectedItem.tag.Enchantments.[{id:"minecraft:unbreaking"}].lvl
- scoreboard players add @s Unbreaking 1
- scoreboard players set #random_min random 1
- scoreboard players set #random_max random 65536
- function random:random
- scoreboard players operation @s random = #result random
- scoreboard players operation @s random *= @s Unbreaking
- #在潜影盒内扣除耐久
- execute as @s store result score @s Duriable run data get entity @s SelectedItem.tag.Damage 1
- scoreboard players add @s[scores={random=1..65536}] Duriable 1
- execute store result block ~ 255 ~ Items[0].tag.Damage short 1 run scoreboard players get @s Duriable
- #将潜影盒内物品调包到玩家手上并清除潜影盒
- replaceitem entity @s weapon.mainhand air
- execute if score @s Duriable > @s DamageMax run data remove block ~ 255 ~ Items
- loot replace entity @s weapon.mainhand 1 mine ~ 255 ~ minecraft:diamond_pickaxe{isShulkerMarker:1b}
- setblock ~ 255 ~ air
- #检测是否需要更多次消耗耐久
- scoreboard players remove @s Customdamage 1
- execute if entity @s[scores={Customdamage=1..}] run function cam:magic/weapon/customdamage/function
复制代码 #放置潜影盒并获取玩家手中物品信息,#将潜影盒内物品调包到玩家手上并清除潜影盒:这两块内容与修改玩家物品栏信息的方法相同,不再赘述。
只有一个问题,这里获取了手上物品的最大耐久值,后面还会讲到。
#耐久附魔模块:
原版耐久附魔计算机制如下:
对于多数物品,每次使用时消耗耐久度的概率将降至(100/(等级+1))%。物品的期望寿命为原来的(等级+1)倍。对于盔甲,每次使用时消耗耐久度的概率将降至(60+(40/(等级+1)))%(即耐久度每次都有20%/27%/30%的概率不会减少)。盔甲的期望寿命为原来的125%/136%/143%。 当物品单次承受的耐久度损耗超过1点时(例如使用钓鱼竿拉扯生物,或带有荆棘魔咒的盔甲造成反伤时),每1点损耗都将应用以上规则进行减免。
这里不涉及盔甲。
计算原理:
1、获取耐久附魔等级并加1,便于计算;
2、设置一个1到65536的随机数值,将这个数乘以耐久等级,若这个数还在1到65536的范围内,则扣除耐久。
(在一个范围内取任意值,将其乘以一个数n,数据还在原范围的概率为1/n)
因为计分板只支持整型(int,-2147483648~2147483647),所以要达到乘的效果只能在65536(2147483647开方)内计算,因此最多支持到耐久65536级。
#在潜影盒内扣除耐久:
获取一下物品损耗值,若满足上述条件,扣除1耐久。计算完后,储存到潜影盒里,再在下面返还给玩家。
最大耐久获取:customdamage v1.2\data\customdamage\functions\max:
- <div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:bow"}]} run scoreboard players set @s DamageMax 384</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:iron_sword"}]} run scoreboard players set @s DamageMax 250</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:stone_sword"}]} run scoreboard players set @s DamageMax 131</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:wooden_sword"}]} run scoreboard players set @s DamageMax 59</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:diamond_sword"}]} run scoreboard players set @s DamageMax 1561</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:golden_sword"}]} run scoreboard players set @s DamageMax 32</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:netherite_sword"}]} run scoreboard players set @s DamageMax 2031</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:iron_axe"}]} run scoreboard players set @s DamageMax 250</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:stone_axe"}]} run scoreboard players set @s DamageMax 131</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:wooden_axe"}]} run scoreboard players set @s DamageMax 59</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:diamond_axe"}]} run scoreboard players set @s DamageMax 1561</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:golden_axe"}]} run scoreboard players set @s DamageMax 32</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:netherite_axe"}]} run scoreboard players set @s DamageMax 2031</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:iron_pickaxe"}]} run scoreboard players set @s DamageMax 250</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:stone_pickaxe"}]} run scoreboard players set @s DamageMax 131</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:wooden_pickaxe"}]} run scoreboard players set @s DamageMax 59</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:diamond_pickaxe"}]} run scoreboard players set @s DamageMax 1561</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:golden_pickaxe"}]} run scoreboard players set @s DamageMax 32</div><div>execute if data block ~ 255 ~ {Items:[{Slot:0b,id:"minecraft:netherite_pickaxe"}]} run scoreboard players set @s DamageMax 2031</div>
复制代码 这里穷举了原版所有工具、武器的最大耐久值,用于在该物品耐久消耗到0时清除物品。
若要添加模组适配,请自行扩展此列表。
(我不确定mod物品是否有对应的可侦测的数据值,对mod一窍不通,所以就交给你们了)
讲解到此结束。
|
|