添加直升机的火箭弹发射

This commit is contained in:
Atsuihsio 2025-01-03 23:31:58 +08:00
parent 2e7e789bc0
commit e7971c812f
8 changed files with 135 additions and 35 deletions

View file

@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig; 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.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities; 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.level.Level;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
@ -44,18 +46,21 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.Comparator; 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); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = 200; public static final float MAX_HEALTH = 200;
public static final int MAX_ENERGY = 4000000; public static final int MAX_ENERGY = 4000000;
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> PROPELLER_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> PROPELLER_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> WEAPON_TYPE = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT);
public boolean engineStart; public boolean engineStart;
public boolean engineStartOver; public boolean engineStartOver;
public float propellerRot; public float propellerRot;
public float propellerRotO; public float propellerRotO;
public int fireIndex;
public Ah6Entity(PlayMessages.SpawnEntity packet, Level world) { public Ah6Entity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.AH_6.get(), world); this(ModEntities.AH_6.get(), world);
} }
@ -69,6 +74,7 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico
protected void defineSynchedData() { protected void defineSynchedData() {
super.defineSynchedData(); super.defineSynchedData();
this.entityData.define(DELTA_ROT, 0f); this.entityData.define(DELTA_ROT, 0f);
this.entityData.define(WEAPON_TYPE, 0);
this.entityData.define(PROPELLER_ROT, 0f); 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, 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); this.getX(), this.getY(), this.getZ(), 5f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
this.discard(); this.discard();
@ -327,43 +333,88 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico
public void vehicleShoot(Player player) { public void vehicleShoot(Player player) {
Matrix4f transform = getVehicleTransform(); Matrix4f transform = getVehicleTransform();
float x = 1f; float x;
float y = 0.62f; float y;
float z = 0.8f; float z;
Vector4f worldPositionRight = transformPosition(transform, -x, y, z); Vector4f worldPositionRight;
ProjectileEntity projectileRight = new ProjectileEntity(player.level()) Vector4f worldPositionLeft;
.shooter(player)
.damage(20)
.headShot(2f)
.zoom(false);
projectileRight.heBullet(true, 8); if (entityData.get(WEAPON_TYPE) == 0) {
projectileRight.bypassArmorRate(1); x = 1f;
projectileRight.setPos(worldPositionRight.x, worldPositionRight.y, worldPositionRight.z); y = 0.62f;
projectileRight.shoot(player, this.getLookAngle().x, this.getLookAngle().y+ 0.03, this.getLookAngle().z, 20, z = 0.8f;
(float) 0.2);
this.level().addFreshEntity(projectileRight);
Vector4f worldPositionLeft = transformPosition(transform, x, y, z); worldPositionRight = transformPosition(transform, -x, y, z);
ProjectileEntity projectileLeft = new ProjectileEntity(player.level()) worldPositionLeft = transformPosition(transform, x, y, z);
.shooter(player)
.damage(20)
.headShot(2f)
.zoom(false);
projectileLeft.heBullet(true, 8); ProjectileEntity projectileRight = new ProjectileEntity(player.level())
projectileLeft.bypassArmorRate(1); .shooter(player)
projectileLeft.setPos(worldPositionLeft.x, worldPositionLeft.y, worldPositionLeft.z); .damage(25)
projectileLeft.shoot(player, this.getLookAngle().x, this.getLookAngle().y + 0.03, this.getLookAngle().z, 20, .headShot(2f)
(float) 0.2); .zoom(false);
this.level().addFreshEntity(projectileLeft);
if (!player.level().isClientSide) { projectileRight.heBullet(true, 5);
if (player instanceof ServerPlayer serverPlayer) { projectileRight.bypassArmorRate(1);
serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_FIRE_3P.get(), 4, 1); projectileRight.setPos(worldPositionRight.x, worldPositionRight.y, worldPositionRight.z);
serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_FAR.get(), 12, 1); projectileRight.shoot(player, this.getLookAngle().x, this.getLookAngle().y+ 0.03, this.getLookAngle().z, 20,
serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_VERYFAR.get(), 24, 1); (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() { public float getPower() {
return this.entityData.get(POWER); 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);
}
} }

View file

@ -0,0 +1,6 @@
package com.atsuishio.superbwarfare.entity;
public interface MultiWeaponVehicleEntity {
void changeWeapon();
int getWeaponType();
}

View file

@ -55,6 +55,7 @@ import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier; import java.util.function.Supplier;
import static com.atsuishio.superbwarfare.entity.Ah6Entity.WEAPON_TYPE;
import static com.atsuishio.superbwarfare.entity.SpeedboatEntity.HEAT; import static com.atsuishio.superbwarfare.entity.SpeedboatEntity.HEAT;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) @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); player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1);
} }
if (iVehicle instanceof Ah6Entity ah6Entity) { 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);
}
} }
} }

View file

@ -363,5 +363,7 @@ public class ModSounds {
public static final RegistryObject<SoundEvent> HELICOPTER_CANNON_FIRE_3P = REGISTRY.register("heli_cannon_fire_3p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_cannon_fire_3p"))); public static final RegistryObject<SoundEvent> HELICOPTER_CANNON_FIRE_3P = REGISTRY.register("heli_cannon_fire_3p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_cannon_fire_3p")));
public static final RegistryObject<SoundEvent> HELICOPTER_CANNON_FAR = REGISTRY.register("heli_cannon_far", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_cannon_far"))); public static final RegistryObject<SoundEvent> HELICOPTER_CANNON_FAR = REGISTRY.register("heli_cannon_far", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_cannon_far")));
public static final RegistryObject<SoundEvent> HELICOPTER_CANNON_VERYFAR = REGISTRY.register("heli_cannon_veryfar", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_cannon_veryfar"))); public static final RegistryObject<SoundEvent> HELICOPTER_CANNON_VERYFAR = REGISTRY.register("heli_cannon_veryfar", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_cannon_veryfar")));
public static final RegistryObject<SoundEvent> HELICOPTER_ROCKET_FIRE_1P = REGISTRY.register("heli_rocket_fire_1p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_rocket_fire_1p")));
public static final RegistryObject<SoundEvent> HELICOPTER_ROCKET_FIRE_3P = REGISTRY.register("heli_rocket_fire_3p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("heli_rocket_fire_3p")));
} }

View file

@ -1,5 +1,7 @@
package com.atsuishio.superbwarfare.network.message; 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.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -125,6 +127,10 @@ public class FireModeMessage {
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true); GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true);
} }
} }
return;
}
if (player.getVehicle() instanceof IArmedVehicleEntity iArmedVehicle && iArmedVehicle.isDriver(player) && iArmedVehicle instanceof MultiWeaponVehicleEntity multiWeaponVehicle) {
multiWeaponVehicle.changeWeapon();
} }
} }

View file

@ -2553,5 +2553,21 @@
"stream": false "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
}
]
} }
} }