合并重复代码

This commit is contained in:
Atsuihsio 2025-03-14 03:41:11 +08:00
parent a7d25de8fb
commit cc719ea384
10 changed files with 69 additions and 160 deletions

View file

@ -36,6 +36,7 @@ import org.joml.Matrix4f;
import org.joml.Vector4f; import org.joml.Vector4f;
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.HEAT;
@Mod.EventBusSubscriber(value = Dist.CLIENT) @Mod.EventBusSubscriber(value = Dist.CLIENT)
public class HelicopterHudOverlay { public class HelicopterHudOverlay {
@ -119,7 +120,7 @@ public class HelicopterHudOverlay {
if (mobileVehicle instanceof Ah6Entity ah6Entity) { if (mobileVehicle instanceof Ah6Entity ah6Entity) {
if (weaponVehicle.getWeaponIndex(0) == 0) { if (weaponVehicle.getWeaponIndex(0) == 0) {
double heat = 1 - ah6Entity.heat / 100.0F; double heat = 1 - ah6Entity.getEntityData().get(HEAT) / 100.0F;
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : iHelicopterEntity.getAmmoCount(player))), w / 2 - 160, h / 2 - 60, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : iHelicopterEntity.getAmmoCount(player))), w / 2 - 160, h / 2 - 60, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false);
} else { } else {
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("70MM ROCKET " + iHelicopterEntity.getAmmoCount(player)), w / 2 - 160, h / 2 - 60, 0x66FF00, false); guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("70MM ROCKET " + iHelicopterEntity.getAmmoCount(player)), w / 2 - 160, h / 2 - 60, 0x66FF00, false);
@ -187,7 +188,7 @@ public class HelicopterHudOverlay {
if (mobileVehicle instanceof Ah6Entity ah6Entity) { if (mobileVehicle instanceof Ah6Entity ah6Entity) {
if (weaponVehicle.getWeaponIndex(0) == 0) { if (weaponVehicle.getWeaponIndex(0) == 0) {
double heat = ah6Entity.heat / 100.0F; double heat = ah6Entity.getEntityData().get(HEAT) / 100.0F;
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : iHelicopterEntity.getAmmoCount(player))), 25, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : iHelicopterEntity.getAmmoCount(player))), 25, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false);
} else { } else {
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("70MM ROCKET " + iHelicopterEntity.getAmmoCount(player)), 25, -9, -1, false); guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("70MM ROCKET " + iHelicopterEntity.getAmmoCount(player)), 25, -9, -1, false);

View file

@ -48,9 +48,7 @@ import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
import static com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay.*; import static com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay.*;
import static com.atsuishio.superbwarfare.entity.vehicle.Bmp2Entity.LOADED_MISSILE; import static com.atsuishio.superbwarfare.entity.vehicle.Bmp2Entity.LOADED_MISSILE;
import static com.atsuishio.superbwarfare.entity.vehicle.Bmp2Entity.MISSILE_COUNT; import static com.atsuishio.superbwarfare.entity.vehicle.Bmp2Entity.MISSILE_COUNT;
import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.COAX_HEAT; import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.*;
import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.HEAT;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.AMMO;
@Mod.EventBusSubscriber(value = Dist.CLIENT) @Mod.EventBusSubscriber(value = Dist.CLIENT)
public class VehicleHudOverlay { public class VehicleHudOverlay {
@ -280,8 +278,11 @@ public class VehicleHudOverlay {
if (player.getVehicle() instanceof Yx100Entity yx100) { if (player.getVehicle() instanceof Yx100Entity yx100) {
if (weaponVehicle.getWeaponIndex(0) == 0) { if (weaponVehicle.getWeaponIndex(0) == 0) {
guiGraphics.drawString(mc.font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false); guiGraphics.drawString(mc.font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false);
} else { } else if (weaponVehicle.getWeaponIndex(0) == 1) {
guiGraphics.drawString(mc.font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false); guiGraphics.drawString(mc.font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false);
} else if (weaponVehicle.getWeaponIndex(0) == 2) {
double heat = 1 - yx100.getEntityData().get(COAX_HEAT) / 100.0F;
guiGraphics.drawString(mc.font, Component.literal(" 12.7MM HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false);
} }
} }
@ -333,8 +334,11 @@ public class VehicleHudOverlay {
if (weaponVehicle instanceof Yx100Entity yx100) { if (weaponVehicle instanceof Yx100Entity yx100) {
if (weaponVehicle.getWeaponIndex(0) == 0) { if (weaponVehicle.getWeaponIndex(0) == 0) {
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false); guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false);
} else { } else if (weaponVehicle.getWeaponIndex(0) == 1) {
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false); guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false);
} else if (weaponVehicle.getWeaponIndex(0) == 2) {
double heat2 = yx100.getEntityData().get(COAX_HEAT) / 100.0F;
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("7.62MM ПКТ " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat2, 1.0F), false);
} }
} }

View file

@ -32,10 +32,9 @@ import org.joml.Math;
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
import static com.atsuishio.superbwarfare.client.overlay.VehicleHudOverlay.renderKillIndicator3P; import static com.atsuishio.superbwarfare.client.overlay.VehicleHudOverlay.renderKillIndicator3P;
import static com.atsuishio.superbwarfare.entity.vehicle.SpeedboatEntity.AMMO;
import static com.atsuishio.superbwarfare.entity.vehicle.SpeedboatEntity.HEAT;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.MACHINE_GUN_HEAT;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.MG_AMMO; import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.MG_AMMO;
import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.AMMO;
import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.HEAT;
@Mod.EventBusSubscriber(value = Dist.CLIENT) @Mod.EventBusSubscriber(value = Dist.CLIENT)
public class VehicleMgHudOverlay { public class VehicleMgHudOverlay {
@ -96,7 +95,7 @@ public class VehicleMgHudOverlay {
// YX-100 // YX-100
if (player.getVehicle() instanceof Yx100Entity yx100) { if (player.getVehicle() instanceof Yx100Entity yx100) {
double heat = yx100.getEntityData().get(MACHINE_GUN_HEAT) / 100.0F; double heat = yx100.getEntityData().get(HEAT) / 100.0F;
guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getEntityData().get(MG_AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "" : yx100.getEntityData().get(MG_AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false);
} }

View file

@ -14,7 +14,10 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.ProjectileWeapon;
import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.*; import com.atsuishio.superbwarfare.tools.AmmoType;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -75,8 +78,6 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
public double velocity; public double velocity;
public int decoyReloadCoolDown; public int decoyReloadCoolDown;
public int fireIndex; public int fireIndex;
public int heat;
public int holdTick; public int holdTick;
public int holdPowerTick; public int holdPowerTick;
@ -164,24 +165,6 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
setZRot(getRoll() * (backInputDown ? 0.9f : 0.99f)); setZRot(getRoll() * (backInputDown ? 0.9f : 0.99f));
if (heat > 0) {
heat--;
}
if (heat < 40) {
cannotFire = false;
}
Entity driver = this.getFirstPassenger();
if (driver instanceof Player player) {
if (heat > 100) {
cannotFire = true;
if (!player.level().isClientSide() && player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.MINIGUN_OVERHEAT.get(), 1f, 1f);
}
}
}
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
if (reloadCoolDown > 0) { if (reloadCoolDown > 0) {
reloadCoolDown--; reloadCoolDown--;
@ -603,6 +586,8 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
} }
this.entityData.set(HEAT, this.entityData.get(HEAT) + 5);
if (!player.level().isClientSide) { if (!player.level().isClientSide) {
if (player instanceof ServerPlayer serverPlayer) { if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_FIRE_3P.get(), 4, 1); serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_FIRE_3P.get(), 4, 1);

View file

@ -13,7 +13,10 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon;
import com.atsuishio.superbwarfare.entity.vehicle.weapon.WgMissileWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.WgMissileWeapon;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.*; import com.atsuishio.superbwarfare.tools.AmmoType;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
@ -178,25 +181,6 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
setRightTrack(0); setRightTrack(0);
} }
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 (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
if (reloadCoolDown > 0) { if (reloadCoolDown > 0) {
@ -205,22 +189,6 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
this.handleAmmo(); 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);
}
}
}
double fluidFloat; double fluidFloat;
fluidFloat = 0.052 * getSubmergedHeight(this); fluidFloat = 0.052 * getSubmergedHeight(this);
this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0)); this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0));

View file

@ -12,7 +12,10 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.SmallCannonShellWeapon;
import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.*; import com.atsuishio.superbwarfare.tools.AmmoType;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
@ -155,46 +158,10 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
super.baseTick(); super.baseTick();
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 (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
this.handleAmmo(); 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);
}
}
}
double fluidFloat; double fluidFloat;
fluidFloat = 0.052 * getSubmergedHeight(this); fluidFloat = 0.052 * getSubmergedHeight(this);
this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0)); this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0));

View file

@ -13,7 +13,10 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.network.ModVariables;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.*; import com.atsuishio.superbwarfare.tools.AmmoType;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -126,32 +129,6 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
public void baseTick() { public void baseTick() {
super.baseTick(); super.baseTick();
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.level() instanceof ServerLevel) {
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);
}
}
}
double fluidFloat; double fluidFloat;
fluidFloat = 0.12 * getSubmergedHeight(this); fluidFloat = 0.12 * getSubmergedHeight(this);
this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0)); this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0));

View file

@ -69,7 +69,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
public static final EntityDataAccessor<Integer> MG_AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> MG_AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> LOADED_AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> LOADED_AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> GUN_FIRE_TIME = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> GUN_FIRE_TIME = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> MACHINE_GUN_HEAT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final float MAX_HEALTH = VehicleConfig.YX_100_HP.get(); public static final float MAX_HEALTH = VehicleConfig.YX_100_HP.get();
public static final int MAX_ENERGY = VehicleConfig.YX_100_MAX_ENERGY.get(); public static final int MAX_ENERGY = VehicleConfig.YX_100_MAX_ENERGY.get();
@ -134,7 +133,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.entityData.define(LOADED_AMMO, 0); this.entityData.define(LOADED_AMMO, 0);
this.entityData.define(CANNON_FIRE_TIME, 0); this.entityData.define(CANNON_FIRE_TIME, 0);
this.entityData.define(GUN_FIRE_TIME, 0); this.entityData.define(GUN_FIRE_TIME, 0);
this.entityData.define(MACHINE_GUN_HEAT, 0);
} }
@Override @Override
@ -213,10 +211,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.entityData.set(GUN_FIRE_TIME, this.entityData.get(GUN_FIRE_TIME) - 1); this.entityData.set(GUN_FIRE_TIME, this.entityData.get(GUN_FIRE_TIME) - 1);
} }
if (this.entityData.get(MACHINE_GUN_HEAT) > 0) {
this.entityData.set(MACHINE_GUN_HEAT, this.entityData.get(MACHINE_GUN_HEAT) - 1);
}
if (reloadCoolDown == 70 && this.getFirstPassenger() instanceof Player player) { if (reloadCoolDown == 70 && this.getFirstPassenger() instanceof Player player) {
SoundTool.playLocalSound(player, ModSounds.YX_100_RELOAD.get()); SoundTool.playLocalSound(player, ModSounds.YX_100_RELOAD.get());
} }
@ -228,20 +222,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.handleAmmo(); this.handleAmmo();
} }
if (this.entityData.get(MACHINE_GUN_HEAT) < 40) {
cannotFire = false;
}
Entity gunner = this.getNthEntity(1);
if (gunner instanceof Player player) {
if (this.entityData.get(MACHINE_GUN_HEAT) > 100) {
cannotFire = true;
if (!player.level().isClientSide() && player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.MINIGUN_OVERHEAT.get(), 1f, 1f);
}
}
}
if (this.onGround()) { if (this.onGround()) {
float f0 = 0.54f + 0.25f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90; 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()))); this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.05 * this.getDeltaMovement().horizontalDistance())));
@ -414,7 +394,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.level().addFreshEntity(projectileEntity); this.level().addFreshEntity(projectileEntity);
float pitch = this.entityData.get(MACHINE_GUN_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - this.entityData.get(MACHINE_GUN_HEAT))); 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.level().isClientSide) {
if (player instanceof ServerPlayer serverPlayer) { if (player instanceof ServerPlayer serverPlayer) {
@ -425,7 +405,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
} }
this.entityData.set(GUN_FIRE_TIME, 2); this.entityData.set(GUN_FIRE_TIME, 2);
this.entityData.set(MACHINE_GUN_HEAT, this.entityData.get(MACHINE_GUN_HEAT) + 4); this.entityData.set(HEAT, this.entityData.get(HEAT) + 4);
Level level = player.level(); Level level = player.level();
final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ()); final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ());

View file

@ -20,6 +20,7 @@ import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@ -141,6 +142,35 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity {
turretYRotO = deltaT + getTurretYRot(); turretYRotO = deltaT + getTurretYRot();
} }
if (this.entityData.get(HEAT) > 0) {
this.entityData.set(HEAT, this.entityData.get(HEAT) - 1);
}
if (this.entityData.get(COAX_HEAT) > 0) {
this.entityData.set(COAX_HEAT, this.entityData.get(COAX_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) < 40) {
cannotFireCoax = false;
}
if (this.entityData.get(HEAT) > 100) {
cannotFire = true;
this.level().playSound(null, this.getOnPos(), ModSounds.MINIGUN_OVERHEAT.get(), SoundSource.PLAYERS, 1, 1);
}
if (this.entityData.get(COAX_HEAT) > 100) {
cannotFireCoax = true;
this.level().playSound(null, this.getOnPos(), ModSounds.MINIGUN_OVERHEAT.get(), SoundSource.PLAYERS, 1, 1);
}
preventStacking(); preventStacking();
crushEntities(this.getDeltaMovement()); crushEntities(this.getDeltaMovement());
if (!(this instanceof DroneEntity)) { if (!(this instanceof DroneEntity)) {

View file

@ -62,9 +62,8 @@ import java.util.List;
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.vehicle.Lav150Entity.COAX_HEAT; import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.COAX_HEAT;
import static com.atsuishio.superbwarfare.entity.vehicle.SpeedboatEntity.HEAT; import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.HEAT;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.MACHINE_GUN_HEAT;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class ClientEventHandler { public class ClientEventHandler {
@ -739,9 +738,8 @@ public class ClientEventHandler {
} }
if (iVehicle instanceof Ah6Entity ah6Entity) { if (iVehicle instanceof Ah6Entity ah6Entity) {
float pitch = ah6Entity.heat <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - ah6Entity.heat)); float pitch = ah6Entity.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - ah6Entity.getEntityData().get(HEAT)));
if (ah6Entity.getWeaponIndex(0) == 0) { if (ah6Entity.getWeaponIndex(0) == 0) {
ah6Entity.heat += 5;
player.playSound(ModSounds.HELICOPTER_CANNON_FIRE_1P.get(), 1f, pitch); player.playSound(ModSounds.HELICOPTER_CANNON_FIRE_1P.get(), 1f, pitch);
} else if (ah6Entity.getWeaponIndex(0) == 1) { } else if (ah6Entity.getWeaponIndex(0) == 1) {
player.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_1P.get(), 1f, 1); player.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_1P.get(), 1f, 1);
@ -772,7 +770,7 @@ public class ClientEventHandler {
} }
if (iVehicle instanceof Yx100Entity yx100) { if (iVehicle instanceof Yx100Entity yx100) {
if (type == 1) { if (type == 1) {
float pitch = yx100.getEntityData().get(MACHINE_GUN_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - yx100.getEntityData().get(MACHINE_GUN_HEAT))); float pitch = yx100.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - yx100.getEntityData().get(HEAT)));
player.playSound(ModSounds.M_2_FIRE_1P.get(), 1f, pitch); player.playSound(ModSounds.M_2_FIRE_1P.get(), 1f, pitch);
player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1);
} else { } else {