Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit c3206a7

Browse files
committed
2.1.0 release with new HUD modules and a lot of bug fixes
1 parent 9c95d39 commit c3206a7

28 files changed

+481
-160
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ Open a terminal and run `./gradlew build`.
5858
- DarkKronicle - Developer for KronHUD
5959
- Chronos22 - Created logo
6060
- qsefthuopq - Created Chinese translations
61-
- TheKodeToad - Contributor
61+
- TheKodeToad - Contributor (also has mouse movement HUD from [Sol Client](https://github.com/Sol-Client/))
6262
- moehreag - Contributor

src/main/java/io/github/darkkronicle/kronhud/KronHUD.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ public void initHuds() {
6464
hudManager.add(new CoordsHud());
6565
hudManager.add(new BossBarHud());
6666
hudManager.add(new ScoreboardHud());
67+
hudManager.add(new PlayerHud());
6768
hudManager.add(new ActionBarHud());
6869
hudManager.add(new ToggleSprintHud());
69-
HudRenderCallback.EVENT.register((matrixStack, v) -> hudManager.render(matrixStack));
70+
HudRenderCallback.EVENT.register((matrixStack, v) -> hudManager.render(matrixStack, v));
7071
setupComplete = true;
7172
}
7273

src/main/java/io/github/darkkronicle/kronhud/config/KronBoolean.java

+17
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@
22

33

44
import io.github.darkkronicle.darkkore.config.options.BooleanOption;
5+
import org.jetbrains.annotations.Nullable;
6+
7+
import java.util.function.Consumer;
58

69
public class KronBoolean extends BooleanOption implements KronConfig<Boolean> {
710

811
private final String entryId;
12+
private final Consumer<Boolean> callback;
913

1014
public KronBoolean(String id, String entryId, boolean defaultValue) {
15+
this(id, entryId, defaultValue, null);
16+
}
17+
18+
public KronBoolean(String id, String entryId, boolean defaultValue, @Nullable Consumer<Boolean> callback) {
1119
super(id, entryId, "", defaultValue);
1220
this.entryId = entryId;
21+
this.callback = callback;
22+
}
23+
24+
@Override
25+
public void setValue(Boolean value) {
26+
super.setValue(value);
27+
if (callback != null) {
28+
callback.accept(value);
29+
}
1330
}
1431

1532
@Override

src/main/java/io/github/darkkronicle/kronhud/config/KronDouble.java

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ public class KronDouble extends DoubleOption implements KronConfig<Double> {
1010
private final String entryId;
1111
private final AbstractHudEntry refreshHud;
1212

13+
public KronDouble(String id, String entryId, double defaultValue, double min, double max) {
14+
this(id, entryId, defaultValue, min, max, null);
15+
}
16+
1317
public KronDouble(String id, String entryId, double defaultValue, double min, double max, @Nullable AbstractHudEntry toRefresh) {
1418
super(id, entryId, "", defaultValue, min, max);
1519
this.entryId = entryId;

src/main/java/io/github/darkkronicle/kronhud/gui/AbstractHudEntry.java

+46-37
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import io.github.darkkronicle.darkkore.colors.ExtendedColor;
44
import io.github.darkkronicle.darkkore.config.options.Option;
55
import io.github.darkkronicle.darkkore.gui.Tab;
6-
import io.github.darkkronicle.darkkore.util.Color;
76
import io.github.darkkronicle.kronhud.config.*;
87
import io.github.darkkronicle.kronhud.util.ColorUtil;
98
import io.github.darkkronicle.kronhud.util.DrawPosition;
109
import io.github.darkkronicle.kronhud.util.DrawUtil;
1110
import io.github.darkkronicle.kronhud.util.Rectangle;
11+
import lombok.Getter;
1212
import lombok.Setter;
1313
import net.minecraft.client.MinecraftClient;
14-
import net.minecraft.client.render.BufferBuilder;
15-
import net.minecraft.client.render.BufferRenderer;
1614
import net.minecraft.client.util.math.MatrixStack;
1715
import net.minecraft.text.Text;
1816
import net.minecraft.util.Identifier;
@@ -30,16 +28,23 @@ public abstract class AbstractHudEntry extends DrawUtil {
3028
protected KronBoolean shadow = new KronBoolean("shadow", null, getShadowDefault());
3129
protected KronBoolean background = new KronBoolean("background", null, true);
3230
protected KronExtendedColor backgroundColor = new KronExtendedColor("backgroundcolor", null, new ExtendedColor(0x64000000, ExtendedColor.ChromaOptions.getDefault()));
31+
32+
protected KronBoolean outline = new KronBoolean("outline", null, false);
33+
protected KronExtendedColor outlineColor = new KronExtendedColor("outlinecolor", null, new ExtendedColor(-1, ExtendedColor.ChromaOptions.getDefault()));
34+
3335
private final KronDouble x = new KronDouble("x", null, getDefaultX(), 0, 1, this);
3436
private final KronDouble y = new KronDouble("y", null, getDefaultY(), 0, 1, this);
3537

36-
private Rectangle scaledBounds = null;
37-
private Rectangle unscaledBounds = null;
38-
private DrawPosition scaledPosition = null;
39-
private DrawPosition unscaledPosition;
38+
private Rectangle trueBounds = null;
39+
private Rectangle renderBounds = null;
40+
private DrawPosition truePosition = null;
41+
private DrawPosition renderPosition;
42+
43+
@Getter
44+
protected int width;
45+
@Getter
46+
protected int height;
4047

41-
public int width;
42-
public int height;
4348
@Setter
4449
protected boolean hovered = false;
4550
protected MinecraftClient client = MinecraftClient.getInstance();
@@ -57,21 +62,21 @@ public static float intToFloat(int current, int max, int offset) {
5762
return MathHelper.clamp((float) (current) / (max - offset), 0, 1);
5863
}
5964

60-
public void renderHud(MatrixStack matrices) {
61-
render(matrices);
65+
public void renderHud(MatrixStack matrices, float delta) {
66+
render(matrices, delta);
6267
}
6368

64-
public abstract void render(MatrixStack matrices);
69+
public abstract void render(MatrixStack matrices, float delta);
6570

66-
public abstract void renderPlaceholder(MatrixStack matrices);
71+
public abstract void renderPlaceholder(MatrixStack matrices, float delta);
6772

6873
public void renderPlaceholderBackground(MatrixStack matrices) {
6974
if (hovered) {
70-
fillRect(matrices, getScaledBounds(), ColorUtil.SELECTOR_BLUE.withAlpha(100));
75+
fillRect(matrices, getTrueBounds(), ColorUtil.SELECTOR_BLUE.withAlpha(100));
7176
} else {
72-
fillRect(matrices, getScaledBounds(), ColorUtil.WHITE.withAlpha(50));
77+
fillRect(matrices, getTrueBounds(), ColorUtil.WHITE.withAlpha(50));
7378
}
74-
outlineRect(matrices, getScaledBounds(), ColorUtil.BLACK);
79+
outlineRect(matrices, getTrueBounds(), ColorUtil.BLACK);
7580
}
7681

7782
public abstract Identifier getId();
@@ -91,22 +96,22 @@ public void setXY(int x, int y) {
9196
}
9297

9398
public int getX() {
94-
return getScaledPos().x();
99+
return getPos().x();
95100
}
96101

97102
public void setX(int x) {
98103
this.x.setValue((double) intToFloat(x, client.getWindow().getScaledWidth(),
99-
Math.round(width * getScale())
104+
Math.round(getWidth() * getScale())
100105
));
101106
}
102107

103108
public int getY() {
104-
return getScaledPos().y();
109+
return getPos().y();
105110
}
106111

107112
public void setY(int y) {
108113
this.y.setValue((double) intToFloat(y, client.getWindow().getScaledHeight(),
109-
Math.round(height * getScale())
114+
Math.round(getHeight() * getScale())
110115
));
111116
}
112117

@@ -122,17 +127,17 @@ protected boolean getShadowDefault() {
122127
return true;
123128
}
124129

125-
public Rectangle getScaledBounds() {
126-
return scaledBounds;
130+
public Rectangle getTrueBounds() {
131+
return trueBounds;
127132
}
128133

129134
/**
130135
* Gets the hud's bounds when the matrix has already been scaled.
131136
*
132137
* @return The bounds.
133138
*/
134-
public Rectangle getBounds() {
135-
return unscaledBounds;
139+
public Rectangle getRenderBounds() {
140+
return renderBounds;
136141
}
137142

138143
public float getScale() {
@@ -144,11 +149,15 @@ public void scale(MatrixStack matrices) {
144149
}
145150

146151
public DrawPosition getPos() {
147-
return unscaledPosition;
152+
return renderPosition;
153+
}
154+
155+
public DrawPosition getTruePos() {
156+
return truePosition;
148157
}
149158

150-
public DrawPosition getScaledPos() {
151-
return scaledPosition;
159+
public void onSizeUpdate() {
160+
setBounds();
152161
}
153162

154163
public void setBounds() {
@@ -157,22 +166,22 @@ public void setBounds() {
157166

158167
public void setBounds(float scale) {
159168
if (client.getWindow() == null) {
160-
scaledPosition = new DrawPosition(0, 0);
161-
unscaledPosition = new DrawPosition(0, 0);
162-
unscaledBounds = new Rectangle(0, 0, 1, 1);
163-
scaledBounds = new Rectangle(0, 0, 1, 1);
169+
truePosition = new DrawPosition(0, 0);
170+
renderPosition = new DrawPosition(0, 0);
171+
renderBounds = new Rectangle(0, 0, 1, 1);
172+
trueBounds = new Rectangle(0, 0, 1, 1);
164173
return;
165174
}
166175
int scaledX = floatToInt(x.getValue().floatValue(), client.getWindow().getScaledWidth(),
167-
Math.round(width * scale)
176+
Math.round(getWidth() * scale)
168177
);
169178
int scaledY = floatToInt(y.getValue().floatValue(), client.getWindow().getScaledHeight(),
170-
Math.round(height * scale)
179+
Math.round(getHeight() * scale)
171180
);
172-
scaledPosition = new DrawPosition(scaledX, scaledY);
173-
unscaledPosition = scaledPosition.divide(getScale());
174-
scaledBounds = new Rectangle(getX(), getY(), Math.round(width * getScale()), Math.round(height * getScale()));
175-
unscaledBounds = new Rectangle(getX(), getY(), width, height);
181+
truePosition = new DrawPosition(scaledX, scaledY);
182+
renderPosition = truePosition.divide(getScale());
183+
trueBounds = new Rectangle(scaledX, scaledY, Math.round(getWidth() * getScale()), Math.round(getHeight() * getScale()));
184+
renderBounds = new Rectangle(renderPosition.x(), renderPosition.y(), getWidth(), getHeight());
176185
}
177186

178187
public Tab getOptionWrapper() {

src/main/java/io/github/darkkronicle/kronhud/gui/hud/ActionBarHud.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void setActionBar(Text bar, int color) {
3535
}
3636

3737
@Override
38-
public void render(MatrixStack matrices) {
38+
public void render(MatrixStack matrices, float delta) {
3939
if (ticksShown >= timeShown.getValue()) {
4040
this.actionBar = null;
4141
}
@@ -46,7 +46,7 @@ public void render(MatrixStack matrices) {
4646
scale(matrices);
4747
if (shadow.getValue()) {
4848
client.textRenderer.drawWithShadow(matrices, actionBar,
49-
(float) getPos().x() + Math.round((float) width / 2) - (float) client.textRenderer.getWidth(actionBar) / 2,
49+
(float) getPos().x() + Math.round((float) getWidth() / 2) - (float) client.textRenderer.getWidth(actionBar) / 2,
5050
(float) getPos().y() + 3,
5151
customTextColor.getValue() ? (
5252
textColor.getValue().alpha() == 255 ?
@@ -63,7 +63,7 @@ public void render(MatrixStack matrices) {
6363
} else {
6464

6565
client.textRenderer.draw(matrices, actionBar,
66-
(float) getPos().x() + Math.round((float) width / 2) - ((float) client.textRenderer.getWidth(actionBar) / 2),
66+
(float) getPos().x() + Math.round((float) getWidth() / 2) - ((float) client.textRenderer.getWidth(actionBar) / 2),
6767
(float) getPos().y() + 3,
6868
customTextColor.getValue() ? (
6969
textColor.getValue().alpha() == 255 ?
@@ -86,13 +86,13 @@ public void render(MatrixStack matrices) {
8686
}
8787

8888
@Override
89-
public void renderPlaceholder(MatrixStack matrices) {
89+
public void renderPlaceholder(MatrixStack matrices, float delta) {
9090
matrices.push();
9191
renderPlaceholderBackground(matrices);
9292
scale(matrices);
9393
client.textRenderer.draw(
9494
matrices, placeholder,
95-
(float) getPos().x() + Math.round((float) width / 2) - (float) client.textRenderer.getWidth(placeholder) / 2,
95+
(float) getPos().x() + Math.round((float) getWidth() / 2) - (float) client.textRenderer.getWidth(placeholder) / 2,
9696
(float) getPos().y() + 3, -1
9797
);
9898
matrices.pop();

src/main/java/io/github/darkkronicle/kronhud/gui/hud/ArmorHud.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ public ArmorHud() {
1919
}
2020

2121
@Override
22-
public void render(MatrixStack matrices) {
22+
public void render(MatrixStack matrices, float delta) {
2323
matrices.push();
2424
scale(matrices);
2525
DrawPosition pos = getPos();
26-
if (background.getValue()) {
27-
fillRect(matrices, getBounds(), backgroundColor.getValue());
26+
if (background.getValue() && backgroundColor.getValue().alpha() > 0) {
27+
fillRect(matrices, getRenderBounds(), backgroundColor.getValue());
28+
}
29+
if (outline.getValue() && outlineColor.getValue().alpha() > 0) {
30+
outlineRect(matrices, getRenderBounds(), outlineColor.getValue());
2831
}
2932
int lastY = 2 + (4 * 20);
3033
renderMainItem(matrices, client.player.getInventory().getMainHandStack(), pos.x() + 2, pos.y() + lastY);
@@ -38,12 +41,12 @@ public void render(MatrixStack matrices) {
3841
}
3942

4043
public void renderItem(MatrixStack matrices, ItemStack stack, int x, int y) {
41-
ItemUtil.renderGuiItemModel(matrices, stack, x, y);
44+
ItemUtil.renderGuiItemModel(getScale(), stack, x, y);
4245
ItemUtil.renderGuiItemOverlay(matrices, client.textRenderer, stack, x, y, null, textColor.getValue().color(), shadow.getValue());
4346
}
4447

4548
public void renderMainItem(MatrixStack matrices, ItemStack stack, int x, int y) {
46-
ItemUtil.renderGuiItemModel(matrices, stack, x, y);
49+
ItemUtil.renderGuiItemModel(getScale(), stack, x, y);
4750
String total = String.valueOf(ItemUtil.getTotal(client, stack));
4851
if (total.equals("1")) {
4952
total = null;
@@ -52,13 +55,13 @@ public void renderMainItem(MatrixStack matrices, ItemStack stack, int x, int y)
5255
}
5356

5457
@Override
55-
public void renderPlaceholder(MatrixStack matrices) {
58+
public void renderPlaceholder(MatrixStack matrices, float delta) {
5659
matrices.push();
5760
renderPlaceholderBackground(matrices);
5861
scale(matrices);
5962
DrawPosition pos = getPos();
6063
int lastY = 2 + (4 * 20);
61-
ItemUtil.renderGuiItemModel(matrices, new ItemStack(Items.GRASS_BLOCK), pos.x() + 2, pos.y() + lastY);
64+
ItemUtil.renderGuiItemModel(getScale(), new ItemStack(Items.GRASS_BLOCK), pos.x() + 2, pos.y() + lastY);
6265
ItemUtil.renderGuiItemOverlay(matrices, client.textRenderer, new ItemStack(Items.GRASS_BLOCK), pos.x() + 2, pos.y() + lastY, "90",
6366
textColor.getValue().color(), shadow.getValue()
6467
);
@@ -83,6 +86,8 @@ public List<KronConfig<?>> getConfigurationOptions() {
8386
options.add(shadow);
8487
options.add(background);
8588
options.add(backgroundColor);
89+
options.add(outline);
90+
options.add(outlineColor);
8691
return options;
8792
}
8893

0 commit comments

Comments
 (0)