diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java index 29e7c0eb4..917d7d5d0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java @@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.entity; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig; +import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModEntities; @@ -29,6 +30,7 @@ import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PlayMessages; @@ -44,18 +46,21 @@ import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; -public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelicopterEntity { +public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelicopterEntity, MultiWeaponVehicleEntity { private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public static final float MAX_HEALTH = 200; public static final int MAX_ENERGY = 4000000; public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor PROPELLER_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor WEAPON_TYPE = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT); public boolean engineStart; public boolean engineStartOver; public float propellerRot; public float propellerRotO; + public int fireIndex; + public Ah6Entity(PlayMessages.SpawnEntity packet, Level world) { this(ModEntities.AH_6.get(), world); } @@ -69,6 +74,7 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DELTA_ROT, 0f); + this.entityData.define(WEAPON_TYPE, 0); this.entityData.define(PROPELLER_ROT, 0f); } @@ -297,7 +303,7 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker == null ? this : attacker, attacker == null ? this : attacker), 25.0f, this.getX(), this.getY(), this.getZ(), 5f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); - net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); + ForgeEventFactory.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); this.discard(); @@ -327,43 +333,88 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico public void vehicleShoot(Player player) { Matrix4f transform = getVehicleTransform(); - float x = 1f; - float y = 0.62f; - float z = 0.8f; + float x; + float y; + float z; - Vector4f worldPositionRight = transformPosition(transform, -x, y, z); - ProjectileEntity projectileRight = new ProjectileEntity(player.level()) - .shooter(player) - .damage(20) - .headShot(2f) - .zoom(false); + Vector4f worldPositionRight; + Vector4f worldPositionLeft; - projectileRight.heBullet(true, 8); - projectileRight.bypassArmorRate(1); - projectileRight.setPos(worldPositionRight.x, worldPositionRight.y, worldPositionRight.z); - projectileRight.shoot(player, this.getLookAngle().x, this.getLookAngle().y+ 0.03, this.getLookAngle().z, 20, - (float) 0.2); - this.level().addFreshEntity(projectileRight); + if (entityData.get(WEAPON_TYPE) == 0) { + x = 1f; + y = 0.62f; + z = 0.8f; - Vector4f worldPositionLeft = transformPosition(transform, x, y, z); - ProjectileEntity projectileLeft = new ProjectileEntity(player.level()) - .shooter(player) - .damage(20) - .headShot(2f) - .zoom(false); + worldPositionRight = transformPosition(transform, -x, y, z); + worldPositionLeft = transformPosition(transform, x, y, z); - projectileLeft.heBullet(true, 8); - projectileLeft.bypassArmorRate(1); - projectileLeft.setPos(worldPositionLeft.x, worldPositionLeft.y, worldPositionLeft.z); - projectileLeft.shoot(player, this.getLookAngle().x, this.getLookAngle().y + 0.03, this.getLookAngle().z, 20, - (float) 0.2); - this.level().addFreshEntity(projectileLeft); + ProjectileEntity projectileRight = new ProjectileEntity(player.level()) + .shooter(player) + .damage(25) + .headShot(2f) + .zoom(false); - if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_FIRE_3P.get(), 4, 1); - serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_FAR.get(), 12, 1); - serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_VERYFAR.get(), 24, 1); + projectileRight.heBullet(true, 5); + projectileRight.bypassArmorRate(1); + projectileRight.setPos(worldPositionRight.x, worldPositionRight.y, worldPositionRight.z); + projectileRight.shoot(player, this.getLookAngle().x, this.getLookAngle().y+ 0.03, this.getLookAngle().z, 20, + (float) 0.2); + this.level().addFreshEntity(projectileRight); + + ProjectileEntity projectileLeft = new ProjectileEntity(player.level()) + .shooter(player) + .damage(25) + .headShot(2f) + .zoom(false); + + projectileLeft.heBullet(true, 5); + projectileLeft.bypassArmorRate(1); + projectileLeft.setPos(worldPositionLeft.x, worldPositionLeft.y, worldPositionLeft.z); + projectileLeft.shoot(player, this.getLookAngle().x, this.getLookAngle().y + 0.03, this.getLookAngle().z, 20, + (float) 0.2); + this.level().addFreshEntity(projectileLeft); + + if (!player.level().isClientSide) { + if (player instanceof ServerPlayer serverPlayer) { + serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_FIRE_3P.get(), 4, 1); + serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_FAR.get(), 12, 1); + serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_VERYFAR.get(), 24, 1); + } + } + } else if (entityData.get(WEAPON_TYPE) == 1) { + x = 1.15f; + y = 0.62f; + z = 0.8f; + + worldPositionRight = transformPosition(transform, -x, y, z); + worldPositionLeft = transformPosition(transform, x, y, z); + + if (fireIndex == 0) { + GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, player.level(), + 110, + 40, + 6); + + gunGrenadeEntity.setPos(worldPositionRight.x, worldPositionRight.y, worldPositionRight.z); + gunGrenadeEntity.shoot(this.getLookAngle().x, this.getLookAngle().y+ 0.03, this.getLookAngle().z, 8, 0.25f); + player.level().addFreshEntity(gunGrenadeEntity); + fireIndex = 1; + } else if (fireIndex == 1){ + GunGrenadeEntity gunGrenadeEntityLeft = new GunGrenadeEntity(player, player.level(), + 110, + 40, + 5); + + gunGrenadeEntityLeft.setPos(worldPositionLeft.x, worldPositionLeft.y, worldPositionLeft.z); + gunGrenadeEntityLeft.shoot(this.getLookAngle().x, this.getLookAngle().y+ 0.03, this.getLookAngle().z, 8, 0.25f); + player.level().addFreshEntity(gunGrenadeEntityLeft); + fireIndex = 0; + } + + if (!player.level().isClientSide) { + if (player instanceof ServerPlayer serverPlayer) { + serverPlayer.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_3P.get(), 6, 1); + } } } @@ -417,4 +468,17 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico public float getPower() { return this.entityData.get(POWER); } + + @Override + public void changeWeapon() { + entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + 1); + if (entityData.get(WEAPON_TYPE) == 2) { + entityData.set(WEAPON_TYPE, 0); + } + } + + @Override + public int getWeaponType() { + return entityData.get(WEAPON_TYPE); + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/MultiWeaponVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/MultiWeaponVehicleEntity.java new file mode 100644 index 000000000..71f13f3d2 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/entity/MultiWeaponVehicleEntity.java @@ -0,0 +1,6 @@ +package com.atsuishio.superbwarfare.entity; + +public interface MultiWeaponVehicleEntity { + void changeWeapon(); + int getWeaponType(); +} diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index 15cf2fcb4..0fcb6b695 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -55,6 +55,7 @@ import software.bernie.geckolib.core.animatable.model.CoreGeoBone; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; +import static com.atsuishio.superbwarfare.entity.Ah6Entity.WEAPON_TYPE; import static com.atsuishio.superbwarfare.entity.SpeedboatEntity.HEAT; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) @@ -649,7 +650,12 @@ public class ClientEventHandler { player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); } if (iVehicle instanceof Ah6Entity ah6Entity) { - player.playSound(ModSounds.HELICOPTER_CANNON_FIRE_1P.get(), 1f, 1); + if (ah6Entity.getEntityData().get(WEAPON_TYPE) == 0) { + player.playSound(ModSounds.HELICOPTER_CANNON_FIRE_1P.get(), 1f, 1); + } else if (ah6Entity.getEntityData().get(WEAPON_TYPE) == 1) { + player.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_1P.get(), 1f, 1); + } + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java b/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java index 6593c9f10..b5845810b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java @@ -363,5 +363,7 @@ public class ModSounds { public static final RegistryObject HELICOPTER_CANNON_FIRE_3P = REGISTRY.register("heli_cannon_fire_3p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_cannon_fire_3p"))); public static final RegistryObject HELICOPTER_CANNON_FAR = REGISTRY.register("heli_cannon_far", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_cannon_far"))); public static final RegistryObject HELICOPTER_CANNON_VERYFAR = REGISTRY.register("heli_cannon_veryfar", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_cannon_veryfar"))); + public static final RegistryObject HELICOPTER_ROCKET_FIRE_1P = REGISTRY.register("heli_rocket_fire_1p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_rocket_fire_1p"))); + public static final RegistryObject HELICOPTER_ROCKET_FIRE_3P = REGISTRY.register("heli_rocket_fire_3p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_rocket_fire_3p"))); } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/FireModeMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/FireModeMessage.java index d56b35290..dd6dd08a4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/FireModeMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/FireModeMessage.java @@ -1,5 +1,7 @@ package com.atsuishio.superbwarfare.network.message; +import com.atsuishio.superbwarfare.entity.IArmedVehicleEntity; +import com.atsuishio.superbwarfare.entity.MultiWeaponVehicleEntity; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; @@ -125,6 +127,10 @@ public class FireModeMessage { GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true); } } + return; + } + if (player.getVehicle() instanceof IArmedVehicleEntity iArmedVehicle && iArmedVehicle.isDriver(player) && iArmedVehicle instanceof MultiWeaponVehicleEntity multiWeaponVehicle) { + multiWeaponVehicle.changeWeapon(); } } diff --git a/src/main/resources/assets/superbwarfare/sounds.json b/src/main/resources/assets/superbwarfare/sounds.json index 091110cf1..6c464bc51 100644 --- a/src/main/resources/assets/superbwarfare/sounds.json +++ b/src/main/resources/assets/superbwarfare/sounds.json @@ -2553,5 +2553,21 @@ "stream": false } ] + }, + "heli_rocket_fire_1p": { + "sounds": [ + { + "name": "superbwarfare:helicopter/heli_rocket_fire_1p", + "stream": false + } + ] + }, + "heli_rocket_fire_3p": { + "sounds": [ + { + "name": "superbwarfare:helicopter/heli_rocket_fire_3p", + "stream": false + } + ] } } \ No newline at end of file diff --git a/src/main/resources/assets/superbwarfare/sounds/helicopter/heli_rocket_fire_1p.ogg b/src/main/resources/assets/superbwarfare/sounds/helicopter/heli_rocket_fire_1p.ogg new file mode 100644 index 000000000..76d9e1b86 Binary files /dev/null and b/src/main/resources/assets/superbwarfare/sounds/helicopter/heli_rocket_fire_1p.ogg differ diff --git a/src/main/resources/assets/superbwarfare/sounds/helicopter/heli_rocket_fire_3p.ogg b/src/main/resources/assets/superbwarfare/sounds/helicopter/heli_rocket_fire_3p.ogg new file mode 100644 index 000000000..f2be92117 Binary files /dev/null and b/src/main/resources/assets/superbwarfare/sounds/helicopter/heli_rocket_fire_3p.ogg differ