From e781363c0c27ab66911ec026eb96529b083d3f71 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Sun, 5 Jan 2025 23:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9D=A0=E6=9C=BA=E4=BC=A4?= =?UTF-8?q?=E5=AE=B3=E5=AE=9E=E7=8E=B0=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vehicle/Ah6Entity.java | 46 ++++++------------- .../superbwarfare/init/ModDamageTypes.java | 38 ++++++++------- .../assets/superbwarfare/lang/en_us.json | 3 +- .../assets/superbwarfare/lang/zh_cn.json | 3 +- .../tags/damage_type/bypasses_armor.json | 3 +- .../tags/damage_type/bypasses_effects.json | 3 +- .../damage_type/bypasses_enchantments.json | 3 +- .../tags/damage_type/bypasses_resistance.json | 3 +- .../superbwarfare/damage_type/air_crash.json | 5 ++ 9 files changed, 53 insertions(+), 54 deletions(-) create mode 100644 src/main/resources/data/superbwarfare/damage_type/air_crash.json diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java index 414b2a72d..494d6c38c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -13,7 +13,6 @@ import com.google.common.collect.Lists; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.syncher.EntityDataAccessor; @@ -34,7 +33,6 @@ import net.minecraft.world.entity.vehicle.DismountHelper; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; -import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.ForgeEventFactory; @@ -135,6 +133,7 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli this.hurt(0.75f * Math.max(amount - 5, 0)); return true; } + @Override public void baseTick() { propellerRotO = this.getPropellerRot(); @@ -171,7 +170,7 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.95, f)); } - if (this.isInWater() && this.tickCount %4 == 0) { + if (this.isInWater() && this.tickCount % 4 == 0) { this.setDeltaMovement(this.getDeltaMovement().multiply(0.6, 0.6, 0.6)); this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger()), 26 + (float) (60 * ((lastTickSpeed - 0.4) * (lastTickSpeed - 0.4)))); } @@ -326,7 +325,7 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); } - if (passenger != this.getFirstPassenger()){ + if (passenger != this.getFirstPassenger()) { passenger.setXRot(passenger.getXRot() + (getXRot() - xRotO)); } @@ -355,34 +354,17 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli @Override public void destroy() { Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - if (crash) { - List passenger = this.getPassengers(); - for (var e : passenger) { - if (e instanceof LivingEntity living) { - if (e instanceof ServerPlayer victim && !(victim.isCreative() || victim.isSpectator())) { - living.setHealth(0); - if (attacker == null || attacker == victim) { - living.level().players().forEach( - p -> p.sendSystemMessage( - Component.translatable("death.attack.air_crash", victim.getDisplayName()) - ) - ); - } else { - living.level().players().forEach( - p -> p.sendSystemMessage( - Component.translatable("death.attack.air_crash_entity", - victim.getDisplayName(), - attacker.getDisplayName() - ) - ) - ); - } - } else { - living.setHealth(0); - living.level().broadcastEntityEvent(living, (byte) 60); - living.remove(RemovalReason.KILLED); - living.gameEvent(GameEvent.ENTITY_DIE); - } + if (this.crash) { + List passengers = this.getPassengers(); + for (var entity : passengers) { + if (entity instanceof LivingEntity living) { + var tempAttacker = living == attacker ? null : attacker; + + living.hurt(ModDamageTypes.causeAirCrashDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); + living.invulnerableTime = 0; + living.hurt(ModDamageTypes.causeAirCrashDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); + living.invulnerableTime = 0; + living.hurt(ModDamageTypes.causeAirCrashDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModDamageTypes.java b/src/main/java/com/atsuishio/superbwarfare/init/ModDamageTypes.java index 345f316fe..0ed526563 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModDamageTypes.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModDamageTypes.java @@ -6,7 +6,6 @@ import net.minecraft.core.RegistryAccess; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageType; import net.minecraft.world.entity.Entity; @@ -16,21 +15,23 @@ import javax.annotation.Nullable; @SuppressWarnings("OptionalGetWithoutIsPresent") public class ModDamageTypes { - public static final ResourceKey GUN_FIRE = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "gunfire")); - public static final ResourceKey GUN_FIRE_ABSOLUTE = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "gunfire_absolute")); - public static final ResourceKey GUN_FIRE_HEADSHOT = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "gunfire_headshot")); - public static final ResourceKey GUN_FIRE_HEADSHOT_ABSOLUTE = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "gunfire_headshot_absolute")); - public static final ResourceKey BURN = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "burn")); - public static final ResourceKey MINE = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "mine")); - public static final ResourceKey BEAST = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "beast")); - public static final ResourceKey SHOCK = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "shock")); - public static final ResourceKey PROJECTILE_BOOM = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "projectile_boom")); - public static final ResourceKey CANNON_FIRE = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "cannon_fire")); - public static final ResourceKey CUSTOM_EXPLOSION = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "custom_explosion")); - public static final ResourceKey DRONE_HIT = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "drone_hit")); - public static final ResourceKey LASER = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "laser")); - public static final ResourceKey LASER_HEADSHOT = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "laser_headshot")); - public static final ResourceKey VEHICLE_STRIKE = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "vehicle_strike")); + + public static final ResourceKey GUN_FIRE = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("gunfire")); + public static final ResourceKey GUN_FIRE_ABSOLUTE = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("gunfire_absolute")); + public static final ResourceKey GUN_FIRE_HEADSHOT = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("gunfire_headshot")); + public static final ResourceKey GUN_FIRE_HEADSHOT_ABSOLUTE = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("gunfire_headshot_absolute")); + public static final ResourceKey BURN = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("burn")); + public static final ResourceKey MINE = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("mine")); + public static final ResourceKey BEAST = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("beast")); + public static final ResourceKey SHOCK = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("shock")); + public static final ResourceKey PROJECTILE_BOOM = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("projectile_boom")); + public static final ResourceKey CANNON_FIRE = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("cannon_fire")); + public static final ResourceKey CUSTOM_EXPLOSION = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("custom_explosion")); + public static final ResourceKey DRONE_HIT = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("drone_hit")); + public static final ResourceKey LASER = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("laser")); + public static final ResourceKey LASER_HEADSHOT = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("laser_headshot")); + public static final ResourceKey VEHICLE_STRIKE = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("vehicle_strike")); + public static final ResourceKey AIR_CRASH = ResourceKey.create(Registries.DAMAGE_TYPE, ModUtils.loc("air_crash")); public static DamageSource causeGunFireDamage(RegistryAccess registryAccess, @Nullable Entity directEntity, @Nullable Entity attacker) { return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(GUN_FIRE), directEntity, attacker); @@ -88,7 +89,12 @@ public class ModDamageTypes { return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(VEHICLE_STRIKE), directEntity, attacker); } + public static DamageSource causeAirCrashDamage(RegistryAccess registryAccess, @Nullable Entity directEntity, @Nullable Entity attacker) { + return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(AIR_CRASH), directEntity, attacker); + } + private static class DamageMessages extends DamageSource { + public DamageMessages(Holder.Reference typeReference) { super(typeReference); } diff --git a/src/main/resources/assets/superbwarfare/lang/en_us.json b/src/main/resources/assets/superbwarfare/lang/en_us.json index 49fc88afc..f57045dd7 100644 --- a/src/main/resources/assets/superbwarfare/lang/en_us.json +++ b/src/main/resources/assets/superbwarfare/lang/en_us.json @@ -352,7 +352,8 @@ "death.attack.vehicle_strike.entity": "%1$s被%2$s创死了", "death.attack.vehicle_strike.item": "%1$s的被%2$s用%3$s创死了", "death.attack.air_crash": "%1$s坠机了", - "death.attack.air_crash_entity": "%1$s坠机了,凶手是%2$s", + "death.attack.air_crash.entity": "%1$s坠机了,凶手是%2$s", + "death.attack.air_crash.item": "%1$s坠机了,凶手是%2$s", "entity.superbwarfare.projectile": "Bullet", "entity.superbwarfare.projectile_mortar_shell": "Mortar Shell", diff --git a/src/main/resources/assets/superbwarfare/lang/zh_cn.json b/src/main/resources/assets/superbwarfare/lang/zh_cn.json index 365f5e5c4..cab9feca7 100644 --- a/src/main/resources/assets/superbwarfare/lang/zh_cn.json +++ b/src/main/resources/assets/superbwarfare/lang/zh_cn.json @@ -352,7 +352,8 @@ "death.attack.vehicle_strike.entity": "%1$s被%2$s创死了", "death.attack.vehicle_strike.item": "%1$s的被%2$s用%3$s创死了", "death.attack.air_crash": "%1$s坠机了", - "death.attack.air_crash_entity": "%1$s坠机了,凶手是%2$s", + "death.attack.air_crash.entity": "%1$s坠机了,凶手是%2$s", + "death.attack.air_crash.item": "%1$s坠机了,凶手是%2$s", "entity.superbwarfare.projectile": "子弹", "entity.superbwarfare.projectile_mortar_shell": "迫击炮弹", diff --git a/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json b/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json index 564095052..1714584b5 100644 --- a/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json +++ b/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json @@ -7,6 +7,7 @@ "superbwarfare:cannon_fire", "superbwarfare:laser", "superbwarfare:laser_headshot", - "superbwarfare:vehicle_strike" + "superbwarfare:vehicle_strike", + "superbwarfare:air_crash" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json b/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json index 564095052..1714584b5 100644 --- a/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json +++ b/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json @@ -7,6 +7,7 @@ "superbwarfare:cannon_fire", "superbwarfare:laser", "superbwarfare:laser_headshot", - "superbwarfare:vehicle_strike" + "superbwarfare:vehicle_strike", + "superbwarfare:air_crash" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json b/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json index 564095052..1714584b5 100644 --- a/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json +++ b/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json @@ -7,6 +7,7 @@ "superbwarfare:cannon_fire", "superbwarfare:laser", "superbwarfare:laser_headshot", - "superbwarfare:vehicle_strike" + "superbwarfare:vehicle_strike", + "superbwarfare:air_crash" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/damage_type/bypasses_resistance.json b/src/main/resources/data/minecraft/tags/damage_type/bypasses_resistance.json index 564095052..1714584b5 100644 --- a/src/main/resources/data/minecraft/tags/damage_type/bypasses_resistance.json +++ b/src/main/resources/data/minecraft/tags/damage_type/bypasses_resistance.json @@ -7,6 +7,7 @@ "superbwarfare:cannon_fire", "superbwarfare:laser", "superbwarfare:laser_headshot", - "superbwarfare:vehicle_strike" + "superbwarfare:vehicle_strike", + "superbwarfare:air_crash" ] } \ No newline at end of file diff --git a/src/main/resources/data/superbwarfare/damage_type/air_crash.json b/src/main/resources/data/superbwarfare/damage_type/air_crash.json new file mode 100644 index 000000000..02284592e --- /dev/null +++ b/src/main/resources/data/superbwarfare/damage_type/air_crash.json @@ -0,0 +1,5 @@ +{ + "exhaustion": 0, + "message_id": "air_crash", + "scaling": "never" +} \ No newline at end of file