682 lines
28 KiB
Java
682 lines
28 KiB
Java
package com.atsuishio.superbwarfare.entity.vehicle;
|
|
|
|
import com.atsuishio.superbwarfare.Mod;
|
|
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
|
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
|
import com.atsuishio.superbwarfare.entity.projectile.*;
|
|
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
|
|
import com.atsuishio.superbwarfare.entity.vehicle.base.HelicopterEntity;
|
|
import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition;
|
|
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
|
|
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
|
|
import com.atsuishio.superbwarfare.entity.vehicle.weapon.HeliRocketWeapon;
|
|
import com.atsuishio.superbwarfare.entity.vehicle.weapon.SmallCannonShellWeapon;
|
|
import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon;
|
|
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
|
import com.atsuishio.superbwarfare.init.ModItems;
|
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
|
import com.atsuishio.superbwarfare.init.ModTags;
|
|
import com.atsuishio.superbwarfare.tools.Ammo;
|
|
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
|
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
|
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
|
import com.mojang.math.Axis;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
|
import net.minecraft.network.syncher.SynchedEntityData;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.sounds.SoundEvent;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.world.damagesource.DamageTypes;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.Explosion;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import net.neoforged.neoforge.event.EventHooks;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.joml.Math;
|
|
import org.joml.Matrix4f;
|
|
import org.joml.Vector3f;
|
|
import org.joml.Vector4f;
|
|
import software.bernie.geckolib.animatable.GeoEntity;
|
|
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
|
import software.bernie.geckolib.animation.AnimatableManager;
|
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
|
|
|
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
|
|
|
|
public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity, HelicopterEntity, WeaponVehicleEntity {
|
|
|
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
|
public static final EntityDataAccessor<Float> PROPELLER_ROT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.FLOAT);
|
|
public static final EntityDataAccessor<Integer> LOADED_ROCKET = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT);
|
|
public boolean engineStart;
|
|
public boolean engineStartOver;
|
|
|
|
public double velocity;
|
|
public int fireIndex;
|
|
public int holdTick;
|
|
public int holdPowerTick;
|
|
public float destroyRot;
|
|
|
|
public Ah6Entity(EntityType<?> pEntityType, Level pLevel) {
|
|
super(pEntityType, pLevel);
|
|
}
|
|
|
|
@Override
|
|
public float maxUpStep() {
|
|
return 1.1F;
|
|
}
|
|
|
|
@Override
|
|
public VehicleWeapon[][] initWeapons() {
|
|
return new VehicleWeapon[][]{
|
|
new VehicleWeapon[]{
|
|
new SmallCannonShellWeapon()
|
|
.damage(VehicleConfig.AH_6_CANNON_DAMAGE.get())
|
|
.explosionDamage(VehicleConfig.AH_6_CANNON_EXPLOSION_DAMAGE.get().floatValue())
|
|
.explosionRadius(VehicleConfig.AH_6_CANNON_EXPLOSION_RADIUS.get().floatValue())
|
|
.sound(ModSounds.INTO_CANNON.get())
|
|
.icon(Mod.loc("textures/screens/vehicle_weapon/cannon_20mm.png"))
|
|
.sound1p(ModSounds.HELICOPTER_CANNON_FIRE_1P.get())
|
|
.sound3p(ModSounds.HELICOPTER_CANNON_FIRE_3P.get())
|
|
.sound3pFar(ModSounds.HELICOPTER_CANNON_FAR.get())
|
|
.sound3pVeryFar(ModSounds.HELICOPTER_CANNON_VERYFAR.get()),
|
|
new HeliRocketWeapon()
|
|
.damage(VehicleConfig.AH_6_ROCKET_DAMAGE.get())
|
|
.explosionDamage(VehicleConfig.AH_6_ROCKET_EXPLOSION_DAMAGE.get())
|
|
.explosionRadius(VehicleConfig.AH_6_ROCKET_EXPLOSION_RADIUS.get())
|
|
.sound(ModSounds.INTO_MISSILE.get())
|
|
.sound1p(ModSounds.HELICOPTER_ROCKET_FIRE_1P.get())
|
|
.sound3p(ModSounds.HELICOPTER_ROCKET_FIRE_3P.get()),
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override
|
|
public ThirdPersonCameraPosition getThirdPersonCameraPosition(int index) {
|
|
return new ThirdPersonCameraPosition(7, 1, -2.7);
|
|
}
|
|
|
|
@Override
|
|
protected void defineSynchedData(SynchedEntityData.Builder builder) {
|
|
super.defineSynchedData(builder);
|
|
builder.define(LOADED_ROCKET, 0)
|
|
.define(PROPELLER_ROT, 0f);
|
|
}
|
|
|
|
@Override
|
|
public void addAdditionalSaveData(CompoundTag compound) {
|
|
super.addAdditionalSaveData(compound);
|
|
compound.putInt("LoadedRocket", this.entityData.get(LOADED_ROCKET));
|
|
compound.putFloat("PropellerRot", this.entityData.get(PROPELLER_ROT));
|
|
}
|
|
|
|
@Override
|
|
public void readAdditionalSaveData(CompoundTag compound) {
|
|
super.readAdditionalSaveData(compound);
|
|
this.entityData.set(LOADED_ROCKET, compound.getInt("LoadedRocket"));
|
|
this.entityData.set(PROPELLER_ROT, compound.getFloat("PropellerRot"));
|
|
}
|
|
|
|
@Override
|
|
public DamageModifier getDamageModifier() {
|
|
return super.getDamageModifier()
|
|
.multiply(0.5f)
|
|
.multiply(0.2f, DamageTypes.ARROW)
|
|
.multiply(0.4f, DamageTypes.TRIDENT)
|
|
.multiply(0.4f, DamageTypes.MOB_ATTACK)
|
|
.multiply(0.4f, DamageTypes.MOB_ATTACK_NO_AGGRO)
|
|
.multiply(0.4f, DamageTypes.MOB_PROJECTILE)
|
|
.multiply(0.4f, DamageTypes.PLAYER_ATTACK)
|
|
.multiply(4, DamageTypes.LAVA)
|
|
.multiply(4, DamageTypes.EXPLOSION)
|
|
.multiply(4, DamageTypes.PLAYER_EXPLOSION)
|
|
.multiply(0.8f, ModDamageTypes.CANNON_FIRE)
|
|
.multiply(0.16f, ModTags.DamageTypes.PROJECTILE)
|
|
.multiply(10, ModDamageTypes.VEHICLE_STRIKE)
|
|
.custom((source, damage) -> {
|
|
if (source.getDirectEntity() instanceof CannonShellEntity) {
|
|
return 0.9f * damage;
|
|
}
|
|
if (source.getDirectEntity() instanceof SmallCannonShellEntity) {
|
|
return 1.3f * damage;
|
|
}
|
|
if (source.getDirectEntity() instanceof GunGrenadeEntity) {
|
|
return 2.2f * damage;
|
|
}
|
|
if (source.getDirectEntity() instanceof AerialBombEntity) {
|
|
return 2f * damage;
|
|
}
|
|
if (source.getDirectEntity() instanceof RgoGrenadeEntity) {
|
|
return 6f * damage;
|
|
}
|
|
if (source.getDirectEntity() instanceof HandGrenadeEntity) {
|
|
return 5f * damage;
|
|
}
|
|
if (source.getDirectEntity() instanceof MortarShellEntity) {
|
|
return 3f * damage;
|
|
}
|
|
return damage;
|
|
})
|
|
|
|
.reduce(2);
|
|
}
|
|
|
|
@Override
|
|
public void baseTick() {
|
|
super.baseTick();
|
|
|
|
if (this.level() instanceof ServerLevel) {
|
|
if (reloadCoolDown > 0) {
|
|
reloadCoolDown--;
|
|
}
|
|
handleAmmo();
|
|
}
|
|
|
|
if (this.onGround()) {
|
|
this.setDeltaMovement(this.getDeltaMovement().multiply(0.8, 1, 0.8));
|
|
} else {
|
|
setZRot(getRoll() * (backInputDown ? 0.9f : 0.99f));
|
|
float f = (float) Mth.clamp(0.9f - 0.015 * getDeltaMovement().length() + 0.02f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90, 0.01, 0.99);
|
|
this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).scale((this.getXRot() < 0 ? -0.035 : (this.getXRot() > 0 ? 0.035 : 0)) * this.getDeltaMovement().length())));
|
|
this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.95, f));
|
|
}
|
|
|
|
if (this.isInWater() && this.tickCount % 4 == 0 && getSubmergedHeight(this) > 0.5 * getBbHeight()) {
|
|
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6, 0.6, 0.6));
|
|
this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger()), 6 + (float) (20 * ((lastTickSpeed - 0.4) * (lastTickSpeed - 0.4))));
|
|
}
|
|
|
|
releaseDecoy();
|
|
lowHealthWarning();
|
|
this.terrainCompact(2.7f, 2.7f);
|
|
|
|
this.refreshDimensions();
|
|
}
|
|
|
|
private void handleAmmo() {
|
|
if (!(this.getFirstPassenger() instanceof Player player)) return;
|
|
|
|
int ammoCount = this.getItemStacks().stream().filter(stack -> {
|
|
if (stack.is(ModItems.AMMO_BOX.get())) {
|
|
return Ammo.HEAVY.get(stack) > 0;
|
|
}
|
|
return false;
|
|
}).mapToInt(Ammo.HEAVY::get).sum() + countItem(ModItems.SMALL_SHELL.get());
|
|
|
|
if ((hasItem(ModItems.ROCKET_70.get()) || InventoryTool.hasCreativeAmmoBox(player)) && reloadCoolDown == 0 && this.getEntityData().get(LOADED_ROCKET) < 14) {
|
|
this.entityData.set(LOADED_ROCKET, this.getEntityData().get(LOADED_ROCKET) + 1);
|
|
reloadCoolDown = 25;
|
|
if (!InventoryTool.hasCreativeAmmoBox(player)) {
|
|
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.ROCKET_70.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
|
}
|
|
this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1);
|
|
}
|
|
|
|
if (this.getWeaponIndex(0) == 0) {
|
|
this.entityData.set(AMMO, ammoCount);
|
|
} else {
|
|
this.entityData.set(AMMO, this.getEntityData().get(LOADED_ROCKET));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void travel() {
|
|
Entity passenger = getFirstPassenger();
|
|
Entity passenger2 = getNthEntity(1);
|
|
Entity passenger3 = getNthEntity(2);
|
|
Entity passenger4 = getNthEntity(3);
|
|
float diffX;
|
|
float diffY;
|
|
float diffZ;
|
|
|
|
if (getHealth() > 0.1f * getMaxHealth()) {
|
|
if (passenger == null) {
|
|
this.leftInputDown = false;
|
|
this.rightInputDown = false;
|
|
this.forwardInputDown = false;
|
|
this.backInputDown = false;
|
|
this.upInputDown = false;
|
|
this.downInputDown = false;
|
|
this.setZRot(this.roll * 0.98f);
|
|
this.setXRot(this.getXRot() * 0.98f);
|
|
if (passenger2 == null && passenger3 == null && passenger4 == null) {
|
|
this.entityData.set(POWER, this.entityData.get(POWER) * 0.99f);
|
|
}
|
|
} else if (passenger instanceof Player) {
|
|
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
|
|
diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot()));
|
|
|
|
if (rightInputDown) {
|
|
holdTick++;
|
|
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) - 2f * Math.min(holdTick, 7) * this.entityData.get(POWER));
|
|
} else if (this.leftInputDown) {
|
|
holdTick++;
|
|
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) + 2f * Math.min(holdTick, 7) * this.entityData.get(POWER));
|
|
} else {
|
|
holdTick = 0;
|
|
}
|
|
|
|
this.setYRot(this.getYRot() + Mth.clamp((this.onGround() ? 0.1f : 2f) * diffY * this.entityData.get(PROPELLER_ROT), -10f, 10f));
|
|
this.setXRot(Mth.clamp(this.getXRot() + ((this.onGround()) ? 0 : 1.5f) * diffX * this.entityData.get(PROPELLER_ROT), -80, 80));
|
|
this.setZRot(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.25f) * diffY * this.entityData.get(PROPELLER_ROT));
|
|
}
|
|
|
|
if (this.level() instanceof ServerLevel) {
|
|
if (this.getEnergy() > 0) {
|
|
boolean up = upInputDown || forwardInputDown;
|
|
boolean down = this.downInputDown;
|
|
|
|
if (!engineStart && up) {
|
|
engineStart = true;
|
|
this.level().playSound(null, this, ModSounds.HELICOPTER_ENGINE_START.get(), this.getSoundSource(), 3, 1);
|
|
}
|
|
|
|
if (up && engineStartOver) {
|
|
holdPowerTick++;
|
|
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0007f * Math.min(holdPowerTick, 10), 0.12f));
|
|
}
|
|
|
|
if (engineStartOver) {
|
|
if (down) {
|
|
holdPowerTick++;
|
|
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.001f * Math.min(holdPowerTick, 5), this.onGround() ? 0 : 0.025f));
|
|
} else if (backInputDown) {
|
|
holdPowerTick++;
|
|
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.001f * Math.min(holdPowerTick, 5), this.onGround() ? 0 : 0.052f));
|
|
if (passenger != null) {
|
|
passenger.setXRot(0.8f * passenger.getXRot());
|
|
}
|
|
}
|
|
}
|
|
|
|
if (engineStart && !engineStartOver) {
|
|
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0012f, 0.045f));
|
|
}
|
|
|
|
if (!(up || down || backInputDown) && engineStartOver) {
|
|
if (this.getDeltaMovement().y() < 0) {
|
|
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0002f, 0.12f));
|
|
} else {
|
|
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - (this.onGround() ? 0.00005f : 0.0002f), 0));
|
|
}
|
|
holdPowerTick = 0;
|
|
}
|
|
} else {
|
|
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0001f, 0));
|
|
this.forwardInputDown = false;
|
|
this.backInputDown = false;
|
|
engineStart = false;
|
|
engineStartOver = false;
|
|
}
|
|
}
|
|
} else if (!onGround() && engineStartOver) {
|
|
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0003f, 0.01f));
|
|
destroyRot += 0.15f;
|
|
|
|
diffX = 45 - this.getXRot();
|
|
diffZ = -20 - this.getRoll();
|
|
|
|
this.setXRot(this.getXRot() + diffX * 0.1f * this.entityData.get(PROPELLER_ROT));
|
|
this.setYRot(this.getYRot() + destroyRot);
|
|
this.setZRot(this.getRoll() + diffZ * 0.1f * this.entityData.get(PROPELLER_ROT));
|
|
setDeltaMovement(getDeltaMovement().add(0, -0.03, 0));
|
|
}
|
|
|
|
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.9f);
|
|
this.entityData.set(PROPELLER_ROT, Mth.lerp(0.18f, this.entityData.get(PROPELLER_ROT), this.entityData.get(POWER)));
|
|
this.setPropellerRot(this.getPropellerRot() + 30 * this.entityData.get(PROPELLER_ROT));
|
|
this.entityData.set(PROPELLER_ROT, this.entityData.get(PROPELLER_ROT) * 0.9995f);
|
|
|
|
if (engineStart) {
|
|
this.consumeEnergy((int) (VehicleConfig.AH_6_MIN_ENERGY_COST.get() + this.entityData.get(POWER) * ((VehicleConfig.AH_6_MAX_ENERGY_COST.get() - VehicleConfig.AH_6_MIN_ENERGY_COST.get()) / 0.12)));
|
|
}
|
|
|
|
setDeltaMovement(getDeltaMovement().add(0.0f, Math.min(Math.sin((90 - this.getXRot()) * Mth.DEG_TO_RAD), Math.sin((90 + this.getRoll()) * Mth.DEG_TO_RAD)) * this.entityData.get(POWER), 0.0f));
|
|
|
|
Vector3f direction = getRightDirection().mul(-Math.sin(this.getRoll() * Mth.DEG_TO_RAD) * this.entityData.get(PROPELLER_ROT));
|
|
setDeltaMovement(getDeltaMovement().add(new Vec3(direction.x, direction.y, direction.z).scale(3)));
|
|
|
|
Vector3f directionZ = getForwardDirection().mul(-Math.cos((this.getXRot() + 90) * Mth.DEG_TO_RAD) * this.entityData.get(PROPELLER_ROT));
|
|
setDeltaMovement(getDeltaMovement().add(new Vec3(directionZ.x, directionZ.y, directionZ.z).scale(3)));
|
|
|
|
if (this.entityData.get(POWER) > 0.04f) {
|
|
engineStartOver = true;
|
|
}
|
|
|
|
if (this.entityData.get(POWER) < 0.0004f) {
|
|
engineStart = false;
|
|
engineStartOver = false;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public SoundEvent getEngineSound() {
|
|
return ModSounds.HELICOPTER_ENGINE.get();
|
|
}
|
|
|
|
@Override
|
|
public float getEngineSoundVolume() {
|
|
return entityData.get(PROPELLER_ROT) * 2f;
|
|
}
|
|
|
|
protected void clampRotation(Entity entity) {
|
|
if (entity == getNthEntity(0) || entity == getNthEntity(1)) {
|
|
float f = Mth.wrapDegrees(entity.getXRot());
|
|
float f1 = Mth.clamp(f, -80.0F, 80F);
|
|
entity.xRotO += f1 - f;
|
|
entity.setXRot(entity.getXRot() + f1 - f);
|
|
|
|
float f2 = Mth.wrapDegrees(entity.getYRot() - this.getYRot());
|
|
float f3 = Mth.clamp(f2, -80.0F, 80.0F);
|
|
entity.yRotO += f3 - f2;
|
|
entity.setYRot(entity.getYRot() + f3 - f2);
|
|
entity.setYBodyRot(this.getYRot());
|
|
} else if (entity == getNthEntity(2)) {
|
|
float f2 = Mth.wrapDegrees(entity.getYRot() - this.getYRot());
|
|
float f3 = Mth.clamp(f2, 10.0F, 170.0F);
|
|
entity.yRotO += f3 - f2;
|
|
entity.setYRot(entity.getYRot() + f3 - f2);
|
|
entity.setYBodyRot(getYRot() + 90);
|
|
} else if (entity == getNthEntity(3)) {
|
|
float f2 = Mth.wrapDegrees(entity.getYRot() - this.getYRot());
|
|
float f3 = Mth.clamp(f2, -170.0F, -10.0F);
|
|
entity.yRotO += f3 - f2;
|
|
entity.setYRot(entity.getYRot() + f3 - f2);
|
|
entity.setYBodyRot(getYRot() - 90);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPassengerTurned(@NotNull Entity entity) {
|
|
this.clampRotation(entity);
|
|
}
|
|
|
|
@Override
|
|
public void positionRider(@NotNull Entity passenger, @NotNull MoveFunction callback) {
|
|
// From Immersive_Aircraft
|
|
if (!this.hasPassenger(passenger)) {
|
|
return;
|
|
}
|
|
|
|
Matrix4f transform = getVehicleTransform(1);
|
|
|
|
float x = 0.6f;
|
|
float y = -0.65f;
|
|
float z = 1f;
|
|
|
|
int i = this.getOrderedPassengers().indexOf(passenger);
|
|
|
|
if (i == 0) {
|
|
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
|
passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
|
|
callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z);
|
|
} else if (i == 1) {
|
|
Vector4f worldPosition = transformPosition(transform, -x, y, z);
|
|
passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
|
|
callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z);
|
|
} else if (i == 2) {
|
|
Vector4f worldPosition = transformPosition(transform, -1.4f, -1.05f, 0);
|
|
passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
|
|
callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z);
|
|
} else if (i == 3) {
|
|
Vector4f worldPosition = transformPosition(transform, 1.4f, -1.05f, 0);
|
|
passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
|
|
callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z);
|
|
}
|
|
|
|
if (passenger != this.getFirstPassenger()) {
|
|
passenger.setXRot(passenger.getXRot() + (getXRot() - xRotO));
|
|
}
|
|
|
|
copyEntityData(passenger);
|
|
}
|
|
|
|
public void copyEntityData(Entity entity) {
|
|
if (entity == getNthEntity(0) || entity == getNthEntity(1)) {
|
|
float f = Mth.wrapDegrees(entity.getYRot() - getYRot());
|
|
float g = Mth.clamp(f, -105.0f, 105.0f);
|
|
entity.yRotO += g - f;
|
|
entity.setYRot(entity.getYRot() + g - f + 0.9f * destroyRot);
|
|
entity.setYHeadRot(entity.getYRot());
|
|
entity.setYBodyRot(getYRot());
|
|
} else if (entity == getNthEntity(2)) {
|
|
float f = Mth.wrapDegrees(entity.getYRot() - getYRot());
|
|
float g = Mth.clamp(f, 10.0f, 170.0f);
|
|
entity.yRotO += g - f;
|
|
entity.setYRot(entity.getYRot() + g - f + 0.9f * destroyRot);
|
|
entity.setYHeadRot(entity.getYRot());
|
|
entity.setYBodyRot(getYRot() + 90);
|
|
} else if (entity == getNthEntity(3)) {
|
|
float f = Mth.wrapDegrees(entity.getYRot() - getYRot());
|
|
float g = Mth.clamp(f, -170.0f, -10.0f);
|
|
entity.yRotO += g - f;
|
|
entity.setYRot(entity.getYRot() + g - f + 0.9f * destroyRot);
|
|
entity.setYHeadRot(entity.getYRot());
|
|
entity.setYBodyRot(getYRot() - 90);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Matrix4f getVehicleTransform(float ticks) {
|
|
Matrix4f transform = new Matrix4f();
|
|
transform.translate((float) Mth.lerp(ticks, xo, getX()), (float) Mth.lerp(ticks, yo + 1.45f, getY() + 1.45f), (float) Mth.lerp(ticks, zo, getZ()));
|
|
transform.rotate(Axis.YP.rotationDegrees(-Mth.lerp(ticks, yRotO, getYRot())));
|
|
transform.rotate(Axis.XP.rotationDegrees(Mth.lerp(ticks, xRotO, getXRot())));
|
|
transform.rotate(Axis.ZP.rotationDegrees(Mth.lerp(ticks, prevRoll, getRoll())));
|
|
return transform;
|
|
}
|
|
|
|
@Override
|
|
public void destroy() {
|
|
if (this.crash) {
|
|
crashPassengers();
|
|
} else {
|
|
explodePassengers();
|
|
}
|
|
|
|
if (level() instanceof ServerLevel) {
|
|
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
|
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, getAttacker()), 300.0f,
|
|
this.getX(), this.getY(), this.getZ(), 8f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
|
|
explosion.explode();
|
|
EventHooks.onExplosionStart(this.level(), explosion);
|
|
explosion.finalizeExplosion(false);
|
|
ParticleTool.spawnHugeExplosionParticles(this.level(), this.position());
|
|
}
|
|
super.destroy();
|
|
}
|
|
|
|
@Override
|
|
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
|
}
|
|
|
|
@Override
|
|
public AnimatableInstanceCache getAnimatableInstanceCache() {
|
|
return this.cache;
|
|
}
|
|
|
|
@Override
|
|
public float getMaxHealth() {
|
|
return VehicleConfig.AH_6_HP.get();
|
|
}
|
|
|
|
@Override
|
|
public int getMaxEnergy() {
|
|
return VehicleConfig.AH_6_MAX_ENERGY.get();
|
|
}
|
|
|
|
@Override
|
|
public void vehicleShoot(Player player, int type) {
|
|
boolean hasCreativeAmmo = false;
|
|
for (int i = 0; i < getMaxPassengers() - 1; i++) {
|
|
if (getNthEntity(i) instanceof Player pPlayer && InventoryTool.hasCreativeAmmoBox(pPlayer)) {
|
|
hasCreativeAmmo = true;
|
|
}
|
|
}
|
|
|
|
Matrix4f transform = getVehicleTransform(1);
|
|
float x;
|
|
float y;
|
|
float z;
|
|
|
|
if (getWeaponIndex(0) == 0) {
|
|
if (this.cannotFire) return;
|
|
|
|
x = 1.15f;
|
|
y = 0.62f - 1.45f;
|
|
z = 0.8f;
|
|
|
|
Vector4f worldPosition;
|
|
|
|
if (fireIndex == 0) {
|
|
worldPosition = transformPosition(transform, -x, y, z);
|
|
fireIndex = 1;
|
|
} else {
|
|
worldPosition = transformPosition(transform, x, y, z);
|
|
fireIndex = 0;
|
|
}
|
|
|
|
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
|
var entityToSpawn = ((SmallCannonShellWeapon) getWeapon(0)).create(player);
|
|
|
|
entityToSpawn.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
|
|
entityToSpawn.shoot(getLookAngle().x, getLookAngle().y + 0.008, getLookAngle().z, 20, 0.15f);
|
|
level().addFreshEntity(entityToSpawn);
|
|
|
|
sendParticle((ServerLevel) this.level(), ParticleTypes.LARGE_SMOKE, worldPosition.x, worldPosition.y, worldPosition.z, 1, 0, 0, 0, 0, false);
|
|
|
|
if (!hasCreativeAmmo) {
|
|
ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> {
|
|
if (stack.is(ModItems.AMMO_BOX.get())) {
|
|
return Ammo.HEAVY.get(stack) > 0;
|
|
}
|
|
return false;
|
|
}).findFirst().orElse(ItemStack.EMPTY);
|
|
|
|
if (!ammoBox.isEmpty()) {
|
|
Ammo.HEAVY.add(ammoBox, -1);
|
|
} else {
|
|
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
this.entityData.set(HEAT, this.entityData.get(HEAT) + 4);
|
|
|
|
if (!player.level().isClientSide) {
|
|
playShootSound3p(player, 0, 4, 12, 24);
|
|
}
|
|
|
|
} else if (getWeaponIndex(0) == 1 && this.getEntityData().get(LOADED_ROCKET) > 0) {
|
|
x = 1.7f;
|
|
y = 0.62f - 1.45f;
|
|
z = 0.8f;
|
|
|
|
var heliRocketEntity = ((HeliRocketWeapon) getWeapon(0)).create(player);
|
|
|
|
Vector4f worldPosition;
|
|
|
|
if (fireIndex == 0) {
|
|
worldPosition = transformPosition(transform, -x, y, z);
|
|
fireIndex = 1;
|
|
} else {
|
|
worldPosition = transformPosition(transform, x, y, z);
|
|
fireIndex = 0;
|
|
}
|
|
|
|
heliRocketEntity.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
|
|
heliRocketEntity.shoot(this.getLookAngle().x, this.getLookAngle().y + 0.008, this.getLookAngle().z, 7, 0.25f);
|
|
player.level().addFreshEntity(heliRocketEntity);
|
|
|
|
if (!player.level().isClientSide) {
|
|
playShootSound3p(player, 0, 6, 6, 6);
|
|
}
|
|
|
|
this.entityData.set(LOADED_ROCKET, this.getEntityData().get(LOADED_ROCKET) - 1);
|
|
reloadCoolDown = 30;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int mainGunRpm(Player player) {
|
|
return 500;
|
|
}
|
|
|
|
@Override
|
|
public boolean canShoot(Player player) {
|
|
if (getWeaponIndex(0) == 0) {
|
|
return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFire;
|
|
} else if (getWeaponIndex(0) == 1) {
|
|
return this.entityData.get(AMMO) > 0;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public int getAmmoCount(Player player) {
|
|
return this.entityData.get(AMMO);
|
|
}
|
|
|
|
@Override
|
|
public boolean hidePassenger(Entity entity) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public int zoomFov() {
|
|
return 3;
|
|
}
|
|
|
|
@Override
|
|
public int getWeaponHeat(Player player) {
|
|
return entityData.get(HEAT);
|
|
}
|
|
|
|
@Override
|
|
public float getRotX(float tickDelta) {
|
|
return this.getPitch(tickDelta);
|
|
}
|
|
|
|
@Override
|
|
public float getRotY(float tickDelta) {
|
|
return this.getYaw(tickDelta);
|
|
}
|
|
|
|
@Override
|
|
public float getRotZ(float tickDelta) {
|
|
return this.getRoll(tickDelta);
|
|
}
|
|
|
|
@Override
|
|
public float getPower() {
|
|
return this.entityData.get(POWER);
|
|
}
|
|
|
|
@Override
|
|
public int getDecoy() {
|
|
return this.entityData.get(DECOY_COUNT);
|
|
}
|
|
|
|
public int getMaxPassengers() {
|
|
return 4;
|
|
}
|
|
|
|
@Override
|
|
public ResourceLocation getVehicleIcon() {
|
|
return Mod.loc("textures/vehicle_icon/ah_6_icon.png");
|
|
}
|
|
|
|
@Override
|
|
public boolean allowFreeCam() {
|
|
return true;
|
|
}
|
|
}
|