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 596bd6372..dcf9681ba 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -12,7 +12,10 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.*; +import com.atsuishio.superbwarfare.tools.AmmoType; +import com.atsuishio.superbwarfare.tools.CustomExplosion; +import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.atsuishio.superbwarfare.tools.SoundTool; import com.google.common.collect.Lists; import com.mojang.math.Axis; import net.minecraft.core.BlockPos; @@ -56,7 +59,6 @@ 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; @@ -457,46 +459,9 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity @Override public void destroy() { - Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - 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); - 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); - } - } - } else { - List passengers = this.getPassengers(); - for (var entity : passengers) { - if (entity instanceof LivingEntity living) { - var tempAttacker = living == attacker ? null : attacker; - - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - } - } - } - if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, attacker), 300.0f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, getAttacker()), 300.0f, this.getX(), this.getY(), this.getZ(), 8f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); ForgeEventFactory.onExplosionStart(this.level(), explosion); @@ -504,6 +469,11 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity ParticleTool.spawnHugeExplosionParticles(this.level(), this.position()); } + if (this.crash) { + crashPassengers(); + } else { + explodePassengers(); + } this.discard(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java index 58206865d..ff4a02114 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java @@ -56,7 +56,6 @@ import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; -import java.util.List; public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, CannonEntity { @@ -408,11 +407,9 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, @Override public void destroy() { - Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 600f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 600f, this.getX(), this.getY(), this.getZ(), 15f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); ForgeEventFactory.onExplosionStart(this.level(), explosion); @@ -420,24 +417,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, ParticleTool.spawnHugeExplosionParticles(this.level(), this.position()); } - - List passengers = this.getPassengers(); - for (var entity : passengers) { - if (entity instanceof LivingEntity living) { - var tempAttacker = living == attacker ? null : attacker; - - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - } - } - + explodePassengers(); this.discard(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java index 566eb5669..1bab086ea 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -12,7 +12,10 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.*; +import com.atsuishio.superbwarfare.tools.AmmoType; +import com.atsuishio.superbwarfare.tools.CustomExplosion; +import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.atsuishio.superbwarfare.tools.SoundTool; import com.mojang.math.Axis; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; @@ -30,7 +33,6 @@ import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -55,7 +57,6 @@ import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; -import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; @@ -638,11 +639,9 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit @Override public void destroy() { - Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 80f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f, this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); @@ -650,24 +649,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } - - List passengers = this.getPassengers(); - for (var entity : passengers) { - if (entity instanceof LivingEntity living) { - var tempAttacker = living == attacker ? null : attacker; - - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - } - } - + explodePassengers(); this.discard(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java index b8765765c..6a5f563f0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java @@ -241,13 +241,14 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity, Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 10f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker, attacker), 10f, this.getX(), this.getY(), this.getZ(), 3f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } + this.discard(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java index 2443fffba..cea4cea4b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -11,7 +11,10 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.*; +import com.atsuishio.superbwarfare.tools.AmmoType; +import com.atsuishio.superbwarfare.tools.CustomExplosion; +import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.atsuishio.superbwarfare.tools.SoundTool; import com.mojang.math.Axis; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; @@ -29,7 +32,6 @@ import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -57,7 +59,6 @@ import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; -import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; @@ -584,11 +585,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt @Override public void destroy() { - Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 80f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f, this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); @@ -596,24 +595,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } - - List passengers = this.getPassengers(); - for (var entity : passengers) { - if (entity instanceof LivingEntity living) { - var tempAttacker = living == attacker ? null : attacker; - - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - } - } - + explodePassengers(); this.discard(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java index 5a88d7292..a4aa64765 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -11,7 +11,6 @@ import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.core.particles.ParticleTypes; @@ -51,7 +50,6 @@ import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; -import java.util.List; public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity { @@ -218,11 +216,9 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity @Override public void destroy() { - Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 100f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 100f, this.getX(), this.getY(), this.getZ(), 7f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); @@ -230,26 +226,8 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } - - List passengers = this.getPassengers(); - for (var entity : passengers) { - if (entity instanceof LivingEntity living) { - var tempAttacker = living == attacker ? null : attacker; - - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - } - } - + explodePassengers(); this.discard(); - } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java index 409f8f018..aa01e4c1b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -11,7 +11,6 @@ import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.core.particles.ParticleTypes; @@ -52,7 +51,6 @@ import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; -import java.util.List; public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEntity { @@ -232,11 +230,9 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt @Override public void destroy() { - Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 120f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 120f, this.getX(), this.getY(), this.getZ(), 6f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); @@ -244,23 +240,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } - List passengers = this.getPassengers(); - for (var entity : passengers) { - if (entity instanceof LivingEntity living) { - var tempAttacker = living == attacker ? null : attacker; - - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - } - } - + explodePassengers(); this.discard(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java index d4f579b00..d885ec337 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -11,7 +11,10 @@ import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.*; +import com.atsuishio.superbwarfare.tools.AmmoType; +import com.atsuishio.superbwarfare.tools.CustomExplosion; +import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; @@ -27,7 +30,6 @@ import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; @@ -48,7 +50,6 @@ import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; -import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; @@ -412,28 +413,9 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo @Override public void destroy() { - Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - - List passengers = this.getPassengers(); - for (var entity : passengers) { - if (entity instanceof LivingEntity living) { - var tempAttacker = living == attacker ? null : attacker; - - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - } - } - if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 80f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f, this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); @@ -441,6 +423,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } + explodePassengers(); this.discard(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java index d9fedb1fd..c422c318f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java @@ -10,7 +10,6 @@ import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.mojang.math.Axis; import net.minecraft.core.BlockPos; @@ -30,7 +29,6 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Items; import net.minecraft.world.level.Explosion; @@ -48,8 +46,6 @@ import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; -import java.util.List; - public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.FLOAT); @@ -301,47 +297,10 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { @Override public void destroy() { - Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - 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); - 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); - } - } - } else { - List passengers = this.getPassengers(); - for (var entity : passengers) { - if (entity instanceof LivingEntity living) { - var tempAttacker = living == attacker ? null : attacker; - - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - } - } - } - if (level() instanceof ServerLevel) { if (entityData.get(MELON)) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, attacker), VehicleConfig.TOM_6_BOMB_EXPLOSION_DAMAGE.get(), + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, getAttacker()), VehicleConfig.TOM_6_BOMB_EXPLOSION_DAMAGE.get(), this.getX(), this.getY(), this.getZ(), VehicleConfig.TOM_6_BOMB_EXPLOSION_RADIUS.get().floatValue(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); ForgeEventFactory.onExplosionStart(this.level(), explosion); @@ -349,7 +308,7 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { ParticleTool.spawnHugeExplosionParticles(this.level(), this.position()); } else { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, attacker), 15.0f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, getAttacker()), 15.0f, this.getX(), this.getY(), this.getZ(), 2f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); ForgeEventFactory.onExplosionStart(this.level(), explosion); @@ -358,6 +317,11 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { } } + if (this.crash) { + crashPassengers(); + } else { + explodePassengers(); + } this.discard(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java index bf656ee2f..8c08a8a86 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java @@ -8,7 +8,6 @@ import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.ParticleTool; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; @@ -267,11 +266,9 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity { @Override public void destroy() { - Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 10f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 10f, this.getX(), this.getY(), this.getZ(), 2f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java index d7a635e0d..5e373ab97 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -11,7 +11,10 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.*; +import com.atsuishio.superbwarfare.tools.AmmoType; +import com.atsuishio.superbwarfare.tools.CustomExplosion; +import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.atsuishio.superbwarfare.tools.SoundTool; import com.mojang.math.Axis; import net.minecraft.client.CameraType; import net.minecraft.client.Minecraft; @@ -33,7 +36,6 @@ import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; @@ -60,7 +62,6 @@ import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; -import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; @@ -798,11 +799,9 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public void destroy() { - Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); - if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), attacker, attacker), 80f, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f, this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); ForgeEventFactory.onExplosionStart(this.level(), explosion); @@ -810,24 +809,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } - - List passengers = this.getPassengers(); - for (var entity : passengers) { - if (entity instanceof LivingEntity living) { - var tempAttacker = living == attacker ? null : attacker; - - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - living.invulnerableTime = 0; - living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); - } - } - + explodePassengers(); this.discard(); } @@ -901,15 +883,12 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public boolean canShoot(Player player) { - if (player == getNthEntity(0)) { - return this.entityData.get(LOADED_AMMO) > 0; - } - - if (player == getNthEntity(1)) { - return (this.entityData.get(MG_AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; - } - - return false; + return switch (getSeatIndex(player)) { + case 0 -> this.entityData.get(LOADED_AMMO) > 0; + case 1 -> + (this.entityData.get(MG_AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; + default -> false; + }; } @Override @@ -964,18 +943,19 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public int getWeaponType(int index) { - if (index == 0) { - return entityData.get(WEAPON_TYPE); - } else if (index == 1) { - return entityData.get(PASSENGER_WEAPON_TYPE); - } - return -1; + return switch (index) { + case 0 -> entityData.get(WEAPON_TYPE); + case 1 -> entityData.get(PASSENGER_WEAPON_TYPE); + default -> -1; + }; } @Override public void setWeaponType(int index, int type) { - if (index == 0) entityData.set(WEAPON_TYPE, type); - if (index == 1) entityData.set(PASSENGER_WEAPON_TYPE, type); + switch (index) { + case 0 -> entityData.set(WEAPON_TYPE, type); + case 1 -> entityData.set(PASSENGER_WEAPON_TYPE, type); + } } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java index ddcf926f6..8350890c4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java @@ -532,6 +532,46 @@ public abstract class VehicleEntity extends Entity { public void destroy() { } + protected Entity getAttacker() { + return EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); + } + + protected void crashPassengers() { + for (var entity : this.getPassengers()) { + if (entity instanceof LivingEntity living) { + var tempAttacker = living == getAttacker() ? null : getAttacker(); + + 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); + 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); + } + } + } + + protected void explodePassengers() { + for (var entity : this.getPassengers()) { + if (entity instanceof LivingEntity living) { + var tempAttacker = living == getAttacker() ? null : getAttacker(); + + living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); + living.invulnerableTime = 0; + living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); + living.invulnerableTime = 0; + living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); + living.invulnerableTime = 0; + living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); + living.invulnerableTime = 0; + living.hurt(ModDamageTypes.causeVehicleExplosionDamage(this.level().registryAccess(), null, tempAttacker), Integer.MAX_VALUE); + } + } + } + public void travel() { }