添加垂直方向消失动画
This commit is contained in:
parent
8145ab4db3
commit
6178b87a9a
3 changed files with 58 additions and 40 deletions
|
@ -2,14 +2,12 @@ package net.mcreator.target.client.screens;
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.*;
|
|
||||||
import net.mcreator.target.init.TargetModAttributes;
|
import net.mcreator.target.init.TargetModAttributes;
|
||||||
import net.mcreator.target.init.TargetModItems;
|
import net.mcreator.target.init.TargetModItems;
|
||||||
import net.mcreator.target.init.TargetModTags;
|
import net.mcreator.target.init.TargetModTags;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
import net.minecraft.client.CameraType;
|
import net.minecraft.client.CameraType;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
@ -18,7 +16,8 @@ import net.minecraftforge.client.event.RenderGuiEvent;
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
import net.minecraftforge.eventbus.api.EventPriority;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import org.joml.Matrix4f;
|
|
||||||
|
import static net.mcreator.target.tools.RenderTool.preciseBlit;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber({Dist.CLIENT})
|
@Mod.EventBusSubscriber({Dist.CLIENT})
|
||||||
public class CrossHairOverlay {
|
public class CrossHairOverlay {
|
||||||
|
@ -84,28 +83,6 @@ public class CrossHairOverlay {
|
||||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void preciseBlit(GuiGraphics gui, ResourceLocation pAtlasLocation, float pX, float pY, float pUOffset, float pVOffset, float pWidth, float pHeight, float pTextureWidth, float pTextureHeight) {
|
|
||||||
float pX2 = pX + pWidth;
|
|
||||||
float pY2 = pY + pHeight;
|
|
||||||
float pBlitOffset = 0;
|
|
||||||
|
|
||||||
float pMinU = pUOffset / pTextureWidth;
|
|
||||||
float pMaxU = (pUOffset + pWidth) / pTextureWidth;
|
|
||||||
float pMinV = pVOffset / pTextureHeight;
|
|
||||||
float pMaxV = (pVOffset + pHeight) / pTextureHeight;
|
|
||||||
|
|
||||||
RenderSystem.setShaderTexture(0, pAtlasLocation);
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
|
||||||
Matrix4f matrix4f = gui.pose().last().pose();
|
|
||||||
BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder();
|
|
||||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
|
|
||||||
bufferbuilder.vertex(matrix4f, pX, pY, pBlitOffset).uv(pMinU, pMinV).endVertex();
|
|
||||||
bufferbuilder.vertex(matrix4f, pX, pY2, pBlitOffset).uv(pMinU, pMaxV).endVertex();
|
|
||||||
bufferbuilder.vertex(matrix4f, pX2, pY2, pBlitOffset).uv(pMaxU, pMaxV).endVertex();
|
|
||||||
bufferbuilder.vertex(matrix4f, pX2, pY, pBlitOffset).uv(pMaxU, pMinV).endVertex();
|
|
||||||
BufferUploader.drawWithShader(bufferbuilder.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean shouldRenderCrosshair(Player player) {
|
private static boolean shouldRenderCrosshair(Player player) {
|
||||||
if (player == null) return false;
|
if (player == null) return false;
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ import top.theillusivec4.curios.api.CuriosApi;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static net.mcreator.target.tools.RenderTool.preciseBlit;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||||
public class KillMessageOverlay {
|
public class KillMessageOverlay {
|
||||||
private static final ResourceLocation HEADSHOT = new ResourceLocation(TargetMod.MODID, "textures/screens/damage_types/headshot.png");
|
private static final ResourceLocation HEADSHOT = new ResourceLocation(TargetMod.MODID, "textures/screens/damage_types/headshot.png");
|
||||||
|
@ -51,17 +53,16 @@ public class KillMessageOverlay {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = 0;
|
float totalTop = 5;
|
||||||
for (PlayerKillRecord record : KillMessageHandler.QUEUE) {
|
for (PlayerKillRecord record : KillMessageHandler.QUEUE) {
|
||||||
renderKillMessages(record, event, index);
|
totalTop = renderKillMessages(record, event, totalTop);
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderKillMessages(PlayerKillRecord record, RenderGuiEvent.Pre event, int index) {
|
private static float renderKillMessages(PlayerKillRecord record, RenderGuiEvent.Pre event, float baseTop) {
|
||||||
int w = event.getWindow().getGuiScaledWidth();
|
int w = event.getWindow().getGuiScaledWidth();
|
||||||
int h = 10 + index * 10;
|
float top = baseTop;
|
||||||
|
|
||||||
Font font = Minecraft.getInstance().font;
|
Font font = Minecraft.getInstance().font;
|
||||||
|
|
||||||
|
@ -100,9 +101,12 @@ public class KillMessageOverlay {
|
||||||
|
|
||||||
// 4s后开始消失
|
// 4s后开始消失
|
||||||
if (record.tick >= 80) {
|
if (record.tick >= 80) {
|
||||||
double rate = Math.pow((record.tick + event.getPartialTick() - 80) / 20, 5);
|
float rate = (float) Math.pow((record.tick + event.getPartialTick() - 80) / 20, 5);
|
||||||
gui.pose().translate(rate * 100, 0, 0);
|
gui.pose().translate(rate * 100, 0, 0);
|
||||||
gui.setColor(1, 1, 1, (float) (1 - rate));
|
gui.setColor(1, 1, 1, 1 - rate);
|
||||||
|
baseTop += 10 * (1 - rate);
|
||||||
|
} else {
|
||||||
|
baseTop += 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 击杀提示是右对齐的,这里从右向左渲染
|
// 击杀提示是右对齐的,这里从右向左渲染
|
||||||
|
@ -112,7 +116,7 @@ public class KillMessageOverlay {
|
||||||
Minecraft.getInstance().font,
|
Minecraft.getInstance().font,
|
||||||
targetName.get(),
|
targetName.get(),
|
||||||
w - targetNameWidth - 10f,
|
w - targetNameWidth - 10f,
|
||||||
h,
|
top,
|
||||||
record.target.getTeamColor(),
|
record.target.getTeamColor(),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -123,9 +127,10 @@ public class KillMessageOverlay {
|
||||||
ResourceLocation damageTypeIcon = getDamageTypeIcon(record);
|
ResourceLocation damageTypeIcon = getDamageTypeIcon(record);
|
||||||
|
|
||||||
if (damageTypeIcon != null) {
|
if (damageTypeIcon != null) {
|
||||||
gui.blit(damageTypeIcon,
|
preciseBlit(gui,
|
||||||
|
damageTypeIcon,
|
||||||
damageTypeIconW,
|
damageTypeIconW,
|
||||||
h - 2,
|
top - 2,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
12,
|
12,
|
||||||
|
@ -143,9 +148,10 @@ public class KillMessageOverlay {
|
||||||
|
|
||||||
ResourceLocation resourceLocation = gunItem.getGunIcon();
|
ResourceLocation resourceLocation = gunItem.getGunIcon();
|
||||||
|
|
||||||
gui.blit(resourceLocation,
|
preciseBlit(gui,
|
||||||
|
resourceLocation,
|
||||||
itemIconW,
|
itemIconW,
|
||||||
h,
|
top,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
32,
|
32,
|
||||||
|
@ -159,9 +165,10 @@ public class KillMessageOverlay {
|
||||||
if (record.stack.getItem().getDescriptionId().equals("item.dreamaticvoyage.world_peace_staff")) {
|
if (record.stack.getItem().getDescriptionId().equals("item.dreamaticvoyage.world_peace_staff")) {
|
||||||
renderItem = true;
|
renderItem = true;
|
||||||
|
|
||||||
gui.blit(WORLD_PEACE_STAFF,
|
preciseBlit(gui,
|
||||||
|
WORLD_PEACE_STAFF,
|
||||||
itemIconW,
|
itemIconW,
|
||||||
h,
|
top,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
32,
|
32,
|
||||||
|
@ -196,7 +203,7 @@ public class KillMessageOverlay {
|
||||||
Minecraft.getInstance().font,
|
Minecraft.getInstance().font,
|
||||||
attackerName.get(),
|
attackerName.get(),
|
||||||
nameW,
|
nameW,
|
||||||
h,
|
top,
|
||||||
record.attacker.getTeamColor(),
|
record.attacker.getTeamColor(),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -208,6 +215,8 @@ public class KillMessageOverlay {
|
||||||
|
|
||||||
gui.setColor(1, 1, 1, 1);
|
gui.setColor(1, 1, 1, 1);
|
||||||
gui.pose().popPose();
|
gui.pose().popPose();
|
||||||
|
|
||||||
|
return baseTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
32
src/main/java/net/mcreator/target/tools/RenderTool.java
Normal file
32
src/main/java/net/mcreator/target/tools/RenderTool.java
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package net.mcreator.target.tools;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.mojang.blaze3d.vertex.*;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import org.joml.Matrix4f;
|
||||||
|
|
||||||
|
public class RenderTool {
|
||||||
|
public static void preciseBlit(GuiGraphics gui, ResourceLocation pAtlasLocation, float pX, float pY, float pUOffset, float pVOffset, float pWidth, float pHeight, float pTextureWidth, float pTextureHeight) {
|
||||||
|
float pX2 = pX + pWidth;
|
||||||
|
float pY2 = pY + pHeight;
|
||||||
|
float pBlitOffset = 0;
|
||||||
|
|
||||||
|
float pMinU = pUOffset / pTextureWidth;
|
||||||
|
float pMaxU = (pUOffset + pWidth) / pTextureWidth;
|
||||||
|
float pMinV = pVOffset / pTextureHeight;
|
||||||
|
float pMaxV = (pVOffset + pHeight) / pTextureHeight;
|
||||||
|
|
||||||
|
RenderSystem.setShaderTexture(0, pAtlasLocation);
|
||||||
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||||
|
Matrix4f matrix4f = gui.pose().last().pose();
|
||||||
|
BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder();
|
||||||
|
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
|
||||||
|
bufferbuilder.vertex(matrix4f, pX, pY, pBlitOffset).uv(pMinU, pMinV).endVertex();
|
||||||
|
bufferbuilder.vertex(matrix4f, pX, pY2, pBlitOffset).uv(pMinU, pMaxV).endVertex();
|
||||||
|
bufferbuilder.vertex(matrix4f, pX2, pY2, pBlitOffset).uv(pMaxU, pMaxV).endVertex();
|
||||||
|
bufferbuilder.vertex(matrix4f, pX2, pY, pBlitOffset).uv(pMaxU, pMinV).endVertex();
|
||||||
|
BufferUploader.drawWithShader(bufferbuilder.end());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue