Show the passive ability when sneaking

This commit is contained in:
Sollace 2020-09-25 13:27:20 +02:00
parent d9e92ff0ea
commit babc9e680d
2 changed files with 14 additions and 10 deletions

View file

@ -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);

View file

@ -28,9 +28,9 @@ public class UHud extends DrawableHelper {
private final MinecraftClient client = MinecraftClient.getInstance();
private final List<Slot> 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();