Skip to content

Commit

Permalink
Merge pull request #636
Browse files Browse the repository at this point in the history
* same team's hurt damage is limited

* fix

* 完成修正
  • Loading branch information
Azumic authored Jan 5, 2025
1 parent e4a362c commit 4db6b74
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 4db6b74

Please sign in to comment.