diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/event/GunHurtMaidEvent.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/event/GunHurtMaidEvent.java index 935ae2936..0bf56d1cb 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/event/GunHurtMaidEvent.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/compat/tacz/event/GunHurtMaidEvent.java @@ -35,7 +35,8 @@ public void onPlayerHurt(LivingAttackEvent event) { DamageSource source = event.getSource(); if (entity instanceof Player player && isBulletDamage(source)) { Entity causingEntity = source.getEntity(); - if (causingEntity instanceof EntityMaid maid && maid.isOwnedBy(player)) { + // 主人和同 Team 玩家免伤 + if (causingEntity instanceof EntityMaid maid && maid.isAlliedTo(player)) { event.setCanceled(true); } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/passive/EntityMaid.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/passive/EntityMaid.java index 93b17212d..f78935e20 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/passive/EntityMaid.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/passive/EntityMaid.java @@ -738,9 +738,10 @@ public boolean hurt(DamageSource source, float amount) { if (MinecraftForge.EVENT_BUS.post(new MaidAttackEvent(this, source, amount))) { return false; } - if (source.getEntity() instanceof Player && this.isOwnedBy((Player) source.getEntity())) { - // 玩家对自己女仆的伤害数值为 1/5,最大为 2 + if (source.getEntity() instanceof Player player && this.isAlliedTo(player)) { + // 主人和同 Team 玩家对自己女仆的伤害数值为 1/5,最大为 2 amount = Mth.clamp(amount / 5, 0, 2); + return super.hurt(source, amount); } return super.hurt(source, amount); } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/projectile/EntityDanmaku.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/projectile/EntityDanmaku.java index 531f350cf..f9a25d208 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/projectile/EntityDanmaku.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/projectile/EntityDanmaku.java @@ -75,13 +75,12 @@ protected void onHitBlock(BlockHitResult result) { protected void onHitEntity(EntityHitResult result) { Entity thrower = getOwner(); Entity hit = result.getEntity(); - if (thrower instanceof TamableAnimal) { - TamableAnimal tameable = (TamableAnimal) thrower; - if (hit instanceof TamableAnimal && hasSameOwner(tameable, (TamableAnimal) hit)) { + if (thrower instanceof TamableAnimal tameable) { + if (hit instanceof TamableAnimal hitTameable && hasSameOwner(tameable, hitTameable)) { this.discard(); return; } - if (hit instanceof LivingEntity && tameable.isOwnedBy((LivingEntity) hit)) { + if (hit instanceof LivingEntity livingEntity && tameable.isAlliedTo(livingEntity)) { this.discard(); return; } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/event/EntityHurtEvent.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/event/EntityHurtEvent.java index f0133c85e..d5d51744b 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/event/EntityHurtEvent.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/event/EntityHurtEvent.java @@ -1,6 +1,5 @@ package com.github.tartaricacid.touhoulittlemaid.event; -import com.github.tartaricacid.touhoulittlemaid.api.event.MaidHurtEvent; import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MaidConfig; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; @@ -19,17 +18,17 @@ public final class EntityHurtEvent { public static void onArrowImpact(ProjectileImpactEvent event) { Entity attacker = event.getProjectile().getOwner(); HitResult ray = event.getRayTraceResult(); - if (attacker instanceof TamableAnimal && ray instanceof EntityHitResult) { - TamableAnimal thrower = (TamableAnimal) attacker; - Entity victim = ((EntityHitResult) ray).getEntity(); - if (victim instanceof TamableAnimal) { - TamableAnimal tameable = (TamableAnimal) victim; + if (attacker instanceof TamableAnimal thrower && ray instanceof EntityHitResult hitResult) { + Entity victim = hitResult.getEntity(); + if (victim instanceof TamableAnimal tameable) { + // 同一主人,那么免伤 if (tameable.getOwnerUUID() != null && tameable.getOwnerUUID().equals(thrower.getOwnerUUID())) { event.setCanceled(true); } } - if (victim instanceof LivingEntity) { - if (thrower.isOwnedBy((LivingEntity) victim)) { + if (victim instanceof LivingEntity livingVictim) { + // 主人和同 Team 玩家免伤 + if (thrower.isAlliedTo(livingVictim)) { event.setCanceled(true); } }