添加过热条动画效果
This commit is contained in:
parent
3eeb8795d3
commit
dc7d7501c0
2 changed files with 37 additions and 11 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ public class AnimationCurves {
|
|||
public static final Function<Double, Double> EASE_IN_EXPO = x -> x == 0 ? 0 : Math.pow(2, 10 * x - 10);
|
||||
public static final Function<Double, Double> EASE_OUT_EXPO = x -> x == 1 ? 1 : (1 - Math.pow(2, -10 * x));
|
||||
public static final Function<Double, Double> EASE_IN_OUT_QUINT = x -> x < 0.5 ? 4 * x * x * x : (1 - Math.pow(-2 * x + 2, 3) / 2);
|
||||
public static final Function<Double, Double> EASE_IN_QUART = x -> Math.pow(x, 4);
|
||||
|
||||
// wtf
|
||||
public static final Function<Double, Double> PARABOLA = x -> -Math.pow(2 * x - 1, 2) + 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue