UID19188性别保密经验 EP铁粒 粒回帖0主题精华在线时间 小时注册时间2020-11-1最后登录1970-1-1
|
发表于 2026-1-18 01:02:20|显示全部楼层 IP:黑龙江省 本帖最后由 冥王大大 于 2026-1-18 17:02 编辑
脚本用自定义组件实现很容易,但前提是要会这个东西,比如: import { world, system } from"@minecraft/server"; system.beforeEvents.startup.subscribe((ini) => { ini.itemComponentRegistry.registerCustomComponent("gm:damage_in_range", {onHitEntity: (h, p) => {
const paras = p.params
const inidam = paras.min+Math.random()*(paras.max-paras.min)
const uplvl = (h.attackingEntity.getEffect("strength")?.amplifier??-1)+1
const downlvl = (h.attackingEntity.getEffect("weakness")?.amplifier??-1)+1
const sharplvl = h.itemStack.getComponent("minecraft:enchantable")?.getEnchantment("sharpness")?.level??0
let moddam = (1.3**uplvl)*inidam*(0.8**downlvl)+Math.floor(1.25*sharplvl)
if (h.hitEntity.getComponent("minecraft:type_family").hasTypeFamily("arthropod")) {
moddam = moddam+Math.floor(2.5*(h.itemStack.getComponent("minecraft:enchantable")?.getEnchantment("bane_of_arthropods")?.level??0))
}
if (h.hitEntity.getComponent("minecraft:type_family").hasTypeFamily("undead")) {
moddam = moddam+Math.floor(2.5*(h.itemStack.getComponent("minecraft:enchantable")?.getEnchantment("smite")?.level??0))
}
if (h.hitEntity.isInWater) {
moddam = moddam+Math.floor(2.5*(h.itemStack.getComponent("minecraft:enchantable")?.getEnchantment("impaling")?.level??0))
}
h.hitEntity.applyDamage(moddam, {cause: "entityAttack", damaingEntity: h.attackingEntity})
}});
}); 武器(剑)的JSON:
- {
- "format_version": "1.21.90",
- "minecraft:item": {
- "description": {
- "identifier": "namespace:test_sword",
- "menu_category": {
- "group": "minecraft:itemGroup.name.sword",
- "category": "equipment"
- }
- },
- "components": {
- "minecraft:icon": {
- "textures": {
- "default":"stick"
- }
- },
- "minecraft:durability": {
- "max_durability": 372,
- "damage_chance": {
- "min": 20,
- "max": 60
- }
- },
- "minecraft:hand_equipped": true,
- "minecraft:can_destroy_in_creative": false,
- "minecraft:max_stack_size": 1,
- "minecraft:mining_speed": 1,
- "minecraft:digger": {
- "use_efficiency": true,
- "destroy_speeds": [
- {
- "block": "minecraft:web",
- "speed": 15
- },
- {
- "block": "minecraft:bamboo",
- "speed": 100
- }
- ]
- },
- "gm:damage_in_range": {
- "min": 1,
- "max": 10
- }
- }
- }
- }
复制代码
需要注意,玩家是有基础伤害的,这个只是在玩家的基础伤害上加额外伤害,模拟伤害可能跟游戏逻辑有出入 |
2#2026-1-18 01:02:20回复(0)收起回复 |