修复武器开火后可能出现的神秘颤抖

This commit is contained in:
Atsuihsio 2024-12-24 02:52:38 +08:00
parent 7155b5c441
commit 647754850a
6 changed files with 40 additions and 49 deletions

View file

@ -1,9 +1,9 @@
package com.atsuishio.superbwarfare.block;
import com.atsuishio.superbwarfare.network.ModVariables;
import com.atsuishio.superbwarfare.entity.ICannonEntity;
import com.atsuishio.superbwarfare.entity.TargetEntity;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.network.ModVariables;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundSource;
@ -100,8 +100,6 @@ public class JumpPadBlock extends Block {
// 禁止套娃
if (entity instanceof TargetEntity || entity instanceof ICannonEntity) return;
boolean zooming = entity.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.zoom).orElse(false);
if (entity.isShiftKeyDown()) {
if (entity.onGround()) {
entity.setDeltaMovement(new Vec3(5 * entity.getLookAngle().x, 1.5, 5 * entity.getLookAngle().z));
@ -112,10 +110,6 @@ public class JumpPadBlock extends Block {
entity.setDeltaMovement(new Vec3(0.7 * entity.getDeltaMovement().x(), 1.7, 0.7 * entity.getDeltaMovement().z()));
}
if (!zooming) {
entity.getPersistentData().putDouble("vy", 0.8);
}
if (!level.isClientSide()) {
level.playSound(null, BlockPos.containing(pos.getX(), pos.getY(), pos.getZ()), ModSounds.JUMP.get(), SoundSource.BLOCKS, 1, 1);
} else {

View file

@ -59,13 +59,26 @@ public class DroneModel extends GeoModel<DroneEntity> {
ammo1.setHidden(animatable.getEntityData().get(AMMO) <= 0);
shell.setHidden(!animatable.getEntityData().get(KAMIKAZE));
float times = (float) (0.5f * Math.min(Minecraft.getInstance().getDeltaFrameTime(), 0.8));
float times = Math.min(Minecraft.getInstance().getDeltaFrameTime(), 1);
rotX = Mth.lerp(0.2f * times, rotX, animatable.getEntityData().get(MOVE_X) * Mth.DEG_TO_RAD);
rotZ = Mth.lerp(0.2f * times, rotZ, animatable.getEntityData().get(MOVE_Z) * Mth.DEG_TO_RAD);
if (Minecraft.getInstance().options.keyUp.isDown()) {
rotX = Mth.lerp(0.025f * times, rotX, -0.25f);
} else if (Minecraft.getInstance().options.keyDown.isDown()) {
rotX = Mth.lerp(0.025f * times, rotX, 0.25f);
} else {
rotX = Mth.lerp(0.04f * times, rotX, 0);
}
main.setRotZ(rotX);
main.setRotX(rotZ);
if (Minecraft.getInstance().options.keyRight.isDown()) {
rotZ = Mth.lerp(0.025f * times, rotZ, -0.25f);
} else if (Minecraft.getInstance().options.keyLeft.isDown()) {
rotZ = Mth.lerp(0.025f * times, rotZ, 0.25f);
} else {
rotZ = Mth.lerp(0.04f * times, rotZ, 0);
}
main.setRotX(rotX);
main.setRotZ(rotZ);
droneBodyAngle(rotX, rotZ);

View file

@ -66,12 +66,13 @@ public class DroneEntity extends LivingEntity implements GeoEntity {
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Boolean> KAMIKAZE = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Float> MOVE_X = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> MOVE_Z = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static double lastTickSpeed = 0;
public double moveX = 0;
public double moveY = 0;
public double moveZ = 0;
public DroneEntity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.DRONE.get(), world);
}
@ -92,8 +93,6 @@ public class DroneEntity extends LivingEntity implements GeoEntity {
this.entityData.define(LINKED, false);
this.entityData.define(AMMO, 0);
this.entityData.define(KAMIKAZE, false);
this.entityData.define(MOVE_X, 0f);
this.entityData.define(MOVE_Z, 0f);
}
@Override
@ -176,45 +175,38 @@ public class DroneEntity extends LivingEntity implements GeoEntity {
public void baseTick() {
super.baseTick();
double moveX;
double moveZ;
if (!this.onGround()) {
// left and right
moveX = 0;
if (this.getPersistentData().getBoolean("left")) {
moveX = Mth.clamp(moveX + 0.1f, 0, 1);
moveX = Mth.clamp(moveX + 0.3f, 0, 3);
} else if (this.getPersistentData().getBoolean("right")) {
moveX = Mth.clamp(moveX - 0.1f, -1, 0);
} else {
moveX = Mth.lerp(0.9 * moveX, moveX, 0);
moveX = Mth.clamp(moveX - 0.3f, -3, 0);
}
// forward and backward
moveZ = 0;
if (this.getPersistentData().getBoolean("forward")) {
moveZ = Mth.clamp(moveZ + 0.1f, 0, 1);
moveZ = Mth.clamp(moveZ + 0.3f, 0, 3);
} else if (this.getPersistentData().getBoolean("backward")) {
moveZ= Mth.clamp(moveZ - 0.1f, -1, 0);
} else {
moveZ = Mth.lerp(0.9 * moveZ, moveZ, 0);
moveZ= Mth.clamp(moveZ - 0.3f, -3, 0);
}
moveX *= 0.25;
moveZ *= 0.25;
} else {
moveX = 0;
moveZ = 0;
}
// up and down
double moveY = 0;
if (this.getPersistentData().getBoolean("up")) {
moveY = Mth.clamp(moveY + 0.05f, 0, 1);
moveY = Mth.clamp(moveY + 0.3f, 0, 3);
} else if (this.getPersistentData().getBoolean("down")) {
moveY = Mth.clamp(moveY - 0.05f, -1, 0);
} else {
moveY = Mth.lerp(0.99 * moveY, moveY, 0);
moveY = Mth.clamp(moveY - 0.15f, -2, 0);
}
moveY *= 0.3;
setDeltaMovement(getDeltaMovement().add(0.0f, (this.onGround() ? 0.059 : 0) + moveY, 0.0f));
Vector3f direction = getRightDirection().mul((float) moveX);

View file

@ -709,8 +709,8 @@ public class ClientEventHandler {
DroneEntity drone = EntityFindUtil.findDrone(entity.level(), stack.getOrCreateTag().getString("LinkedDrone"));
if (drone != null) {
event.setPitch((float) (pitch - Mth.RAD_TO_DEG * droneRotZ));
event.setRoll((float) (roll - Mth.RAD_TO_DEG * droneRotX));
event.setPitch((float) (pitch - Mth.RAD_TO_DEG * droneRotX));
event.setRoll((float) (roll - Mth.RAD_TO_DEG * droneRotZ));
}
if (drone != null && stack.getOrCreateTag().getBoolean("Using")) {
@ -836,9 +836,7 @@ public class ClientEventHandler {
double velocity = entity.getDeltaMovement().y() + 0.078;
if (-0.8 < velocity && velocity < 0.8) {
velocityY = Mth.lerp(0.5f * times, velocityY, velocity) * (1 - 0.8 * zoomTime);
}
velocityY = Mth.clamp(Mth.lerp(0.23f * times, velocityY, velocity) * (1 - 0.8 * zoomTime), -0.8, 0.8);
}
}
@ -885,7 +883,7 @@ public class ClientEventHandler {
}
fireSpread = Mth.clamp(fireSpread - 0.1 * (Math.pow(fireSpread, 2) * times), 0, 2);
firePosZ = Mth.clamp(firePosZ - 1.2 * (Math.pow(firePosZ, 2) * times), 0, 1.5);
firePosZ = Mth.clamp(firePosZ - 1.2 * (Math.pow(firePosZ, 2) * times), 0, 1.5) * 0.98;
if (0 < firePosTimer) {
firePosTimer += 0.35 * (1.1 - firePosTimer) * times;

View file

@ -69,7 +69,8 @@ public abstract class CameraMixin {
var CameraPos = new Vector3d(0.22, 0.075, 0);
CameraPos.rotateZ(-drone.getXRot() * Mth.DEG_TO_RAD);
CameraPos.rotateY(-yRot * Mth.DEG_TO_RAD);
setRotation(drone.getViewYRot(partialTicks), drone.getViewXRot(partialTicks));
setRotation(Mth.lerp(partialTicks, player.yBobO, player.yBob), drone.getViewXRot(partialTicks));
setPosition(Mth.lerp(partialTicks, drone.xo + CameraPos.x, drone.getX() + CameraPos.x), Mth.lerp(partialTicks, drone.yo + 0.075, drone.getEyeY()), Mth.lerp(partialTicks, drone.zo + CameraPos.z, drone.getZ() + CameraPos.z));
info.cancel();
}

View file

@ -9,9 +9,6 @@ import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
import static com.atsuishio.superbwarfare.entity.DroneEntity.MOVE_X;
import static com.atsuishio.superbwarfare.entity.DroneEntity.MOVE_Z;
public class DroneMovementMessage {
private final int direction;
private final boolean clicked;
@ -44,19 +41,15 @@ public class DroneMovementMessage {
switch (message.direction) {
case 0:
drone.getPersistentData().putBoolean("left", message.clicked);
drone.getEntityData().set(MOVE_X, message.clicked ? 10f : 0);
break;
case 1:
drone.getPersistentData().putBoolean("right", message.clicked);
drone.getEntityData().set(MOVE_X, message.clicked ? -10f : 0);
break;
case 2:
drone.getPersistentData().putBoolean("forward", message.clicked);
drone.getEntityData().set(MOVE_Z, message.clicked ? -10f : 0);
break;
case 3:
drone.getPersistentData().putBoolean("backward", message.clicked);
drone.getEntityData().set(MOVE_Z, message.clicked ? 10f : 0);
break;
case 4:
drone.getPersistentData().putBoolean("up", message.clicked);