= 创作分享 =
编程开发
怎么改武器的伤害类型?
jsghsgh

怎么改武器的伤害类型?

jsghsgh 于 2022-7-6 09:49 ( 1年前 ) [复制链接] [显示全部楼层] [打印]
1119 3
仙勾子
在LivingAttackEvent里检查是否用弓箭攻击,用hurt()造成虚空伤害
现在你的箭矢甚至能射杀创造模式的玩家!如图
未死之前,终有希望
发表于 2023-1-8 14:24:35 | 显示全部楼层

回复 | 举报

仙勾子
本帖最后由 xm94732568960 于 2023-1-8 14:38 编辑

这里写错了,会崩溃

屏幕截图 2023-01-08 143034.png (66.6 KB, 下载次数: 87)

屏幕截图 2023-01-08 143034.png
未死之前,终有希望
发表于 2023-1-8 14:33:13 | 显示全部楼层

回复 | 举报

仙勾子
本帖最后由 xm94732568960 于 2023-1-8 14:46 编辑

这么写更好,可以继承玩家使用箭矢的攻击判定
public static void on(LivingAttackEvent e){
    DamageSource source=e.getSource();
    if (source==null)return;
    Entity target=e.getEntity();
    if (target.getLevel()instanceof ClientLevel)return;
    Entity attacker=source.getEntity();
    Entity useEntity=source.getDirectEntity();
    if (useEntity instanceof Arrow){
        source.bypassArmor().bypassInvul();
        try {
            Field f=DamageSource.class.getDeclaredField("msgId");
            f.setAccessible(true);
            f.set(source,"outOfWorld");
        }catch (Exception exception){
        }
    }
}
未死之前,终有希望
发表于 2023-1-8 14:36:53 | 显示全部楼层

回复 | 举报

仙勾子
我写的是1.19.2的,1.12.2的稍作改动就行了
未死之前,终有希望
发表于 2023-1-8 14:46:20 | 显示全部楼层

回复 | 举报

百科目前不允许匿名发帖哦~ 请先 [ 登陆 ][ 注册 ] 吧~

本版积分规则

发新帖
  • 回复
  • 点评
  • 评分

[ MC百科(mcmod.cn) 除另有声明,所有开放公共编辑的内容均使用 BY-NC-SA 3.0 协议 ]

Minecraft百科CC协议
快速回复 返回顶部 返回列表