From 6340223db3a3f27c61f5d89eecd8e38014a696c2 Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Mon, 12 May 2025 23:44:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8F=96ProjectileType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/projectile/AerialBombEntity.java | 2 +- .../entity/projectile/Agm65Entity.java | 18 +++++++- .../entity/projectile/CannonShellEntity.java | 19 +++++++- .../projectile/ExplosiveProjectile.java | 9 ++++ .../entity/projectile/GunGrenadeEntity.java | 5 ++- .../entity/projectile/HandGrenadeEntity.java | 18 +++++++- .../entity/projectile/HeliRocketEntity.java | 21 +++++++-- .../projectile/JavelinMissileEntity.java | 17 +++++++- .../entity/projectile/MelonBombEntity.java | 16 +++++++ .../entity/projectile/Mk82Entity.java | 16 +++++++ .../entity/projectile/MortarShellEntity.java | 41 ++++++++++++------ .../entity/projectile/RgoGrenadeEntity.java | 16 ++++++- .../entity/projectile/RpgRocketEntity.java | 12 ++++-- .../projectile/SmallCannonShellEntity.java | 17 +++++++- .../entity/projectile/SwarmDroneEntity.java | 18 +++++++- .../entity/projectile/WgMissileEntity.java | 21 +++++++-- .../superbwarfare/item/gun/GunItem.java | 43 +++++++++++++++---- .../item/gun/data/DefaultGunData.java | 4 ++ .../superbwarfare/item/gun/data/GunData.java | 4 ++ .../item/gun/launcher/M79Item.java | 39 +++-------------- .../item/gun/launcher/RpgItem.java | 40 +++-------------- .../item/gun/launcher/SecondaryCataclysm.java | 1 + .../data/superbwarfare/guns/m_79.json | 1 + .../data/superbwarfare/guns/rpg.json | 1 + 24 files changed, 288 insertions(+), 111 deletions(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/entity/projectile/ExplosiveProjectile.java diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/AerialBombEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/AerialBombEntity.java index 660ed0bb4..382bf8ba9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/AerialBombEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/AerialBombEntity.java @@ -1,4 +1,4 @@ package com.atsuishio.superbwarfare.entity.projectile; -public interface AerialBombEntity { +public interface AerialBombEntity extends ExplosiveProjectile { } 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 c90239a46..67b6f5c27 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Agm65Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Agm65Entity.java @@ -49,7 +49,7 @@ import software.bernie.geckolib.util.GeckoLibUtil; import java.util.List; -public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity { +public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity, ExplosiveProjectile { public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(Agm65Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor TARGET_UUID = SynchedEntityData.defineId(Agm65Entity.class, EntityDataSerializers.STRING); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -292,4 +292,20 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, D public float getVolume() { return 0.7f; } + + // TODO setter + @Override + public void setDamage(float damage) { + + } + + @Override + public void setExplosionDamage(float explosionDamage) { + + } + + @Override + public void setExplosionRadius(float radius) { + + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java index cdc4d41a8..f519ddec4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java @@ -42,7 +42,7 @@ import software.bernie.geckolib.util.GeckoLibUtil; import java.util.HashSet; import java.util.Set; -public class CannonShellEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity { +public class CannonShellEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity, ExplosiveProjectile { private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private float damage = 0; @@ -336,7 +336,7 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt } @Override - public SoundEvent getSound() { + public @NotNull SoundEvent getSound() { return ModSounds.SHELL_FLY.get(); } @@ -344,4 +344,19 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt public float getVolume() { return 0.07f; } + + @Override + public void setDamage(float damage) { + this.damage = damage; + } + + @Override + public void setExplosionDamage(float damage) { + this.explosionDamage = damage; + } + + @Override + public void setExplosionRadius(float radius) { + this.radius = radius; + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ExplosiveProjectile.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ExplosiveProjectile.java new file mode 100644 index 000000000..393474103 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ExplosiveProjectile.java @@ -0,0 +1,9 @@ +package com.atsuishio.superbwarfare.entity.projectile; + +public interface ExplosiveProjectile { + void setDamage(float damage); + + void setExplosionDamage(float explosionDamage); + + void setExplosionRadius(float radius); +} diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/GunGrenadeEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/GunGrenadeEntity.java index df2967323..307a52dc9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/GunGrenadeEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/GunGrenadeEntity.java @@ -29,7 +29,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; -public class GunGrenadeEntity extends FastThrowableProjectile implements GeoEntity { +public class GunGrenadeEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile { private float monsterMultiplier = 0.0f; private float damage = 40.0f; @@ -50,14 +50,17 @@ public class GunGrenadeEntity extends FastThrowableProjectile implements GeoEnti this.explosionRadius = explosionRadius; } + @Override public void setDamage(float damage) { this.damage = damage; } + @Override public void setExplosionDamage(float explosionDamage) { this.explosionDamage = explosionDamage; } + @Override public void setExplosionRadius(float explosionRadius) { this.explosionRadius = explosionRadius; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java index 188174cf5..aeb940e18 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java @@ -31,7 +31,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; -public class HandGrenadeEntity extends FastThrowableProjectile implements GeoEntity { +public class HandGrenadeEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile { private int fuse = 100; private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -151,4 +151,20 @@ public class HandGrenadeEntity extends FastThrowableProjectile implements GeoEnt protected double getDefaultGravity() { return 0.07F; } + + // TODO setter + @Override + public void setDamage(float damage) { + + } + + @Override + public void setExplosionDamage(float explosionDamage) { + + } + + @Override + public void setExplosionRadius(float radius) { + + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HeliRocketEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HeliRocketEntity.java index 0bf2f52d5..66392ce76 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HeliRocketEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HeliRocketEntity.java @@ -34,7 +34,7 @@ import software.bernie.geckolib.util.GeckoLibUtil; import javax.annotation.Nullable; -public class HeliRocketEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity { +public class HeliRocketEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity, ExplosiveProjectile { private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private float damage = 140f; @@ -166,12 +166,12 @@ public class HeliRocketEntity extends FastThrowableProjectile implements GeoEnti } @Override - public SoundEvent getCloseSound() { + public @NotNull SoundEvent getCloseSound() { return ModSounds.ROCKET_ENGINE.get(); } @Override - public SoundEvent getSound() { + public @NotNull SoundEvent getSound() { return ModSounds.ROCKET_FLY.get(); } @@ -179,4 +179,19 @@ public class HeliRocketEntity extends FastThrowableProjectile implements GeoEnti public float getVolume() { return 0.1f; } + + @Override + public void setDamage(float damage) { + this.damage = damage; + } + + @Override + public void setExplosionDamage(float damage) { + this.explosionDamage = damage; + } + + @Override + public void setExplosionRadius(float radius) { + this.explosionRadius = radius; + } } 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 3d87a8ff8..c63338958 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/JavelinMissileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/JavelinMissileEntity.java @@ -50,7 +50,7 @@ import software.bernie.geckolib.util.GeckoLibUtil; import java.util.List; -public class JavelinMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity { +public class JavelinMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity, ExplosiveProjectile { public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor TARGET_UUID = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor TOP = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.BOOLEAN); @@ -388,4 +388,19 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo public float getVolume() { return 0.4f; } + + @Override + public void setDamage(float damage) { + this.damage = damage; + } + + @Override + public void setExplosionDamage(float damage) { + this.explosion_damage = damage; + } + + @Override + public void setExplosionRadius(float radius) { + this.explosion_radius = radius; + } } 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 67e1007ff..41c0d40dd 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MelonBombEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MelonBombEntity.java @@ -19,6 +19,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; import org.jetbrains.annotations.NotNull; +// TODO 配置文件 public class MelonBombEntity extends FastThrowableProjectile implements DestroyableProjectileEntity, AerialBombEntity { public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(MelonBombEntity.class, EntityDataSerializers.FLOAT); @@ -108,4 +109,19 @@ public class MelonBombEntity extends FastThrowableProjectile implements Destroya protected double getDefaultGravity() { return 0.05F; } + + @Override + public void setDamage(float damage) { + + } + + @Override + public void setExplosionDamage(float damage) { + + } + + @Override + public void setExplosionRadius(float radius) { + + } } 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 9f2809c2c..a13fdd8b4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Mk82Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/Mk82Entity.java @@ -162,4 +162,20 @@ public class Mk82Entity extends FastThrowableProjectile implements GeoEntity, De public boolean shouldSyncMotion() { return true; } + + // TODO setter + @Override + public void setDamage(float damage) { + + } + + @Override + public void setExplosionDamage(float damage) { + + } + + @Override + public void setExplosionRadius(float radius) { + + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java index 177a01e48..5fc8885f7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java @@ -47,9 +47,9 @@ import java.util.HashSet; import java.util.Objects; import java.util.Set; -public class MortarShellEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity { - - private float damage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get(); +public class MortarShellEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity, ExplosiveProjectile { + private float damage = 50; + private float explosionDamage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get(); private int life = 600; private float radius = ExplosionConfig.MORTAR_SHELL_EXPLOSION_RADIUS.get(); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -72,14 +72,14 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt super(ModEntities.MORTAR_SHELL.get(), entity, level); } - public MortarShellEntity(LivingEntity entity, Level world, float damage) { + public MortarShellEntity(LivingEntity entity, Level world, float explosionDamage) { super(ModEntities.MORTAR_SHELL.get(), entity, world); - this.damage = damage; + this.explosionDamage = explosionDamage; } - public MortarShellEntity(LivingEntity entity, Level world, float damage, float radius) { + public MortarShellEntity(LivingEntity entity, Level world, float explosionDamage, float radius) { super(ModEntities.MORTAR_SHELL.get(), entity, world); - this.damage = damage; + this.explosionDamage = explosionDamage; this.radius = radius; } @@ -100,7 +100,7 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt @Override public void addAdditionalSaveData(@NotNull CompoundTag pCompound) { super.addAdditionalSaveData(pCompound); - pCompound.putFloat("Damage", this.damage); + pCompound.putFloat("Damage", this.explosionDamage); pCompound.putInt("Life", this.life); pCompound.putFloat("Radius", this.radius); @@ -129,9 +129,9 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt public void readAdditionalSaveData(@NotNull CompoundTag pCompound) { super.readAdditionalSaveData(pCompound); if (pCompound.contains("Damage")) { - this.damage = pCompound.getFloat("Damage"); + this.explosionDamage = pCompound.getFloat("Damage"); } else { - this.damage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get(); + this.explosionDamage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get(); } if (pCompound.contains("Life")) { @@ -233,7 +233,7 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), - damage, + explosionDamage, vec3.x, vec3.y, vec3.z, @@ -276,7 +276,7 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt for (MobEffectInstance effect : this.effects) { cloud.addEffect(effect); } - cloud.setDuration((int) this.damage); + cloud.setDuration((int) this.explosionDamage); cloud.setRadius(this.radius); if (this.getOwner() instanceof LivingEntity living) { cloud.setOwner(living); @@ -285,7 +285,7 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt } @Override - public SoundEvent getSound() { + public @NotNull SoundEvent getSound() { return ModSounds.SHELL_FLY.get(); } @@ -293,4 +293,19 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt public float getVolume() { return 0.06f; } + + @Override + public void setDamage(float damage) { + this.damage = damage; + } + + @Override + public void setExplosionDamage(float explosionDamage) { + this.explosionDamage = explosionDamage; + } + + @Override + public void setExplosionRadius(float radius) { + this.radius = radius; + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java index 1ce46639c..06064b7f6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java @@ -32,7 +32,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; -public class RgoGrenadeEntity extends FastThrowableProjectile implements GeoEntity { +public class RgoGrenadeEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile { private int fuse = 80; private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -138,4 +138,18 @@ public class RgoGrenadeEntity extends FastThrowableProjectile implements GeoEnti this.xRotO = this.getXRot(); } + // TODO setter + @Override + public void setDamage(float damage) { + } + + @Override + public void setExplosionDamage(float explosionDamage) { + + } + + @Override + public void setExplosionRadius(float radius) { + + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RpgRocketEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RpgRocketEntity.java index 76d95bb04..426a6bd2a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RpgRocketEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RpgRocketEntity.java @@ -32,7 +32,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animation.*; import software.bernie.geckolib.util.GeckoLibUtil; -public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity { +public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity, ExplosiveProjectile { private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -67,14 +67,18 @@ public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntit this.explosionRadius = explosionRadius; } - public void setExplosionRadius(float explosionRadius) { - this.explosionRadius = explosionRadius; - } + @Override public void setDamage(float damage) { this.damage = damage; } + @Override + public void setExplosionRadius(float explosionRadius) { + this.explosionRadius = explosionRadius; + } + + @Override public void setExplosionDamage(float explosionDamage) { this.explosionDamage = explosionDamage; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SmallCannonShellEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SmallCannonShellEntity.java index 40f07c0c9..b73db28a7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SmallCannonShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SmallCannonShellEntity.java @@ -34,7 +34,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; -public class SmallCannonShellEntity extends FastThrowableProjectile implements GeoEntity { +public class SmallCannonShellEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile { private float damage = 40.0f; private float explosionDamage = 80f; private float explosionRadius = 5f; @@ -172,4 +172,19 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G public AnimatableInstanceCache getAnimatableInstanceCache() { return this.cache; } + + @Override + public void setDamage(float damage) { + this.damage = damage; + } + + @Override + public void setExplosionDamage(float explosionDamage) { + this.explosionDamage = explosionDamage; + } + + @Override + public void setExplosionRadius(float radius) { + this.explosionRadius = radius; + } } 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 201cb517c..cbc7f06e2 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java @@ -45,7 +45,7 @@ import software.bernie.geckolib.util.GeckoLibUtil; import javax.annotation.Nullable; import java.util.List; -public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity { +public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity, ExplosiveProjectile { public static final EntityDataAccessor TARGET_UUID = SynchedEntityData.defineId(SwarmDroneEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor TARGET_X = SynchedEntityData.defineId(SwarmDroneEntity.class, EntityDataSerializers.FLOAT); @@ -291,7 +291,7 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti } @Override - public SoundEvent getSound() { + public @NotNull SoundEvent getSound() { return ModSounds.DRONE_SOUND.get(); } @@ -299,4 +299,18 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti public float getVolume() { return 0.07f; } + + @Override + public void setDamage(float damage) { + } + + @Override + public void setExplosionDamage(float explosionDamage) { + this.explosionDamage = explosionDamage; + } + + @Override + public void setExplosionRadius(float radius) { + this.explosionRadius = radius; + } } 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 5cef0c2a5..dc9bc9629 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/WgMissileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/WgMissileEntity.java @@ -44,7 +44,7 @@ import software.bernie.geckolib.util.GeckoLibUtil; import javax.annotation.Nullable; -public class WgMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity { +public class WgMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity, ExplosiveProjectile { public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(WgMissileEntity.class, EntityDataSerializers.FLOAT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -238,12 +238,12 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit } @Override - public SoundEvent getCloseSound() { + public @NotNull SoundEvent getCloseSound() { return ModSounds.ROCKET_ENGINE.get(); } @Override - public SoundEvent getSound() { + public @NotNull SoundEvent getSound() { return ModSounds.ROCKET_FLY.get(); } @@ -251,4 +251,19 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit public float getVolume() { return 0.4f; } + + @Override + public void setDamage(float damage) { + this.damage = damage; + } + + @Override + public void setExplosionDamage(float explosionDamage) { + this.explosionDamage = explosionDamage; + } + + @Override + public void setExplosionRadius(float radius) { + this.explosionRadius = radius; + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/GunItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/GunItem.java index 0e10d2af5..28c488c0b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/GunItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/GunItem.java @@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.item.gun; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.client.PoseTool; import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent; +import com.atsuishio.superbwarfare.entity.projectile.ExplosiveProjectile; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModItems; @@ -25,11 +26,13 @@ import net.minecraft.sounds.SoundEvent; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EquipmentSlotGroup; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -45,6 +48,7 @@ import org.jetbrains.annotations.NotNull; import javax.annotation.ParametersAreNonnullByDefault; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; @EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD) @@ -563,19 +567,40 @@ public abstract class GunItem extends Item implements CustomRendererItem { */ public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) { var stack = data.stack; + var level = player.level(); float headshot = (float) data.headshot(); float damage = (float) data.damage(); float velocity = (float) data.velocity(); float bypassArmorRate = (float) data.bypassArmor(); - ProjectileEntity projectile = new ProjectileEntity(player.level()) - .shooter(player) - .damage(damage) - .headShot(headshot) - .zoom(zoom) - .bypassArmorRate(bypassArmorRate) - .setGunItemId(stack); + var projectileType = data.projectileType(); + AtomicReference projectileHolder = new AtomicReference<>(); + EntityType.byString(projectileType).ifPresent(entityType -> { + var entity = entityType.create(level); + if (!(entity instanceof Projectile)) return; + ((Projectile) entity).setOwner(player); + + if (entity instanceof ProjectileEntity projectile) { + projectile.shooter(player) + .damage(damage) + .headShot(headshot) + .zoom(zoom) + .bypassArmorRate(bypassArmorRate) + .setGunItemId(stack); + } + + if (entity instanceof ExplosiveProjectile explosive) { + explosive.setDamage(damage); + explosive.setExplosionDamage((float) data.explosionDamage()); + explosive.setExplosionRadius((float) data.explosionRadius()); + } + + projectileHolder.set((Projectile) entity); + }); + + var projectile = projectileHolder.get(); + if (projectile == null) return false; for (Perk.Type type : Perk.Type.values()) { var instance = data.perk.getInstance(type); @@ -588,8 +613,8 @@ public abstract class GunItem extends Item implements CustomRendererItem { } projectile.setPos(player.getX() - 0.1 * player.getLookAngle().x, player.getEyeY() - 0.1 - 0.1 * player.getLookAngle().y, player.getZ() + -0.1 * player.getLookAngle().z); - projectile.shoot(player, player.getLookAngle().x, player.getLookAngle().y + 0.001f, player.getLookAngle().z, velocity, (float) spread); - player.level().addFreshEntity(projectile); + projectile.shoot(player.getLookAngle().x, player.getLookAngle().y + 0.001f, player.getLookAngle().z, velocity, (float) spread); + level.addFreshEntity(projectile); return true; } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/data/DefaultGunData.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/data/DefaultGunData.java index 6397c8f89..bedb33079 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/data/DefaultGunData.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/data/DefaultGunData.java @@ -29,6 +29,10 @@ public class DefaultGunData { public double velocity; @SerializedName("Magazine") public int magazine; + + @SerializedName("ProjectileType") + public String projectileType = "superbwarfare:projectile"; + @SerializedName("ProjectileAmount") public int projectileAmount = 1; @SerializedName("Weight") diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/data/GunData.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/data/GunData.java index 0523936cb..77a139325 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/data/GunData.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/data/GunData.java @@ -187,6 +187,10 @@ public class GunData { return magazine() <= 0; } + public String projectileType() { + return defaultGunData().projectileType; + } + public int projectileAmount() { return defaultGunData().projectileAmount; } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/M79Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/M79Item.java index 2bfc4bb8e..87880af0e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/M79Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/M79Item.java @@ -3,13 +3,10 @@ package com.atsuishio.superbwarfare.item.gun.launcher; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.client.renderer.item.M79ItemRenderer; import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent; -import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; -import com.atsuishio.superbwarfare.perk.AmmoPerk; -import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.tools.ParticleTool; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -103,6 +100,7 @@ public class M79Item extends GunItem implements GeoItem { public @NotNull Optional getTooltipImage(@NotNull ItemStack pStack) { return Optional.of(new LauncherImageComponent(pStack)); } + @Override public String getAmmoDisplayName(GunData data) { return "40mm Grenade"; @@ -110,37 +108,12 @@ public class M79Item extends GunItem implements GeoItem { @Override public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) { - if (data.reloading()) return false; + if (!super.shootBullet(player, data, spread, zoom)) return false; - if (player.level() instanceof ServerLevel serverLevel) { - GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel, - (float) data.damage(), - (float) data.explosionDamage(), - (float) data.explosionRadius() - ); - - float velocity = (float) data.velocity(); - - for (Perk.Type type : Perk.Type.values()) { - var instance = data.perk.getInstance(type); - if (instance != null) { - instance.perk().modifyProjectile(data, instance, gunGrenadeEntity); - if (instance.perk() instanceof AmmoPerk ammoPerk) { - velocity = (float) ammoPerk.getModifiedVelocity(data, instance); - } - } - } - - gunGrenadeEntity.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ()); - gunGrenadeEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, velocity, - (float) (zoom ? 0.1 : spread)); - serverLevel.addFreshEntity(gunGrenadeEntity); - - ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x, - player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y, - player.getZ() + 1.8 * player.getLookAngle().z, - 4, 0.1, 0.1, 0.1, 0.002, true); - } + ParticleTool.sendParticle((ServerLevel) player.level(), ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x, + player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y, + player.getZ() + 1.8 * player.getLookAngle().z, + 4, 0.1, 0.1, 0.1, 0.002, true); return true; } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java index fdc1beece..0e1df2b10 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java @@ -3,13 +3,10 @@ package com.atsuishio.superbwarfare.item.gun.launcher; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.client.renderer.item.RpgItemRenderer; import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent; -import com.atsuishio.superbwarfare.entity.projectile.RpgRocketEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; -import com.atsuishio.superbwarfare.perk.AmmoPerk; -import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.tools.ParticleTool; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -134,40 +131,13 @@ public class RpgItem extends GunItem implements GeoItem { @Override public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) { - Level level = player.level(); + if (!super.shootBullet(player, data, spread, zoom)) return false; - if (data.reloading()) return false; + ParticleTool.sendParticle((ServerLevel) player.level(), ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x, + player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y, + player.getZ() + 1.8 * player.getLookAngle().z, + 30, 0.4, 0.4, 0.4, 0.005, true); - if (player.level() instanceof ServerLevel serverLevel) { - RpgRocketEntity rocket = new RpgRocketEntity(player, level, - (float) data.damage(), - (float) data.explosionDamage(), - (float) data.explosionRadius() - ); - - float velocity = (float) data.velocity(); - - for (Perk.Type type : Perk.Type.values()) { - var instance = data.perk.getInstance(type); - if (instance != null) { - instance.perk().modifyProjectile(data, instance, rocket); - if (instance.perk() instanceof AmmoPerk ammoPerk) { - velocity = (float) ammoPerk.getModifiedVelocity(data, instance); - } - } - } - - rocket.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ()); - rocket.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, velocity, - (float) (zoom ? 0.1 : spread)); - level.addFreshEntity(rocket); - - ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x, - player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y, - player.getZ() + 1.8 * player.getLookAngle().z, - 30, 0.4, 0.4, 0.4, 0.005, true); - - } data.isEmpty.set(true); data.closeHammer.set(true); diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java index 2faca2e83..16b3fc734 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java @@ -215,6 +215,7 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, EnergyStorag return "40mm Grenade"; } + // TODO 这玩意能提取吗 @Override public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) { if (data.reloading()) return false; diff --git a/src/main/resources/data/superbwarfare/guns/m_79.json b/src/main/resources/data/superbwarfare/guns/m_79.json index 1107baad5..176e24f1f 100644 --- a/src/main/resources/data/superbwarfare/guns/m_79.json +++ b/src/main/resources/data/superbwarfare/guns/m_79.json @@ -3,6 +3,7 @@ "RecoilX": 0.004, "RecoilY": 0.023, "Damage": 40, + "ProjectileType": "superbwarfare:gun_grenade", "ExplosionDamage": 80, "ExplosionRadius": 5, "Velocity": 3.75, diff --git a/src/main/resources/data/superbwarfare/guns/rpg.json b/src/main/resources/data/superbwarfare/guns/rpg.json index ad6f33df0..bb12eae5b 100644 --- a/src/main/resources/data/superbwarfare/guns/rpg.json +++ b/src/main/resources/data/superbwarfare/guns/rpg.json @@ -3,6 +3,7 @@ "RecoilX": 0.008, "RecoilY": 0.018, "Damage": 270, + "ProjectileType": "superbwarfare:rpg_rocket", "ExplosionDamage": 130, "ExplosionRadius": 10, "Velocity": 4,