修改坠机方法

This commit is contained in:
Atsuihsio 2025-01-05 16:38:19 +08:00
parent b15d4a9a36
commit 06a1f0b827
10 changed files with 44 additions and 26 deletions

View file

@ -16,6 +16,7 @@ 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;
@ -35,6 +36,7 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.vehicle.DismountHelper;
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;
@ -53,6 +55,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
@ -325,16 +328,48 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico
@Override
public void destroy() {
if (level() instanceof ServerLevel) {
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
if (crash) {
List<Entity> passenger = this.getPassengers();
for (var e : passenger) {
if (e instanceof LivingEntity living) {
if (e instanceof ServerPlayer victim) {
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 (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
crash ? ModDamageTypes.causeAirCrashDamage(this.level().registryAccess(), this, attacker) : ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, attacker), 300.0f,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, attacker), 300.0f,
this.getX(), this.getY(), this.getZ(), 8f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode();
ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), this.position());
this.remove(RemovalReason.KILLED);
this.discard();
}
}

View file

@ -259,7 +259,6 @@ public class VehicleEntity extends Entity {
handleClientSync();
if (this.level() instanceof ServerLevel && this.getHealth() <= 0) {
this.ejectPassengers();
destroy();
}

View file

@ -31,7 +31,6 @@ public class ModDamageTypes {
public static final ResourceKey<DamageType> LASER = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "laser"));
public static final ResourceKey<DamageType> LASER_HEADSHOT = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "laser_headshot"));
public static final ResourceKey<DamageType> VEHICLE_STRIKE = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "vehicle_strike"));
public static final ResourceKey<DamageType> AIR_CRASH = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "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);
@ -89,10 +88,6 @@ 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<DamageType> typeReference) {
super(typeReference);

View file

@ -351,8 +351,7 @@
"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坠机了",
"death.attack.air_crash.item": "%1$s坠机了",
"death.attack.air_crash_entity": "%1$s坠机了,凶手是%2$s",
"entity.superbwarfare.projectile": "Bullet",
"entity.superbwarfare.projectile_mortar_shell": "Mortar Shell",

View file

@ -351,8 +351,7 @@
"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坠机了",
"death.attack.air_crash.item": "%1$s坠机了",
"death.attack.air_crash_entity": "%1$s坠机了,凶手是%2$s",
"entity.superbwarfare.projectile": "子弹",
"entity.superbwarfare.projectile_mortar_shell": "迫击炮弹",

View file

@ -7,7 +7,6 @@
"superbwarfare:cannon_fire",
"superbwarfare:laser",
"superbwarfare:laser_headshot",
"superbwarfare:vehicle_strike",
"superbwarfare:air_crash"
"superbwarfare:vehicle_strike"
]
}

View file

@ -7,7 +7,6 @@
"superbwarfare:cannon_fire",
"superbwarfare:laser",
"superbwarfare:laser_headshot",
"superbwarfare:vehicle_strike",
"superbwarfare:air_crash"
"superbwarfare:vehicle_strike"
]
}

View file

@ -7,7 +7,6 @@
"superbwarfare:cannon_fire",
"superbwarfare:laser",
"superbwarfare:laser_headshot",
"superbwarfare:vehicle_strike",
"superbwarfare:air_crash"
"superbwarfare:vehicle_strike"
]
}

View file

@ -7,7 +7,6 @@
"superbwarfare:cannon_fire",
"superbwarfare:laser",
"superbwarfare:laser_headshot",
"superbwarfare:vehicle_strike",
"superbwarfare:air_crash"
"superbwarfare:vehicle_strike"
]
}

View file

@ -1,5 +0,0 @@
{
"exhaustion": 0,
"message_id": "air_crash",
"scaling": "never"
}