From 00fff469bee6f63752cd8149a3d9ec39d16ce476 Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Mon, 23 Jun 2025 02:46:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=85=B6=E4=BB=96=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E7=9A=84=E4=BC=A4=E5=AE=B3=E5=87=8F=E5=85=8D=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/vehicle/VehicleData.java | 11 ++----- .../superbwarfare/entity/Blu43Entity.java | 28 +++++----------- .../superbwarfare/entity/ClaymoreEntity.java | 28 +++++----------- .../superbwarfare/entity/TargetEntity.java | 24 +++++--------- .../superbwarfare/entity/Tm62Entity.java | 28 +++++----------- .../entity/projectile/Agm65Entity.java | 28 +++++----------- .../projectile/JavelinMissileEntity.java | 25 ++++---------- .../entity/projectile/MelonBombEntity.java | 23 +++---------- .../entity/projectile/Mk82Entity.java | 28 ++++------------ .../entity/projectile/SwarmDroneEntity.java | 27 ++++----------- .../entity/projectile/WgMissileEntity.java | 25 ++++---------- .../entity/vehicle/damage/DamageModifier.java | 33 ++++++++++++++----- 12 files changed, 100 insertions(+), 208 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/data/vehicle/VehicleData.java b/src/main/java/com/atsuishio/superbwarfare/data/vehicle/VehicleData.java index a62a8e5fc..5b3b72016 100644 --- a/src/main/java/com/atsuishio/superbwarfare/data/vehicle/VehicleData.java +++ b/src/main/java/com/atsuishio/superbwarfare/data/vehicle/VehicleData.java @@ -10,7 +10,6 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; import net.minecraft.util.Mth; -import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.EntityType; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; @@ -114,14 +113,8 @@ public class VehicleData { var modifier = new DamageModifier(); if (data.applyDefaultDamageModifiers) { - modifier.immuneTo(EntityType.POTION) - .immuneTo(EntityType.AREA_EFFECT_CLOUD) - .immuneTo(DamageTypes.FALL) - .immuneTo(DamageTypes.DROWN) - .immuneTo(DamageTypes.DRAGON_BREATH) - .immuneTo(DamageTypes.WITHER) - .immuneTo(DamageTypes.WITHER_SKULL) - .reduce(5, ModDamageTypes.VEHICLE_STRIKE); + modifier.addAll(DamageModifier.createDefaultModifier().toList()); + modifier.reduce(5, ModDamageTypes.VEHICLE_STRIKE); } return modifier.addAll(data.damageModifiers); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/Blu43Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/Blu43Entity.java index 38ff1a6e6..8d18a6072 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/Blu43Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/Blu43Entity.java @@ -1,5 +1,6 @@ package com.atsuishio.superbwarfare.entity; +import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModItems; @@ -21,7 +22,6 @@ import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.*; import net.minecraft.world.entity.decoration.HangingEntity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; @@ -71,25 +71,15 @@ public class Blu43Entity extends Entity implements GeoEntity, OwnableEntity { return !this.isRemoved(); } + private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier() + .multiply(0.02f, ModDamageTypes.CUSTOM_EXPLOSION) + .multiply(0.02f, ModDamageTypes.MINE) + .multiply(0.02f, ModDamageTypes.PROJECTILE_BOOM) + .multiply(0.02f, DamageTypes.EXPLOSION); + @Override - public boolean hurt(DamageSource source, float amount) { - if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud) - return false; - if (source.is(DamageTypes.FALL)) - return false; - if (source.is(DamageTypes.CACTUS)) - return false; - if (source.is(DamageTypes.DROWN)) - return false; - if (source.is(DamageTypes.DRAGON_BREATH)) - return false; - if (source.is(DamageTypes.WITHER)) - return false; - if (source.is(DamageTypes.WITHER_SKULL)) - return false; - if (source.is(ModDamageTypes.CUSTOM_EXPLOSION) || source.is(ModDamageTypes.MINE) || source.is(ModDamageTypes.PROJECTILE_BOOM) || source.is(DamageTypes.EXPLOSION)) { - amount *= 0.02f; - } + public boolean hurt(@NotNull DamageSource source, float amount) { + amount = DAMAGE_MODIFIER.compute(source, amount); if (source.getEntity() != null) { this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID()); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java index 16f308247..32f9f72ae 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java @@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.EntityFindUtil; @@ -18,10 +19,8 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.*; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; @@ -71,25 +70,14 @@ public class ClaymoreEntity extends Entity implements GeoEntity, OwnableEntity { return !this.isRemoved(); } + private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier() + .multiply(0.2f, ModDamageTypes.CUSTOM_EXPLOSION) + .multiply(0.2f, ModDamageTypes.MINE) + .multiply(0.2f, ModDamageTypes.PROJECTILE_BOOM); + @Override - public boolean hurt(DamageSource source, float amount) { - if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud) - return false; - if (source.is(DamageTypes.FALL)) - return false; - if (source.is(DamageTypes.CACTUS)) - return false; - if (source.is(DamageTypes.DROWN)) - return false; - if (source.is(DamageTypes.DRAGON_BREATH)) - return false; - if (source.is(DamageTypes.WITHER)) - return false; - if (source.is(DamageTypes.WITHER_SKULL)) - return false; - if (source.is(ModDamageTypes.CUSTOM_EXPLOSION) || source.is(ModDamageTypes.MINE) || source.is(ModDamageTypes.PROJECTILE_BOOM)) { - amount *= 0.2f; - } + public boolean hurt(@NotNull DamageSource source, float amount) { + amount = DAMAGE_MODIFIER.compute(source, amount); if (source.getEntity() != null) { this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID()); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java index fa08b6152..30aeb3478 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.entity; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.tools.FormatTool; @@ -21,7 +22,6 @@ import net.minecraft.world.entity.*; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; @@ -77,21 +77,15 @@ public class TargetEntity extends LivingEntity implements GeoEntity { return true; } + private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier() + .immuneTo(DamageTypes.LIGHTNING_BOLT) + .immuneTo(DamageTypes.FALLING_ANVIL) + .immuneTo(DamageTypes.MAGIC); + @Override - public boolean hurt(DamageSource source, float amount) { - if (source.is(DamageTypes.IN_FIRE) - || source.getDirectEntity() instanceof ThrownPotion - || source.getDirectEntity() instanceof AreaEffectCloud - || source.is(DamageTypes.FALL) - || source.is(DamageTypes.CACTUS) - || source.is(DamageTypes.DROWN) - || source.is(DamageTypes.LIGHTNING_BOLT) - || source.is(DamageTypes.FALLING_ANVIL) - || source.is(DamageTypes.DRAGON_BREATH) - || source.is(DamageTypes.WITHER) - || source.is(DamageTypes.WITHER_SKULL) - || source.is(DamageTypes.MAGIC) - || this.entityData.get(DOWN_TIME) > 0) { + public boolean hurt(@NotNull DamageSource source, float amount) { + amount = DAMAGE_MODIFIER.compute(source, amount); + if (amount <= 0 || this.entityData.get(DOWN_TIME) > 0) { return false; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/Tm62Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/Tm62Entity.java index 2e8a4dff3..5f53e4d4d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/Tm62Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/Tm62Entity.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.entity; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; +import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModItems; @@ -21,7 +22,6 @@ import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.*; import net.minecraft.world.entity.decoration.HangingEntity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; @@ -75,25 +75,15 @@ public class Tm62Entity extends Entity implements GeoEntity, OwnableEntity { return !this.isRemoved(); } + private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier() + .multiply(0.02f, ModDamageTypes.CUSTOM_EXPLOSION) + .multiply(0.02f, ModDamageTypes.MINE) + .multiply(0.02f, ModDamageTypes.PROJECTILE_BOOM) + .multiply(0.02f, DamageTypes.EXPLOSION); + @Override - public boolean hurt(DamageSource source, float amount) { - if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud) - return false; - if (source.is(DamageTypes.FALL)) - return false; - if (source.is(DamageTypes.CACTUS)) - return false; - if (source.is(DamageTypes.DROWN)) - return false; - if (source.is(DamageTypes.DRAGON_BREATH)) - return false; - if (source.is(DamageTypes.WITHER)) - return false; - if (source.is(DamageTypes.WITHER_SKULL)) - return false; - if (source.is(ModDamageTypes.CUSTOM_EXPLOSION) || source.is(ModDamageTypes.MINE) || source.is(ModDamageTypes.PROJECTILE_BOOM) || source.is(DamageTypes.EXPLOSION)) { - amount *= 0.02f; - } + public boolean hurt(@NotNull DamageSource source, float amount) { + amount = DAMAGE_MODIFIER.compute(source, amount); if (source.getEntity() != null) { this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID()); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Agm65Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Agm65Entity.java index fa211ff6a..fb9792b2e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Agm65Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Agm65Entity.java @@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.projectile; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage; import com.atsuishio.superbwarfare.tools.*; @@ -19,14 +20,11 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageTypes; -import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.animal.Pig; import net.minecraft.world.entity.boss.enderdragon.EnderDragon; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.Item; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; @@ -54,7 +52,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E private float explosionDamage = ExplosionConfig.AGM_65_EXPLOSION_DAMAGE.get(); private float explosionRadius = ExplosionConfig.AGM_65_EXPLOSION_RADIUS.get().floatValue(); private boolean distracted = false; - private int durability = 50; + private int durability; public Agm65Entity(EntityType type, Level world) { super(type, world); @@ -76,22 +74,12 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E return ModItems.AGM.get(); } + + private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier(); + @Override - public boolean hurt(DamageSource source, float amount) { - if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud) - return false; - if (source.is(DamageTypes.FALL)) - return false; - if (source.is(DamageTypes.CACTUS)) - return false; - if (source.is(DamageTypes.DROWN)) - return false; - if (source.is(DamageTypes.DRAGON_BREATH)) - return false; - if (source.is(DamageTypes.WITHER)) - return false; - if (source.is(DamageTypes.WITHER_SKULL)) - return false; + public boolean hurt(@NotNull DamageSource source, float amount) { + amount = DAMAGE_MODIFIER.compute(source, amount); this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount); return super.hurt(source, amount); @@ -278,7 +266,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E this.setDeltaMovement(this.getDeltaMovement().multiply(f, f, f)); destroyBlock(); } - + @Override public boolean isNoGravity() { return true; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/JavelinMissileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/JavelinMissileEntity.java index 34b009d58..6a4b144d7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/JavelinMissileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/JavelinMissileEntity.java @@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.projectile; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage; import com.atsuishio.superbwarfare.tools.*; @@ -19,15 +20,12 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageTypes; -import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.animal.Pig; import net.minecraft.world.entity.boss.enderdragon.EnderDragon; import net.minecraft.world.entity.monster.Monster; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.Item; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; @@ -94,22 +92,11 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo this.entityData.set(TOP, mode); } + private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier(); + @Override - public boolean hurt(DamageSource source, float amount) { - if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud) - return false; - if (source.is(DamageTypes.FALL)) - return false; - if (source.is(DamageTypes.CACTUS)) - return false; - if (source.is(DamageTypes.DROWN)) - return false; - if (source.is(DamageTypes.DRAGON_BREATH)) - return false; - if (source.is(DamageTypes.WITHER)) - return false; - if (source.is(DamageTypes.WITHER_SKULL)) - return false; + public boolean hurt(@NotNull DamageSource source, float amount) { + amount = DAMAGE_MODIFIER.compute(source, amount); this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount); return super.hurt(source, amount); @@ -362,7 +349,7 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo this.setDeltaMovement(this.getDeltaMovement().multiply(0.96, 0.96, 0.96)); destroyBlock(); } - + private PlayState movementPredicate(AnimationState event) { return event.setAndContinue(RawAnimation.begin().thenLoop("animation.jvm.idle")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MelonBombEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MelonBombEntity.java index 692b7eb60..8cf5430bb 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MelonBombEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MelonBombEntity.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.entity.projectile; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; +import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.tools.ProjectileTool; import net.minecraft.core.BlockPos; @@ -10,11 +11,8 @@ import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageTypes; -import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; @@ -48,22 +46,11 @@ public class MelonBombEntity extends FastThrowableProjectile implements Explosiv return true; } + private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier(); + @Override - public boolean hurt(DamageSource source, float amount) { - if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud) - return false; - if (source.is(DamageTypes.FALL)) - return false; - if (source.is(DamageTypes.CACTUS)) - return false; - if (source.is(DamageTypes.DROWN)) - return false; - if (source.is(DamageTypes.DRAGON_BREATH)) - return false; - if (source.is(DamageTypes.WITHER)) - return false; - if (source.is(DamageTypes.WITHER_SKULL)) - return false; + public boolean hurt(@NotNull DamageSource source, float amount) { + amount = DAMAGE_MODIFIER.compute(source, amount); this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount); return super.hurt(source, amount); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Mk82Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Mk82Entity.java index 1316599b1..2eb6131aa 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Mk82Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Mk82Entity.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.entity.projectile; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; +import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; @@ -12,12 +13,9 @@ import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageTypes; -import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.ThrowableItemProjectile; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; @@ -56,25 +54,13 @@ public class Mk82Entity extends FastThrowableProjectile implements GeoEntity, Ex return ModItems.MEDIUM_AERIAL_BOMB.get(); } + private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier() + .immuneTo(ModEntities.MK_82.get()); + @Override - public boolean hurt(DamageSource source, float amount) { - if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud) - return false; - if (source.is(DamageTypes.FALL)) - return false; - if (source.is(DamageTypes.CACTUS)) - return false; - if (source.is(DamageTypes.DROWN)) - return false; - if (source.is(DamageTypes.DRAGON_BREATH)) - return false; - if (source.is(DamageTypes.WITHER)) - return false; - if (source.is(DamageTypes.WITHER_SKULL)) - return false; - if (source.getDirectEntity() instanceof Mk82Entity) - return false; - this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount); + public boolean hurt(@NotNull DamageSource source, float amount) { + var newAmount = DAMAGE_MODIFIER.compute(source, amount); + this.entityData.set(HEALTH, this.entityData.get(HEALTH) - newAmount); return super.hurt(source, amount); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java index 6361a2e0c..65df77bed 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.entity.projectile; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; +import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; @@ -18,12 +19,9 @@ import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageTypes; -import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.Item; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; @@ -96,25 +94,12 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti this.entityData.set(TARGET_Z, (float) targetPos.z); } + private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier() + .immuneTo(ModEntities.SWARM_DRONE.get()); + @Override - public boolean hurt(DamageSource source, float amount) { - if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud) - return false; - if (source.is(DamageTypes.FALL)) - return false; - if (source.is(DamageTypes.CACTUS)) - return false; - if (source.is(DamageTypes.DROWN)) - return false; - if (source.is(DamageTypes.DRAGON_BREATH)) - return false; - if (source.is(DamageTypes.WITHER)) - return false; - if (source.is(DamageTypes.WITHER_SKULL)) - return false; - if (source.getDirectEntity() instanceof SwarmDroneEntity) { - return false; - } + public boolean hurt(@NotNull DamageSource source, float amount) { + amount = DAMAGE_MODIFIER.compute(source, amount); this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount); return super.hurt(source, amount); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/WgMissileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/WgMissileEntity.java index def264b5e..ab0540ead 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/WgMissileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/WgMissileEntity.java @@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.projectile; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModItems; @@ -22,12 +23,9 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageTypes; -import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.Item; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Explosion; @@ -65,22 +63,11 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit this.durability = 50; } + private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier(); + @Override - public boolean hurt(DamageSource source, float amount) { - if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud) - return false; - if (source.is(DamageTypes.FALL)) - return false; - if (source.is(DamageTypes.CACTUS)) - return false; - if (source.is(DamageTypes.DROWN)) - return false; - if (source.is(DamageTypes.DRAGON_BREATH)) - return false; - if (source.is(DamageTypes.WITHER)) - return false; - if (source.is(DamageTypes.WITHER_SKULL)) - return false; + public boolean hurt(@NotNull DamageSource source, float amount) { + amount = DAMAGE_MODIFIER.compute(source, amount); this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount); return super.hurt(source, amount); @@ -248,7 +235,7 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit } destroyBlock(); } - + private PlayState movementPredicate(AnimationState event) { return event.setAndContinue(RawAnimation.begin().thenLoop("animation.jvm.idle")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/damage/DamageModifier.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/damage/DamageModifier.java index 58003ba61..39e728a21 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/damage/DamageModifier.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/damage/DamageModifier.java @@ -4,6 +4,7 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageType; +import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.EntityType; import java.util.ArrayList; @@ -18,6 +19,18 @@ public class DamageModifier { private final List multiplyList = new ArrayList<>(); private final List> customList = new ArrayList<>(); + public static DamageModifier createDefaultModifier() { + return new DamageModifier() + .immuneTo(EntityType.POTION) + .immuneTo(EntityType.AREA_EFFECT_CLOUD) + .immuneTo(DamageTypes.FALL) + .immuneTo(DamageTypes.CACTUS) + .immuneTo(DamageTypes.DROWN) + .immuneTo(DamageTypes.DRAGON_BREATH) + .immuneTo(DamageTypes.WITHER) + .immuneTo(DamageTypes.WITHER_SKULL); + } + /** * 免疫所有伤害 */ @@ -224,6 +237,17 @@ public class DamageModifier { return this; } + public List toList() { + var list = new ArrayList(); + + // 计算优先级 免疫 > 固定减伤 > 乘 + list.addAll(immuneList); + list.addAll(reduceList); + list.addAll(multiplyList); + + return list; + } + /** * 计算减伤后的伤害值 * @@ -232,14 +256,7 @@ public class DamageModifier { * @return 减伤后的伤害值 */ public float compute(DamageSource source, float damage) { - var list = new ArrayList(); - - // 计算优先级 免疫 > 固定减伤 > 乘 - list.addAll(immuneList); - list.addAll(reduceList); - list.addAll(multiplyList); - - for (DamageModify damageModify : list) { + for (DamageModify damageModify : toList()) { if (damageModify.match(source)) { damage = damageModify.compute(damage);