diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java index 85ce92aab..e0473d9f4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java @@ -38,6 +38,7 @@ import static com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay.*; import static com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity.WEAPON_TYPE; import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.COAX_HEAT; import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.HEAT; +import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.AMMO; @Mod.EventBusSubscriber(value = Dist.CLIENT) public class VehicleHudOverlay { @@ -295,6 +296,14 @@ public class VehicleHudOverlay { } + if (player.getVehicle() instanceof Yx100Entity yx100) { + if (multiWeaponVehicle.getWeaponType() == 0) { + guiGraphics.drawString(mc.font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + yx100.getEntityData().get(AMMO)), w / 2 - 33, h - 65, 0x66FF00, false); + } else { + guiGraphics.drawString(mc.font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + yx100.getEntityData().get(AMMO)), w / 2 - 33, h - 65, 0x66FF00, false); + } + } + // 血量 double heal = mobileVehicle.getHealth() / mobileVehicle.getMaxHealth(); guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(FormatTool.format0D(100 * heal)), w / 2 - 165, h / 2 - 46, Mth.hsvToRgb((float) heal / 3.745318352059925F, 1.0F, 1.0F), false); 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 ff1ff8a11..0338554fb 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java @@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.projectile; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.entity.AnimatedEntity; +import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage; import com.atsuishio.superbwarfare.tools.ChunkLoadTool; @@ -162,106 +163,79 @@ public class CannonShellEntity extends ThrowableItemProjectile implements GeoEnt @Override public void onHitEntity(EntityHitResult entityHitResult) { - Entity entity = entityHitResult.getEntity(); - entity.hurt(ModDamageTypes.causeCannonFireDamage(this.level().registryAccess(), this, this.getOwner()), this.damage); + if (this.level() instanceof ServerLevel) { + Entity entity = entityHitResult.getEntity(); + entity.hurt(ModDamageTypes.causeCannonFireDamage(this.level().registryAccess(), this, this.getOwner()), this.damage); - if (entity instanceof LivingEntity) { - entity.invulnerableTime = 0; - } - - if (this.getOwner() instanceof LivingEntity living) { - if (!living.level().isClientSide() && living instanceof ServerPlayer player) { - living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1); - - ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5)); + if (entity instanceof LivingEntity) { + entity.invulnerableTime = 0; } - } - ParticleTool.cannonHitParticles(this.level(), this.position()); + if (this.getOwner() instanceof LivingEntity living) { + if (!living.level().isClientSide() && living instanceof ServerPlayer player) { + living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1); - Vec3 vec = this.getDeltaMovement(); - double vec_x = vec.x; - double vec_y = vec.y; - double vec_z = vec.z; - - this.setDeltaMovement(vec_x - 0.02 * vec_x, vec_y - 0.02 * vec_y, vec_z - 0.02 * vec_z); - - this.durability -= 2; - if (this.durability <= 0) { - if (!this.level().isClientSide()) { - causeExplode(entity); + ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5)); + } } - this.discard(); + + ParticleTool.cannonHitParticles(this.level(), this.position(), this); + causeExplode(entity); + if (entity instanceof VehicleEntity) { + this.discard(); + } + } } @Override public void onHitBlock(BlockHitResult blockHitResult) { - super.onHitBlock(blockHitResult); + if (this.level() instanceof ServerLevel) { + int x = blockHitResult.getBlockPos().getX(); + int y = blockHitResult.getBlockPos().getY(); + int z = blockHitResult.getBlockPos().getZ(); - int x = blockHitResult.getBlockPos().getX(); - int y = blockHitResult.getBlockPos().getY(); - int z = blockHitResult.getBlockPos().getZ(); - - BlockState blockState = this.level().getBlockState(BlockPos.containing(x, y, z)); - if (blockState.is(Blocks.BEDROCK) || blockState.is(Blocks.BARRIER)) { - this.discard(); - causeExplodeBlock(blockHitResult); - return; - } - - float hardness = this.level().getBlockState(BlockPos.containing(x, y, z)).getBlock().defaultDestroyTime(); - this.durability -= (int) hardness; - - if (ExplosionConfig.EXPLOSION_DESTROY.get() && hardness != -1 && hardness <= 50) { - BlockPos blockPos = BlockPos.containing(x, y, z); - Block.dropResources(this.level().getBlockState(blockPos), this.level(), BlockPos.containing(x, y, z), null); - this.level().destroyBlock(blockPos, true); - } - - Vec3 vec = this.getDeltaMovement(); - this.setDeltaMovement(vec.multiply(0.4, 0.4, 0.4)); - - if (blockState.is(ModBlocks.SANDBAG.get()) || blockState.is(Blocks.NETHERITE_BLOCK)) { - this.durability -= 10; - } - - if (blockState.is(Blocks.IRON_BLOCK) || blockState.is(Blocks.COPPER_BLOCK)) { - this.durability -= 5; - } - - if (blockState.is(Blocks.GOLD_BLOCK)) { - this.durability -= 3; - } - - if (this.durability <= 0) { - if (!this.level().isClientSide()) { - causeExplodeBlock(blockHitResult); + BlockState blockState = this.level().getBlockState(BlockPos.containing(x, y, z)); + if (blockState.is(Blocks.BEDROCK) || blockState.is(Blocks.BARRIER)) { this.discard(); + causeExplodeBlock(blockHitResult); + return; } - } else { - if (!this.level().isClientSide()) { + + float hardness = this.level().getBlockState(BlockPos.containing(x, y, z)).getBlock().defaultDestroyTime(); + this.durability -= (int) hardness; + + if (ExplosionConfig.EXPLOSION_DESTROY.get() && hardness != -1 && hardness <= 50) { + BlockPos blockPos = BlockPos.containing(x, y, z); + Block.dropResources(this.level().getBlockState(blockPos), this.level(), BlockPos.containing(x, y, z), null); + this.level().destroyBlock(blockPos, true); + } + + if (blockState.is(ModBlocks.SANDBAG.get()) || blockState.is(Blocks.NETHERITE_BLOCK)) { + this.durability -= 10; + } + + if (blockState.is(Blocks.IRON_BLOCK) || blockState.is(Blocks.COPPER_BLOCK)) { + this.durability -= 5; + } + + if (blockState.is(Blocks.GOLD_BLOCK)) { + this.durability -= 3; + } + + if (this.durability <= 0) { + causeExplodeBlock(blockHitResult); + } else { if (ExplosionConfig.EXPLOSION_DESTROY.get()) { if (this.firstHit) { - ParticleTool.cannonHitParticles(this.level(), this.position()); + ParticleTool.cannonHitParticles(this.level(), this.position(), this); causeExplodeBlock(blockHitResult); this.firstHit = false; - this.setNoGravity(true); - } else { - apExplode(blockHitResult); } } + apExplode(blockHitResult); } } - - if (this.durability > 0) { - ModUtils.queueServerWork(2, () -> { - if (!this.level().isClientSide()) { - causeExplodeBlock(blockHitResult); - this.discard(); - } - }); - } } @Override @@ -340,6 +314,7 @@ public class CannonShellEntity extends ThrowableItemProjectile implements GeoEnt } else { ParticleTool.spawnMediumExplosionParticles(this.level(), result.getLocation()); } + this.discard(); } private void apExplode(HitResult result) { @@ -352,9 +327,9 @@ public class CannonShellEntity extends ThrowableItemProjectile implements GeoEnt this, this.getOwner()), explosionDamage, - result.getLocation().x, - result.getLocation().y, - result.getLocation().z, + result.getLocation().x + 5 * getDeltaMovement().normalize().x, + result.getLocation().y + 5 * getDeltaMovement().normalize().y, + result.getLocation().z + 5 * getDeltaMovement().normalize().z, radius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP). setDamageMultiplier(1).setFireTime(fireTime); @@ -367,6 +342,7 @@ public class CannonShellEntity extends ThrowableItemProjectile implements GeoEnt } else { ParticleTool.spawnMediumExplosionParticles(this.level(), result.getLocation()); } + this.discard(); } private PlayState movementPredicate(AnimationState event) { 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 8b99bd7cc..c835c53c1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java @@ -193,8 +193,8 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, .multiply(0.2f, ModDamageTypes.PROJECTILE_BOOM) .multiply(0.1f, ModDamageTypes.MINE) .multiply(0.12f, ModDamageTypes.LUNGE_MINE) - .multiply(0.22f, ModDamageTypes.CANNON_FIRE) - .multiply(0.07f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE) + .multiply(0.16f, ModDamageTypes.CANNON_FIRE) + .multiply(0.03f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE) .reduce(10); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java index 4496e870d..a556b7eca 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java @@ -139,13 +139,13 @@ public class VehicleEntity extends Entity { return InteractionResult.SUCCESS; } else if (!player.isShiftKeyDown()) { if (this.getFirstPassenger() == null) { -// player.setXRot(this.getXRot()); -// player.setYRot(this.getYRot()); + player.setXRot(this.getXRot()); + player.setYRot(this.getYRot()); return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS; } else if (!(this.getFirstPassenger() instanceof Player)) { this.getFirstPassenger().stopRiding(); -// player.setXRot(this.getXRot()); -// player.setYRot(this.getYRot()); + player.setXRot(this.getXRot()); + player.setYRot(this.getYRot()); return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS; } if (this.canAddPassenger(player)) { @@ -468,7 +468,7 @@ public class VehicleEntity extends Entity { } protected Vec3 getDismountOffset(double vehicleWidth, double passengerWidth) { - double offset = (vehicleWidth + passengerWidth + (double) 1.0E-5f) / 2.0; + double offset = (vehicleWidth + passengerWidth + (double) 1.0E-5f) / 1.75; float yaw = getYRot() + 90.0f; float x = -Mth.sin(yaw * ((float) java.lang.Math.PI / 180)); float z = Mth.cos(yaw * ((float) java.lang.Math.PI / 180)); 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 f29c5ff30..7e6545ca6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -3,8 +3,7 @@ package com.atsuishio.superbwarfare.entity.vehicle; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; -import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; -import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity; +import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; @@ -58,15 +57,14 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public static final EntityDataAccessor FIRE_ANIM = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor HEAT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); - public static final EntityDataAccessor COAX_HEAT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); + public static final EntityDataAccessor LOADED_AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor WEAPON_TYPE = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor TRACK_L = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor TRACK_R = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT); - public static final float MAX_HEALTH = VehicleConfig.BMP_2_HP.get(); - public static final int MAX_ENERGY = VehicleConfig.BMP_2_MAX_ENERGY.get(); + public static final float MAX_HEALTH = 400; + public static final int MAX_ENERGY = 5000000; private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public float turretYRot; @@ -77,8 +75,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public float rightWheelRot; public float leftWheelRotO; public float rightWheelRotO; - public boolean cannotFire; - public boolean cannotFireCoax; public int reloadCoolDown; public Yx100Entity(PlayMessages.SpawnEntity packet, Level world) { @@ -94,10 +90,9 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(AMMO, 0); + this.entityData.define(LOADED_AMMO, 0); this.entityData.define(FIRE_ANIM, 0); this.entityData.define(DELTA_ROT, 0f); - this.entityData.define(HEAT, 0); - this.entityData.define(COAX_HEAT, 0); this.entityData.define(WEAPON_TYPE, 0); this.entityData.define(TRACK_L, 0f); this.entityData.define(TRACK_R, 0f); @@ -106,11 +101,15 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public void addAdditionalSaveData(CompoundTag compound) { super.addAdditionalSaveData(compound); + compound.putInt("LoadedAmmo", this.entityData.get(LOADED_AMMO)); + compound.putInt("WeaponType", this.entityData.get(WEAPON_TYPE)); } @Override public void readAdditionalSaveData(CompoundTag compound) { super.readAdditionalSaveData(compound); + this.entityData.set(LOADED_AMMO, compound.getInt("LoadedAmmo")); + this.entityData.set(WEAPON_TYPE, compound.getInt("WeaponType")); } @Override @@ -121,24 +120,22 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public DamageModifier getDamageModifier() { return super.getDamageModifier() - .multiply(0.3f, DamageTypes.ARROW) - .multiply(0.3f, DamageTypes.TRIDENT) - .multiply(0.5f, DamageTypes.MOB_ATTACK) - .multiply(0.4f, DamageTypes.MOB_ATTACK_NO_AGGRO) - .multiply(0.3f, DamageTypes.MOB_PROJECTILE) - .multiply(0.2f, DamageTypes.PLAYER_ATTACK) - .multiply(2.5f, DamageTypes.LAVA) - .multiply(1.2f, DamageTypes.EXPLOSION) - .multiply(1.2f, DamageTypes.PLAYER_EXPLOSION) - .multiply(0.4f, ModDamageTypes.CUSTOM_EXPLOSION) - .multiply(0.4f, ModDamageTypes.PROJECTILE_BOOM) - .multiply(0.14f, ModDamageTypes.MINE) - .multiply(0.18f, ModDamageTypes.LUNGE_MINE) - .multiply(0.3f, ModDamageTypes.CANNON_FIRE) - .multiply(0.02f, ModTags.DamageTypes.PROJECTILE) - .multiply(0.14f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE) - .multiply(1.7f, ModDamageTypes.VEHICLE_STRIKE) - .reduce(8); + .immuneTo(DamageTypes.ARROW) + .immuneTo(DamageTypes.TRIDENT) + .immuneTo(DamageTypes.MOB_ATTACK) + .immuneTo(DamageTypes.MOB_ATTACK_NO_AGGRO) + .immuneTo(DamageTypes.MOB_PROJECTILE) + .immuneTo(DamageTypes.PLAYER_ATTACK) + .immuneTo(ModTags.DamageTypes.PROJECTILE) + .immuneTo(ModDamageTypes.VEHICLE_STRIKE) + .multiply(0.75f, DamageTypes.EXPLOSION) + .multiply(0.23f, ModDamageTypes.CUSTOM_EXPLOSION) + .multiply(0.23f, ModDamageTypes.PROJECTILE_BOOM) + .multiply(0.13f, ModDamageTypes.MINE) + .multiply(0.15f, ModDamageTypes.LUNGE_MINE) + .multiply(0.2f, ModDamageTypes.CANNON_FIRE) + .multiply(0.05f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE) + .reduce(9); } @Override @@ -176,49 +173,21 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti this.entityData.set(TRACK_L, 0f); } - if (this.entityData.get(HEAT) > 0) { - this.entityData.set(HEAT, this.entityData.get(HEAT) - 1); - } - if (this.entityData.get(FIRE_ANIM) > 0) { this.entityData.set(FIRE_ANIM, this.entityData.get(FIRE_ANIM) - 1); } - if (this.entityData.get(HEAT) < 40) { - cannotFire = false; - } - - if (this.entityData.get(COAX_HEAT) > 0) { - this.entityData.set(COAX_HEAT, this.entityData.get(COAX_HEAT) - 1); - } - - if (this.entityData.get(COAX_HEAT) < 40) { - cannotFireCoax = false; + if (reloadCoolDown == 70 && this.getFirstPassenger() instanceof Player player) { + SoundTool.playLocalSound(player, ModSounds.YX_100_RELOAD.get()); } if (this.level() instanceof ServerLevel) { - if (reloadCoolDown > 0) { + if (reloadCoolDown > 0 && this.entityData.get(AMMO) > 0) { reloadCoolDown--; } this.handleAmmo(); } - Entity driver = this.getFirstPassenger(); - if (driver instanceof Player player) { - if (this.entityData.get(HEAT) > 100) { - cannotFire = true; - if (!player.level().isClientSide() && player instanceof ServerPlayer serverPlayer) { - SoundTool.playLocalSound(serverPlayer, ModSounds.MINIGUN_OVERHEAT.get(), 1f, 1f); - } - } - if (this.entityData.get(COAX_HEAT) > 100) { - cannotFireCoax = true; - if (!player.level().isClientSide() && player instanceof ServerPlayer serverPlayer) { - SoundTool.playLocalSound(serverPlayer, ModSounds.MINIGUN_OVERHEAT.get(), 1f, 1f); - } - } - } - if (this.onGround()) { float f0 = 0.54f + 0.25f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90; this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.05 * this.getDeltaMovement().horizontalDistance()))); @@ -253,20 +222,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti gunnerAngle(); lowHealthWarning(); - -// List entities = this.getPassengers(); -// -// for (var e : entities) { -// if (!(e instanceof Yx100GunEntity)) { -// Yx100GunEntity yx100Gun = new Yx100GunEntity(ModEntities.YX_100_GUN.get(), this.level()); -// this.level().addFreshEntity(yx100Gun); -// yx100Gun.startRiding(this, true); -// } -// } -// -//// if (!(this.hasPassenger(yx100Gun))) { -//// -//// } this.refreshDimensions(); } @@ -281,11 +236,28 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti }).mapToInt(stack -> stack.getOrCreateTag().getInt("RifleAmmo")).sum() + this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).mapToInt(ItemStack::getCount).sum(); + boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); - if (this.getEntityData().get(WEAPON_TYPE) == 0) { - this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).mapToInt(ItemStack::getCount).sum()); + if (hasCreativeAmmo) { + this.entityData.set(AMMO, 9999); + } else if (this.getEntityData().get(WEAPON_TYPE) == 0) { + this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.AP_5_INCHES.get())).mapToInt(ItemStack::getCount).sum()); } else if (this.getEntityData().get(WEAPON_TYPE) == 1) { - this.entityData.set(AMMO, ammoCount); + this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HE_5_INCHES.get())).mapToInt(ItemStack::getCount).sum()); + } + + if (this.getEntityData().get(LOADED_AMMO) == 0 && reloadCoolDown <= 0) { + if (this.getEntityData().get(WEAPON_TYPE) == 0 && (this.getItemStacks().stream().filter(stack -> stack.is(ModItems.AP_5_INCHES.get())).mapToInt(ItemStack::getCount).sum() > 0 || hasCreativeAmmo)) { + this.entityData.set(LOADED_AMMO, 1); + if (!hasCreativeAmmo) { + this.getItemStacks().stream().filter(stack -> stack.is(ModItems.AP_5_INCHES.get())).findFirst().ifPresent(stack -> stack.shrink(1)); + } + } else if (this.getEntityData().get(WEAPON_TYPE) == 1 && (this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HE_5_INCHES.get())).mapToInt(ItemStack::getCount).sum() > 0 || hasCreativeAmmo)) { + this.entityData.set(LOADED_AMMO, 1); + if (!hasCreativeAmmo) { + this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HE_5_INCHES.get())).findFirst().ifPresent(stack -> stack.shrink(1)); + } + } } } @@ -299,95 +271,65 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public void vehicleShoot(Player player) { + if (reloadCoolDown > 0) { + return; + } + Matrix4f transform = getBarrelTransform(); + float hitDamage = 0; + float explosionRadius = 0; + float explosionDamage = 0; + float fireProbability = 0; + int fireTime = 0; + int durability = 0; + float v = 0; + if (entityData.get(WEAPON_TYPE) == 0) { - if (this.cannotFire) return; - float x = -0.1125f; - float y = 0.174025f; - float z = 4.2f; - - Vector4f worldPosition = transformPosition(transform, x, y, z); - SmallCannonShellEntity smallCannonShell = new SmallCannonShellEntity(player, this.level(), - VehicleConfig.BMP_2_CANNON_DAMAGE.get(), - VehicleConfig.BMP_2_CANNON_EXPLOSION_DAMAGE.get(), - VehicleConfig.BMP_2_CANNON_EXPLOSION_RADIUS.get().floatValue()); - - smallCannonShell.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z); - smallCannonShell.shoot(getBarrelVector(1).x, getBarrelVector(1).y + 0.005f, getBarrelVector(1).z, 20, - 0.25f); - this.level().addFreshEntity(smallCannonShell); - - sendParticle((ServerLevel) this.level(), ParticleTypes.LARGE_SMOKE, worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z, 1, 0.02, 0.02, 0.02, 0, false); - - float pitch = this.entityData.get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - this.entityData.get(HEAT))); - - if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.BMP_CANNON_FIRE_3P.get(), 4, pitch); - serverPlayer.playSound(ModSounds.LAV_CANNON_FAR.get(), 12, pitch); - serverPlayer.playSound(ModSounds.LAV_CANNON_VERYFAR.get(), 24, pitch); - } - } - - Level level = player.level(); - final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ()); - - for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(4), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) { - if (target instanceof ServerPlayer serverPlayer) { - ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(6, 5, 9, this.getX(), this.getEyeY(), this.getZ())); - } - } - - this.entityData.set(HEAT, this.entityData.get(HEAT) + 7); - this.entityData.set(FIRE_ANIM, 3); - this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).findFirst().ifPresent(stack -> stack.shrink(1)); + hitDamage = 500; + explosionRadius = 4; + explosionDamage = 100; + fireProbability = 0; + durability = 60; + v = 40; } else if (entityData.get(WEAPON_TYPE) == 1) { - if (this.cannotFireCoax) return; - float x = 0.1125f; - float y = 0.174025f; - float z = 2f; + hitDamage = 100; + explosionRadius = 10; + explosionDamage = 150; + fireProbability = 0.18F; + fireTime = 2; + durability = 1; + v = 25; + } - Vector4f worldPosition = transformPosition(transform, x, y, z); - boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + Vector4f worldPosition = transformPosition(transform, 0, 0, 0); - if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) { - ProjectileEntity projectileRight = new ProjectileEntity(player.level()) - .shooter(player) - .damage(9.5f) - .headShot(2f) - .zoom(false); + CannonShellEntity entityToSpawn = new CannonShellEntity(player, level(), hitDamage, explosionRadius, explosionDamage, fireProbability, fireTime) + .durability(durability); - projectileRight.bypassArmorRate(0.2f); - projectileRight.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z); - projectileRight.shoot(player, getBarrelVector(1).x, getBarrelVector(1).y + 0.002f, getBarrelVector(1).z, 36, - 0.25f); - this.level().addFreshEntity(projectileRight); + entityToSpawn.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z); + entityToSpawn.shoot(getBarrelVector(1).x, getBarrelVector(1).y + 0.005f, getBarrelVector(1).z, v, 0.02f); + level().addFreshEntity(entityToSpawn); - if (!hasCreativeAmmo) { - ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { - if (stack.is(ModItems.AMMO_BOX.get())) { - return stack.getOrCreateTag().getInt("RifleAmmo") > 0; - } - return false; - }).findFirst().orElse(ItemStack.EMPTY); - - if (!ammoBox.isEmpty()) { - ammoBox.getOrCreateTag().putInt("RifleAmmo", Math.max(0, ammoBox.getOrCreateTag().getInt("RifleAmmo") - 1)); - } else { - this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1)); - } - } + if (!player.level().isClientSide) { + if (player instanceof ServerPlayer serverPlayer) { + serverPlayer.playSound(ModSounds.BMP_CANNON_FIRE_3P.get(), 4, 1); + serverPlayer.playSound(ModSounds.LAV_CANNON_FAR.get(), 12, 1); + serverPlayer.playSound(ModSounds.LAV_CANNON_VERYFAR.get(), 24, 1); } + } - this.entityData.set(COAX_HEAT, this.entityData.get(COAX_HEAT) + 3); - this.entityData.set(FIRE_ANIM, 2); + this.entityData.set(FIRE_ANIM, 20); + this.entityData.set(LOADED_AMMO, 0); + this.consumeEnergy(10000); - if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.M_60_FIRE_3P.get(), 3, 1); - serverPlayer.playSound(ModSounds.M_60_FAR.get(), 6, 1); - serverPlayer.playSound(ModSounds.M_60_VERYFAR.get(), 12, 1); - } + reloadCoolDown = 80; + + Level level = player.level(); + final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ()); + + for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(8), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) { + if (target instanceof ServerPlayer serverPlayer) { + ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(10, 8, 40, this.getX(), this.getEyeY(), this.getZ())); } } } @@ -695,17 +637,12 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public boolean canShoot(Player player) { - if (entityData.get(WEAPON_TYPE) == 0) { - return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; - } else if (entityData.get(WEAPON_TYPE) == 1) { - return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax; - } - return false; + return this.entityData.get(LOADED_AMMO) > 0; } @Override public int getAmmoCount(Player player) { - return this.entityData.get(AMMO); + return this.entityData.get(LOADED_AMMO); } @Override @@ -725,11 +662,22 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public void changeWeapon(int scroll) { - var type = (entityData.get(WEAPON_TYPE) + scroll + 3) % 3; + if (entityData.get(LOADED_AMMO) > 0 && this.reloadCoolDown == 0) { + this.reloadCoolDown = 80; + if (entityData.get(WEAPON_TYPE) == 0) { + this.getItemStacks().stream().filter(stack -> stack.is(ModItems.AP_5_INCHES.get())).findFirst().ifPresent(stack -> stack.grow(1)); + } else if (entityData.get(WEAPON_TYPE) == 1) { + this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HE_5_INCHES.get())).findFirst().ifPresent(stack -> stack.grow(1)); + } + + entityData.set(LOADED_AMMO, 0); + } + + var type = (entityData.get(WEAPON_TYPE) + scroll + 2) % 2; entityData.set(WEAPON_TYPE, type); var sound = switch (type) { - case 0, 2 -> ModSounds.INTO_MISSILE.get(); + case 0 -> ModSounds.INTO_MISSILE.get(); case 1 -> ModSounds.INTO_CANNON.get(); default -> throw new IllegalStateException("Unexpected type: " + type); }; diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index dce53ebe5..562d8450d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -761,7 +761,9 @@ public class ClientEventHandler { } else if (multiWeaponVehicle.getWeaponType() == 2) { player.playSound(ModSounds.BMP_MISSILE_FIRE_1P.get(), 1f, 1); } - + } + if (iVehicle instanceof Yx100Entity) { + player.playSound(ModSounds.YX_100_FIRE_1P.get(), 1f, 1); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java index 8a69aa279..3d697dd24 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java @@ -72,6 +72,14 @@ public class ClientSoundHandler { player.level().playLocalSound(BlockPos.containing(engineSoundPos), engineSound, mobileVehicle.getSoundSource(), 5 * (Mth.abs(mobileVehicle.getEntityData().get(POWER)) + Mth.abs(0.08f * mobileVehicle.getEntityData().get(DELTA_ROT)) - 0.004f) * distanceReduce * distanceReduce, (float) ((2 * Math.random() - 1) * 0.1f + 1), false); } } + if (e instanceof Yx100Entity yx100) { + distanceReduce = (float) Math.max((1 - distance / 64), 0); + if (player.getVehicle() == yx100) { + player.playSound(ModSounds.BMP_ENGINE_1P.get(), 1 * (Mth.abs(mobileVehicle.getEntityData().get(POWER)) + Mth.abs(0.08f * mobileVehicle.getEntityData().get(DELTA_ROT)) - 0.004f), (float) ((2 * Math.random() - 1) * 0.1f + 0.95f)); + } else { + player.level().playLocalSound(BlockPos.containing(engineSoundPos), engineSound, mobileVehicle.getSoundSource(), 5 * (Mth.abs(mobileVehicle.getEntityData().get(POWER)) + Mth.abs(0.08f * mobileVehicle.getEntityData().get(DELTA_ROT)) - 0.004f) * distanceReduce * distanceReduce, (float) ((2 * Math.random() - 1) * 0.1f + 1), false); + } + } if (e instanceof DroneEntity drone) { distanceReduce = (float) Math.max((1 - distance / 64), 0); ItemStack stack = player.getMainHandItem(); diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java b/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java index 2caa7442e..8630b4ef4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java @@ -417,5 +417,7 @@ public class ModSounds { public static final RegistryObject BMP_STEP = REGISTRY.register("bmp_step", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("bmp_step"))); public static final RegistryObject WHEEL_STEP = REGISTRY.register("wheel_step", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("wheel_step"))); public static final RegistryObject LASER_TOWER_SHOOT = REGISTRY.register("laser_tower_shoot", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("laser_tower_shoot"))); + public static final RegistryObject YX_100_RELOAD = REGISTRY.register("yx_100_reload", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("yx_100_reload"))); + public static final RegistryObject YX_100_FIRE_1P = REGISTRY.register("yx_100_fire_1p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("yx_100_fire_1p"))); } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java index e22e14687..aaa255846 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java @@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.google.common.collect.Sets; import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; @@ -70,9 +69,6 @@ public class CustomExplosion extends Explosion { ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(20 + 0.02 * damage,3 * pRadius,50 + 0.05 * damage, pToBlowX, pToBlowY, pToBlowZ)); } } - if (pLevel instanceof ServerLevel) { - pLevel.explode(source == null ? null : source.getEntity(), pToBlowX, pToBlowY, pToBlowZ, 0.5f * pRadius , ExplosionConfig.EXPLOSION_DESTROY.get() ? Level.ExplosionInteraction.BLOCK : Level.ExplosionInteraction.NONE); - } } public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius) { diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/ParticleTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/ParticleTool.java index 5ff7b9bad..31c612766 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/ParticleTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/ParticleTool.java @@ -9,6 +9,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.phys.Vec3; @@ -158,10 +159,10 @@ public class ParticleTool { } - public static void cannonHitParticles(Level level, Vec3 pos) { - double x = pos.x; - double y = pos.y; - double z = pos.z; + public static void cannonHitParticles(Level level, Vec3 pos, Entity entity) { + double x = pos.x + 0.5 * entity.getDeltaMovement().x; + double y = pos.y + 0.5 * entity.getDeltaMovement().y; + double z = pos.z + 0.5 * entity.getDeltaMovement().z; if (level instanceof ServerLevel serverLevel) { sendParticle(serverLevel, ParticleTypes.EXPLOSION, x, y, z, 2, 0.5, 0.5, 0.5, 1, true); diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java index afdf0cd6a..36f238dfe 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java @@ -2,10 +2,13 @@ package com.atsuishio.superbwarfare.tools; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.init.ModDamageTypes; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.projectile.ThrowableItemProjectile; import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; import javax.annotation.Nullable; @@ -20,6 +23,7 @@ public class ProjectileTool { explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(projectile.level(), explosion); explosion.finalizeExplosion(false); + if (radius <= 5) { ParticleTool.spawnSmallExplosionParticles(projectile.level(), projectile.position().add(projectile.getDeltaMovement().scale(0.5))); } else if (radius > 5 && radius < 10) { @@ -28,6 +32,12 @@ public class ProjectileTool { ParticleTool.spawnHugeExplosionParticles(projectile.level(), projectile.position().add(projectile.getDeltaMovement().scale(0.5))); } + Vec3 pos = projectile.position().add(projectile.getDeltaMovement().scale(0.5)); + + if (projectile.level() instanceof ServerLevel) { + projectile.level().explode(source == null ? null : source.getEntity(), pos.x, pos.y, pos.z, 0.5f * radius , ExplosionConfig.EXPLOSION_DESTROY.get() ? Level.ExplosionInteraction.BLOCK : Level.ExplosionInteraction.NONE); + } + projectile.discard(); } diff --git a/src/main/resources/assets/superbwarfare/sounds.json b/src/main/resources/assets/superbwarfare/sounds.json index 42fafae4e..71fec0554 100644 --- a/src/main/resources/assets/superbwarfare/sounds.json +++ b/src/main/resources/assets/superbwarfare/sounds.json @@ -2867,5 +2867,21 @@ "stream": false } ] + }, + "yx_100_reload": { + "sounds": [ + { + "name": "superbwarfare:yx100/yx100_reload", + "stream": false + } + ] + }, + "yx_100_fire_1p": { + "sounds": [ + { + "name": "superbwarfare:yx100/yx100_fire_1p", + "stream": false + } + ] } } \ No newline at end of file diff --git a/src/main/resources/assets/superbwarfare/sounds/yx100/yx100_fire_1p.ogg b/src/main/resources/assets/superbwarfare/sounds/yx100/yx100_fire_1p.ogg new file mode 100644 index 000000000..b8433e046 Binary files /dev/null and b/src/main/resources/assets/superbwarfare/sounds/yx100/yx100_fire_1p.ogg differ diff --git a/src/main/resources/assets/superbwarfare/sounds/yx100/yx100_reload.ogg b/src/main/resources/assets/superbwarfare/sounds/yx100/yx100_reload.ogg new file mode 100644 index 000000000..004e05713 Binary files /dev/null and b/src/main/resources/assets/superbwarfare/sounds/yx100/yx100_reload.ogg differ