合并重复代码

This commit is contained in:
Atsuihsio 2025-03-12 21:30:58 +08:00
parent fd555460dd
commit 314ba3056a
12 changed files with 302 additions and 695 deletions

View file

@ -8,9 +8,6 @@ import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.model.GeoModel;
import static com.atsuishio.superbwarfare.entity.vehicle.Bmp2Entity.TRACK_L;
import static com.atsuishio.superbwarfare.entity.vehicle.Bmp2Entity.TRACK_R;
public class Bmp2Model extends GeoModel<Bmp2Entity> {
@Override
@ -49,7 +46,7 @@ public class Bmp2Model extends GeoModel<Bmp2Entity> {
CoreGeoBone trackR = getAnimationProcessor().getBone("trackR" + i);
CoreGeoBone trackRRot = getAnimationProcessor().getBone("trackRRot" + i);
float t = animatable.getEntityData().get(TRACK_L) + 2 * i;
float t = animatable.getLeftTrack() + 2 * i;
if (t >= 100) {
t -= 100;
@ -57,7 +54,7 @@ public class Bmp2Model extends GeoModel<Bmp2Entity> {
trackAnimation(trackL, trackLRot, t);
float t2 = animatable.getEntityData().get(TRACK_R) + 2 * i;
float t2 = animatable.getRightTrack() + 2 * i;
if (t2 >= 100) {
t2 -= 100;

View file

@ -8,9 +8,6 @@ import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.model.GeoModel;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.TRACK_L;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.TRACK_R;
public class Yx100Model extends GeoModel<Yx100Entity> {
@Override
@ -49,7 +46,7 @@ public class Yx100Model extends GeoModel<Yx100Entity> {
CoreGeoBone trackR = getAnimationProcessor().getBone("trackR" + i);
CoreGeoBone trackRRot = getAnimationProcessor().getBone("trackRRot" + i);
float t = animatable.getEntityData().get(TRACK_L) + 2 * i;
float t = animatable.getLeftTrack() + 2 * i;
if (t >= 80) {
t -= 80;
@ -57,7 +54,7 @@ public class Yx100Model extends GeoModel<Yx100Entity> {
trackAnimation(trackL, trackLRot, t);
float t2 = animatable.getEntityData().get(TRACK_R) + 2 * i;
float t2 = animatable.getRightTrack() + 2 * i;
if (t2 >= 80) {
t2 -= 80;

View file

@ -66,25 +66,17 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = VehicleConfig.AH_6_HP.get();
public static final int MAX_ENERGY = VehicleConfig.AH_6_MAX_ENERGY.get();
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<Integer> AMMO = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> DECOY_COUNT = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> LOADED_ROCKET = SynchedEntityData.defineId(Ah6Entity.class, EntityDataSerializers.INT);
public boolean engineStart;
public boolean engineStartOver;
public float propellerRot;
public float propellerRotO;
public double velocity;
public int reloadCoolDown;
public int decoyReloadCoolDown;
public int fireIndex;
public boolean cannotFire;
public int heat;
public int heat;
public int holdTick;
public int holdPowerTick;
@ -121,9 +113,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(AMMO, 0);
this.entityData.define(LOADED_ROCKET, 0);
this.entityData.define(DELTA_ROT, 0f);
this.entityData.define(PROPELLER_ROT, 0f);
this.entityData.define(DECOY_COUNT, 6);
}
@ -172,7 +162,6 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
@Override
public void baseTick() {
propellerRotO = this.getPropellerRot();
super.baseTick();
setZRot(getRoll() * (backInputDown ? 0.9f : 0.99f));
@ -403,14 +392,6 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
return ModSounds.HELICOPTER_ENGINE.get();
}
public float getPropellerRot() {
return this.propellerRot;
}
public void setPropellerRot(float pPropellerRot) {
this.propellerRot = pPropellerRot;
}
protected void clampRotation(Entity entity) {
if (entity == getNthEntity(0) || entity == getNthEntity(1)) {
float f = Mth.wrapDegrees(entity.getXRot());

View file

@ -59,31 +59,12 @@ import java.util.Comparator;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> COAX_HEAT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> LOADED_MISSILE = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> MISSILE_COUNT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> TRACK_L = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> TRACK_R = SynchedEntityData.defineId(Bmp2Entity.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();
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public float turretYRot;
public float turretXRot;
public float turretYRotO;
public float turretXRotO;
public float leftWheelRot;
public float rightWheelRot;
public float leftWheelRotO;
public float rightWheelRotO;
public boolean cannotFire;
public boolean cannotFireCoax;
public int reloadCoolDown;
public Bmp2Entity(PlayMessages.SpawnEntity packet, Level world) {
@ -123,15 +104,8 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(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(LOADED_MISSILE, 0);
this.entityData.define(MISSILE_COUNT, 0);
this.entityData.define(TRACK_L, 0f);
this.entityData.define(TRACK_R, 0f);
}
@Override
@ -186,27 +160,22 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
@Override
public void baseTick() {
turretYRotO = this.getTurretYRot();
turretXRotO = this.getTurretXRot();
leftWheelRotO = this.getLeftWheelRot();
rightWheelRotO = this.getRightWheelRot();
super.baseTick();
if (this.entityData.get(TRACK_R) < 0) {
this.entityData.set(TRACK_R, 100f);
if (getLeftTrack() < 0) {
setLeftTrack(100);
}
if (this.entityData.get(TRACK_R) > 100) {
this.entityData.set(TRACK_R, 0f);
if (getLeftTrack() > 100) {
setLeftTrack(0);
}
if (this.entityData.get(TRACK_L) < 0) {
this.entityData.set(TRACK_L, 100f);
if (getRightTrack() < 0) {
setRightTrack(100);
}
if (this.entityData.get(TRACK_L) > 100) {
this.entityData.set(TRACK_L, 0f);
if (getRightTrack() > 100) {
setRightTrack(0);
}
if (this.entityData.get(HEAT) > 0) {
@ -273,22 +242,12 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int) (2 + 10 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true);
}
float deltaT = Math.abs(getTurretYRot() - turretYRotO);
while (getTurretYRot() > 180F) {
setTurretYRot(getTurretYRot() - 360F);
turretYRotO = getTurretYRot() - deltaT;
}
while (getTurretYRot() <= -180F) {
setTurretYRot(getTurretYRot() + 360F);
turretYRotO = deltaT + getTurretYRot();
}
collideBlock();
if (this.getDeltaMovement().length() > 0.15) {
collideHardBlock();
}
gunnerAngle();
turretAngle(15, 10);
lowHealthWarning();
this.refreshDimensions();
}
@ -448,18 +407,6 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
}
}
public final Vec3 getBarrelVector(float pPartialTicks) {
return this.calculateViewVector(this.getBarrelXRot(pPartialTicks), this.getBarrelYRot(pPartialTicks));
}
public float getBarrelXRot(float pPartialTicks) {
return Mth.lerp(pPartialTicks, turretXRotO - this.xRotO, getTurretXRot() - this.getXRot());
}
public float getBarrelYRot(float pPartialTick) {
return -Mth.lerp(pPartialTick, turretYRotO - this.yRotO, getTurretYRot() - this.getYRot());
}
@Override
public void travel() {
Entity passenger0 = this.getFirstPassenger();
@ -512,8 +459,8 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
this.setLeftWheelRot((float) ((this.getLeftWheelRot() - 1.25 * s0) + Mth.clamp(0.75f * this.entityData.get(DELTA_ROT), -5f, 5f)));
this.setRightWheelRot((float) ((this.getRightWheelRot() - 1.25 * s0) - Mth.clamp(0.75f * this.entityData.get(DELTA_ROT), -5f, 5f)));
this.entityData.set(TRACK_L, (float) ((entityData.get(TRACK_L) - 1.9 * Math.PI * s0) + Mth.clamp(0.4f * Math.PI * this.entityData.get(DELTA_ROT), -5f, 5f)));
this.entityData.set(TRACK_R, (float) ((entityData.get(TRACK_R) - 1.9 * Math.PI * s0) - Mth.clamp(0.4f * Math.PI * this.entityData.get(DELTA_ROT), -5f, 5f)));
setLeftTrack((float) ((getLeftTrack() - 1.9 * Math.PI * s0) + Mth.clamp(0.4f * Math.PI * this.entityData.get(DELTA_ROT), -5f, 5f)));
setRightTrack((float) ((getRightTrack() - 1.9 * Math.PI * s0) - Mth.clamp(0.4f * Math.PI * this.entityData.get(DELTA_ROT), -5f, 5f)));
if (this.isInWater() || onGround()) {
this.setYRot((float) (this.getYRot() - (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT)));
@ -521,86 +468,6 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
}
}
private void gunnerAngle() {
Entity driver = this.getFirstPassenger();
if (driver == null) return;
float gunAngle = -Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot());
float diffY;
float diffX;
diffY = Mth.wrapDegrees(gunAngle - getTurretYRot() + 0.05f);
diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot());
turretTurnSound(diffX, diffY, 0.95f);
this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -5, 5), -74f, 7.5f));
this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.95f * diffY, -15, 15));
}
@Override
public float turretYRotO() {
return turretYRotO;
}
@Override
public float turretYRot() {
return turretYRot;
}
@Override
public float turretXRotO() {
return turretXRotO;
}
@Override
public float turretXRot() {
return turretXRot;
}
@Override
public Vec3 getBarrelVec(float ticks) {
return getBarrelVector(ticks);
}
@Override
public Vec3 getGunVec(float ticks) {
return null;
}
public float getTurretYRot() {
return this.turretYRot;
}
public void setTurretYRot(float pTurretYRot) {
this.turretYRot = pTurretYRot;
}
public float getTurretXRot() {
return this.turretXRot;
}
public void setTurretXRot(float pTurretXRot) {
this.turretXRot = pTurretXRot;
}
public float getLeftWheelRot() {
return this.leftWheelRot;
}
public void setLeftWheelRot(float pLeftWheelRot) {
this.leftWheelRot = pLeftWheelRot;
}
public float getRightWheelRot() {
return this.rightWheelRot;
}
public void setRightWheelRot(float pRightWheelRot) {
this.rightWheelRot = pRightWheelRot;
}
@Override
public SoundEvent getEngineSound() {
return ModSounds.BMP_ENGINE.get();

View file

@ -72,9 +72,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
public static final EntityDataAccessor<Boolean> LINKED = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<String> CONTROLLER = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> KAMIKAZE_MODE = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> DELTA_X_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -136,11 +134,9 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(DELTA_ROT, 0f);
this.entityData.define(DELTA_X_ROT, 0f);
this.entityData.define(CONTROLLER, "undefined");
this.entityData.define(LINKED, false);
this.entityData.define(AMMO, 0);
this.entityData.define(KAMIKAZE_MODE, 0);
}

View file

@ -19,9 +19,6 @@ import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
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.server.level.ServerPlayer;
@ -61,29 +58,9 @@ import java.util.Comparator;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> COAX_HEAT = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
public static final float MAX_HEALTH = VehicleConfig.LAV_150_HP.get();
public static final int MAX_ENERGY = VehicleConfig.LAV_150_MAX_ENERGY.get();
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public float turretYRot;
public float turretXRot;
public float turretYRotO;
public float turretXRotO;
public float rudderRot;
public float rudderRotO;
public float leftWheelRot;
public float rightWheelRot;
public float leftWheelRotO;
public float rightWheelRotO;
public boolean cannotFire;
public boolean cannotFireCoax;
public Lav150Entity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.LAV_150.get(), world);
}
@ -116,11 +93,6 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(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);
}
@Override
@ -246,22 +218,12 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int) (2 + 10 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true);
}
float deltaT = Math.abs(getTurretYRot() - turretYRotO);
while (getTurretYRot() > 180F) {
setTurretYRot(getTurretYRot() - 360F);
turretYRotO = getTurretYRot() - deltaT;
}
while (getTurretYRot() <= -180F) {
setTurretYRot(getTurretYRot() + 360F);
turretYRotO = deltaT + getTurretYRot();
}
collideBlock();
if (this.getDeltaMovement().length() > 0.2) {
collideHardBlock();
}
gunnerAngle();
turretAngle(15, 12.5f);
lowHealthWarning();
this.refreshDimensions();
@ -390,18 +352,6 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
}
}
public final Vec3 getBarrelVector(float pPartialTicks) {
return this.calculateViewVector(this.getBarrelXRot(pPartialTicks), this.getBarrelYRot(pPartialTicks));
}
public float getBarrelXRot(float pPartialTicks) {
return Mth.lerp(pPartialTicks, turretXRotO - this.xRotO, getTurretXRot() - this.getXRot());
}
public float getBarrelYRot(float pPartialTick) {
return -Mth.lerp(pPartialTick, turretYRotO - this.yRotO, getTurretYRot() - this.getYRot());
}
@Override
public void travel() {
Entity passenger0 = this.getFirstPassenger();
@ -457,94 +407,6 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
}
}
private void gunnerAngle() {
Entity driver = this.getFirstPassenger();
if (driver == null) return;
float gunAngle = -Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot());
float diffY;
float diffX;
diffY = Mth.wrapDegrees(gunAngle - getTurretYRot() + 0.05f);
diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot());
turretTurnSound(diffX, diffY, 0.95f);
this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -5, 5), -32.5f, 15));
this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.95f * diffY, -20, 20));
}
@Override
public float turretYRotO() {
return turretYRotO;
}
@Override
public float turretYRot() {
return turretYRot;
}
@Override
public float turretXRotO() {
return turretXRotO;
}
@Override
public float turretXRot() {
return turretXRot;
}
@Override
public Vec3 getBarrelVec(float ticks) {
return getBarrelVector(ticks);
}
@Override
public Vec3 getGunVec(float ticks) {
return null;
}
public float getTurretYRot() {
return this.turretYRot;
}
public void setTurretYRot(float pTurretYRot) {
this.turretYRot = pTurretYRot;
}
public float getTurretXRot() {
return this.turretXRot;
}
public void setTurretXRot(float pTurretXRot) {
this.turretXRot = pTurretXRot;
}
public float getRudderRot() {
return this.rudderRot;
}
public void setRudderRot(float pRudderRot) {
this.rudderRot = pRudderRot;
}
public float getLeftWheelRot() {
return this.leftWheelRot;
}
public void setLeftWheelRot(float pLeftWheelRot) {
this.leftWheelRot = pLeftWheelRot;
}
public float getRightWheelRot() {
return this.rightWheelRot;
}
public void setRightWheelRot(float pRightWheelRot) {
this.rightWheelRot = pRightWheelRot;
}
@Override
public SoundEvent getEngineSound() {
return ModSounds.LAV_ENGINE.get();

View file

@ -19,9 +19,6 @@ import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
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.server.level.ServerPlayer;
@ -56,26 +53,9 @@ import java.util.Comparator;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class SpeedboatEntity extends ContainerMobileVehicleEntity implements GeoEntity, ArmedVehicleEntity, WeaponVehicleEntity, LandArmorEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
public static final float MAX_HEALTH = VehicleConfig.SPEEDBOAT_HP.get();
public static final int MAX_ENERGY = VehicleConfig.SPEEDBOAT_MAX_ENERGY.get();
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public float turretYRot;
public float turretXRot;
public float turretYRotO;
public float turretXRotO;
public float rotorRot;
public float rudderRot;
public float rotorRotO;
public float rudderRotO;
public boolean cannotFire;
public SpeedboatEntity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.SPEEDBOAT.get(), world);
@ -101,10 +81,6 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(AMMO, 0);
this.entityData.define(FIRE_ANIM, 0);
this.entityData.define(DELTA_ROT, 0f);
this.entityData.define(HEAT, 0);
}
@Override
@ -152,11 +128,6 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
@Override
public void baseTick() {
turretYRotO = this.getTurretYRot();
turretXRotO = this.getTurretXRot();
rotorRotO = this.getRotorRot();
rudderRotO = this.getRudderRot();
super.baseTick();
if (this.entityData.get(HEAT) > 0) {
@ -204,7 +175,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() - 4.5 * this.getLookAngle().x, this.getY() - 0.25, this.getZ() - 4.5 * this.getLookAngle().z, (int) (40 * Mth.abs(this.entityData.get(POWER))), 0.15, 0.15, 0.15, 0.02, true);
}
gunnerAngle();
turretAngle(40, 40);
lowHealthWarning();
collideBlock();
if (this.getDeltaMovement().length() > 0.15) {
@ -357,24 +328,6 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
}
}
private void gunnerAngle() {
Entity driver = this.getFirstPassenger();
if (driver == null) return;
float gunAngle = -Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot());
float diffY;
float diffX;
diffY = Mth.wrapDegrees(gunAngle - getTurretYRot() + 0.05f);
diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot());
turretTurnSound(diffX, diffY, 0.95f);
this.setTurretXRot(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -40, 40));
this.setTurretYRot(Mth.clamp(this.getTurretYRot() + Mth.clamp(0.95f * diffY, -40, 40), -140, 140));
}
public Matrix4f getBarrelTransform() {
Matrix4f transformT = getTurretTransform();
float x = 0f;
@ -404,39 +357,6 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
transform.rotate(Axis.ZP.rotationDegrees(getRoll()));
return transform;
}
public float getTurretYRot() {
return this.turretYRot;
}
public void setTurretYRot(float pTurretYRot) {
this.turretYRot = pTurretYRot;
}
public float getTurretXRot() {
return this.turretXRot;
}
public void setTurretXRot(float pTurretXRot) {
this.turretXRot = pTurretXRot;
}
public float getRotorRot() {
return this.rotorRot;
}
public void setRotorRot(float pRotorRot) {
this.rotorRot = pRotorRot;
}
public float getRudderRot() {
return this.rudderRot;
}
public void setRudderRot(float pRudderRot) {
this.rudderRot = pRudderRot;
}
@Override
public SoundEvent getEngineSound() {
return ModSounds.BOAT_ENGINE.get();
@ -572,43 +492,6 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
return ModUtils.loc("textures/vehicle_icon/speedboat_icon.png");
}
@Override
public float turretYRotO() {
return turretYRotO;
}
@Override
public float turretYRot() {
return turretYRot;
}
@Override
public float turretXRotO() {
return turretXRotO;
}
@Override
public float turretXRot() {
return turretXRot;
}
@Override
public Vec3 getBarrelVec(float ticks) {
return getBarrelVector(ticks);
}
public final Vec3 getBarrelVector(float pPartialTicks) {
return this.calculateViewVector(this.getBarrelXRot(pPartialTicks), this.getBarrelYRot(pPartialTicks));
}
public float getBarrelXRot(float pPartialTicks) {
return Mth.lerp(pPartialTicks, turretXRotO - this.xRotO, getTurretXRot() - this.getXRot());
}
public float getBarrelYRot(float pPartialTick) {
return -Mth.lerp(pPartialTick, turretYRotO - this.yRotO, getTurretYRot() - this.getYRot());
}
@Override
public Vec3 getGunVec(float ticks) {
return getBarrelVector(ticks);

View file

@ -47,8 +47,6 @@ import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil;
public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Boolean> MELON = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.BOOLEAN);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = VehicleConfig.TOM_6_HP.get();
@ -66,7 +64,6 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(DELTA_ROT, 0f);
this.entityData.define(MELON, false);
}

View file

@ -43,10 +43,6 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = 30;
public static final int MAX_ENERGY = 24000;
public float leftWheelRot;
public float rightWheelRot;
public float leftWheelRotO;
public float rightWheelRotO;
public int jumpCoolDown;
public int handBusyTime;
@ -108,9 +104,6 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity {
@Override
public void baseTick() {
leftWheelRotO = this.getLeftWheelRot();
rightWheelRotO = this.getRightWheelRot();
if (jumpCoolDown > 0 && onGround()) {
jumpCoolDown--;
}
@ -235,22 +228,6 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity {
return ModSounds.WHEEL_CHAIR_ENGINE.get();
}
public float getLeftWheelRot() {
return this.leftWheelRot;
}
public void setLeftWheelRot(float pLeftWheelRot) {
this.leftWheelRot = pLeftWheelRot;
}
public float getRightWheelRot() {
return this.rightWheelRot;
}
public void setRightWheelRot(float pRightWheelRot) {
this.rightWheelRot = pRightWheelRot;
}
protected void clampRotation(Entity entity) {
entity.setYBodyRot(this.getYRot());
float f2 = Mth.wrapDegrees(entity.getYRot() - this.getYRot());

View file

@ -65,42 +65,16 @@ import java.util.Comparator;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity {
public static final EntityDataAccessor<Integer> CANNON_FIRE_TIME = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> 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<Float> TRACK_L = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> TRACK_R = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT);
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 int MAX_ENERGY = VehicleConfig.YX_100_MAX_ENERGY.get();
public static final int SHOOT_COST = VehicleConfig.YX_100_SHOOT_COST.get();
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public float turretYRot;
public float turretXRot;
public float turretYRotO;
public float turretXRotO;
public float turretRot;
public float gunYRot;
public float gunXRot;
public float gunYRotO;
public float gunXRotO;
public float leftWheelRot;
public float rightWheelRot;
public float leftWheelRotO;
public float rightWheelRotO;
public double recoilShake;
public double recoilShakeO;
public int reloadCoolDown;
public boolean cannotFire;
public Yx100Entity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.YX_100.get(), world);
@ -156,14 +130,9 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(AMMO, 0);
this.entityData.define(MG_AMMO, 0);
this.entityData.define(LOADED_AMMO, 0);
this.entityData.define(CANNON_FIRE_TIME, 0);
this.entityData.define(DELTA_ROT, 0f);
this.entityData.define(TRACK_L, 0f);
this.entityData.define(TRACK_R, 0f);
this.entityData.define(YAW, 0f);
this.entityData.define(GUN_FIRE_TIME, 0);
this.entityData.define(MACHINE_GUN_HEAT, 0);
}
@ -217,32 +186,22 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
@Override
public void baseTick() {
turretYRotO = this.getTurretYRot();
turretXRotO = this.getTurretXRot();
gunYRotO = this.getGunYRot();
gunXRotO = this.getGunXRot();
leftWheelRotO = this.getLeftWheelRot();
rightWheelRotO = this.getRightWheelRot();
recoilShakeO = this.getRecoilShake();
this.setRecoilShake(Math.pow(entityData.get(CANNON_FIRE_TIME), 4) * 0.0000007 * Math.sin(0.2 * Math.PI * (entityData.get(CANNON_FIRE_TIME) - 2.5)));
super.baseTick();
if (this.entityData.get(TRACK_R) < 0) {
this.entityData.set(TRACK_R, 80f);
if (getLeftTrack() < 0) {
setLeftTrack(80);
}
if (this.entityData.get(TRACK_R) > 80) {
this.entityData.set(TRACK_R, 0f);
if (getLeftTrack() > 80) {
setLeftTrack(0);
}
if (this.entityData.get(TRACK_L) < 0) {
this.entityData.set(TRACK_L, 80f);
if (getRightTrack() < 0) {
setRightTrack(80);
}
if (this.entityData.get(TRACK_L) > 80) {
this.entityData.set(TRACK_L, 0f);
if (getRightTrack() > 80) {
setRightTrack(0);
}
if (this.entityData.get(CANNON_FIRE_TIME) > 0) {
@ -299,23 +258,15 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int) (2 + 10 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true);
}
float deltaT = Math.abs(getTurretYRot() - turretYRotO);
while (getTurretYRot() > 180F) {
setTurretYRot(getTurretYRot() - 360F);
turretYRotO = getTurretYRot() - deltaT;
}
while (getTurretYRot() <= -180F) {
setTurretYRot(getTurretYRot() + 360F);
turretYRotO = deltaT + getTurretYRot();
}
collideBlock();
if (this.getDeltaMovement().length() > 0.15) {
collideHardBlock();
}
turretAngle();
gunnerAngle();
this.setRecoilShake(Math.pow(entityData.get(CANNON_FIRE_TIME), 4) * 0.0000007 * Math.sin(0.2 * Math.PI * (entityData.get(CANNON_FIRE_TIME) - 2.5)));
turretAngle(7, 7);
gunnerAngle(15, 15);
lowHealthWarning();
this.refreshDimensions();
}
@ -501,30 +452,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
}
}
public Vec3 getBarrelVector(float pPartialTicks) {
return this.calculateViewVector(this.getBarrelXRot(pPartialTicks), this.getBarrelYRot(pPartialTicks));
}
public float getBarrelXRot(float pPartialTicks) {
return Mth.lerp(pPartialTicks, turretXRotO - this.xRotO, getTurretXRot() - this.getXRot());
}
public float getBarrelYRot(float pPartialTick) {
return -Mth.lerp(pPartialTick, turretYRotO - this.yRotO, getTurretYRot() - this.getYRot());
}
public Vec3 getGunVector(float pPartialTicks) {
return this.calculateViewVector(this.getGunXRot(pPartialTicks), this.getGunYRot(pPartialTicks));
}
public float getGunXRot(float pPartialTicks) {
return Mth.lerp(pPartialTicks, gunXRotO - this.xRotO, getGunXRot() - this.getXRot());
}
public float getGunYRot(float pPartialTick) {
return -Mth.lerp(pPartialTick, gunYRotO - this.yRotO, getGunYRot() - this.getYRot());
}
@Override
public void travel() {
Entity passenger0 = this.getFirstPassenger();
@ -577,8 +504,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.setLeftWheelRot((float) ((this.getLeftWheelRot() - 1.25 * s0) + Mth.clamp(0.75f * this.entityData.get(DELTA_ROT), -5f, 5f)));
this.setRightWheelRot((float) ((this.getRightWheelRot() - 1.25 * s0) - Mth.clamp(0.75f * this.entityData.get(DELTA_ROT), -5f, 5f)));
this.entityData.set(TRACK_L, (float) ((entityData.get(TRACK_L) - 1.9 * Math.PI * s0) + Mth.clamp(0.4f * Math.PI * this.entityData.get(DELTA_ROT), -5f, 5f)));
this.entityData.set(TRACK_R, (float) ((entityData.get(TRACK_R) - 1.9 * Math.PI * s0) - Mth.clamp(0.4f * Math.PI * this.entityData.get(DELTA_ROT), -5f, 5f)));
setLeftTrack((float) ((getLeftTrack() - 1.9 * Math.PI * s0) + Mth.clamp(0.4f * Math.PI * this.entityData.get(DELTA_ROT), -5f, 5f)));
setRightTrack((float) ((getRightTrack() - 1.9 * Math.PI * s0) - Mth.clamp(0.4f * Math.PI * this.entityData.get(DELTA_ROT), -5f, 5f)));
if (this.isInWater() || onGround()) {
this.setYRot((float) (this.getYRot() - (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT)));
@ -586,151 +513,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
}
}
private void turretAngle() {
Entity driver = this.getFirstPassenger();
if (driver != null) {
float turretAngle = -Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot());
float diffY;
float diffX;
diffY = Mth.wrapDegrees(turretAngle - getTurretYRot() + 0.05f);
diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot());
turretTurnSound(diffX, diffY, 0.95f);
float min = -5 + (float) (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT);
float max = 5 + (float) (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT);
this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -5, 5), -30f, 4f));
this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.9f * diffY, min, max));
turretRot = Mth.clamp(0.9f * diffY, min, max);
} else {
turretRot = 0;
}
}
private void gunnerAngle() {
Entity gunner = this.getNthEntity(1);
float diffY = 0;
float diffX = 0;
float speed = 1;
if (gunner instanceof Player) {
float gunAngle = -Mth.wrapDegrees(gunner.getYHeadRot() - this.getYRot());
diffY = Mth.wrapDegrees(gunAngle - getGunYRot());
diffX = Mth.wrapDegrees(gunner.getXRot() - this.getGunXRot());
turretTurnSound(diffX, diffY, 0.95f);
speed = 0;
}
this.setGunXRot(Mth.clamp(this.getGunXRot() + Mth.clamp(0.95f * diffX, -10, 10), -60f, 12.5f));
this.setGunYRot(this.getGunYRot() + Mth.clamp(0.9f * diffY, -15, 15) + speed * turretRot);
}
@Override
public float turretYRotO() {
return turretYRotO;
}
@Override
public float turretYRot() {
return turretYRot;
}
@Override
public float turretXRotO() {
return turretXRotO;
}
@Override
public float turretXRot() {
return turretXRot;
}
public float gunYRotO() {
return gunYRotO;
}
public float gunYRot() {
return gunYRot;
}
public float gunXRotO() {
return gunXRotO;
}
public float gunXRot() {
return gunXRot;
}
@Override
public Vec3 getBarrelVec(float ticks) {
return getBarrelVector(ticks);
}
@Override
public Vec3 getGunVec(float ticks) {
return getGunVector(ticks);
}
public float getTurretYRot() {
return this.turretYRot;
}
public void setTurretYRot(float pTurretYRot) {
this.turretYRot = pTurretYRot;
}
public float getTurretXRot() {
return this.turretXRot;
}
public void setTurretXRot(float pTurretXRot) {
this.turretXRot = pTurretXRot;
}
public float getGunYRot() {
return this.gunYRot;
}
public void setGunYRot(float pGunYRot) {
this.gunYRot = pGunYRot;
}
public float getGunXRot() {
return this.gunXRot;
}
public void setGunXRot(float pGunXRot) {
this.gunXRot = pGunXRot;
}
public float getLeftWheelRot() {
return this.leftWheelRot;
}
public void setLeftWheelRot(float pLeftWheelRot) {
this.leftWheelRot = pLeftWheelRot;
}
public float getRightWheelRot() {
return this.rightWheelRot;
}
public void setRightWheelRot(float pRightWheelRot) {
this.rightWheelRot = pRightWheelRot;
}
public double getRecoilShake() {
return this.recoilShake;
}
public void setRecoilShake(double pRecoilShake) {
this.recoilShake = pRecoilShake;
}
@Override
public SoundEvent getEngineSound() {
return ModSounds.BMP_ENGINE.get();

View file

@ -40,8 +40,14 @@ import org.joml.Math;
import org.joml.Vector3f;
public abstract class MobileVehicleEntity extends EnergyVehicleEntity {
public static final EntityDataAccessor<Float> POWER = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> COAX_HEAT = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(MobileVehicleEntity.class, EntityDataSerializers.INT);
public boolean leftInputDown;
public boolean rightInputDown;
@ -54,6 +60,32 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity {
public double lastTickVerticalSpeed;
public int collisionCoolDown;
public float rudderRot;
public float rudderRotO;
public float leftWheelRot;
public float rightWheelRot;
public float leftWheelRotO;
public float rightWheelRotO;
public float leftTrackO;
public float rightTrackO;
public float leftTrack;
public float rightTrack;
public float rotorRot;
public float rotorRotO;
public float propellerRot;
public float propellerRotO;
public double recoilShake;
public double recoilShakeO;
public boolean cannotFire;
public boolean cannotFireCoax;
public int reloadCoolDown;
public MobileVehicleEntity(EntityType<?> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
@ -72,12 +104,43 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity {
@Override
public void baseTick() {
turretYRotO = this.getTurretYRot();
turretXRotO = this.getTurretXRot();
gunYRotO = this.getGunYRot();
gunXRotO = this.getGunXRot();
leftWheelRotO = this.getLeftWheelRot();
rightWheelRotO = this.getRightWheelRot();
leftTrackO = this.getLeftTrack();
rightTrackO = this.getRightTrack();
rotorRotO = this.getRotorRot();
rudderRotO = this.getRudderRot();
propellerRotO = this.getPropellerRot();
recoilShakeO = this.getRecoilShake();
lastTickSpeed = new Vec3(this.getDeltaMovement().x, this.getDeltaMovement().y + 0.06, this.getDeltaMovement().z).length();
lastTickVerticalSpeed = this.getDeltaMovement().y + 0.06;
if (collisionCoolDown > 0) {
collisionCoolDown--;
}
super.baseTick();
float deltaT = java.lang.Math.abs(getTurretYRot() - turretYRotO);
while (getTurretYRot() > 180F) {
setTurretYRot(getTurretYRot() - 360F);
turretYRotO = getTurretYRot() - deltaT;
}
while (getTurretYRot() <= -180F) {
setTurretYRot(getTurretYRot() + 360F);
turretYRotO = deltaT + getTurretYRot();
}
preventStacking();
crushEntities(this.getDeltaMovement());
if (!(this instanceof DroneEntity)) {
@ -285,10 +348,80 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity {
return SoundEvents.EMPTY;
}
public float getRudderRot() {
return this.rudderRot;
}
public void setRudderRot(float pRudderRot) {
this.rudderRot = pRudderRot;
}
public float getLeftWheelRot() {
return this.leftWheelRot;
}
public void setLeftWheelRot(float pLeftWheelRot) {
this.leftWheelRot = pLeftWheelRot;
}
public float getRightWheelRot() {
return this.rightWheelRot;
}
public void setRightWheelRot(float pRightWheelRot) {
this.rightWheelRot = pRightWheelRot;
}
public float getLeftTrack() {
return this.leftTrack;
}
public void setLeftTrack(float pLeftTrack) {
this.leftTrack = pLeftTrack;
}
public float getRightTrack() {
return this.rightTrack;
}
public void setRightTrack(float pRightTrack) {
this.rightTrack = pRightTrack;
}
public float getRotorRot() {
return this.rotorRot;
}
public void setRotorRot(float pRotorRot) {
this.rotorRot = pRotorRot;
}
public float getPropellerRot() {
return this.propellerRot;
}
public void setPropellerRot(float pPropellerRot) {
this.propellerRot = pPropellerRot;
}
public double getRecoilShake() {
return this.recoilShake;
}
public void setRecoilShake(double pRecoilShake) {
this.recoilShake = pRecoilShake;
}
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(POWER, 0f);
this.entityData.define(YAW, 0f);
this.entityData.define(AMMO, 0);
this.entityData.define(FIRE_ANIM, 0);
this.entityData.define(HEAT, 0);
this.entityData.define(COAX_HEAT, 0);
}
@Override

View file

@ -61,11 +61,11 @@ import java.util.function.Function;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public abstract class VehicleEntity extends Entity {
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT);
protected static final EntityDataAccessor<String> LAST_ATTACKER_UUID = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.STRING);
protected static final EntityDataAccessor<String> LAST_DRIVER_UUID = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT);
protected static final EntityDataAccessor<IntList> SELECTED_WEAPON = SynchedEntityData.defineId(VehicleEntity.class, ModSerializers.INT_LIST_SERIALIZER.get());
public VehicleWeapon[][] availableWeapons;
@ -83,6 +83,17 @@ public abstract class VehicleEntity extends Entity {
public int repairCoolDown = maxRepairCoolDown();
public boolean crash;
public float turretYRot;
public float turretXRot;
public float turretYRotO;
public float turretXRotO;
public float turretRot;
public float gunYRot;
public float gunXRot;
public float gunYRotO;
public float gunXRotO;
// 自定义骑乘
private final List<Entity> orderedPassengers = generatePassengersList();
@ -233,6 +244,7 @@ public abstract class VehicleEntity extends Entity {
this.entityData.define(HEALTH, this.getMaxHealth());
this.entityData.define(LAST_ATTACKER_UUID, "undefined");
this.entityData.define(LAST_DRIVER_UUID, "undefined");
this.entityData.define(DELTA_ROT, 0f);
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
this.entityData.define(SELECTED_WEAPON, IntList.of(initSelectedWeaponArray(weaponVehicle)));
@ -605,6 +617,49 @@ public abstract class VehicleEntity extends Entity {
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 1, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true);
}
public void turretAngle(float ySpeed, float xSpeed) {
Entity driver = this.getFirstPassenger();
if (driver != null) {
float turretAngle = -Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot());
float diffY;
float diffX;
diffY = Mth.wrapDegrees(turretAngle - getTurretYRot() + 0.05f);
diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot());
turretTurnSound(diffX, diffY, 0.95f);
float min = -ySpeed + (float) (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT);
float max = ySpeed + (float) (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT);
this.setTurretXRot(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -xSpeed, xSpeed));
this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.9f * diffY, min, max));
turretRot = Mth.clamp(0.9f * diffY, min, max);
} else {
turretRot = 0;
}
}
public void gunnerAngle(float ySpeed, float xSpeed) {
Entity gunner = this.getNthEntity(1);
float diffY = 0;
float diffX = 0;
float speed = 1;
if (gunner instanceof Player) {
float gunAngle = -Mth.wrapDegrees(gunner.getYHeadRot() - this.getYRot());
diffY = Mth.wrapDegrees(gunAngle - getGunYRot());
diffX = Mth.wrapDegrees(gunner.getXRot() - this.getGunXRot());
turretTurnSound(diffX, diffY, 0.95f);
speed = 0;
}
this.setGunXRot(this.getGunXRot() + Mth.clamp(0.95f * diffX, -xSpeed, xSpeed));
this.setGunYRot(this.getGunYRot() + Mth.clamp(0.9f * diffY, -ySpeed, ySpeed) + speed * turretRot);
}
public void destroy() {
}
@ -753,4 +808,84 @@ public abstract class VehicleEntity extends Entity {
@Override
public void push(double pX, double pY, double pZ) {
}
public Vec3 getBarrelVector(float pPartialTicks) {
return this.calculateViewVector(this.getBarrelXRot(pPartialTicks), this.getBarrelYRot(pPartialTicks));
}
public float getBarrelXRot(float pPartialTicks) {
return Mth.lerp(pPartialTicks, turretXRotO - this.xRotO, getTurretXRot() - this.getXRot());
}
public float getBarrelYRot(float pPartialTick) {
return -Mth.lerp(pPartialTick, turretYRotO - this.yRotO, getTurretYRot() - this.getYRot());
}
public Vec3 getGunVector(float pPartialTicks) {
return this.calculateViewVector(this.getGunXRot(pPartialTicks), this.getGunYRot(pPartialTicks));
}
public float getGunXRot(float pPartialTicks) {
return Mth.lerp(pPartialTicks, gunXRotO - this.xRotO, getGunXRot() - this.getXRot());
}
public float getGunYRot(float pPartialTick) {
return -Mth.lerp(pPartialTick, gunYRotO - this.yRotO, getGunYRot() - this.getYRot());
}
public float turretYRotO() {
return turretYRotO;
}
public float turretYRot() {
return turretYRot;
}
public float turretXRotO() {
return turretXRotO;
}
public float turretXRot() {
return turretXRot;
}
public Vec3 getBarrelVec(float ticks) {
return getBarrelVector(ticks);
}
public Vec3 getGunVec(float ticks) {
return getGunVector(ticks);
}
public float getTurretYRot() {
return this.turretYRot;
}
public void setTurretYRot(float pTurretYRot) {
this.turretYRot = pTurretYRot;
}
public float getTurretXRot() {
return this.turretXRot;
}
public void setTurretXRot(float pTurretXRot) {
this.turretXRot = pTurretXRot;
}
public float getGunYRot() {
return this.gunYRot;
}
public void setGunYRot(float pGunYRot) {
this.gunYRot = pGunYRot;
}
public float getGunXRot() {
return this.gunXRot;
}
public void setGunXRot(float pGunXRot) {
this.gunXRot = pGunXRot;
}
}