diff --git a/README.md b/README.md index c9a5309..8a5992e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/main/java/io/github/darkkronicle/kronhud/KronHUD.java b/src/main/java/io/github/darkkronicle/kronhud/KronHUD.java index a943a5f..3141585 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/KronHUD.java +++ b/src/main/java/io/github/darkkronicle/kronhud/KronHUD.java @@ -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; } diff --git a/src/main/java/io/github/darkkronicle/kronhud/config/KronBoolean.java b/src/main/java/io/github/darkkronicle/kronhud/config/KronBoolean.java index 7bbca7c..e6eeb12 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/config/KronBoolean.java +++ b/src/main/java/io/github/darkkronicle/kronhud/config/KronBoolean.java @@ -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 { private final String entryId; + private final Consumer callback; public KronBoolean(String id, String entryId, boolean defaultValue) { + this(id, entryId, defaultValue, null); + } + + public KronBoolean(String id, String entryId, boolean defaultValue, @Nullable Consumer 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 diff --git a/src/main/java/io/github/darkkronicle/kronhud/config/KronDouble.java b/src/main/java/io/github/darkkronicle/kronhud/config/KronDouble.java index 9e8aca2..c05f9b8 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/config/KronDouble.java +++ b/src/main/java/io/github/darkkronicle/kronhud/config/KronDouble.java @@ -10,6 +10,10 @@ public class KronDouble extends DoubleOption implements KronConfig { 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; diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/AbstractHudEntry.java b/src/main/java/io/github/darkkronicle/kronhud/gui/AbstractHudEntry.java index 0d8b42f..343a928 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/AbstractHudEntry.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/AbstractHudEntry.java @@ -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; @@ -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(); @@ -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(); @@ -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()) )); } @@ -122,8 +127,8 @@ protected boolean getShadowDefault() { return true; } - public Rectangle getScaledBounds() { - return scaledBounds; + public Rectangle getTrueBounds() { + return trueBounds; } /** @@ -131,8 +136,8 @@ public Rectangle getScaledBounds() { * * @return The bounds. */ - public Rectangle getBounds() { - return unscaledBounds; + public Rectangle getRenderBounds() { + return renderBounds; } public float getScale() { @@ -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() { @@ -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() { diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ActionBarHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ActionBarHud.java index 9ea2b15..f123b2a 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ActionBarHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ActionBarHud.java @@ -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; } @@ -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 ? @@ -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 ? @@ -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(); diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ArmorHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ArmorHud.java index e516e7c..bf123b1 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ArmorHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ArmorHud.java @@ -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); @@ -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; @@ -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() ); @@ -83,6 +86,8 @@ public List> getConfigurationOptions() { options.add(shadow); options.add(background); options.add(backgroundColor); + options.add(outline); + options.add(outlineColor); return options; } diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ArrowHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ArrowHud.java index fdf753a..39cebfa 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ArrowHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ArrowHud.java @@ -28,7 +28,7 @@ public ArrowHud() { } @Override - public void render(MatrixStack matrices) { + public void render(MatrixStack matrices, float delta) { if (dynamic.getValue()) { ClientPlayerEntity player = MinecraftClient.getInstance().player; if (!( @@ -42,14 +42,17 @@ public void render(MatrixStack matrices) { 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()); } drawCenteredString( - matrices, client.textRenderer, String.valueOf(arrows), pos.x() + width / 2, pos.y() + height - 10, + matrices, client.textRenderer, String.valueOf(arrows), pos.x() + getWidth() / 2, pos.y() + getHeight() - 10, textColor.getValue(), shadow.getValue() ); - ItemUtil.renderGuiItemModel(matrices, currentArrow, pos.x() + 2, pos.y() + 2); + ItemUtil.renderGuiItemModel(getScale(), currentArrow, pos.x() + 2, pos.y() + 2); matrices.pop(); } @@ -77,16 +80,16 @@ public void tick() { } @Override - public void renderPlaceholder(MatrixStack matrices) { + public void renderPlaceholder(MatrixStack matrices, float delta) { matrices.push(); renderPlaceholderBackground(matrices); scale(matrices); DrawPosition pos = getPos(); drawCenteredString( - matrices, client.textRenderer, "64", pos.x() + width / 2, pos.y() + height - 10, textColor.getValue(), + matrices, client.textRenderer, "64", pos.x() + getWidth() / 2, pos.y() + getHeight() - 10, textColor.getValue(), shadow.getValue() ); - ItemUtil.renderGuiItemModel(matrices, new ItemStack(Items.ARROW), pos.x() + 2, pos.y() + 2); + ItemUtil.renderGuiItemModel(getScale(), new ItemStack(Items.ARROW), pos.x() + 2, pos.y() + 2); hovered = false; matrices.pop(); } @@ -98,6 +101,8 @@ public List> getConfigurationOptions() { options.add(shadow); options.add(background); options.add(backgroundColor); + options.add(outline); + options.add(outlineColor); options.add(dynamic); options.add(allArrowTypes); return options; diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/BossBarHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/BossBarHud.java index e3e5bfe..42179d4 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/BossBarHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/BossBarHud.java @@ -49,7 +49,7 @@ public void setBossBars() { @Override - public void render(MatrixStack matrices) { + public void render(MatrixStack matrices, float delta) { setBossBars(); if (this.bossBars.isEmpty()) { return; @@ -62,7 +62,7 @@ public void render(MatrixStack matrices) { for (ClientBossBar bossBar : bossBars.values()) { renderBossBar(matrices, scaledPos.x(), by + scaledPos.y(), bossBar); by = by + 19; - if (by > height) { + if (by > getHeight()) { break; } } @@ -70,12 +70,12 @@ public void render(MatrixStack matrices) { } @Override - public void renderPlaceholder(MatrixStack matrices) { + public void renderPlaceholder(MatrixStack matrices, float delta) { matrices.push(); renderPlaceholderBackground(matrices); scale(matrices); DrawPosition pos = getPos(); - outlineRect(matrices, getBounds(), ColorUtil.BLACK); + outlineRect(matrices, getRenderBounds(), ColorUtil.BLACK); renderBossBar(matrices, pos.x(), pos.y() + 12, placeholder); renderBossBar(matrices, pos.x(), pos.y() + 31, placeholder2); hovered = false; @@ -100,7 +100,7 @@ private void renderBossBar(MatrixStack matrices, int x, int y, BossBar bossBar) } if (text.getValue()) { Text text = bossBar.getName(); - float textX = x + ((float) width / 2) - ((float) client.textRenderer.getWidth(text) / 2); + float textX = x + ((float) getWidth() / 2) - ((float) client.textRenderer.getWidth(text) / 2); float textY = y - 9; if (shadow.getValue()) { client.textRenderer.drawWithShadow(matrices, text, textX, textY, textColor.getValue().color()); @@ -127,6 +127,8 @@ public List> getConfigurationOptions() { options.add(textColor); options.add(shadow); options.add(bar); + options.remove(outline); + options.remove(outlineColor); return options; } diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CleanHudEntry.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CleanHudEntry.java index deb1762..386d95e 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CleanHudEntry.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CleanHudEntry.java @@ -1,14 +1,10 @@ package io.github.darkkronicle.kronhud.gui.hud; import com.mojang.blaze3d.systems.RenderSystem; -import io.github.darkkronicle.darkkore.util.Color; import io.github.darkkronicle.kronhud.config.KronConfig; import io.github.darkkronicle.kronhud.gui.AbstractHudEntry; import io.github.darkkronicle.kronhud.util.DrawPosition; -import io.github.darkkronicle.kronhud.util.Rectangle; -import net.minecraft.client.render.*; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.Matrix4f; import org.lwjgl.opengl.GL11; import java.util.List; @@ -24,20 +20,23 @@ protected CleanHudEntry(int width, int height) { } @Override - public void render(MatrixStack matrices) { + public void render(MatrixStack matrices, float delta) { matrices.push(); scale(matrices); RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); RenderSystem.disableTexture(); 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()); } drawCenteredString( matrices, client.textRenderer, getValue(), - pos.x() + (Math.round(width) / 2), - pos.y() + (Math.round((float) height / 2)) - 4, + pos.x() + (Math.round(getWidth()) / 2), + pos.y() + (Math.round((float) getHeight() / 2)) - 4, textColor.getValue(), shadow.getValue() ); matrices.pop(); @@ -46,15 +45,15 @@ matrices, client.textRenderer, getValue(), } @Override - public void renderPlaceholder(MatrixStack matrices) { + public void renderPlaceholder(MatrixStack matrices, float delta) { matrices.push(); renderPlaceholderBackground(matrices); scale(matrices); DrawPosition pos = getPos(); drawCenteredString( matrices, client.textRenderer, getPlaceholder(), - pos.x() + (Math.round(width) / 2), - pos.y() + (Math.round((float) height / 2)) - 4, + pos.x() + (Math.round(getWidth()) / 2), + pos.y() + (Math.round((float) getHeight() / 2)) - 4, textColor.getValue(), shadow.getValue() ); matrices.pop(); @@ -68,6 +67,8 @@ public List> getConfigurationOptions() { options.add(shadow); options.add(background); options.add(backgroundColor); + options.add(outline); + options.add(outlineColor); return options; } diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CoordsHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CoordsHud.java index a3f7d32..fd6e4f9 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CoordsHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CoordsHud.java @@ -88,12 +88,15 @@ public static int getDirection(double yaw) { } @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()); } StringBuilder format = new StringBuilder("#"); if (decimalPlaces.getValue() > 0) { @@ -165,7 +168,7 @@ matrices, getZDir(dir), } @Override - public void renderPlaceholder(MatrixStack matrices) { + public void renderPlaceholder(MatrixStack matrices, float delta) { matrices.push(); renderPlaceholderBackground(matrices); scale(matrices); @@ -222,6 +225,8 @@ public List> getConfigurationOptions() { List> options = super.getConfigurationOptions(); options.add(background); options.add(backgroundColor); + options.add(outline); + options.add(outlineColor); options.add(firstColor); options.add(secondColor); options.add(decimalPlaces); diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CrosshairHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CrosshairHud.java index 5e3e27e..93c2aa5 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CrosshairHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/CrosshairHud.java @@ -14,19 +14,13 @@ import net.minecraft.block.AbstractChestBlock; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.option.AttackIndicator; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.Camera; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat.DrawMode; -import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Vec3f; import net.minecraft.world.World; @@ -58,7 +52,7 @@ protected float getDefaultY() { } @Override - public void render(MatrixStack matrices) { + public void render(MatrixStack matrices, float delta) { if (!client.options.getPerspective().isFirstPerson() && !showInF5.getValue()) { return; } @@ -70,17 +64,17 @@ public void render(MatrixStack matrices) { AttackIndicator indicator = this.client.options.getAttackIndicator().getValue(); if (type.getValue() == Crosshair.DOT) { - fillRect(matrices, new Rectangle(pos.x() + (width / 2) - 2, pos.y() + (height / 2) - 2, 3, 3), color); + fillRect(matrices, new Rectangle(pos.x() + (getWidth() / 2) - 2, pos.y() + (getHeight() / 2) - 2, 3, 3), color); } else if (type.getValue() == Crosshair.CROSS) { - fillRect(matrices, new Rectangle(pos.x() + (width / 2) - 6, pos.y() + (height / 2) - 1, 6, 1), color); - fillRect(matrices, new Rectangle(pos.x() + (width / 2), pos.y() + (height / 2) - 1, 5, 1), color); - fillRect(matrices, new Rectangle(pos.x() + (width / 2) - 1, pos.y() + (height / 2) - 6, 1, 6), color); - fillRect(matrices, new Rectangle(pos.x() + (width / 2) - 1, pos.y() + (height / 2), 1, 5), color); + fillRect(matrices, new Rectangle(pos.x() + (getWidth() / 2) - 6, pos.y() + (getHeight() / 2) - 1, 6, 1), color); + fillRect(matrices, new Rectangle(pos.x() + (getWidth() / 2), pos.y() + (getHeight() / 2) - 1, 5, 1), color); + fillRect(matrices, new Rectangle(pos.x() + (getWidth() / 2) - 1, pos.y() + (getHeight() / 2) - 6, 1, 6), color); + fillRect(matrices, new Rectangle(pos.x() + (getWidth() / 2) - 1, pos.y() + (getHeight() / 2), 1, 5), color); } else if (type.getValue() == Crosshair.DIRECTION) { Camera camera = this.client.gameRenderer.getCamera(); MatrixStack matrixStack = RenderSystem.getModelViewStack(); matrixStack.push(); - matrixStack.translate(getX() + ((float) width / 2), getY() + ((float) height / 2), 0); + matrixStack.translate(getX() + ((float) getWidth() / 2), getY() + ((float) getHeight() / 2), 0); matrixStack.multiply(Vec3f.NEGATIVE_X.getDegreesQuaternion(camera.getPitch())); matrixStack.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(camera.getYaw())); matrixStack.scale(-getScale(), -getScale(), getScale()); @@ -127,12 +121,12 @@ public void render(MatrixStack matrices) { if (indicator == AttackIndicator.CROSSHAIR) { float progress = this.client.player.getAttackCooldownProgress(0.0F); if (progress != 1.0F) { - RenderUtil.fill( - matrices.peek().getPositionMatrix(), pos.x() + (width / 2) - 6, pos.y() + (height / 2) + 9, 11, 1, + RenderUtil.drawRectangle( + matrices, pos.x() + (getWidth() / 2) - 6, pos.y() + (getHeight() / 2) + 9, 11, 1, attackIndicatorBackgroundColor.getValue() ); - RenderUtil.fill( - matrices.peek().getPositionMatrix(), pos.x() + (width / 2) - 6, pos.y() + (height / 2) + 9, + RenderUtil.drawRectangle( + matrices, pos.x() + (getWidth() / 2) - 6, pos.y() + (getHeight() / 2) + 9, (int) (progress * 11), 1, attackIndicatorForegroundColor.getValue() ); } @@ -158,7 +152,7 @@ public Color getColor() { } @Override - public void renderPlaceholder(MatrixStack matrices) { + public void renderPlaceholder(MatrixStack matrices, float delta) { // Shouldn't need this... } diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/HudManager.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/HudManager.java index 8667964..151dd9d 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/HudManager.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/HudManager.java @@ -59,27 +59,27 @@ public AbstractHudEntry get(Identifier identifier) { return entries.get(identifier); } - public void render(MatrixStack matrices) { + public void render(MatrixStack matrices, float delta) { if (!(client.currentScreen instanceof HudEditScreen) && !client.options.debugEnabled) { for (AbstractHudEntry hud : getEntries()) { if (hud.isEnabled()) { - hud.renderHud(matrices); + hud.renderHud(matrices, delta); } } } } - public void renderPlaceholder(MatrixStack matrices) { + public void renderPlaceholder(MatrixStack matrices, float delta) { for (AbstractHudEntry hud : getEntries()) { if (hud.isEnabled()) { - hud.renderPlaceholder(matrices); + hud.renderPlaceholder(matrices, delta); } } } public Optional getEntryXY(int x, int y) { for (AbstractHudEntry entry : getMoveableEntries()) { - Rectangle bounds = entry.getScaledBounds(); + Rectangle bounds = entry.getTrueBounds(); if (bounds.x() <= x && bounds.x() + bounds.width() >= x && bounds.y() <= y && bounds.y() + bounds.height() >= y) { return Optional.of(entry); } @@ -90,7 +90,7 @@ public Optional getEntryXY(int x, int y) { public List getAllBounds() { ArrayList bounds = new ArrayList<>(); for (AbstractHudEntry entry : getMoveableEntries()) { - bounds.add(entry.getScaledBounds()); + bounds.add(entry.getTrueBounds()); } return bounds; } diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ItemUpdateHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ItemUpdateHud.java index 6d7c724..dc978e8 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ItemUpdateHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ItemUpdateHud.java @@ -93,7 +93,7 @@ private void updateRemoved() { } @Override - public void render(MatrixStack matrices) { + public void render(MatrixStack matrices, float delta) { matrices.push(); scale(matrices); DrawPosition pos = getPos(); @@ -151,7 +151,7 @@ public void render(MatrixStack matrices) { } @Override - public void renderPlaceholder(MatrixStack matrices) { + public void renderPlaceholder(MatrixStack matrices, float delta) { matrices.push(); renderPlaceholderBackground(matrices); scale(matrices); diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/KeystrokeHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/KeystrokeHud.java index d502dbc..66fd36f 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/KeystrokeHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/KeystrokeHud.java @@ -2,6 +2,8 @@ import io.github.darkkronicle.darkkore.colors.ExtendedColor; import io.github.darkkronicle.darkkore.util.Color; +import io.github.darkkronicle.darkkore.util.render.RenderUtil; +import io.github.darkkronicle.kronhud.config.KronBoolean; import io.github.darkkronicle.kronhud.config.KronColor; import io.github.darkkronicle.kronhud.config.KronConfig; import io.github.darkkronicle.kronhud.config.KronExtendedColor; @@ -28,13 +30,21 @@ public class KeystrokeHud extends AbstractHudEntry { private final KronColor pressedTextColor = new KronColor("heldtextcolor", ID.getPath(), new Color(0xFF000000)); private final KronExtendedColor pressedBackgroundColor = new KronExtendedColor("heldbackgroundcolor", ID.getPath(), new ExtendedColor(0x64FFFFFF, ExtendedColor.ChromaOptions.getDefault())); + private final KronExtendedColor pressedOutlineColor = new KronExtendedColor("heldoutlinecolor", ID.getPath(), new ExtendedColor(0, ExtendedColor.ChromaOptions.getDefault())); + private final KronBoolean mouseMovement = new KronBoolean("mousemovement", ID.getPath(), false, this::onMouseMovementOption); private ArrayList keystrokes; private final MinecraftClient client; + private float mouseX = 0; + private float mouseY = 0; + private float lastMouseX = 0; + private float lastMouseY = 0; + public KeystrokeHud() { super(53, 61); this.client = MinecraftClient.getInstance(); KronHudHooks.KEYBIND_CHANGE.register(key -> setKeystrokes()); + KronHudHooks.PLAYER_DIRECTION_CHANGE.register(this::onPlayerDirectionChange); } public static Optional getMouseKeyBindName(KeyBinding keyBinding) { @@ -91,7 +101,7 @@ public void setKeystrokes() { } @Override - public void render(MatrixStack matrices) { + public void render(MatrixStack matrices, float delta) { matrices.push(); scale(matrices); if (keystrokes == null) { @@ -100,9 +110,47 @@ public void render(MatrixStack matrices) { for (Keystroke stroke : keystrokes) { stroke.render(matrices); } + if (mouseMovement.getValue()) { + int spaceY = 62 + getY(); + int spaceX = getX(); + if (background.getValue()) { + RenderUtil.drawRectangle(matrices, spaceX, spaceY, width, 35, backgroundColor.getValue()); + } + if (outline.getValue()) { + RenderUtil.drawOutline(matrices, spaceX, spaceY, width, 35, outlineColor.getValue()); + } + + float calculatedMouseX = (lastMouseX + ((mouseX - lastMouseX) * delta)) - 5; + float calculatedMouseY = (lastMouseY + ((mouseY - lastMouseY) * delta)) - 5; + + RenderUtil.drawRectangle(matrices, spaceX + (width / 2) - 1, spaceY + 17, 1, 1, ColorUtil.WHITE); + + matrices.translate(calculatedMouseX, calculatedMouseY, 0); // Woah KodeToad, good use of translate + + RenderUtil.drawOutline( + matrices, + spaceX + (width / 2) - 1, + spaceY + 17, + 11, + 11, + ColorUtil.WHITE + ); + } matrices.pop(); } + public void onPlayerDirectionChange(float prevPitch, float prevYaw, float pitch, float yaw) { + // Implementation credit goes to TheKodeToad + // This project has the author's approval to use this + // https://github.com/Sol-Client/Client/blob/main/game/src/main/java/io/github/solclient/client/mod/impl/hud/keystrokes/KeystrokesMod.java + mouseX += (yaw - prevYaw) / 7F; + mouseY += (pitch - prevPitch) / 7F; + // 0, 0 will be the center of the HUD element + float halfWidth = getWidth() / 2f; + mouseX = MathHelper.clamp(mouseX, -halfWidth + 4, halfWidth - 4); + mouseY = MathHelper.clamp(mouseY, -13, 13); + } + @Override public boolean tickable() { return true; @@ -117,6 +165,10 @@ public void tick() { for (Keystroke stroke : keystrokes) { stroke.offset = pos; } + lastMouseX = mouseX; + lastMouseY = mouseY; + mouseX *= .75f; + mouseY *= .75f; } @Override @@ -125,10 +177,10 @@ protected boolean getShadowDefault() { } @Override - public void renderPlaceholder(MatrixStack matrices) { + public void renderPlaceholder(MatrixStack matrices, float delta) { matrices.push(); renderPlaceholderBackground(matrices); - renderHud(matrices); + renderHud(matrices, delta); hovered = false; matrices.pop(); } @@ -165,20 +217,33 @@ public boolean movable() { @Override public List> getConfigurationOptions() { List> options = super.getConfigurationOptions(); + options.add(mouseMovement); options.add(textColor); options.add(pressedTextColor); options.add(shadow); options.add(background); options.add(backgroundColor); options.add(pressedBackgroundColor); + options.add(outline); + options.add(outlineColor); + options.add(pressedOutlineColor); return options; } + public void onMouseMovementOption(boolean value) { + int baseHeight = 61; + if (value) { + baseHeight += 36; + } + height = baseHeight; + onSizeUpdate(); + } + public class Keystroke { - public final KeyBinding key; - public final KeystrokeRenderer render; - public Rectangle bounds; - public DrawPosition offset; + protected final KeyBinding key; + protected final KeystrokeRenderer render; + protected Rectangle bounds; + protected DrawPosition offset; private float start = -1; private final int animTime = 100; private boolean wasPressed = false; @@ -190,26 +255,16 @@ public Keystroke(Rectangle bounds, DrawPosition offset, KeyBinding key, Keystrok this.render = render; } - public void setPos(int x, int y) { - bounds = new Rectangle(x, y, bounds.width(), bounds.height()); - } - - public void setDimensions(int width, int height) { - bounds = new Rectangle(bounds.x(), bounds.y(), width, height); - } - - public void setBounds(int x, int y, int width, int height) { - bounds = new Rectangle(x, y, width, height); - } - public void renderStroke(MatrixStack matrices) { if (key.isPressed() != wasPressed) { start = Util.getMeasuringTimeMs(); } + Rectangle rect = bounds.offset(offset); if (background.getValue()) { - fillRect(matrices, bounds.offset(offset), - getColor() - ); + fillRect(matrices, rect, getColor()); + } + if (outline.getValue()) { + outlineRect(matrices, rect, getOutlineColor()); } if ((Util.getMeasuringTimeMs() - start) / animTime >= 1) { start = -1; @@ -222,6 +277,10 @@ private float getPercentPressed() { } public Color getColor() { + if (backgroundColor.getValue().getChroma().isActive() || pressedBackgroundColor.getValue().getChroma().isActive()) { + // Can't blend chroma ATM + return key.isPressed() ? pressedBackgroundColor.getValue() : backgroundColor.getValue(); + } return key.isPressed() ? ColorUtil.blend(backgroundColor.getValue(), pressedBackgroundColor.getValue(), getPercentPressed() ) : @@ -232,6 +291,21 @@ public Color getColor() { ); } + public Color getOutlineColor() { + if (outlineColor.getValue().getChroma().isActive() || pressedOutlineColor.getValue().getChroma().isActive()) { + // Can't blend chroma ATM + return key.isPressed() ? pressedOutlineColor.getValue() : outlineColor.getValue(); + } + return key.isPressed() ? ColorUtil.blend(outlineColor.getValue(), pressedOutlineColor.getValue(), + getPercentPressed() + ) : + ColorUtil.blend( + pressedOutlineColor.getValue(), + outlineColor.getValue(), + getPercentPressed() + ); + } + public Color getFGColor() { return key.isPressed() ? ColorUtil.blend(textColor.getValue(), pressedTextColor.getValue(), getPercentPressed()) : ColorUtil.blend( diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PlayerHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PlayerHud.java new file mode 100644 index 0000000..0cfc3be --- /dev/null +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PlayerHud.java @@ -0,0 +1,120 @@ +package io.github.darkkronicle.kronhud.gui.hud; + +import com.mojang.blaze3d.systems.RenderSystem; +import io.github.darkkronicle.kronhud.config.KronConfig; +import io.github.darkkronicle.kronhud.config.KronDouble; +import io.github.darkkronicle.kronhud.gui.AbstractHudEntry; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.DiffuseLighting; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.Quaternion; +import net.minecraft.util.math.Vec3f; + +import java.util.List; + +public class PlayerHud extends AbstractHudEntry { + + public static final Identifier ID = new Identifier("kronhud", "playerhud"); + + private final KronDouble rotation = new KronDouble("rotation", ID.getPath(), 0, 0, 360); + + public PlayerHud() { + super(62, 94); + } + + @Override + public void render(MatrixStack matrices, float delta) { + matrices.push(); + scale(matrices); + if (background.getValue() && backgroundColor.getValue().alpha() > 0) { + fillRect(matrices, getRenderBounds(), backgroundColor.getValue()); + } + if (outline.getValue() && outlineColor.getValue().alpha() > 0) { + outlineRect(matrices, getRenderBounds(), outlineColor.getValue()); + } + renderPlayer(getTruePos().x() + 31 * getScale(), getTruePos().y() + 86 * getScale(), delta); + matrices.pop(); + } + + @Override + public void renderPlaceholder(MatrixStack matrices, float delta) { + matrices.push(); + renderPlaceholderBackground(matrices); + scale(matrices); + renderPlayer(getTruePos().x() + 31 * getScale(), getTruePos().y() + 86 * getScale(), 0); // If delta was delta, it would start jittering + hovered = false; + matrices.pop(); + } + + public void renderPlayer(double x, double y, float delta) { + MinecraftClient client = MinecraftClient.getInstance(); + if (client.player == null) { + return; + } + + MatrixStack matrixStack = RenderSystem.getModelViewStack(); + matrixStack.push(); + matrixStack.translate(x, y, 1050); + matrixStack.scale(1, 1, -1); + + RenderSystem.applyModelViewMatrix(); + MatrixStack nextStack = new MatrixStack(); + nextStack.translate(0, 0, 1000); + float scale = getScale() * 40; + nextStack.scale(scale, scale, scale); + + Quaternion quaternion = Vec3f.POSITIVE_Z.getDegreesQuaternion(180.0F); + + nextStack.multiply(quaternion); + // Rotate to whatever is wanted. Also make sure to offset the yaw + float deltaYaw = client.player.getYaw(delta); + nextStack.multiply(new Quaternion(new Vec3f(0, 1, 0), deltaYaw - 180 + rotation.getValue().floatValue(), true)); + + // Save these to set them back later + float pastYaw = client.player.getYaw(); + float pastPrevYaw = client.player.prevYaw; + + DiffuseLighting.method_34742(); + EntityRenderDispatcher renderer = client.getEntityRenderDispatcher(); + renderer.setRotation(quaternion); + renderer.setRenderShadows(false); + + VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(); + + renderer.render(client.player, 0, 0, 0, 0, delta, nextStack, immediate, 15728880); + immediate.draw(); + renderer.setRenderShadows(true); + matrixStack.pop(); + + client.player.setYaw(pastYaw); + client.player.prevYaw = pastPrevYaw; + + RenderSystem.applyModelViewMatrix(); + DiffuseLighting.enableGuiDepthLighting(); + } + + + @Override + public Identifier getId() { + return ID; + } + + @Override + public boolean movable() { + return true; + } + + @Override + public List> getConfigurationOptions() { + List> options = super.getConfigurationOptions(); + options.add(rotation); + options.add(background); + options.add(backgroundColor); + options.add(outline); + options.add(outlineColor); + return options; + } +} diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PotionsHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PotionsHud.java index ad33630..7cacec5 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PotionsHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PotionsHud.java @@ -27,7 +27,7 @@ public PotionsHud() { } @Override - public void render(MatrixStack matrices) { + public void render(MatrixStack matrices, float delta) { matrices.push(); scale(matrices); ArrayList effects = new ArrayList<>(client.player.getStatusEffects()); @@ -58,7 +58,7 @@ public void render(MatrixStack matrices) { } @Override - public void renderPlaceholder(MatrixStack matrices) { + public void renderPlaceholder(MatrixStack matrices, float delta) { matrices.push(); renderPlaceholderBackground(matrices); scale(matrices); diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ScoreboardHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ScoreboardHud.java index bbe1412..111f5d3 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ScoreboardHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/ScoreboardHud.java @@ -57,7 +57,7 @@ public ScoreboardHud() { } @Override - public void render(MatrixStack matrices) { + public void render(MatrixStack matrices, float delta) { matrices.push(); scale(matrices); Scoreboard scoreboard = this.client.world.getScoreboard(); @@ -78,7 +78,7 @@ public void render(MatrixStack matrices) { } @Override - public void renderPlaceholder(MatrixStack matrices) { + public void renderPlaceholder(MatrixStack matrices, float delta) { matrices.push(); renderPlaceholderBackground(matrices); scale(matrices); @@ -118,14 +118,14 @@ private void renderScoreboardSidebar(MatrixStack matrices, ScoreboardObjective o } maxWidth = maxWidth + 2; - if (maxWidth > width) { + if (maxWidth > getWidth()) { maxWidth = 200; } int scoresSize = scores.size(); int scoreHeight = scoresSize * 9; DrawPosition pos = getPos(); - Rectangle bounds = getBounds(); + Rectangle bounds = getRenderBounds(); Rectangle inside = new Rectangle(pos.x(), pos.y(), maxWidth, scoreHeight + 9); Rectangle calculated = new Rectangle(bounds.x() + bounds.width() - inside.width(), bounds.y() + (bounds.height() / 2 - inside.height() / 2), inside.width(), inside.height()); @@ -134,15 +134,20 @@ private void renderScoreboardSidebar(MatrixStack matrices, ScoreboardObjective o int num = 0; int textOffset = scoreX - 2; + if (background.getValue() && backgroundColor.getValue().alpha() > 0) { + fillRect(matrices, getRenderBounds(), backgroundColor.getValue()); + } + if (outline.getValue() && outlineColor.getValue().alpha() > 0) { + outlineRect(matrices, getRenderBounds(), outlineColor.getValue()); + } + for (Pair scoreboardPlayerScoreTextPair : scoresWText) { ++num; ScoreboardPlayerScore scoreboardPlayerScore2 = scoreboardPlayerScoreTextPair.getFirst(); Text scoreText = scoreboardPlayerScoreTextPair.getSecond(); String score = "" + scoreboardPlayerScore2.getScore(); int relativeY = scoreY - num * 9; - if (background.getValue()) { - fillRect(matrices, new Rectangle(textOffset, relativeY, maxWidth, 9), backgroundColor.getValue()); - } + if (shadow.getValue()) { client.textRenderer.drawWithShadow(matrices, scoreText, (float) scoreX, (float) relativeY, -1); @@ -178,6 +183,8 @@ public List> getConfigurationOptions() { options.add(background); options.add(topColor); options.add(backgroundColor); + options.add(outline); + options.add(outlineColor); options.add(shadow); options.add(scores); options.add(scoreColor); diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/SpeedHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/SpeedHud.java index a047d6a..a5b723a 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/SpeedHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/SpeedHud.java @@ -30,7 +30,7 @@ public String getValue() { } else { speed = vec.length(); } - return FORMATTER.format(speed) + " BPT"; + return FORMATTER.format(speed * 20) + " BPS"; } @Override @@ -42,6 +42,6 @@ public List> getConfigurationOptions() { @Override public String getPlaceholder() { - return "0.95 BPT"; + return "4.35 BPS"; } } diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/screen/HudEditScreen.java b/src/main/java/io/github/darkkronicle/kronhud/gui/screen/HudEditScreen.java index 3bc2288..ad53d12 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/screen/HudEditScreen.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/screen/HudEditScreen.java @@ -3,6 +3,8 @@ import io.github.darkkronicle.darkkore.config.options.Option; import io.github.darkkronicle.darkkore.gui.Tab; +import io.github.darkkronicle.darkkore.settings.DarkKoreConfig; +import io.github.darkkronicle.darkkore.util.render.RenderUtil; import io.github.darkkronicle.kronhud.KronHUD; import io.github.darkkronicle.kronhud.config.ConfigHandler; import io.github.darkkronicle.kronhud.gui.AbstractHudEntry; @@ -62,10 +64,11 @@ private Text getSnappingButtonText() { @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + RenderUtil.fill(matrices, 0, 0, width, height, DarkKoreConfig.getInstance().screenBackgroundColor.getValue()); super.render(matrices, mouseX, mouseY, delta); Optional entry = KronHUD.hudManager.getEntryXY(mouseX, mouseY); entry.ifPresent(abstractHudEntry -> abstractHudEntry.setHovered(true)); - KronHUD.hudManager.renderPlaceholder(matrices); + KronHUD.hudManager.renderPlaceholder(matrices, delta); if (mouseDown && snap != null) { snap.renderSnaps(matrices); } @@ -79,7 +82,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { mouseDown = true; if (entry.isPresent()) { current = entry.get(); - offset = new DrawPosition((int) Math.round(mouseX - current.getX()), (int) Math.round(mouseY - current.getY())); + offset = new DrawPosition((int) Math.round(mouseX - current.getTruePos().x()), (int) Math.round(mouseY - current.getTruePos().y())); updateSnapState(); return true; } else { @@ -94,8 +97,8 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { private void updateSnapState() { if (snapEnabled && current != null) { List bounds = KronHUD.hudManager.getAllBounds(); - bounds.remove(current.getScaledBounds()); - snap = new SnappingHelper(bounds, current.getScaledBounds()); + bounds.remove(current.getTrueBounds()); + snap = new SnappingHelper(bounds, current.getTrueBounds()); } else if (snap != null) { snap = null; } @@ -123,7 +126,7 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del current.setXY((int) mouseX - offset.x(), (int) mouseY - offset.y()); if (snap != null) { Integer snapX, snapY; - snap.setCurrent(current.getScaledBounds()); + snap.setCurrent(current.getTrueBounds()); if ((snapX = snap.getCurrentXSnap()) != null) { current.setX(snapX); } diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/screen/ModMenuImpl.java b/src/main/java/io/github/darkkronicle/kronhud/gui/screen/ModMenuImpl.java index 8830b20..9edce69 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/screen/ModMenuImpl.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/screen/ModMenuImpl.java @@ -7,6 +7,6 @@ public class ModMenuImpl implements ModMenuApi { @Override public ConfigScreenFactory getModConfigScreenFactory() { - return HudEditScreen::new; + return parent -> new HudEditScreen(null); } } diff --git a/src/main/java/io/github/darkkronicle/kronhud/hooks/KronHudHooks.java b/src/main/java/io/github/darkkronicle/kronhud/hooks/KronHudHooks.java index 167b4e7..d02cdb4 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/hooks/KronHudHooks.java +++ b/src/main/java/io/github/darkkronicle/kronhud/hooks/KronHudHooks.java @@ -18,6 +18,14 @@ public class KronHudHooks { } )); + public static final Event PLAYER_DIRECTION_CHANGE = EventFactory.createArrayBacked(PlayerDirectionCallback.class, listeners -> ( + (prevPitch, prevYaw, pitch, yaw) -> { + for (PlayerDirectionCallback listener : listeners) { + listener.onChange(prevPitch, prevYaw, pitch, yaw); + } + } + )); + public static final Event KEYBIND_CHANGE = EventFactory.createArrayBacked( KeyBindingCallback.ChangeBind.class, listeners -> ( (key) -> { @@ -25,7 +33,8 @@ public class KronHudHooks { listener.setBoundKey(key); } } - )); + ) + ); public static final Event KEYBIND_PRESS = EventFactory.createArrayBacked( KeyBindingCallback.OnPress.class, listeners -> ( @@ -34,7 +43,8 @@ public class KronHudHooks { listener.onPress(key); } } - )); + ) + ); } diff --git a/src/main/java/io/github/darkkronicle/kronhud/hooks/PlayerDirectionCallback.java b/src/main/java/io/github/darkkronicle/kronhud/hooks/PlayerDirectionCallback.java new file mode 100644 index 0000000..2fb1a09 --- /dev/null +++ b/src/main/java/io/github/darkkronicle/kronhud/hooks/PlayerDirectionCallback.java @@ -0,0 +1,7 @@ +package io.github.darkkronicle.kronhud.hooks; + +public interface PlayerDirectionCallback { + + void onChange(float prevPitch, float prevYaw, float pitch, float yaw); + +} diff --git a/src/main/java/io/github/darkkronicle/kronhud/mixins/MixinEntity.java b/src/main/java/io/github/darkkronicle/kronhud/mixins/MixinEntity.java new file mode 100644 index 0000000..1a84b33 --- /dev/null +++ b/src/main/java/io/github/darkkronicle/kronhud/mixins/MixinEntity.java @@ -0,0 +1,33 @@ +package io.github.darkkronicle.kronhud.mixins; + +import io.github.darkkronicle.kronhud.hooks.KronHudHooks; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.MathHelper; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Entity.class) +public abstract class MixinEntity { + + @Shadow public abstract float getPitch(); + + @Shadow public abstract float getYaw(); + + @Inject(method = "changeLookDirection", at = @At("HEAD")) + private void updateLookDirection(double mouseDeltaX, double mouseDeltaY, CallbackInfo ci) { + if (mouseDeltaX == 0 && mouseDeltaY == 0) { + return; + } + + float prevPitch = getPitch(); + float prevYaw = getYaw(); + float pitch = prevPitch + (float) (mouseDeltaY * .15); + float yaw = prevYaw + (float) (mouseDeltaX * .15); + pitch = MathHelper.clamp(pitch, -90.0F, 90.0F); + KronHudHooks.PLAYER_DIRECTION_CHANGE.invoker().onChange(prevPitch, prevYaw, pitch, yaw); + } + +} diff --git a/src/main/java/io/github/darkkronicle/kronhud/util/DrawUtil.java b/src/main/java/io/github/darkkronicle/kronhud/util/DrawUtil.java index e24f9a3..0c38a27 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/util/DrawUtil.java +++ b/src/main/java/io/github/darkkronicle/kronhud/util/DrawUtil.java @@ -14,6 +14,13 @@ public static void fillRect(MatrixStack matrices, Rectangle rectangle, Color col ); } + public static void rectOutline(MatrixStack matrices, Rectangle rectangle, Color color) { + RenderUtil.drawOutline(matrices, rectangle.x(), rectangle.y(), rectangle.width(), + rectangle.height(), + color + ); + } + public static void outlineRect(MatrixStack matrices, Rectangle rectangle, Color color) { RenderUtil.drawOutline(matrices, rectangle.x(), rectangle.y(), rectangle.width(), rectangle.height(), color); } diff --git a/src/main/java/io/github/darkkronicle/kronhud/util/ItemUtil.java b/src/main/java/io/github/darkkronicle/kronhud/util/ItemUtil.java index 62f3ab3..25a4c3d 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/util/ItemUtil.java +++ b/src/main/java/io/github/darkkronicle/kronhud/util/ItemUtil.java @@ -129,38 +129,42 @@ public List compare(List list1, List list return list; } - // Minecraft has decided to not use matrixstack's in their itemrender class. So this is implementing itemRenderer stuff with matrices. - @SuppressWarnings("deprecation") - public void renderGuiItemModel(MatrixStack matrices, ItemStack stack, float x, float y) { + public void renderGuiItemModel(float scale, ItemStack stack, float x, float y) { MinecraftClient client = MinecraftClient.getInstance(); - BakedModel model = client.getItemRenderer().getModel(stack, null, client.player, (int) (x * y)); + BakedModel model = client.getItemRenderer().getModel(stack, null, null, (int) (x * y)); client.getTextureManager().getTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).setFilter(false, false); RenderSystem.setShaderTexture(0, SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE); RenderSystem.enableBlend(); RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - matrices.push(); - matrices.translate(x, y, (100.0F + client.getItemRenderer().zOffset)); - matrices.translate(8.0D, 8.0D, 0.0D); - matrices.scale(1.0F, -1.0F, 1.0F); - matrices.scale(16.0F, 16.0F, 16.0F); + MatrixStack modelStack = RenderSystem.getModelViewStack(); + modelStack.push(); + modelStack.scale(scale, scale, 0); + modelStack.translate(x, y, (100.0F + client.getItemRenderer().zOffset)); + modelStack.translate(8.0D, 8.0D, 0.0D); + modelStack.scale(1.0F, -1.0F, 1.0F); + modelStack.scale(16.0F, 16.0F, 16.0F); + RenderSystem.applyModelViewMatrix(); + MatrixStack nextStack = new MatrixStack(); + VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(); boolean bl = !model.isSideLit(); if (bl) { DiffuseLighting.disableGuiDepthLighting(); } - client.getItemRenderer().renderItem(stack, ModelTransformation.Mode.GUI, false, matrices, immediate, 15728880, - OverlayTexture.DEFAULT_UV, model); + client.getItemRenderer().renderItem( + stack, ModelTransformation.Mode.GUI, false, nextStack, immediate, 15728880, OverlayTexture.DEFAULT_UV, model + ); immediate.draw(); RenderSystem.enableDepthTest(); if (bl) { DiffuseLighting.enableGuiDepthLighting(); } - matrices.pop(); + modelStack.pop(); RenderSystem.applyModelViewMatrix(); } diff --git a/src/main/resources/assets/kronhud/lang/en_us.json b/src/main/resources/assets/kronhud/lang/en_us.json index a79b008..8a8a158 100644 --- a/src/main/resources/assets/kronhud/lang/en_us.json +++ b/src/main/resources/assets/kronhud/lang/en_us.json @@ -15,22 +15,31 @@ "hud.kronhud.actionbarhud": "Action Bar", "hud.kronhud.scoreboardhud": "Scoreboard", "hud.kronhud.togglesprint": "ToggleSprint", + "hud.kronhud.playerhud": "Player Model HUD", "option.kronhud.enabled": "Enabled", "option.kronhud.enabled.comment": "Whether to show the HUD.", "option.kronhud.scale": "Scale", "option.kronhud.scale.comment": "The scale of the HUD.", "option.kronhud.background": "Background", "option.kronhud.background.comment": "Whether to show the background.", + "option.kronhud.outline": "Outline", + "option.kronhud.outline.comment": "Whether to show the outline.", "option.kronhud.shadow": "Text Shadow", "option.kronhud.shadow.comment": "Whether to display a shadow underneath text.", "option.kronhud.backgroundcolor": "Background Color", "option.kronhud.backgroundcolor.comment": "The background color.", + "option.kronhud.outlinecolor": "Outline Color", + "option.kronhud.outlinecolor.comment": "The outline color.", "option.kronhud.textcolor": "Text Color", "option.kronhud.textcolor.comment": "The text color.", "option.kronhud.keystrokehud.heldbackgroundcolor": "Held Background Color", "option.kronhud.keystrokehud.heldbackgroundcolor.comment": "The background color (when held).", "option.kronhud.keystrokehud.heldtextcolor": "Held Text Color", - "option.kronhud.keystrokehud.heldtextcolor.comment": "The text colour (when held).", + "option.kronhud.keystrokehud.heldtextcolor.comment": "The text color (when held).", + "option.kronhud.keystrokehud.heldoutlinecolor": "Held Outline Color", + "option.kronhud.keystrokehud.heldoutlinecolor.comment": "The outline color (when held).", + "option.kronhud.keystrokehud.mousemovement": "Show Mouse Movement", + "option.kronhud.keystrokehud.mousemovement.comment": "Enable this to add a section to the keystrokes that displays mouse movement.", "option.kronhud.crosshairhud.defaultcolor": "Default Color", "option.kronhud.crosshairhud.defaultcolor.comment": "The crosshair color.", "option.kronhud.crosshairhud.entitycolor": "Entity Color", @@ -93,6 +102,8 @@ "option.kronhud.togglesprint.randomPlaceholder.comment": "Whether to use a random placeholder from Minecraft's splash texts.", "option.kronhud.togglesprint.placeholder": "Placeholder", "option.kronhud.togglesprint.placeholder.comment": "The Placeholder to use when no keys are pressed/toggled.", + "option.kronhud.playerhud.rotation": "Model Rotation", + "option.kronhud.playerhud.rotation.comment": "The rotation of the model.", "screen.kronhud.set": "Edit HUD", "button.kronhud.configuration": "Configuration", "button.kronhud.configure": "Configure", @@ -127,6 +138,7 @@ "hud.kronhud.scoreboardhud.info": "Modify the Vanilla Scoreboard", "hud.kronhud.actionbarhud.info": "Modify the Vanilla Action Bar", "hud.kronhud.togglesprint.info": "A HUD component to show sprint/sneak information", + "hud.kronhud.playerhud.info": "Renders a smaller version of the player model", "texts.kronhud.optiontype.info.hudconfig": "Enable/Disable this module from showing. Modify specific options by clicking the gear.", "kronhud.component.toggle.true": "&aActive", "kronhud.component.toggle.false": "&cDisabled" diff --git a/src/main/resources/kronhud.mixins.json b/src/main/resources/kronhud.mixins.json index f50f589..c16bfe6 100644 --- a/src/main/resources/kronhud.mixins.json +++ b/src/main/resources/kronhud.mixins.json @@ -5,6 +5,7 @@ "mixins": [ ], "client": [ + "MixinEntity", "AccessorBossBarHud", "AccessorMinecraftClient", "MixinBossBarHud",