From babc9e680dc511c571683047cfbbef2e67050ea2 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 25 Sep 2020 13:27:20 +0200 Subject: [PATCH] Show the passive ability when sneaking --- .../minelittlepony/unicopia/client/gui/Slot.java | 14 ++++++++------ .../minelittlepony/unicopia/client/gui/UHud.java | 10 ++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java b/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java index 175c2deb..5bb06180 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/Slot.java @@ -12,7 +12,8 @@ import net.minecraft.util.math.MathHelper; class Slot { private final UHud uHud; - private final AbilitySlot slot; + private final AbilitySlot aSlot; + private final AbilitySlot bSlot; private int x; private int y; @@ -31,9 +32,10 @@ class Slot { private int backgroundU = 105; private int backgroundV = 105; - public Slot(UHud uHud, AbilitySlot slot, int x, int y, int padding, int size, int labelOffset, int iconSize) { + public Slot(UHud uHud, AbilitySlot normalSlot, AbilitySlot backupSlot, int x, int y, int padding, int size, int labelOffset, int iconSize) { this.uHud = uHud; - this.slot = slot; + this.aSlot = normalSlot; + this.bSlot = backupSlot; this.x = x; this.y = y; this.slotPadding = padding; @@ -53,11 +55,11 @@ class Slot { return this; } - void renderBackground(MatrixStack matrices, AbilityDispatcher abilities, float tickDelta) { + void renderBackground(MatrixStack matrices, AbilityDispatcher abilities, boolean bSwap, float tickDelta) { matrices.push(); matrices.translate(x, y, 0); - AbilityDispatcher.Stat stat = abilities.getStat(slot); + AbilityDispatcher.Stat stat = abilities.getStat(bSwap ? bSlot : aSlot); float cooldown = stat.getFillProgress(); // background @@ -90,7 +92,7 @@ class Slot { } void renderForeground(MatrixStack matrices, AbilityDispatcher abilities, float tickDelta) { - Text label = KeyBindingsHandler.INSTANCE.getBinding(slot).getBoundKeyLocalizedText(); + Text label = KeyBindingsHandler.INSTANCE.getBinding(aSlot).getBoundKeyLocalizedText(); matrices.push(); matrices.translate(x + labelOffset, y + labelOffset, 0); 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 44dafec1..5dbbdd24 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java @@ -28,9 +28,9 @@ public class UHud extends DrawableHelper { private final MinecraftClient client = MinecraftClient.getInstance(); private final List slots = Util.make(new ArrayList<>(), slots -> { - slots.add(new Slot(this, AbilitySlot.PRIMARY, 0, 0, 8, 49, 38, 42).background(0, 5).foreground(0, 59)); - slots.add(new Slot(this, AbilitySlot.SECONDARY, 26, -5, 3, 22, 17, 19).background(80, 105)); - slots.add(new Slot(this, AbilitySlot.TERTIARY, 36, 19, 3, 22, 17, 19).background(80, 105)); + slots.add(new Slot(this, AbilitySlot.PRIMARY, AbilitySlot.PASSIVE, 0, 0, 8, 49, 38, 42).background(0, 5).foreground(0, 59)); + slots.add(new Slot(this, AbilitySlot.SECONDARY, AbilitySlot.SECONDARY, 26, -5, 3, 22, 17, 19).background(80, 105)); + slots.add(new Slot(this, AbilitySlot.TERTIARY, AbilitySlot.TERTIARY, 36, 19, 3, 22, 17, 19).background(80, 105)); }); public void render(InGameHud hud, MatrixStack matrices, float tickDelta) { @@ -54,7 +54,9 @@ public class UHud extends DrawableHelper { AbilityDispatcher abilities = Pony.of(client.player).getAbilities(); - slots.forEach(slot -> slot.renderBackground(matrices, abilities, tickDelta)); + boolean swap = client.options.keySneak.isPressed(); + + slots.forEach(slot -> slot.renderBackground(matrices, abilities, swap, tickDelta)); slots.forEach(slot -> slot.renderForeground(matrices, abilities, tickDelta)); RenderSystem.disableBlend();