diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/FlightExperienceBar.java b/src/main/java/com/minelittlepony/unicopia/client/gui/FlightExperienceBar.java deleted file mode 100644 index 41b0ca0c..00000000 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/FlightExperienceBar.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.minelittlepony.unicopia.client.gui; - -import com.minelittlepony.unicopia.entity.player.Pony; -import com.mojang.blaze3d.platform.GlStateManager; - -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.util.Identifier; - -class FlightExperienceBar extends DrawableHelper implements HudElement { - - static final Identifier TEXTURE = new Identifier("textures/gui/bars.png"); - - @Override - public boolean shouldRender(Pony player) { - return player.getSpecies().canFly() - && !player.getOwner().abilities.creativeMode; - } - - @Override - public void renderHud(UHud context) { - float xp = context.player.getFlight().getFlightExperience(); - float length = context.player.getFlight().getFlightDuration(); - - context.mc.getTextureManager().bindTexture(TEXTURE); - int x = (context.width - 182) / 2; - int y = context.height - 29; - - int xpFill = (int)Math.floor(xp * 182); - int xpBuff = (int)Math.floor((183 - xpFill) * length); - - int baseV = 0; - - if (context.player.getFlight().isExperienceCritical()) { - - int tickCount = (int)(context.mc.getTickDelta() * 10); - - baseV += (tickCount % 3) * 10; - } - - blit(x, y, 0, baseV, 256, 5, 256, 256); - blit(x, y, 0, baseV + 5, xpFill, 5, 256, 256); - - blit(x + xpFill, y, xpFill, baseV + 10, xpBuff, 5, 256, 256); - } - - @Override - public void repositionHud(UHud context) { - int offset = 6; - - GlStateManager.translatef(0, context.begin ? -offset : offset, 0); - } -} - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/HudElement.java b/src/main/java/com/minelittlepony/unicopia/client/gui/HudElement.java deleted file mode 100644 index 8d165908..00000000 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/HudElement.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.minelittlepony.unicopia.client.gui; - -import com.minelittlepony.unicopia.entity.player.Pony; - -public interface HudElement { - - void repositionHud(UHud context); - - void renderHud(UHud context); - - boolean shouldRender(Pony player); -} diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/HudHooks.java b/src/main/java/com/minelittlepony/unicopia/client/gui/HudHooks.java deleted file mode 100644 index 6f1f8848..00000000 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/HudHooks.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.minelittlepony.unicopia.client.gui; - -import com.minelittlepony.unicopia.entity.player.Pony; -import net.minecraft.client.MinecraftClient; - -@Deprecated -// XXX: hud render events -class HudHooks { - public static void beforePreRenderHud() { - MinecraftClient client = MinecraftClient.getInstance(); - - if (client.player != null && client.world != null) { - UHud.instance.repositionElements(Pony.of(client.player), client.getWindow(), true); - } - } - - public static void postRenderHud() { - MinecraftClient client = MinecraftClient.getInstance(); - - if (client.player != null && client.world != null) { - UHud.instance.renderHud(Pony.of(client.player), client.getWindow()); - } - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java index 8fa0f3f1..fea1859f 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java @@ -1,82 +1,94 @@ package com.minelittlepony.unicopia.client.gui; -import java.util.ArrayList; -import java.util.List; - -import org.lwjgl.opengl.GL11; - -import com.minelittlepony.unicopia.entity.player.Pony; -import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.util.Window; +import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.hud.InGameHud; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.MathHelper; -public class UHud { +public class UHud extends DrawableHelper { public static final UHud instance = new UHud(); - private List elements = new ArrayList<>(); + public static final Identifier HUD_TEXTURE = new Identifier("unicopia", "textures/gui/hud.png"); - MinecraftClient mc = MinecraftClient.getInstance(); + private Slot secondarySlot = new Slot(26, 0); + private Slot tertiarySlot = new Slot(36, 24); - TextRenderer fonts = mc.textRenderer; + public void render(InGameHud hud, float tickDelta) { + MinecraftClient client = MinecraftClient.getInstance(); - Pony player; + int scaledWidth = client.getWindow().getScaledWidth(); + int scaledHeight = client.getWindow().getScaledHeight(); - int width; + int x = 104 + (scaledWidth - 50) / 2; + int y = 20 + scaledHeight - 70; - int height; + RenderSystem.enableAlphaTest(); + RenderSystem.enableBlend(); - boolean begin; + client.getTextureManager().bindTexture(HUD_TEXTURE); - private UHud() { - elements.add(new FlightExperienceBar()); + int frameHeight = 54; + int frameWidth = 54; + + blit(x, y, 0, 0, frameWidth, frameHeight, 128, 128); // background + + float progressPercent = 0.25F; + int progressHeight = (int)(frameHeight * progressPercent); + + blit(x, y + (frameHeight - progressHeight), + 61, frameHeight - progressHeight, + frameWidth, progressHeight, 128, 128); // progress + + blit(x, y, 0, 54, frameWidth, frameHeight, 128, 128); // frame + + + + secondarySlot.render(x, y, 50, 100, tickDelta); + tertiarySlot.render(x, y, 5, 10, tickDelta); + + RenderSystem.disableBlend(); + RenderSystem.disableAlphaTest(); } - public void renderHud(Pony player, Window resolution) { - this.width = resolution.getScaledWidth(); - this.height = resolution.getScaledHeight(); - this.player = player; - this.begin = true; - elements.forEach(this::renderElement); - } + static class Slot { - public void repositionElements(Pony player, Window window, boolean begin) { - this.width = window.getScaledWidth(); - this.height = window.getScaledHeight(); - this.player = player; - this.begin = begin; + private int x; + private int y; - elements.forEach(this::positionElement); - } + private float lastCooldown; - private void positionElement(HudElement element) { - if (!element.shouldRender(player)) { - return; + public Slot(int x, int y) { + this.x = x; + this.y = y; } - element.repositionHud(this); - } + void render(int x, int y, float cooldown, float maxCooldown, float tickDelta) { + x += this.x; + y += this.y; - private void renderElement(HudElement element) { - if (!element.shouldRender(player)) { - return; + if (cooldown > 0 && maxCooldown > 0 && cooldown < maxCooldown) { + float lerpCooldown = MathHelper.lerp(tickDelta, cooldown, lastCooldown); + + lastCooldown = lerpCooldown; + + float cooldownPercent = 1 - lerpCooldown / maxCooldown; + + int slotPadding = 4; + int slotSize = 15; + + int progressBottom = y + slotPadding + slotSize; + int progressTop = progressBottom - (int)(15F * cooldownPercent); + + fill(x + slotPadding, progressTop, x + slotPadding + slotSize, progressBottom, 0xAAFFFFFF); + } + + blit(x, y, 105, 105, 30, 30, 128, 128); } - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - - GlStateManager.pushMatrix(); - GlStateManager.disableLighting(); - GlStateManager.color4f(1, 1, 1, 1); - - element.renderHud(this); - - GlStateManager.popMatrix(); - - GL11.glPopAttrib(); - } - } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinInGameHud.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinInGameHud.java new file mode 100644 index 00000000..2b1e56e0 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinInGameHud.java @@ -0,0 +1,18 @@ +package com.minelittlepony.unicopia.mixin.client; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.minelittlepony.unicopia.client.gui.UHud; + +import net.minecraft.client.gui.hud.InGameHud; + +@Mixin(InGameHud.class) +public class MixinInGameHud { + @Inject(method = "render(F)V", at = @At("HEAD")) + private void onRender(float tickDelta, CallbackInfo info) { + UHud.instance.render((InGameHud)(Object)this, tickDelta); + } +} diff --git a/src/main/resources/assets/unicopia/textures/gui/hud.png b/src/main/resources/assets/unicopia/textures/gui/hud.png new file mode 100644 index 00000000..2db083ca Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/gui/hud.png differ diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index a3e5073a..91159bd5 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -23,6 +23,7 @@ "client.DefaultTexturesRegistry", "client.MixinCamera", "client.MixinEntityRenderDispatcher", + "client.MixinInGameHud", "client.MixinGameRenderer", "client.MixinItemModels", "client.MixinKeyboardInput",