From dc7d7501c074895d11f6e97839b1f698de3ab0cc Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Mon, 14 Jul 2025 19:25:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=87=E7=83=AD=E6=9D=A1?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/overlay/HeatBarOverlay.java | 47 ++++++++++++++----- .../tools/animation/AnimationCurves.java | 1 + 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HeatBarOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HeatBarOverlay.java index 23da796ed..012bd1457 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HeatBarOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HeatBarOverlay.java @@ -6,6 +6,8 @@ import com.atsuishio.superbwarfare.client.RenderHelper; import com.atsuishio.superbwarfare.data.gun.GunData; import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.tools.animation.AnimationCurves; +import com.atsuishio.superbwarfare.tools.animation.AnimationTimer; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.DeltaTracker; @@ -14,9 +16,9 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.LayeredDraw; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.FastColor; import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; import org.jetbrains.annotations.NotNull; @@ -28,22 +30,37 @@ public class HeatBarOverlay implements LayeredDraw.Layer { private static final ResourceLocation TEXTURE = Mod.loc("textures/screens/heat_bar.png"); + private static final AnimationTimer timer = new AnimationTimer(200) + .animation(AnimationCurves.EASE_IN_QUART); + @Override public void render(@NotNull GuiGraphics guiGraphics, @NotNull DeltaTracker deltaTracker) { Minecraft mc = Minecraft.getInstance(); Player player = mc.player; if (player == null) return; - if (ClickHandler.isEditing) return; - if (!(player.getMainHandItem().getItem() instanceof GunItem) || (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))) - return; var screenWidth = guiGraphics.guiWidth(); var screenHeight = guiGraphics.guiHeight(); - ItemStack stack = player.getMainHandItem(); - var data = GunData.from(stack); - double heat = data.heat.get(); - if (heat <= 0) return; + double heat; + if (ClickHandler.isEditing + || !(player.getMainHandItem().getItem() instanceof GunItem) + || (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) + ) { + heat = 0; + } else { + heat = GunData.from(player.getMainHandItem()).heat.get(); + } + + long currentTime = System.currentTimeMillis(); + if (heat <= 0) { + timer.forward(currentTime); + } else { + timer.beginForward(currentTime); + } + if (timer.finished(currentTime)) { + return; + } var poseStack = guiGraphics.pose(); poseStack.pushPose(); @@ -53,7 +70,6 @@ public class HeatBarOverlay implements LayeredDraw.Layer { RenderSystem.enableBlend(); RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); - RenderSystem.setShaderColor(1, 1, 1, 1); int width = 16; int height = 64; @@ -61,9 +77,12 @@ public class HeatBarOverlay implements LayeredDraw.Layer { int i = (screenWidth - width) / 2; int j = (screenHeight - height) / 2; - float posX = i + 64; + float posX = i + 64 + timer.lerp(0, 5, currentTime); float posY = j + 6; + float alpha = timer.lerp(1, 0, currentTime); + RenderSystem.setShaderColor(1, 1, 1, alpha); + RenderHelper.preciseBlit(guiGraphics, TEXTURE, posX, posY, 0, 0, 37 / 4f, 233 / 4f, width, height); float rate = (float) (heat / 100.0); @@ -71,8 +90,14 @@ public class HeatBarOverlay implements LayeredDraw.Layer { poseStack.pushPose(); + var color = rate >= 0.795f ? calculateGradientColor(rate) : 0xFFFFFF; + var red = FastColor.ARGB32.red(color) / 255f; + var green = FastColor.ARGB32.green(color) / 255f; + var blue = FastColor.ARGB32.blue(color) / 255f; + + RenderSystem.setShaderColor(red, green, blue, alpha); RenderHelper.preciseBlit(guiGraphics, TEXTURE, posX + 2.5f, posY + 1.5f + 56 - barHeight, - 10.5f, 0, 2.25f, barHeight, width, height, rate >= 0.795f ? calculateGradientColor(rate) : 0xFFFFFF); + 10.5f, 0, 2.25f, barHeight, width, height); poseStack.popPose(); diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/animation/AnimationCurves.java b/src/main/java/com/atsuishio/superbwarfare/tools/animation/AnimationCurves.java index ad8cc6200..6517f6bab 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/animation/AnimationCurves.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/animation/AnimationCurves.java @@ -11,6 +11,7 @@ public class AnimationCurves { public static final Function EASE_IN_EXPO = x -> x == 0 ? 0 : Math.pow(2, 10 * x - 10); public static final Function EASE_OUT_EXPO = x -> x == 1 ? 1 : (1 - Math.pow(2, -10 * x)); public static final Function EASE_IN_OUT_QUINT = x -> x < 0.5 ? 4 * x * x * x : (1 - Math.pow(-2 * x + 2, 3) / 2); + public static final Function EASE_IN_QUART = x -> Math.pow(x, 4); // wtf public static final Function PARABOLA = x -> -Math.pow(2 * x - 1, 2) + 1;