Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
2.1.0 release with new HUD modules and a lot of bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkKronicle committed Oct 11, 2022
1 parent 9c95d39 commit c3206a7
Show file tree
Hide file tree
Showing 28 changed files with 481 additions and 160 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ Open a terminal and run `./gradlew build`.
- DarkKronicle - Developer for KronHUD
- Chronos22 - Created logo
- qsefthuopq - Created Chinese translations
- TheKodeToad - Contributor
- TheKodeToad - Contributor (also has mouse movement HUD from [Sol Client](https://github.com/Sol-Client/))
- moehreag - Contributor
3 changes: 2 additions & 1 deletion src/main/java/io/github/darkkronicle/kronhud/KronHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ public void initHuds() {
hudManager.add(new CoordsHud());
hudManager.add(new BossBarHud());
hudManager.add(new ScoreboardHud());
hudManager.add(new PlayerHud());
hudManager.add(new ActionBarHud());
hudManager.add(new ToggleSprintHud());
HudRenderCallback.EVENT.register((matrixStack, v) -> hudManager.render(matrixStack));
HudRenderCallback.EVENT.register((matrixStack, v) -> hudManager.render(matrixStack, v));
setupComplete = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,31 @@


import io.github.darkkronicle.darkkore.config.options.BooleanOption;
import org.jetbrains.annotations.Nullable;

import java.util.function.Consumer;

public class KronBoolean extends BooleanOption implements KronConfig<Boolean> {

private final String entryId;
private final Consumer<Boolean> callback;

public KronBoolean(String id, String entryId, boolean defaultValue) {
this(id, entryId, defaultValue, null);
}

public KronBoolean(String id, String entryId, boolean defaultValue, @Nullable Consumer<Boolean> callback) {
super(id, entryId, "", defaultValue);
this.entryId = entryId;
this.callback = callback;
}

@Override
public void setValue(Boolean value) {
super.setValue(value);
if (callback != null) {
callback.accept(value);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public class KronDouble extends DoubleOption implements KronConfig<Double> {
private final String entryId;
private final AbstractHudEntry refreshHud;

public KronDouble(String id, String entryId, double defaultValue, double min, double max) {
this(id, entryId, defaultValue, min, max, null);
}

public KronDouble(String id, String entryId, double defaultValue, double min, double max, @Nullable AbstractHudEntry toRefresh) {
super(id, entryId, "", defaultValue, min, max);
this.entryId = entryId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import io.github.darkkronicle.darkkore.colors.ExtendedColor;
import io.github.darkkronicle.darkkore.config.options.Option;
import io.github.darkkronicle.darkkore.gui.Tab;
import io.github.darkkronicle.darkkore.util.Color;
import io.github.darkkronicle.kronhud.config.*;
import io.github.darkkronicle.kronhud.util.ColorUtil;
import io.github.darkkronicle.kronhud.util.DrawPosition;
import io.github.darkkronicle.kronhud.util.DrawUtil;
import io.github.darkkronicle.kronhud.util.Rectangle;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
Expand All @@ -30,16 +28,23 @@ public abstract class AbstractHudEntry extends DrawUtil {
protected KronBoolean shadow = new KronBoolean("shadow", null, getShadowDefault());
protected KronBoolean background = new KronBoolean("background", null, true);
protected KronExtendedColor backgroundColor = new KronExtendedColor("backgroundcolor", null, new ExtendedColor(0x64000000, ExtendedColor.ChromaOptions.getDefault()));

protected KronBoolean outline = new KronBoolean("outline", null, false);
protected KronExtendedColor outlineColor = new KronExtendedColor("outlinecolor", null, new ExtendedColor(-1, ExtendedColor.ChromaOptions.getDefault()));

private final KronDouble x = new KronDouble("x", null, getDefaultX(), 0, 1, this);
private final KronDouble y = new KronDouble("y", null, getDefaultY(), 0, 1, this);

private Rectangle scaledBounds = null;
private Rectangle unscaledBounds = null;
private DrawPosition scaledPosition = null;
private DrawPosition unscaledPosition;
private Rectangle trueBounds = null;
private Rectangle renderBounds = null;
private DrawPosition truePosition = null;
private DrawPosition renderPosition;

@Getter
protected int width;
@Getter
protected int height;

public int width;
public int height;
@Setter
protected boolean hovered = false;
protected MinecraftClient client = MinecraftClient.getInstance();
Expand All @@ -57,21 +62,21 @@ public static float intToFloat(int current, int max, int offset) {
return MathHelper.clamp((float) (current) / (max - offset), 0, 1);
}

public void renderHud(MatrixStack matrices) {
render(matrices);
public void renderHud(MatrixStack matrices, float delta) {
render(matrices, delta);
}

public abstract void render(MatrixStack matrices);
public abstract void render(MatrixStack matrices, float delta);

public abstract void renderPlaceholder(MatrixStack matrices);
public abstract void renderPlaceholder(MatrixStack matrices, float delta);

public void renderPlaceholderBackground(MatrixStack matrices) {
if (hovered) {
fillRect(matrices, getScaledBounds(), ColorUtil.SELECTOR_BLUE.withAlpha(100));
fillRect(matrices, getTrueBounds(), ColorUtil.SELECTOR_BLUE.withAlpha(100));
} else {
fillRect(matrices, getScaledBounds(), ColorUtil.WHITE.withAlpha(50));
fillRect(matrices, getTrueBounds(), ColorUtil.WHITE.withAlpha(50));
}
outlineRect(matrices, getScaledBounds(), ColorUtil.BLACK);
outlineRect(matrices, getTrueBounds(), ColorUtil.BLACK);
}

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

public int getX() {
return getScaledPos().x();
return getPos().x();
}

public void setX(int x) {
this.x.setValue((double) intToFloat(x, client.getWindow().getScaledWidth(),
Math.round(width * getScale())
Math.round(getWidth() * getScale())
));
}

public int getY() {
return getScaledPos().y();
return getPos().y();
}

public void setY(int y) {
this.y.setValue((double) intToFloat(y, client.getWindow().getScaledHeight(),
Math.round(height * getScale())
Math.round(getHeight() * getScale())
));
}

Expand All @@ -122,17 +127,17 @@ protected boolean getShadowDefault() {
return true;
}

public Rectangle getScaledBounds() {
return scaledBounds;
public Rectangle getTrueBounds() {
return trueBounds;
}

/**
* Gets the hud's bounds when the matrix has already been scaled.
*
* @return The bounds.
*/
public Rectangle getBounds() {
return unscaledBounds;
public Rectangle getRenderBounds() {
return renderBounds;
}

public float getScale() {
Expand All @@ -144,11 +149,15 @@ public void scale(MatrixStack matrices) {
}

public DrawPosition getPos() {
return unscaledPosition;
return renderPosition;
}

public DrawPosition getTruePos() {
return truePosition;
}

public DrawPosition getScaledPos() {
return scaledPosition;
public void onSizeUpdate() {
setBounds();
}

public void setBounds() {
Expand All @@ -157,22 +166,22 @@ public void setBounds() {

public void setBounds(float scale) {
if (client.getWindow() == null) {
scaledPosition = new DrawPosition(0, 0);
unscaledPosition = new DrawPosition(0, 0);
unscaledBounds = new Rectangle(0, 0, 1, 1);
scaledBounds = new Rectangle(0, 0, 1, 1);
truePosition = new DrawPosition(0, 0);
renderPosition = new DrawPosition(0, 0);
renderBounds = new Rectangle(0, 0, 1, 1);
trueBounds = new Rectangle(0, 0, 1, 1);
return;
}
int scaledX = floatToInt(x.getValue().floatValue(), client.getWindow().getScaledWidth(),
Math.round(width * scale)
Math.round(getWidth() * scale)
);
int scaledY = floatToInt(y.getValue().floatValue(), client.getWindow().getScaledHeight(),
Math.round(height * scale)
Math.round(getHeight() * scale)
);
scaledPosition = new DrawPosition(scaledX, scaledY);
unscaledPosition = scaledPosition.divide(getScale());
scaledBounds = new Rectangle(getX(), getY(), Math.round(width * getScale()), Math.round(height * getScale()));
unscaledBounds = new Rectangle(getX(), getY(), width, height);
truePosition = new DrawPosition(scaledX, scaledY);
renderPosition = truePosition.divide(getScale());
trueBounds = new Rectangle(scaledX, scaledY, Math.round(getWidth() * getScale()), Math.round(getHeight() * getScale()));
renderBounds = new Rectangle(renderPosition.x(), renderPosition.y(), getWidth(), getHeight());
}

public Tab getOptionWrapper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void setActionBar(Text bar, int color) {
}

@Override
public void render(MatrixStack matrices) {
public void render(MatrixStack matrices, float delta) {
if (ticksShown >= timeShown.getValue()) {
this.actionBar = null;
}
Expand All @@ -46,7 +46,7 @@ public void render(MatrixStack matrices) {
scale(matrices);
if (shadow.getValue()) {
client.textRenderer.drawWithShadow(matrices, actionBar,
(float) getPos().x() + Math.round((float) width / 2) - (float) client.textRenderer.getWidth(actionBar) / 2,
(float) getPos().x() + Math.round((float) getWidth() / 2) - (float) client.textRenderer.getWidth(actionBar) / 2,
(float) getPos().y() + 3,
customTextColor.getValue() ? (
textColor.getValue().alpha() == 255 ?
Expand All @@ -63,7 +63,7 @@ public void render(MatrixStack matrices) {
} else {

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

@Override
public void renderPlaceholder(MatrixStack matrices) {
public void renderPlaceholder(MatrixStack matrices, float delta) {
matrices.push();
renderPlaceholderBackground(matrices);
scale(matrices);
client.textRenderer.draw(
matrices, placeholder,
(float) getPos().x() + Math.round((float) width / 2) - (float) client.textRenderer.getWidth(placeholder) / 2,
(float) getPos().x() + Math.round((float) getWidth() / 2) - (float) client.textRenderer.getWidth(placeholder) / 2,
(float) getPos().y() + 3, -1
);
matrices.pop();
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/io/github/darkkronicle/kronhud/gui/hud/ArmorHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ public ArmorHud() {
}

@Override
public void render(MatrixStack matrices) {
public void render(MatrixStack matrices, float delta) {
matrices.push();
scale(matrices);
DrawPosition pos = getPos();
if (background.getValue()) {
fillRect(matrices, getBounds(), backgroundColor.getValue());
if (background.getValue() && backgroundColor.getValue().alpha() > 0) {
fillRect(matrices, getRenderBounds(), backgroundColor.getValue());
}
if (outline.getValue() && outlineColor.getValue().alpha() > 0) {
outlineRect(matrices, getRenderBounds(), outlineColor.getValue());
}
int lastY = 2 + (4 * 20);
renderMainItem(matrices, client.player.getInventory().getMainHandStack(), pos.x() + 2, pos.y() + lastY);
Expand All @@ -38,12 +41,12 @@ public void render(MatrixStack matrices) {
}

public void renderItem(MatrixStack matrices, ItemStack stack, int x, int y) {
ItemUtil.renderGuiItemModel(matrices, stack, x, y);
ItemUtil.renderGuiItemModel(getScale(), stack, x, y);
ItemUtil.renderGuiItemOverlay(matrices, client.textRenderer, stack, x, y, null, textColor.getValue().color(), shadow.getValue());
}

public void renderMainItem(MatrixStack matrices, ItemStack stack, int x, int y) {
ItemUtil.renderGuiItemModel(matrices, stack, x, y);
ItemUtil.renderGuiItemModel(getScale(), stack, x, y);
String total = String.valueOf(ItemUtil.getTotal(client, stack));
if (total.equals("1")) {
total = null;
Expand All @@ -52,13 +55,13 @@ public void renderMainItem(MatrixStack matrices, ItemStack stack, int x, int y)
}

@Override
public void renderPlaceholder(MatrixStack matrices) {
public void renderPlaceholder(MatrixStack matrices, float delta) {
matrices.push();
renderPlaceholderBackground(matrices);
scale(matrices);
DrawPosition pos = getPos();
int lastY = 2 + (4 * 20);
ItemUtil.renderGuiItemModel(matrices, new ItemStack(Items.GRASS_BLOCK), pos.x() + 2, pos.y() + lastY);
ItemUtil.renderGuiItemModel(getScale(), new ItemStack(Items.GRASS_BLOCK), pos.x() + 2, pos.y() + lastY);
ItemUtil.renderGuiItemOverlay(matrices, client.textRenderer, new ItemStack(Items.GRASS_BLOCK), pos.x() + 2, pos.y() + lastY, "90",
textColor.getValue().color(), shadow.getValue()
);
Expand All @@ -83,6 +86,8 @@ public List<KronConfig<?>> getConfigurationOptions() {
options.add(shadow);
options.add(background);
options.add(backgroundColor);
options.add(outline);
options.add(outlineColor);
return options;
}

Expand Down
Loading

0 comments on commit c3206a7

Please sign in to comment.