优化数字格式化写法

This commit is contained in:
Light_Quanta 2025-01-30 13:02:36 +08:00
parent cba1cf967c
commit 4e525cb506
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
16 changed files with 36 additions and 36 deletions

View file

@ -98,7 +98,7 @@ public class CannonHudOverlay {
}
if (lookAtEntity) {
event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.drone.range")
.append(Component.literal(new DecimalFormat("##.#").format(entityRange) + "M " + lookingEntity.getDisplayName().getString())),
.append(Component.literal(new DecimalFormat("##.#M ").format(entityRange) + lookingEntity.getDisplayName().getString())),
w / 2 + 14, h / 2 - 20, -1, false);
} else {
if (blockRange > 511) {
@ -106,7 +106,7 @@ public class CannonHudOverlay {
.append(Component.literal("---M")), w / 2 + 14, h / 2 - 20, -1, false);
} else {
event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.drone.range")
.append(Component.literal(new DecimalFormat("##.#").format(blockRange) + "M")),
.append(Component.literal(new DecimalFormat("##.#M").format(blockRange))),
w / 2 + 14, h / 2 - 20, -1, false);
}
}

View file

@ -70,7 +70,7 @@ public class DroneUIOverlay {
guiGraphics.blit(ModUtils.loc("textures/screens/drone_fov.png"), w / 2 + 100, h / 2 - 64, 0, 0, 64, 129, 64, 129);
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/drone_fov_move.png"), (float) w / 2 + 100, (float) (h / 2 - 64 - ((ClientEventHandler.droneFovLerp - 1) * 23.8)), 0, 0, 64, 129, 64, 129);
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##.#").format(ClientEventHandler.droneFovLerp) + "x"),
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##.#x").format(ClientEventHandler.droneFovLerp)),
w / 2 + 144, h / 2 + 56 - (int) ((ClientEventHandler.droneFovLerp - 1) * 23.8), -1, false);
DroneEntity entity = EntityFindUtil.findDrone(player.level(), stack.getOrCreateTag().getString("LinkedDrone"));
@ -101,7 +101,7 @@ public class DroneUIOverlay {
// 距离
guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.distance")
.append(Component.literal(new DecimalFormat("##.#").format(distance) + "M")),
.append(Component.literal(new DecimalFormat("##.#M").format(distance))),
w / 2 + 10, h / 2 + 33, color, false);
// 血量
@ -111,7 +111,7 @@ public class DroneUIOverlay {
if (entity.getEntityData().get(KAMIKAZE_MODE) == 0) {
// 弹药
guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.ammo")
.append(Component.literal(new DecimalFormat("##.#").format(entity.getEntityData().get(AMMO)) + " / 6")),
.append(Component.literal(new DecimalFormat("##.# / 6").format(entity.getEntityData().get(AMMO)))),
w / 2 + 12, h / 2 - 37, -1, false);
} else {
// 神风
@ -122,7 +122,7 @@ public class DroneUIOverlay {
if (lookAtEntity) {
// 实体距离
guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.range")
.append(Component.literal(new DecimalFormat("##.#").format(entityRange) + "M " + lookingEntity.getDisplayName().getString())),
.append(Component.literal(new DecimalFormat("##.#M ").format(entityRange) + lookingEntity.getDisplayName().getString())),
w / 2 + 12, h / 2 - 28, color, false);
} else {
// 方块距离
@ -131,7 +131,7 @@ public class DroneUIOverlay {
.append(Component.literal("---M")), w / 2 + 12, h / 2 - 28, color, false);
} else {
guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.range")
.append(Component.literal(new DecimalFormat("##.#").format(blockRange) + "M")),
.append(Component.literal(new DecimalFormat("##.#M").format(blockRange))),
w / 2 + 12, h / 2 - 28, color, false);
}
}

View file

@ -107,12 +107,12 @@ public class HelicopterHudOverlay {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/helicopter/heli_power.png"), (float) w / 2 + 130f, ((float) h / 2 - 64 + 124 - power * 980), 0, 0, 4, power * 980, 4, power * 980);
lerpVy = (float) Mth.lerp(0.021f * event.getPartialTick(), lerpVy, mobileVehicle.getDeltaMovement().y());
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/helicopter/heli_vy_move.png"), (float) w / 2 + 138, ((float) h / 2 - 3 - Math.max(lerpVy * 20, -24) * 2.5f), 0, 0, 8, 8, 8, 8);
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(lerpVy * 20) + "m/s"),
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##m/s").format(lerpVy * 20) ),
w / 2 + 146, (int) (h / 2 - 3 - Math.max(lerpVy * 20, -24) * 2.5), (lerpVy * 20 < -24 || ((lerpVy * 20 < -10 || (lerpVy * 20 < -1 && length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y, mobileVehicle.getDeltaMovement().z) * 72 > 100)) && height < 36) || (length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y, mobileVehicle.getDeltaMovement().z) * 72 > 40 && blockInWay < 72) ? -65536 : 0x66FF00), false);
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(mobileVehicle.getY())),
w / 2 + 104, h / 2, 0x66FF00, false);
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/helicopter/speed_frame.png"), (float) w / 2 - 144, (float) h / 2 - 6, 0, 0, 50, 18, 50, 18);
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y, mobileVehicle.getDeltaMovement().z) * 72) + "KM/H"),
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##KM/H").format(length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y, mobileVehicle.getDeltaMovement().z) * 72)),
w / 2 - 140, h / 2, 0x66FF00, false);
if (mobileVehicle instanceof Ah6Entity ah6Entity) {

View file

@ -28,10 +28,10 @@ public class MortarInfoOverlay {
}
if (lookingEntity instanceof MortarEntity mortar) {
event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.mortar.yaw")
.append(Component.literal(new DecimalFormat("##.#").format(mortar.getEntityData().get(MortarEntity.Y_ROT)) + "°")),
.append(Component.literal(new DecimalFormat("##.#°").format(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(new DecimalFormat("##.#").format(mortar.getEntityData().get(MortarEntity.PITCH)) + "°")),
.append(Component.literal(new DecimalFormat("##.#°").format(mortar.getEntityData().get(MortarEntity.PITCH)))),
w / 2 + 12, h / 2 - 28, -1, false);
}
}

View file

@ -40,7 +40,7 @@ public class SpyglassRangeOverlay {
if (lookAtEntity) {
event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.drone.range")
.append(Component.literal(new DecimalFormat("##.#").format(entityRange) + "M " + lookingEntity.getDisplayName().getString())),
.append(Component.literal(new DecimalFormat("##.#M ").format(entityRange) + lookingEntity.getDisplayName().getString())),
w / 2 + 12, h / 2 - 28, -1, false);
} else {
if (blockRange > 512) {
@ -48,7 +48,7 @@ public class SpyglassRangeOverlay {
.append(Component.literal("---M")), w / 2 + 12, h / 2 - 28, -1, false);
} else {
event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.drone.range")
.append(Component.literal(new DecimalFormat("##.#").format(blockRange) + "M")),
.append(Component.literal(new DecimalFormat("##.#M").format(blockRange))),
w / 2 + 12, h / 2 - 28, -1, false);
}
}

View file

@ -174,7 +174,7 @@ public class VehicleHudOverlay {
return 9;
}
public static void renderLandArmorHud(RenderGuiEvent.Pre event ,int w, int h) {
public static void renderLandArmorHud(RenderGuiEvent.Pre event, int w, int h) {
Minecraft mc = Minecraft.getInstance();
Player player = mc.player;
GuiGraphics guiGraphics = event.getGuiGraphics();
@ -230,13 +230,13 @@ public class VehicleHudOverlay {
//炮塔方向
poseStack.pushPose();
poseStack.rotateAround(Axis.ZP.rotationDegrees(Mth.lerp(event.getPartialTick(), iLand.turretYRotO(), iLand.turretYRot())),w / 2 + 112, h - 56, 0);
poseStack.rotateAround(Axis.ZP.rotationDegrees(Mth.lerp(event.getPartialTick(), iLand.turretYRotO(), iLand.turretYRot())), w / 2 + 112, h - 56, 0);
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/body.png"), w / 2 + 96, h - 72, 0, 0.0F, 32, 32, 32, 32);
poseStack.popPose();
//时速
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##").format(mobileVehicle.getDeltaMovement().length() * 72) + " KM/H"),
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("## KM/H").format(mobileVehicle.getDeltaMovement().length() * 72)),
w / 2 + 160, h / 2 - 48, 0x66FF00, false);
//低电量警告
@ -265,13 +265,13 @@ public class VehicleHudOverlay {
}
if (lookAtEntity) {
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##").format(entityRange)),
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##.#M").format(entityRange)),
w / 2 - 6, h - 53, 0x66FF00, false);
} else {
if (blockRange > 512) {
guiGraphics.drawString(mc.font, Component.literal("---"), w / 2 - 6, h - 53, 0x66FF00, false);
} else {
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##").format(blockRange)),
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##.#M").format(blockRange)),
w / 2 - 6, h - 53, 0x66FF00, false);
}
}

View file

@ -49,11 +49,11 @@ public class VehicleTeamOverlay {
Component.literal(player1.getDisplayName().getString() + (player1.getTeam() == null ? "" : " <" + (player1.getTeam().getName()) + ">")),
w / 2 + 90, h / 2 - 4, player1.getTeamColor(), false);
event.getGuiGraphics().drawString(Minecraft.getInstance().font,
Component.literal(lookingEntity.getDisplayName().getString() + " " + new DecimalFormat("##.#").format(entityRange) + "M"),
Component.literal(lookingEntity.getDisplayName().getString() + new DecimalFormat(" ##.#M").format(entityRange)),
w / 2 + 90, h / 2 + 5, player1.getTeamColor(), false);
} else {
event.getGuiGraphics().drawString(Minecraft.getInstance().font,
Component.literal(lookingEntity.getDisplayName().getString() + " " + new DecimalFormat("##.#").format(entityRange) + "M"),
Component.literal(lookingEntity.getDisplayName().getString() + new DecimalFormat(" ##.#M").format(entityRange)),
w / 2 + 90, h / 2 + 5, -1, false);
}
poseStack.popPose();

View file

@ -180,7 +180,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
return Component.translatable("des.superbwarfare.guns.bypass").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(new DecimalFormat("##.##").format(bypassRate * 100) + "%").withStyle(ChatFormatting.GOLD));
.append(Component.literal(new DecimalFormat("##.##%").format(bypassRate * 100)).withStyle(ChatFormatting.GOLD));
}
/**
@ -190,7 +190,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
double headshot = GunsTool.getGunDoubleTag(stack, "Headshot", 0);
return Component.translatable("des.superbwarfare.guns.headshot").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(new DecimalFormat("##.#").format(headshot) + "x").withStyle(ChatFormatting.AQUA));
.append(Component.literal(new DecimalFormat("##.#x").format(headshot)).withStyle(ChatFormatting.AQUA));
}
/**

View file

@ -129,7 +129,7 @@ public class TargetEntity extends LivingEntity implements GeoEntity, AnimatedEnt
if (sourceEntity instanceof Player player) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.target.down",
new java.text.DecimalFormat("##.#").format((entity.position()).distanceTo((sourceEntity.position()))) + "M"), true);
new java.text.DecimalFormat("##.#M").format((entity.position()).distanceTo((sourceEntity.position())))), true);
SoundTool.playLocalSound(player, ModSounds.TARGET_DOWN.get(), 1, 1);
targetEntity.entityData.set(DOWN_TIME, 40);
}

View file

@ -411,7 +411,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
player.displayClientMessage(Component.literal(String.valueOf(score))
.append(Component.translatable("tips.superbwarfare.shoot.rings"))
.append(Component.literal(" " + new DecimalFormat("##.#").format(distance) + "m")), false);
.append(Component.literal(" " + new DecimalFormat("##.#m").format(distance) )), false);
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer serverPlayer) {
var holder = score == 10 ? Holder.direct(ModSounds.HEADSHOT.get()) : Holder.direct(ModSounds.INDICATION.get());

View file

@ -237,7 +237,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
}
if (this.level() instanceof ServerLevel) {
if (this.getFirstPassenger() instanceof Player player) {
if (this.getFirstPassenger() instanceof Player) {
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).mapToInt(ItemStack::getCount).sum() > 0 && this.getEntityData().get(LOADED_COAX_AMMO) < 500)) {
this.entityData.set(LOADED_COAX_AMMO, this.getEntityData().get(LOADED_COAX_AMMO) + 30);
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).findFirst().ifPresent(stack -> stack.shrink(1));

View file

@ -63,7 +63,7 @@ public class LivingEventHandler {
|| event.getSource().is(ModDamageTypes.CUSTOM_EXPLOSION)
|| event.getSource().is(ModDamageTypes.MINE)
|| event.getSource().is(ModDamageTypes.PROJECTILE_BOOM))) {
vehicle.hurt(event.getSource(),event.getAmount());
vehicle.hurt(event.getSource(), event.getAmount());
}
event.setCanceled(true);
}
@ -105,7 +105,7 @@ public class LivingEventHandler {
var vehicle = event.getEntity().getVehicle();
if (vehicle instanceof VehicleEntity) {
if (vehicle instanceof IArmedVehicleEntity iArmedVehicle) {
if (iArmedVehicle.hidePassenger()){
if (iArmedVehicle.hidePassenger()) {
if (!event.getSource().is(ModDamageTypes.VEHICLE_EXPLOSION)) {
event.setCanceled(true);
}
@ -115,7 +115,7 @@ public class LivingEventHandler {
|| event.getSource().is(ModDamageTypes.CUSTOM_EXPLOSION)
|| event.getSource().is(ModDamageTypes.MINE)
|| event.getSource().is(ModDamageTypes.PROJECTILE_BOOM))) {
vehicle.hurt(event.getSource(),0.7f * event.getAmount());
vehicle.hurt(event.getSource(), 0.7f * event.getAmount());
}
event.setAmount(0.3f * event.getAmount());
@ -190,7 +190,7 @@ public class LivingEventHandler {
if (entity instanceof TargetEntity && sourceEntity instanceof Player player) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.target.damage",
new DecimalFormat("##.##").format(damage),
new DecimalFormat("##.#").format(entity.position().distanceTo(sourceEntity.position())) + "m"), false);
new DecimalFormat("##.#m").format(entity.position().distanceTo(sourceEntity.position()))), false);
}
}

View file

@ -128,7 +128,7 @@ public class Monitor extends Item {
Vec3 droneVec = new Vec3(stack.getOrCreateTag().getDouble("PosX"), stack.getOrCreateTag().getDouble("PosY"), stack.getOrCreateTag().getDouble("PosZ"));
list.add(Component.translatable("des.superbwarfare.monitor", new DecimalFormat("##.#").format(player.position().distanceTo(droneVec)) + "m").withStyle(ChatFormatting.GRAY));
list.add(Component.translatable("des.superbwarfare.monitor", new DecimalFormat("##.#m").format(player.position().distanceTo(droneVec))).withStyle(ChatFormatting.GRAY));
list.add(Component.literal("X: " + new DecimalFormat("##.#").format(droneVec.x) +
" Y: " + new DecimalFormat("##.#").format(droneVec.y) +
" Z: " + new DecimalFormat("##.#").format(droneVec.z)

View file

@ -42,7 +42,7 @@ public class Transcript extends Item {
tooltip.add(Component.translatable("des.superbwarfare.transcript.score").withStyle(ChatFormatting.GRAY)
.append(Component.literal(score + " ").withStyle(score == 10 ? ChatFormatting.GOLD : ChatFormatting.WHITE))
.append(Component.translatable("des.superbwarfare.transcript.distance").withStyle(ChatFormatting.GRAY))
.append(Component.literal(new DecimalFormat("##.#").format(tag.getDouble("Distance")) + "m").withStyle(ChatFormatting.WHITE)));
.append(Component.literal(new DecimalFormat("##.#m").format(tag.getDouble("Distance"))).withStyle(ChatFormatting.WHITE)));
}
tooltip.add(Component.translatable("des.superbwarfare.transcript.total").withStyle(ChatFormatting.YELLOW)

View file

@ -51,8 +51,8 @@ public class AdjustMortarAngleMessage {
}
player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.angle",
new DecimalFormat("##.##").format(angle) + "°",
new DecimalFormat("##.#").format((int) RangeHelper.getRange(angle)) + "m"), true);
new DecimalFormat("##.##°").format(angle),
new DecimalFormat("##.#m").format((int) RangeHelper.getRange(angle))), true);
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
});
context.get().setPacketHandled(true);

View file

@ -59,7 +59,7 @@ public class AdjustZoomFovMessage {
if (GunsTool.getGunIntTag(stack, "RPM", 0) == 1095) {
GunsTool.setGunIntTag(stack, "RPM", 1100);
}
player.displayClientMessage(Component.literal("RPM: " + new DecimalFormat("##").format(GunsTool.getGunIntTag(stack, "RPM", 0))), true);
player.displayClientMessage(Component.literal(new DecimalFormat("RPM: ##").format(GunsTool.getGunIntTag(stack, "RPM", 0))), true);
int rpm = GunsTool.getGunIntTag(stack, "RPM", 0);
if (rpm > minRpm && rpm < maxRpm) {
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);