From f4e1f495f1f980c48a8dc906717f81b7c445da8d Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Tue, 18 Feb 2025 12:03:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=AB=E5=87=BB=E7=82=AE?= =?UTF-8?q?=EF=BC=8C=E8=B0=83=E6=95=B4=E7=82=AE=E5=8F=B0=E7=9A=84=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/overlay/MortarInfoOverlay.java | 19 ++- .../superbwarfare/entity/MortarEntity.java | 152 ++++++++---------- .../entity/vehicle/AnnihilatorEntity.java | 24 ++- .../entity/vehicle/LaserTowerEntity.java | 25 ++- .../entity/vehicle/Mk42Entity.java | 73 ++++----- .../entity/vehicle/Mle1934Entity.java | 24 ++- .../entity/vehicle/VehicleEntity.java | 2 +- .../message/AdjustMortarAngleMessage.java | 13 +- .../assets/superbwarfare/lang/en_us.json | 2 +- .../assets/superbwarfare/lang/zh_cn.json | 2 +- 10 files changed, 188 insertions(+), 148 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/MortarInfoOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/MortarInfoOverlay.java index 81080ef30..d72b0fa68 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/MortarInfoOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/MortarInfoOverlay.java @@ -1,5 +1,6 @@ package com.atsuishio.superbwarfare.client.overlay; +import com.atsuishio.superbwarfare.client.gui.RangeHelper; import com.atsuishio.superbwarfare.entity.MortarEntity; import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.TraceTool; @@ -26,12 +27,18 @@ public class MortarInfoOverlay { lookingEntity = TraceTool.findLookingEntity(player, 6); } if (lookingEntity instanceof MortarEntity mortar) { - event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.yaw") - .append(Component.literal(FormatTool.format1D(mortar.getEntityData().get(MortarEntity.Y_ROT), "°"))), - w / 2 + 12, h / 2 - 36, -1, false); - event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.pitch") - .append(Component.literal(FormatTool.format1D(mortar.getEntityData().get(MortarEntity.PITCH), "°"))), - w / 2 + 12, h / 2 - 28, -1, false); + + player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.pitch").append(FormatTool.format1D(-mortar.getXRot(), "° ")) + .append(Component.translatable("tips.superbwarfare.mortar.yaw")).append(FormatTool.format1D(mortar.getYRot(), "° ")) + .append(Component.translatable("tips.superbwarfare.mortar.range")).append(FormatTool.format1D((int) RangeHelper.getRange(-mortar.getXRot()))).append("m") + , true); + +// event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.yaw") +// .append(Component.literal(FormatTool.format1D(mortar.getYRot(), "°"))), +// w / 2 + 12, h / 2 - 36, -1, false); +// event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.pitch") +// .append(Component.literal(FormatTool.format1D(-mortar.getXRot(), "°"))), +// w / 2 + 12, h / 2 - 28, -1, false); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java index 32e634730..7f682f966 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java @@ -3,11 +3,10 @@ package com.atsuishio.superbwarfare.entity; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.client.gui.RangeHelper; import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity; +import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModItems; -import com.atsuishio.superbwarfare.init.ModParticleTypes; import com.atsuishio.superbwarfare.init.ModSounds; -import com.atsuishio.superbwarfare.tools.ParticleTool; import net.minecraft.ChatFormatting; import net.minecraft.commands.arguments.EntityAnchorArgument; import net.minecraft.core.BlockPos; @@ -25,17 +24,19 @@ import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageTypes; -import net.minecraft.world.entity.*; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PlayMessages; +import org.joml.Math; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animation.AnimatableManager; @@ -45,22 +46,16 @@ import software.bernie.geckolib.core.animation.RawAnimation; import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; -public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { - +public class MortarEntity extends VehicleEntity implements GeoEntity, AnimatedEntity { public static final EntityDataAccessor FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor Y_ROT = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor YAW = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); - protected int interpolationSteps; - protected double serverYRot; - protected double serverXRot; public MortarEntity(PlayMessages.SpawnEntity packet, Level world) { this(ModEntities.MORTAR.get(), world); - this.noCulling = true; } public MortarEntity(EntityType type, Level world) { @@ -69,10 +64,15 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { @Override protected void defineSynchedData() { + super.defineSynchedData(); this.entityData.define(FIRE_TIME, 0); - this.entityData.define(PITCH, 70f); - this.entityData.define(Y_ROT, 0f); - this.entityData.define(HEALTH, 100f); + this.entityData.define(PITCH, -70f); + this.entityData.define(YAW, 0f); + } + + @Override + public boolean canBeCollidedWith() { + return false; } @Override @@ -92,55 +92,27 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { @Override public boolean hurt(DamageSource source, float amount) { - if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud) - return false; - if (source.is(DamageTypes.FALL)) - return false; - if (source.is(DamageTypes.CACTUS)) - return false; - if (source.is(DamageTypes.DROWN)) - return false; - if (source.is(DamageTypes.LIGHTNING_BOLT)) - return false; - if (source.is(DamageTypes.FALLING_ANVIL)) - return false; - if (source.is(DamageTypes.DRAGON_BREATH)) - return false; - if (source.is(DamageTypes.WITHER)) - return false; - if (source.is(DamageTypes.WITHER_SKULL)) - return false; - - if (this.level() instanceof ServerLevel serverLevel) { - ParticleTool.sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 1, this.getZ(), 2, 0.05, 0.05, 0.05, 0.1, false); - } + super.hurt(source, amount); this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount); - + this.hurt(amount, source.getEntity(), true); return true; } @Override public void addAdditionalSaveData(CompoundTag compound) { - compound.putInt("FireTime", this.entityData.get(FIRE_TIME)); + super.addAdditionalSaveData(compound); compound.putFloat("Pitch", this.entityData.get(PITCH)); - compound.putFloat("YRot", this.entityData.get(Y_ROT)); - compound.putFloat("Health", this.entityData.get(HEALTH)); + compound.putFloat("Yaw", this.entityData.get(YAW)); } @Override public void readAdditionalSaveData(CompoundTag compound) { - if (compound.contains("FireTime")) { - this.entityData.set(FIRE_TIME, compound.getInt("FireTime")); - } + super.readAdditionalSaveData(compound); if (compound.contains("Pitch")) { this.entityData.set(PITCH, compound.getFloat("Pitch")); } if (compound.contains("YRot")) { - this.entityData.set(Y_ROT, compound.getFloat("YRot")); - } - if (compound.contains("Health")) { - this.entityData.set(HEALTH, compound.getFloat("Health")); + this.entityData.set(YAW, compound.getFloat("Yaw")); } } @@ -198,7 +170,7 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MORTAR_DEPLOYER.get())); return InteractionResult.SUCCESS; } - this.entityData.set(Y_ROT, Mth.clamp(player.getYRot(), -180, 180)); + entityData.set(YAW, player.getYRot()); } return InteractionResult.SUCCESS; @@ -218,7 +190,7 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { angles); if (flag) { - this.entityData.set(PITCH, (float) angles[1]); + entityData.set(PITCH, (float) -angles[1]); } return flag; @@ -228,13 +200,12 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { Vec3 vec3 = pAnchor.apply(this); double d0 = (pTarget.x - vec3.x) * 0.2; double d2 = (pTarget.z - vec3.z) * 0.2; - this.entityData.set(Y_ROT, Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F)); + entityData.set(YAW, Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F)); } @Override - public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) { - serverXRot = pitch; - this.interpolationSteps = 10; + public Vec3 getDeltaMovement() { + return new Vec3(0, Math.min(super.getDeltaMovement().y, 0), 0); } @Override @@ -243,36 +214,49 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { if (this.entityData.get(FIRE_TIME) > 0) { this.entityData.set(FIRE_TIME, this.entityData.get(FIRE_TIME) - 1); } - this.setXRot(-Mth.clamp(entityData.get(PITCH), 20, 89)); - this.xRotO = this.getXRot(); - this.setYRot(entityData.get(Y_ROT)); - this.setYBodyRot(this.getYRot()); - this.setYHeadRot(this.getYRot()); - this.yRotO = this.getYRot(); - this.setRot(this.getYRot(), this.getXRot()); - - this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0)); - - if (!this.level().noCollision(this.getBoundingBox())) { - this.moveTowardsClosestSpace(this.getX(), (this.getBoundingBox().minY + this.getBoundingBox().maxY) / 2.0, this.getZ()); - } this.move(MoverType.SELF, this.getDeltaMovement()); - float f = 0.98F; if (this.onGround()) { - BlockPos pos = this.getBlockPosBelowThatAffectsMyMovement(); - f = this.level().getBlockState(pos).getFriction(this.level(), pos, this) * 0.98F; + this.setDeltaMovement(Vec3.ZERO); + } else { + this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0)); + } + } + + @Override + public void handleClientSync() { + if (isControlledByLocalInstance()) { + interpolationSteps = 0; + syncPacketPositionCodec(getX(), getY(), getZ()); + } + if (interpolationSteps <= 0) { + return; } - this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.98, f)); - if (this.onGround()) { - this.setDeltaMovement(this.getDeltaMovement().multiply(1.0, -0.9, 1.0)); - } + double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot()); + setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps); + setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps); + setRot(getYRot(), getXRot()); - if (this.entityData.get(HEALTH) <= 0) { - destroy(); - } - this.refreshDimensions(); + } + + @Override + public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) { + serverYRot = yaw; + serverXRot = pitch; + this.interpolationSteps = 10; + } + + @Override + public void travel() { + float diffY; + float diffX; + + diffY = (float) Mth.wrapDegrees(entityData.get(YAW) - this.getYRot()); + diffX = (float) Mth.wrapDegrees(entityData.get(PITCH) - this.getXRot()); + + this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -20f, 20f)); + this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(0.5f * diffX, -20f, 20f), -89, -20)); } private PlayState movementPredicate(AnimationState event) { @@ -282,7 +266,8 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mortar.idle")); } - protected void destroy() { + @Override + public void destroy() { if (this.level() instanceof ServerLevel level) { var x = this.getX(); var y = this.getY(); @@ -295,6 +280,11 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { } } + @Override + public float getMaxHealth() { + return 100; + } + public String getSyncedAnimation() { return null; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java index 655fc2389..e31874527 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java @@ -256,8 +256,30 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, if (passenger instanceof ServerPlayer serverPlayer && this.entityData.get(COOL_DOWN) == 20) { SoundTool.playLocalSound(serverPlayer, ModSounds.ANNIHILATOR_RELOAD.get(), 1, 1); } + } - this.refreshDimensions(); + @Override + public void handleClientSync() { + if (isControlledByLocalInstance()) { + interpolationSteps = 0; + syncPacketPositionCodec(getX(), getY(), getZ()); + } + if (interpolationSteps <= 0) { + return; + } + + double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot()); + setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps); + setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps); + setRot(getYRot(), getXRot()); + + } + + @Override + public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) { + serverYRot = yaw; + serverXRot = pitch; + this.interpolationSteps = 10; } private float laserLength(Vec3 pos, Entity cannon) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java index eaaddedb7..73dc6beac 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java @@ -249,7 +249,30 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity, this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0)); } autoAim(); - this.refreshDimensions(); + } + + @Override + public void handleClientSync() { + if (isControlledByLocalInstance()) { + interpolationSteps = 0; + syncPacketPositionCodec(getX(), getY(), getZ()); + } + if (interpolationSteps <= 0) { + return; + } + + double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot()); + setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps); + setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps); + setRot(getYRot(), getXRot()); + + } + + @Override + public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) { + serverYRot = yaw; + serverXRot = pitch; + this.interpolationSteps = 10; } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java index 720d1fc27..ca051105a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -1,7 +1,6 @@ package com.atsuishio.superbwarfare.entity.vehicle; import com.atsuishio.superbwarfare.ModUtils; -import com.atsuishio.superbwarfare.client.gui.RangeHelper; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity; @@ -12,8 +11,6 @@ import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.SoundTool; -import net.minecraft.commands.arguments.EntityAnchorArgument; -import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; @@ -191,8 +188,30 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntit } lowHealthWarning(); + } - this.refreshDimensions(); + @Override + public void handleClientSync() { + if (isControlledByLocalInstance()) { + interpolationSteps = 0; + syncPacketPositionCodec(getX(), getY(), getZ()); + } + if (interpolationSteps <= 0) { + return; + } + + double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot()); + setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps); + setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps); + setRot(getYRot(), getXRot()); + + } + + @Override + public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) { + serverYRot = yaw; + serverXRot = pitch; + this.interpolationSteps = 10; } @Override @@ -332,50 +351,14 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntit float diffX = 0; if (passenger instanceof Player player) { - if (player.getOffhandItem().getItem() == ModItems.FIRING_PARAMETERS.get()) { - if (setTarget(player.getOffhandItem())) { - diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(entityData.get(YAW) - this.getYRot())); - diffX = Mth.wrapDegrees(entityData.get(PITCH) - this.getXRot()); - this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -1.75f, 1.75f)); - this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(0.95f * diffX, -5, 5), -85, 15)); - } - } else { - diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot())); - diffX = passenger.getXRot() - 1.3f - this.getXRot(); - diffX = diffX * 0.15f; - this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -1.75f, 1.75f)); - this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -3f, 3f), -85, 16.3f)); - } + diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot())); + diffX = passenger.getXRot() - 1.3f - this.getXRot(); + diffX = diffX * 0.15f; + this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -1.75f, 1.75f)); + this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -3f, 3f), -85, 16.3f)); } } - public boolean setTarget(ItemStack stack) { - int targetX = stack.getOrCreateTag().getInt("TargetX"); - int targetY = stack.getOrCreateTag().getInt("TargetY"); - int targetZ = stack.getOrCreateTag().getInt("TargetZ"); - - this.look(EntityAnchorArgument.Anchor.EYES, new Vec3(targetX, targetY, targetZ)); - - double[] angles = new double[2]; - boolean flag = RangeHelper.canReachTarget(15, 0.05, 0.99, - new BlockPos((int) this.getX(), (int) this.getEyeY(), (int) this.getZ()), - new BlockPos(targetX, targetY, targetZ), - angles); - - if (flag) { - this.entityData.set(PITCH, -(float) angles[1]); - } - - return flag; - } - - private void look(EntityAnchorArgument.Anchor pAnchor, Vec3 pTarget) { - Vec3 vec3 = pAnchor.apply(this); - double d0 = (pTarget.x - vec3.x) * 0.2; - double d2 = (pTarget.z - vec3.z) * 0.2; - this.entityData.set(YAW, Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F)); - } - protected void clampRotation(Entity entity) { float f = Mth.wrapDegrees(entity.getXRot()); float f1 = Mth.clamp(f, -85.0F, 16.3F); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java index 428e5f538..fe841207e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -198,8 +198,30 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, ICannonEn } lowHealthWarning(); + } - this.refreshDimensions(); + @Override + public void handleClientSync() { + if (isControlledByLocalInstance()) { + interpolationSteps = 0; + syncPacketPositionCodec(getX(), getY(), getZ()); + } + if (interpolationSteps <= 0) { + return; + } + + double interpolatedYaw = Mth.wrapDegrees(serverYRot - (double) getYRot()); + setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps); + setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps); + setRot(getYRot(), getXRot()); + + } + + @Override + public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) { + serverYRot = yaw; + serverXRot = pitch; + this.interpolationSteps = 10; } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java index 461db706f..587c6dc0b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java @@ -378,7 +378,7 @@ public class VehicleEntity extends Entity { return transform.transform(new Vector4f(x, y, z, 1)); } - protected void handleClientSync() { + public void handleClientSync() { if (isControlledByLocalInstance()) { interpolationSteps = 0; syncPacketPositionCodec(getX(), getY(), getZ()); diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/AdjustMortarAngleMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/AdjustMortarAngleMessage.java index 0d2443138..1b2994cfc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/AdjustMortarAngleMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/AdjustMortarAngleMessage.java @@ -1,13 +1,10 @@ package com.atsuishio.superbwarfare.network.message; -import com.atsuishio.superbwarfare.client.gui.RangeHelper; import com.atsuishio.superbwarfare.entity.MortarEntity; import com.atsuishio.superbwarfare.init.ModSounds; -import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.SoundTool; import com.atsuishio.superbwarfare.tools.TraceTool; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; @@ -15,6 +12,8 @@ import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; +import static com.atsuishio.superbwarfare.entity.MortarEntity.PITCH; + public class AdjustMortarAngleMessage { private final double scroll; @@ -41,16 +40,10 @@ public class AdjustMortarAngleMessage { Entity looking = TraceTool.findLookingEntity(player, 6); if (looking == null) return; - double angle = 0; - if (looking instanceof MortarEntity mortar) { - mortar.getEntityData().set(MortarEntity.PITCH, (float) Mth.clamp(mortar.getEntityData().get(MortarEntity.PITCH) + 0.5 * message.scroll, 20, 89)); - angle = mortar.getEntityData().get(MortarEntity.PITCH); + mortar.getEntityData().set(PITCH, (float) Mth.clamp(mortar.getEntityData().get(PITCH) + 0.5 * message.scroll, -89, -20)); } - player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.angle", - FormatTool.format2D(angle), - FormatTool.format1D((int) RangeHelper.getRange(angle)), "m"), true); SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f); }); context.get().setPacketHandled(true); diff --git a/src/main/resources/assets/superbwarfare/lang/en_us.json b/src/main/resources/assets/superbwarfare/lang/en_us.json index b198ccc5b..b10aa1043 100644 --- a/src/main/resources/assets/superbwarfare/lang/en_us.json +++ b/src/main/resources/assets/superbwarfare/lang/en_us.json @@ -464,7 +464,7 @@ "tips.superbwarfare.annihilator.energy_not_enough": "Energy is Not Enough", "tips.superbwarfare.target.down": "Target Down %1$s", "tips.superbwarfare.target.damage": "Damage: %1$s Distance: %2$s", - "tips.superbwarfare.mortar.angle": "Angle: %1$s Range: %2$s", + "tips.superbwarfare.mortar.range": "Range: ", "tips.superbwarfare.mortar.yaw": "Yaw:", "tips.superbwarfare.mortar.pitch": "Pitch:", "tips.superbwarfare.mortar.target_pos": "Target Position:", diff --git a/src/main/resources/assets/superbwarfare/lang/zh_cn.json b/src/main/resources/assets/superbwarfare/lang/zh_cn.json index 8ea8f885b..eea17bdc6 100644 --- a/src/main/resources/assets/superbwarfare/lang/zh_cn.json +++ b/src/main/resources/assets/superbwarfare/lang/zh_cn.json @@ -462,7 +462,7 @@ "tips.superbwarfare.annihilator.energy_not_enough": "能量不足", "tips.superbwarfare.target.down": "目标倒下 %1$s", "tips.superbwarfare.target.damage": "伤害:%1$s 距离:%2$s", - "tips.superbwarfare.mortar.angle": "角度:%1$s 射程:%2$s", + "tips.superbwarfare.mortar.range": "射程:", "tips.superbwarfare.mortar.yaw": "水平朝向:", "tips.superbwarfare.mortar.pitch": "俯仰角度:", "tips.superbwarfare.mortar.target_pos": "目标坐标:",