优化载具代码

This commit is contained in:
17146 2025-06-17 18:13:10 +08:00 committed by Light_Quanta
parent 4ab475195d
commit f5d013a45a
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
10 changed files with 80 additions and 123 deletions

View file

@ -594,7 +594,6 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
float flapY = (1 - (Mth.abs(getRoll())) / 90) * Mth.clamp(entityData.get(MOUSE_SPEED_X), -22.5f, 22.5f) + VectorTool.calculateY(getRoll()) * Mth.clamp(entityData.get(MOUSE_SPEED_Y), -22.5f, 22.5f);
setFlap3Rot(flapY * 5);
} else if (!onGround()) {
float diffX;
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0003f, 0.02f));
@ -695,10 +694,9 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
Matrix4f transform = getVehicleTransform(1);
float x = 0f;
float y = -0.2f;
float y = 0.1f + (float) passenger.getVehicleAttachmentPoint(this).y;
float z = 3.95f;
Vector4f worldPosition = transformPosition(transform, x, y, z);
passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z);
@ -706,12 +704,6 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
copyEntityData(passenger);
}
public Vec3 driverPos(float ticks) {
Matrix4f transform = getVehicleTransform(ticks);
Vector4f worldPosition = transformPosition(transform, 0, 1.35f, 4f);
return new Vec3(worldPosition.x, worldPosition.y, worldPosition.z);
}
@Override
public Vec3 driverZoomPos(float ticks) {
Matrix4f transform = getVehicleTransform(ticks);
@ -812,7 +804,6 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
boolean hasCreativeAmmo = getFirstPassenger() instanceof Player pPlayer && InventoryTool.hasCreativeAmmoBox(pPlayer);
Vector4f worldPosition = transformPosition(transform, 0.1321625f, -0.56446875f, 7.85210625f);
Vector4f worldPosition2 = transformPosition(transform, 0.1321625f + 0.01f, -0.56446875f - 0.03f, 8.85210625f);

View file

@ -186,7 +186,6 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
setRightTrack(0);
}
if (this.level() instanceof ServerLevel) {
if (reloadCoolDown > 0) {
reloadCoolDown--;

View file

@ -24,7 +24,6 @@ import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
@ -117,16 +116,6 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
return new ThirdPersonCameraPosition(2.75 + ClientMouseHandler.custom3pDistanceLerp, 1, 0);
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
}
@Override
public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
}
@Override
@ParametersAreNonnullByDefault
protected void playStepSound(BlockPos pPos, BlockState pState) {
@ -154,8 +143,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
this.handleAmmo();
}
double fluidFloat;
fluidFloat = 0.052 * getSubmergedHeight(this);
double fluidFloat = 0.052 * getSubmergedHeight(this);
this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0));
if (this.onGround()) {
@ -396,6 +384,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
}
}
@Override
public int getMaxPassengers() {
return 5;
}

View file

@ -187,7 +187,6 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
return 2.16F;
}
public void positionRider(@NotNull Entity passenger, @NotNull MoveFunction callback) {
if (!this.hasPassenger(passenger)) {
return;

View file

@ -102,10 +102,9 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
@Override
public void baseTick() {
super.baseTick();
updateOBB();
this.updateOBB();
double fluidFloat;
fluidFloat = 0.12 * getSubmergedHeight(this);
double fluidFloat = 0.12 * getSubmergedHeight(this);
this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0));
if (this.onGround()) {
@ -128,9 +127,9 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
this.handleAmmo();
}
turretAngle(40, 40);
lowHealthWarning();
inertiaRotate(2);
this.turretAngle(40, 40);
this.lowHealthWarning();
this.inertiaRotate(2);
this.terrainCompact(2f, 3f);
this.refreshDimensions();
@ -151,14 +150,12 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
return false;
}).mapToInt(Ammo.HEAVY::get).sum() + countItem(ModItems.HEAVY_AMMO.get());
this.entityData.set(AMMO, ammoCount);
}
/**
* 机枪塔开火
*/
@Override
public void vehicleShoot(Player player, int type) {
if (this.cannotFire) return;
@ -179,8 +176,6 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
(float) 0.4);
this.level().addFreshEntity(projectile);
float pitch = this.entityData.get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - this.entityData.get(HEAT)));
if (!player.level().isClientSide) {
playShootSound3p(player, 0, 4, 12, 24);
}
@ -302,24 +297,16 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
float y = -0.65f;
if (i == 0) {
Vector4f worldPosition = transformPosition(transform, 0, y + 0.25f, -0.2f);
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, -0.8f, y, -1.2f);
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, 0.8f, y, -1.2f);
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, -0.8f, y, -2.2f);
passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z);
} else if (i == 4) {
Vector4f worldPosition = transformPosition(transform, 0.8f, y, -2.2f);
Vector4f worldPosition = switch (i) {
case 0 -> transformPosition(transform, 0, y + 0.25f, -0.2f);
case 1 -> transformPosition(transform, -0.8f, y, -1.2f);
case 2 -> transformPosition(transform, 0.8f, y, -1.2f);
case 3 -> transformPosition(transform, -0.8f, y, -2.2f);
case 4 -> transformPosition(transform, 0.8f, y, -2.2f);
default -> null;
};
if (worldPosition != null) {
passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z);
}

View file

@ -61,11 +61,11 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private float yRotSync;
public float delta_xo;
public float delta_yo;
public float deltaXo;
public float deltaYo;
public float delta_x;
public float delta_y;
public float deltaX;
public float deltaY;
public Tom6Entity(EntityType<Tom6Entity> type, Level world) {
super(type, world);
@ -113,16 +113,14 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
@Override
public void baseTick() {
delta_xo = delta_x;
delta_yo = delta_y;
deltaXo = deltaX;
deltaYo = deltaY;
super.baseTick();
delta_x = entityData.get(MOUSE_SPEED_Y);
delta_y = entityData.get(MOUSE_SPEED_X);
deltaX = entityData.get(MOUSE_SPEED_Y);
deltaY = entityData.get(MOUSE_SPEED_X);
float f;
f = (float) Mth.clamp(0.69f + 0.101f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90, 0.01, 0.99);
float f = (float) Mth.clamp(0.69f + 0.101f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90, 0.01, 0.99);
boolean forward = Mth.abs((float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) < 90;
@ -144,11 +142,6 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
public void travel() {
Entity passenger = this.getFirstPassenger();
// if (this.getEnergy() <= 0) return;
float diffX;
float diffY;
if (passenger == null || isInWater()) {
this.leftInputDown = false;
this.rightInputDown = false;
@ -182,8 +175,8 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
}
}
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot()));
float diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
float diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot()));
float roll = Mth.abs(Mth.clamp(getRoll() / 60, -1.5f, 1.5f));
@ -280,7 +273,7 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
Matrix4f transform = getVehicleTransform(1);
float x = 0f;
float y = 0.05f;
float y = 0.45f + (float) passenger.getVehicleAttachmentPoint(this).y;
float z = -0.4f;
int i = this.getSeatIndex(passenger);
@ -300,9 +293,9 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
public void copyEntityData(Entity entity) {
float i = getXRot() / 90;
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 + yRotSync * Mth.abs(i));
entity.setYHeadRot(entity.getYRot());
@ -393,7 +386,7 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
@Override
public @Nullable Vec2 getCameraRotation(float partialTicks, Player player, boolean zoom, boolean isFirstPerson) {
if (isFreeCam(player) && this.getSeatIndex(player) == 0 && Mth.abs((float) (freeCameraYaw * freeCameraPitch)) > 0.01) {
return new Vec2((float) (getYaw(partialTicks) - 0.5f * Mth.lerp(partialTicks, delta_yo, delta_y) - freeCameraYaw), (float) (getPitch(partialTicks) - 0.5f * Mth.lerp(partialTicks, delta_xo, delta_x) + freeCameraPitch));
return new Vec2((float) (getYaw(partialTicks) - 0.5f * Mth.lerp(partialTicks, deltaYo, deltaY) - freeCameraYaw), (float) (getPitch(partialTicks) - 0.5f * Mth.lerp(partialTicks, deltaXo, deltaX) + freeCameraPitch));
}
return super.getCameraRotation(partialTicks, player, false, false);

View file

@ -903,7 +903,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
return transformG;
}
@Override
public void destroy() {
if (level() instanceof ServerLevel) {