From 2f926cadda37f0cf522292f24c47ef653349849f Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Mon, 3 Feb 2025 23:24:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96format#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/overlay/CannonHudOverlay.java | 16 +++---- .../client/overlay/DroneUIOverlay.java | 16 +++---- .../client/overlay/VehicleHudOverlay.java | 45 ++++++++----------- .../client/overlay/VehicleTeamOverlay.java | 12 ++--- .../client/screens/FuMO25Screen.java | 10 ++--- .../tooltip/ClientBocekImageTooltip.java | 11 +++-- .../client/tooltip/ClientGunImageTooltip.java | 15 +++---- .../tooltip/ClientLauncherImageTooltip.java | 7 ++- .../ClientSecondaryCataclysmImageTooltip.java | 7 ++- .../tooltip/ClientSentinelImageTooltip.java | 10 ++--- .../tooltip/ClientShotgunImageTooltip.java | 9 ++-- .../superbwarfare/entity/TargetEntity.java | 3 +- .../entity/projectile/ProjectileEntity.java | 8 +--- .../event/LivingEventHandler.java | 6 +-- .../atsuishio/superbwarfare/item/Monitor.java | 11 ++--- .../superbwarfare/item/Transcript.java | 5 ++- .../item/common/ammo/AmmoBox.java | 10 ++--- .../message/AdjustMortarAngleMessage.java | 12 +++-- .../superbwarfare/tools/FormatTool.java | 3 ++ 19 files changed, 96 insertions(+), 120 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/CannonHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/CannonHudOverlay.java index 8f8c48fbd..465c2fe5a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/CannonHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/CannonHudOverlay.java @@ -4,11 +4,11 @@ import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.entity.vehicle.AnnihilatorEntity; import com.atsuishio.superbwarfare.entity.vehicle.ICannonEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.TraceTool; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.GameRenderer; @@ -26,8 +26,6 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import org.joml.Math; -import java.text.DecimalFormat; - import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; import static com.atsuishio.superbwarfare.client.overlay.VehicleHudOverlay.renderKillIndicator; @@ -40,8 +38,6 @@ public class CannonHudOverlay { int h = event.getWindow().getGuiScaledHeight(); Minecraft mc = Minecraft.getInstance(); Player player = mc.player; - Camera camera = mc.gameRenderer.getMainCamera(); - Vec3 cameraPos = camera.getPosition(); GuiGraphics guiGraphics = event.getGuiGraphics(); PoseStack poseStack = guiGraphics.pose(); @@ -61,13 +57,13 @@ public class CannonHudOverlay { preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/compass_white.png"), (float) w / 2 - 128, (float) 10, 128 + ((float) 64 / 45 * (Mth.lerp(event.getPartialTick(), cannon.yRotO, cannon.getYRot()))), 0, 256, 16, 512, 16); preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/roll_ind_white.png"), w / 2 - 4, 27, 0, 0.0F, 8, 8, 8, 8); - String angle = new DecimalFormat("#0.0").format(Mth.lerp(event.getPartialTick(), cannon.yRotO, cannon.getYRot())); + String angle = FormatTool.DECIMAL_FORMAT_1ZZ.format(Mth.lerp(event.getPartialTick(), cannon.yRotO, cannon.getYRot())); int width = Minecraft.getInstance().font.width(angle); event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.literal(angle), w / 2 - width / 2, 40, -1, false); preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/cannon/cannon_pitch.png"), w / 2 + 166, h / 2 - 64, 0, 0.0F, 8, 128, 8, 128); - String pitch = new DecimalFormat("#0.0").format(-Mth.lerp(event.getPartialTick(), cannon.xRotO, cannon.getXRot())); + String pitch = FormatTool.DECIMAL_FORMAT_1ZZ.format(-Mth.lerp(event.getPartialTick(), cannon.xRotO, cannon.getXRot())); int widthP = Minecraft.getInstance().font.width(pitch); poseStack.pushPose(); @@ -99,15 +95,15 @@ public class CannonHudOverlay { } if (lookAtEntity) { event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.drone.range") - .append(Component.literal(new DecimalFormat("##.#M ").format(entityRange) + lookingEntity.getDisplayName().getString())), + .append(Component.literal(FormatTool.format1D(entityRange, "m ") + lookingEntity.getDisplayName().getString())), w / 2 + 14, h / 2 - 20, -1, false); } else { if (blockRange > 511) { event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.translatable("tips.superbwarfare.drone.range") - .append(Component.literal("---M")), w / 2 + 14, h / 2 - 20, -1, false); + .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("##.#M").format(blockRange))), + .append(Component.literal(FormatTool.format1D(blockRange, "m"))), w / 2 + 14, h / 2 - 20, -1, false); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneUIOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneUIOverlay.java index 9f18a6346..3f189a0a5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneUIOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneUIOverlay.java @@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.tools.EntityFindUtil; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.SeekTool; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; @@ -27,7 +28,6 @@ import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import java.text.DecimalFormat; import java.util.List; import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; @@ -69,7 +69,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("##.#x").format(ClientEventHandler.droneFovLerp)), + guiGraphics.drawString(mc.font, Component.literal(FormatTool.format1D(ClientEventHandler.droneFovLerp, "x")), w / 2 + 144, h / 2 + 56 - (int) ((ClientEventHandler.droneFovLerp - 1) * 23.8), -1, false); DroneEntity entity = EntityFindUtil.findDrone(player.level(), stack.getOrCreateTag().getString("LinkedDrone")); @@ -100,17 +100,17 @@ public class DroneUIOverlay { // 距离 guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.distance") - .append(Component.literal(new DecimalFormat("##.#M").format(distance))), + .append(Component.literal(FormatTool.format1D(distance, "m"))), w / 2 + 10, h / 2 + 33, color, false); // 血量 guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.health") - .append(Component.literal(new DecimalFormat("##.#").format(entity.getHealth()) + "/" + new DecimalFormat("##.#").format(entity.getMaxHealth()))), + .append(Component.literal(FormatTool.format1D(entity.getHealth()) + " / " + FormatTool.format1D(entity.getMaxHealth()))), w / 2 - 77, h / 2 + 33, -1, false); if (entity.getEntityData().get(KAMIKAZE_MODE) == 0) { // 弹药 guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.ammo") - .append(Component.literal(new DecimalFormat("##.# / 6").format(entity.getEntityData().get(AMMO)))), + .append(Component.literal(FormatTool.format1D(entity.getEntityData().get(AMMO), " / 6"))), w / 2 + 12, h / 2 - 37, -1, false); } else { // 神风 @@ -121,16 +121,16 @@ public class DroneUIOverlay { if (lookAtEntity) { // 实体距离 guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.range") - .append(Component.literal(new DecimalFormat("##.#M ").format(entityRange) + lookingEntity.getDisplayName().getString())), + .append(Component.literal(FormatTool.format1D(entityRange, "m ") + lookingEntity.getDisplayName().getString())), w / 2 + 12, h / 2 - 28, color, false); } else { // 方块距离 if (blockRange > 512) { guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.range") - .append(Component.literal("---M")), w / 2 + 12, h / 2 - 28, color, false); + .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("##.#M").format(blockRange))), + .append(Component.literal(FormatTool.format1D(blockRange, "m"))), w / 2 + 12, h / 2 - 28, color, false); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java index 0a09e833c..09296f0d8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java @@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.config.client.DisplayConfig; import com.atsuishio.superbwarfare.entity.vehicle.*; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.SeekTool; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; @@ -32,8 +33,6 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import org.joml.Math; -import java.text.DecimalFormat; - import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; import static com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay.*; import static com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity.WEAPON_TYPE; @@ -42,6 +41,7 @@ import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.HEAT; @Mod.EventBusSubscriber(value = Dist.CLIENT) public class VehicleHudOverlay { + private static float scopeScale = 1; private static final ResourceLocation FRAME = ModUtils.loc("textures/screens/land/tv_frame.png"); private static final ResourceLocation ARMOR = ModUtils.loc("textures/screens/armor.png"); @@ -129,7 +129,6 @@ public class VehicleHudOverlay { ItemStack stack = player.getMainHandItem(); // 渲染弹药类型 - event.getGuiGraphics().drawString( Minecraft.getInstance().font, getVehicleAmmoType(stack, iVehicle), @@ -138,7 +137,6 @@ public class VehicleHudOverlay { 0xFFFFFF, true ); - } } @@ -214,8 +212,7 @@ public class VehicleHudOverlay { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2 - 64, h - 56, 0, 0.0F, 128, 1, 128, 1); preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2 + 112, h - 71, 0, 0.0F, 1, 16, 1, 16); - //不同武器种类的准星 - + // 不同武器种类的准星 if (multiWeaponVehicle.getWeaponType() == 0) { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_cannon_cross.png"), k, l, 0, 0.0F, i, j, i, j); } else if (multiWeaponVehicle.getWeaponType() == 1) { @@ -224,24 +221,21 @@ public class VehicleHudOverlay { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_missile_cross.png"), k, l, 0, 0.0F, i, j, i, j); } - //指南针 - + // 指南针 preciseBlit(guiGraphics, ModUtils.loc("textures/screens/compass.png"), (float) w / 2 - 128, (float) 10, 128 + ((float) 64 / 45 * player.getYRot()), 0, 256, 16, 512, 16); preciseBlit(guiGraphics, ModUtils.loc("textures/screens/helicopter/roll_ind.png"), w / 2 - 8, 30, 0, 0.0F, 16, 16, 16, 16); - //炮塔方向 - + // 炮塔方向 poseStack.pushPose(); 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("## KM/H").format(mobileVehicle.getDeltaMovement().length() * 72)), + // 时速 + guiGraphics.drawString(mc.font, Component.literal(FormatTool.format0D(mobileVehicle.getDeltaMovement().length() * 72, " km/h")), w / 2 + 160, h / 2 - 48, 0x66FF00, false); - //低电量警告 + // 低电量警告 if (mobileVehicle.getEnergy() < 0.02 * mobileVehicle.getMaxEnergy()) { guiGraphics.drawString(mc.font, Component.literal("NO POWER!"), @@ -251,8 +245,7 @@ public class VehicleHudOverlay { w / 2 - 144, h / 2 + 14, 0xFF6B00, false); } - //测距 - + // 测距 boolean lookAtEntity = false; double blockRange = cameraPos.distanceTo((Vec3.atLowerCornerOf(player.level().clip( new ClipContext(player.getEyePosition(), player.getEyePosition().add(iLand.getBarrelVec(event.getPartialTick()).scale(520)), @@ -267,19 +260,18 @@ public class VehicleHudOverlay { } if (lookAtEntity) { - guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##.#M").format(entityRange)), + guiGraphics.drawString(mc.font, Component.literal(FormatTool.format1D(entityRange, "m")), w / 2 - 6, h - 53, 0x66FF00, false); } else { if (blockRange > 512) { - guiGraphics.drawString(mc.font, Component.literal("---"), w / 2 - 6, h - 53, 0x66FF00, false); + guiGraphics.drawString(mc.font, Component.literal("---m"), w / 2 - 6, h - 53, 0x66FF00, false); } else { - guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##.#M").format(blockRange)), + guiGraphics.drawString(mc.font, Component.literal(FormatTool.format1D(blockRange, "m")), w / 2 - 6, h - 53, 0x66FF00, false); } } - //武器名称 - + // 武器名称 if (player.getVehicle() instanceof Lav150Entity lav) { if (multiWeaponVehicle.getWeaponType() == 0) { double heat = 1 - lav.getEntityData().get(HEAT) / 100.0F; @@ -303,10 +295,9 @@ public class VehicleHudOverlay { } - //血量 - + // 血量 double heal = mobileVehicle.getHealth() / mobileVehicle.getMaxHealth(); - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(100 * heal)), w / 2 - 165, h / 2 - 46, Mth.hsvToRgb((float) heal / 3.745318352059925F, 1.0F, 1.0F), false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(FormatTool.format0D(100 * heal)), w / 2 - 165, h / 2 - 46, Mth.hsvToRgb((float) heal / 3.745318352059925F, 1.0F, 1.0F), false); renderKillIndicator(guiGraphics, w, h); @@ -351,11 +342,11 @@ public class VehicleHudOverlay { double heal = 1 - mobileVehicle.getHealth() / mobileVehicle.getMaxHealth(); - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HP " + new DecimalFormat("##").format(100 * mobileVehicle.getHealth() / mobileVehicle.getMaxHealth())), 30, 1, Mth.hsvToRgb(0F, (float) heal, 1.0F), false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HP " + + FormatTool.format0D(100 * mobileVehicle.getHealth() / mobileVehicle.getMaxHealth())), 30, 1, Mth.hsvToRgb(0F, (float) heal, 1.0F), false); + poseStack.popPose(); poseStack.popPose(); - - poseStack.popPose(); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleTeamOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleTeamOverlay.java index db7ec67ae..11e40bc08 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleTeamOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleTeamOverlay.java @@ -1,12 +1,11 @@ package com.atsuishio.superbwarfare.client.overlay; -import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.TraceTool; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.api.distmarker.Dist; @@ -15,13 +14,9 @@ import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import java.text.DecimalFormat; - @Mod.EventBusSubscriber(value = Dist.CLIENT) public class VehicleTeamOverlay { - private static final ResourceLocation TRIANGLE = ModUtils.loc("textures/screens/red_triangle.png"); - @SubscribeEvent(priority = EventPriority.NORMAL) public static void eventHandler(RenderGuiEvent.Pre event) { int w = event.getWindow().getGuiScaledWidth(); @@ -41,7 +36,6 @@ public class VehicleTeamOverlay { } if (lookAtEntity) { - poseStack.pushPose(); poseStack.scale(0.8f, 0.8f, 1); if (lookingEntity.getFirstPassenger() instanceof Player player1) { @@ -49,11 +43,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(" ##.#M").format(entityRange)), + Component.literal(lookingEntity.getDisplayName().getString() + FormatTool.format1D(entityRange, "m")), w / 2 + 90, h / 2 + 5, player1.getTeamColor(), false); } else { event.getGuiGraphics().drawString(Minecraft.getInstance().font, - Component.literal(lookingEntity.getDisplayName().getString() + new DecimalFormat(" ##.#M").format(entityRange)), + Component.literal(lookingEntity.getDisplayName().getString() + " " + FormatTool.format1D(entityRange, "M")), w / 2 + 90, h / 2 + 5, -1, false); } poseStack.popPose(); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/screens/FuMO25Screen.java b/src/main/java/com/atsuishio/superbwarfare/client/screens/FuMO25Screen.java index 1b6620dc3..2ca23032a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/screens/FuMO25Screen.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/screens/FuMO25Screen.java @@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.menu.FuMO25Menu; import com.atsuishio.superbwarfare.network.message.RadarChangeModeMessage; import com.atsuishio.superbwarfare.network.message.RadarSetParametersMessage; import com.atsuishio.superbwarfare.network.message.RadarSetPosMessage; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.math.Axis; @@ -25,7 +26,6 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -162,11 +162,11 @@ public class FuMO25Screen extends AbstractContainerScreen { StringBuilder sb = new StringBuilder(); sb.append(currentTarget.getDisplayName().getString()); if (currentTarget instanceof LivingEntity living) { - sb.append(" (HP: ").append(new DecimalFormat("##.#").format(living.getHealth())) - .append("/").append(new DecimalFormat("##.#").format(living.getMaxHealth())).append(")"); + sb.append(" (HP: ").append(FormatTool.format1D(living.getHealth())) + .append("/").append(FormatTool.format1D(living.getMaxHealth())).append(")"); } else if (currentTarget instanceof VehicleEntity vehicle) { - sb.append(" (HP: ").append(new DecimalFormat("##.#").format(vehicle.getHealth())) - .append("/").append(new DecimalFormat("##.#").format(vehicle.getMaxHealth())).append(")"); + sb.append(" (HP: ").append(FormatTool.format1D(vehicle.getHealth())) + .append("/").append(FormatTool.format1D(vehicle.getMaxHealth())).append(")"); } guiGraphics.drawString(this.font, Component.translatable("des.superbwarfare.fumo_25.current_target", sb), diff --git a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientBocekImageTooltip.java b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientBocekImageTooltip.java index 1e4f03100..6fbc6a271 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientBocekImageTooltip.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientBocekImageTooltip.java @@ -5,12 +5,11 @@ import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; -import java.text.DecimalFormat; - public class ClientBocekImageTooltip extends ClientGunImageTooltip { public ClientBocekImageTooltip(GunImageComponent tooltip) { @@ -31,14 +30,14 @@ public class ClientBocekImageTooltip extends ClientGunImageTooltip { if (slug) { return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##.#").format(total) + (TooltipTool.heBullet(stack) ? " + " + new DecimalFormat("##.#") - .format(0.8 * total * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN)); + .append(Component.literal(FormatTool.format1D(total) + (TooltipTool.heBullet(stack) ? " + " + + FormatTool.format1D(0.8 * total * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN)); } else { return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##.#").format(total * 0.1) + " * 10").withStyle(ChatFormatting.GREEN)) + .append(Component.literal(FormatTool.format1D(total * 0.1, " * 10")).withStyle(ChatFormatting.GREEN)) .append(Component.literal(" / ").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##.#").format(total)).withStyle(ChatFormatting.GREEN)); + .append(Component.literal(FormatTool.format1D(total)).withStyle(ChatFormatting.GREEN)); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientGunImageTooltip.java b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientGunImageTooltip.java index 450c0deec..39d0fe275 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientGunImageTooltip.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientGunImageTooltip.java @@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.Font; @@ -20,8 +21,6 @@ import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; -import java.text.DecimalFormat; - public class ClientGunImageTooltip implements ClientTooltipComponent { protected final int width; @@ -93,8 +92,8 @@ public class ClientGunImageTooltip implements ClientTooltipComponent { double damage = GunsTool.getGunDoubleTag(stack, "Damage", 0) * TooltipTool.perkDamage(stack); return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##.#").format(damage) + (TooltipTool.heBullet(stack) ? " + " - + new DecimalFormat("##.#").format(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN)); + .append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? " + " + + FormatTool.format1D(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN)); } /** @@ -104,7 +103,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent { if (this.stack.getItem() instanceof GunItem gunItem && gunItem.autoWeapon(this.stack)) { return Component.translatable("des.superbwarfare.guns.rpm").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##").format(GunsTool.getGunIntTag(stack, "RPM", 0))) + .append(Component.literal(FormatTool.format0D(GunsTool.getGunIntTag(stack, "RPM", 0))) .withStyle(ChatFormatting.GREEN)); } return Component.literal(""); @@ -143,7 +142,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent { .append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal(level + "").withStyle(formatting).withStyle(ChatFormatting.BOLD)) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(" (" + new DecimalFormat("#0.00").format(rate * 100) + "%)").withStyle(ChatFormatting.GRAY)); + .append(Component.literal(" (" + FormatTool.DECIMAL_FORMAT_2ZZZ.format(rate * 100) + "%)").withStyle(ChatFormatting.GRAY)); } /** @@ -180,7 +179,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(FormatTool.format2D(bypassRate * 100, "%")).withStyle(ChatFormatting.GOLD)); } /** @@ -190,7 +189,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("##.#x").format(headshot)).withStyle(ChatFormatting.AQUA)); + .append(Component.literal(FormatTool.format1D(headshot, "x")).withStyle(ChatFormatting.AQUA)); } /** diff --git a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientLauncherImageTooltip.java b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientLauncherImageTooltip.java index a6d330090..db9f6a2e7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientLauncherImageTooltip.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientLauncherImageTooltip.java @@ -2,12 +2,11 @@ package com.atsuishio.superbwarfare.client.tooltip; import com.atsuishio.superbwarfare.client.TooltipTool; import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; -import java.text.DecimalFormat; - public class ClientLauncherImageTooltip extends ClientGunImageTooltip { public ClientLauncherImageTooltip(GunImageComponent tooltip) { @@ -21,8 +20,8 @@ public class ClientLauncherImageTooltip extends ClientGunImageTooltip { return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##.#").format(damage)).withStyle(ChatFormatting.GREEN) + .append(Component.literal(FormatTool.format1D(damage)).withStyle(ChatFormatting.GREEN) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(" + " + new DecimalFormat("##.#").format(explosionDamage)).withStyle(ChatFormatting.GOLD))); + .append(Component.literal(" + " + FormatTool.format1D(explosionDamage)).withStyle(ChatFormatting.GOLD))); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientSecondaryCataclysmImageTooltip.java b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientSecondaryCataclysmImageTooltip.java index 7340fcf81..8aa7e37c7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientSecondaryCataclysmImageTooltip.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientSecondaryCataclysmImageTooltip.java @@ -2,12 +2,11 @@ package com.atsuishio.superbwarfare.client.tooltip; import com.atsuishio.superbwarfare.client.TooltipTool; import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; -import java.text.DecimalFormat; - public class ClientSecondaryCataclysmImageTooltip extends ClientEnergyImageTooltip { public ClientSecondaryCataclysmImageTooltip(GunImageComponent tooltip) { @@ -21,8 +20,8 @@ public class ClientSecondaryCataclysmImageTooltip extends ClientEnergyImageToolt return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##.#").format(damage)).withStyle(ChatFormatting.GREEN) + .append(Component.literal(FormatTool.format1D(damage)).withStyle(ChatFormatting.GREEN) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(" + " + new DecimalFormat("##.#").format(explosionDamage)).withStyle(ChatFormatting.GOLD))); + .append(Component.literal(" + " + FormatTool.format1D(explosionDamage)).withStyle(ChatFormatting.GOLD))); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientSentinelImageTooltip.java b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientSentinelImageTooltip.java index 9ce470968..49ff23a63 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientSentinelImageTooltip.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientSentinelImageTooltip.java @@ -2,12 +2,12 @@ package com.atsuishio.superbwarfare.client.tooltip; import com.atsuishio.superbwarfare.client.TooltipTool; import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraftforge.common.capabilities.ForgeCapabilities; -import java.text.DecimalFormat; import java.util.concurrent.atomic.AtomicBoolean; public class ClientSentinelImageTooltip extends ClientEnergyImageTooltip { @@ -30,15 +30,15 @@ public class ClientSentinelImageTooltip extends ClientEnergyImageTooltip { * TooltipTool.perkDamage(stack); return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##.#").format(damage) + (TooltipTool.heBullet(stack) ? " + " + new DecimalFormat("##.#") - .format(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")) + .append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? " + " + + FormatTool.format1D(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")) .withStyle(ChatFormatting.AQUA).withStyle(ChatFormatting.BOLD)); } else { double damage = GunsTool.getGunDoubleTag(stack, "Damage", 0) * TooltipTool.perkDamage(stack); return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##.#").format(damage) + (TooltipTool.heBullet(stack) ? new DecimalFormat("##.#") - .format(0.4 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN)); + .append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? + FormatTool.format1D(0.4 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN)); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientShotgunImageTooltip.java b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientShotgunImageTooltip.java index 360fcaedd..0e16f1fca 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientShotgunImageTooltip.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientShotgunImageTooltip.java @@ -5,12 +5,11 @@ import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; -import java.text.DecimalFormat; - public class ClientShotgunImageTooltip extends ClientGunImageTooltip { public ClientShotgunImageTooltip(GunImageComponent tooltip) { @@ -30,13 +29,13 @@ public class ClientShotgunImageTooltip extends ClientGunImageTooltip { double damage = GunsTool.getGunDoubleTag(stack, "Damage", 0) * GunsTool.getGunIntTag(stack, "ProjectileAmount", 1) * TooltipTool.perkDamage(stack); return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##.#").format(damage) + (TooltipTool.heBullet(stack) ? " + " + new DecimalFormat("##.#") - .format(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN)); + .append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? " + " + + FormatTool.format1D(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN)); } else { double damage = GunsTool.getGunDoubleTag(stack, "Damage", 0) * TooltipTool.perkDamage(stack); return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##.#").format(damage) + " * " + new DecimalFormat("##").format(GunsTool.getGunIntTag(stack, "ProjectileAmount", 1))).withStyle(ChatFormatting.GREEN)); + .append(Component.literal(FormatTool.format1D(damage) + " * " + FormatTool.format0D(GunsTool.getGunIntTag(stack, "ProjectileAmount", 1))).withStyle(ChatFormatting.GREEN)); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java index 330cf75be..760367cd6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java @@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.network.ModVariables; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.commands.arguments.EntityAnchorArgument; import net.minecraft.core.BlockPos; @@ -129,7 +130,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("##.#M").format((entity.position()).distanceTo((sourceEntity.position())))), true); + FormatTool.format1D((entity.position()).distanceTo((sourceEntity.position()))), "m"), true); SoundTool.playLocalSound(player, ModSounds.TARGET_DOWN.get(), 1, 1); targetEntity.entityData.set(DOWN_TIME, 40); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java index 10f08c39e..66b34a359 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java @@ -9,10 +9,7 @@ import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.Transcript; import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage; import com.atsuishio.superbwarfare.network.message.PlayerGunKillMessage; -import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.ExtendedEntityRayTraceResult; -import com.atsuishio.superbwarfare.tools.HitboxHelper; -import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.atsuishio.superbwarfare.tools.*; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Holder; @@ -60,7 +57,6 @@ import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; import javax.annotation.Nullable; -import java.text.DecimalFormat; import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; @@ -411,7 +407,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("##.#m").format(distance) )), false); + .append(Component.literal(" " + FormatTool.format1D(distance, "m"))), 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()); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java index 33727eba1..64c3191dc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java @@ -20,6 +20,7 @@ import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.tools.DamageTypeTool; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.nbt.CompoundTag; @@ -48,7 +49,6 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.network.PacketDistributor; -import java.text.DecimalFormat; import java.util.Objects; @Mod.EventBusSubscriber @@ -189,8 +189,8 @@ 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("##.#m").format(entity.position().distanceTo(sourceEntity.position()))), false); + FormatTool.format2D(damage), + FormatTool.format1D(entity.position().distanceTo(sourceEntity.position())), "m"), false); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/Monitor.java b/src/main/java/com/atsuishio/superbwarfare/item/Monitor.java index 8bf223882..978dcf4ec 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/Monitor.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/Monitor.java @@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.network.message.ResetCameraTypeMessage; import com.atsuishio.superbwarfare.tools.EntityFindUtil; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.ItemNBTTool; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; @@ -30,7 +31,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.network.PacketDistributor; -import java.text.DecimalFormat; import java.util.List; public class Monitor extends Item { @@ -128,10 +128,11 @@ 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("##.#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) + list.add(Component.translatable("des.superbwarfare.monitor", + FormatTool.format1D(player.position().distanceTo(droneVec)), "m").withStyle(ChatFormatting.GRAY)); + list.add(Component.literal("X: " + FormatTool.format1D(droneVec.x) + + " Y: " + FormatTool.format1D(droneVec.y) + + " Z: " + FormatTool.format1D(droneVec.z) )); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/Transcript.java b/src/main/java/com/atsuishio/superbwarfare/item/Transcript.java index 7c8206e53..1a5cb0fed 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/Transcript.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/Transcript.java @@ -1,5 +1,6 @@ package com.atsuishio.superbwarfare.item; +import com.atsuishio.superbwarfare.tools.FormatTool; import net.minecraft.ChatFormatting; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -14,10 +15,10 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; -import java.text.DecimalFormat; import java.util.List; public class Transcript extends Item { + public static final String TAG_SCORES = "Scores"; public Transcript() { @@ -42,7 +43,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("##.#m").format(tag.getDouble("Distance"))).withStyle(ChatFormatting.WHITE))); + .append(Component.literal(FormatTool.format1D(tag.getDouble("Distance"), "m")).withStyle(ChatFormatting.WHITE))); } tooltip.add(Component.translatable("des.superbwarfare.transcript.total").withStyle(ChatFormatting.YELLOW) diff --git a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/AmmoBox.java b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/AmmoBox.java index add5b8cc9..f626a5df6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/AmmoBox.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/AmmoBox.java @@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.item.common.ammo; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.network.ModVariables; +import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.ItemNBTTool; import net.minecraft.ChatFormatting; import net.minecraft.nbt.CompoundTag; @@ -18,7 +19,6 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; -import java.text.DecimalFormat; import java.util.List; public class AmmoBox extends Item { @@ -132,19 +132,19 @@ public class AmmoBox extends Item { tooltip.add(Component.translatable("des.superbwarfare.ammo_box").withStyle(ChatFormatting.GRAY)); tooltip.add(Component.translatable("des.superbwarfare.ammo_box.rifle").withStyle(ChatFormatting.GREEN) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##").format(ItemNBTTool.getInt(stack, "RifleAmmo", 0)) + ((type == 0 || type == 1) ? " ←-" : " ")).withStyle(ChatFormatting.BOLD))); + .append(Component.literal(FormatTool.format0D(ItemNBTTool.getInt(stack, "RifleAmmo", 0)) + ((type == 0 || type == 1) ? " ←-" : " ")).withStyle(ChatFormatting.BOLD))); tooltip.add(Component.translatable("des.superbwarfare.ammo_box.handgun").withStyle(ChatFormatting.AQUA) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##").format(ItemNBTTool.getInt(stack, "HandgunAmmo", 0)) + ((type == 0 || type == 2) ? " ←-" : " ")).withStyle(ChatFormatting.BOLD))); + .append(Component.literal(FormatTool.format0D(ItemNBTTool.getInt(stack, "HandgunAmmo", 0)) + ((type == 0 || type == 2) ? " ←-" : " ")).withStyle(ChatFormatting.BOLD))); tooltip.add(Component.translatable("des.superbwarfare.ammo_box.shotgun").withStyle(ChatFormatting.RED) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##").format(ItemNBTTool.getInt(stack, "ShotgunAmmo", 0)) + ((type == 0 || type == 3) ? " ←-" : " ")).withStyle(ChatFormatting.BOLD))); + .append(Component.literal(FormatTool.format0D(ItemNBTTool.getInt(stack, "ShotgunAmmo", 0)) + ((type == 0 || type == 3) ? " ←-" : " ")).withStyle(ChatFormatting.BOLD))); tooltip.add(Component.translatable("des.superbwarfare.ammo_box.sniper").withStyle(ChatFormatting.GOLD) .append(Component.literal("").withStyle(ChatFormatting.RESET)) - .append(Component.literal(new DecimalFormat("##").format(ItemNBTTool.getInt(stack, "SniperAmmo", 0)) + ((type == 0 || type == 4) ? " ←-" : " ")).withStyle(ChatFormatting.BOLD))); + .append(Component.literal(FormatTool.format0D(ItemNBTTool.getInt(stack, "SniperAmmo", 0)) + ((type == 0 || type == 4) ? " ←-" : " ")).withStyle(ChatFormatting.BOLD))); } } 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 5bde22070..0d2443138 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/AdjustMortarAngleMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/AdjustMortarAngleMessage.java @@ -3,6 +3,7 @@ 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; @@ -12,11 +13,8 @@ import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraftforge.network.NetworkEvent; -import java.text.DecimalFormat; import java.util.function.Supplier; -import static com.atsuishio.superbwarfare.entity.MortarEntity.PITCH; - public class AdjustMortarAngleMessage { private final double scroll; @@ -46,13 +44,13 @@ public class AdjustMortarAngleMessage { double angle = 0; if (looking instanceof MortarEntity mortar) { - mortar.getEntityData().set(PITCH, (float) Mth.clamp(mortar.getEntityData().get(PITCH) + 0.5 * message.scroll, 20, 89)); - angle = mortar.getEntityData().get(PITCH); + 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); } player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.angle", - new DecimalFormat("##.##°").format(angle), - new DecimalFormat("##.#m").format((int) RangeHelper.getRange(angle))), true); + 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/java/com/atsuishio/superbwarfare/tools/FormatTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/FormatTool.java index 32d84a68e..805c8a950 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/FormatTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/FormatTool.java @@ -9,6 +9,9 @@ public class FormatTool { public static final DecimalFormat DECIMAL_FORMAT_2 = new DecimalFormat("##.##"); public static final DecimalFormat DECIMAL_FORMAT_1Z = new DecimalFormat("##.0"); + public static final DecimalFormat DECIMAL_FORMAT_1ZZ = new DecimalFormat("#0.0"); + + public static final DecimalFormat DECIMAL_FORMAT_2ZZZ = new DecimalFormat("#0.00"); public static String format0D(double num) { return format0D(num, "");