Skip to content

Commit

Permalink
[+] ArmorHud, bunch of refactors. Changed some of the visual code and…
Browse files Browse the repository at this point in the history
… some reformats.
  • Loading branch information
tanishisherewithhh committed Aug 22, 2024
1 parent 39fc312 commit c486f77
Show file tree
Hide file tree
Showing 36 changed files with 257 additions and 58 deletions.
14 changes: 6 additions & 8 deletions src/main/java/dev/heliosclient/hud/HudElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,16 @@ public class HudElement implements ISettingChange, ISaveAndLoad, Listener {
int startX, startY;
private static int snapSize = 120;

// Default settings
// This is a lot of complete customisation.
// Todo: Add radius setting for rounded background
public BooleanSetting renderBg = sgUI.add(new BooleanSetting.Builder()
.name("Render background")
.description("Render the background for the element")
.value(false)
.defaultValue(false)
.onSettingChange(this)
.build());


// Default settings
// This is a lot of complete customisation.
// Todo: Add radius setting for rounded background
public BooleanSetting rounded = sgUI.add(new BooleanSetting.Builder()
.name("Rounded background")
.description("Rounds the background of the element for better visuals")
Expand Down Expand Up @@ -167,8 +165,8 @@ public void renderEditor(DrawContext drawContext, TextRenderer textRenderer, int

if (this.shiftDown && drawContext != null) {
// Calculate the size of each snap box
int snapBoxWidth = drawContext.getScaledWindowWidth() / this.snapSize;
int snapBoxHeight = drawContext.getScaledWindowHeight() / this.snapSize;
int snapBoxWidth = drawContext.getScaledWindowWidth() / snapSize;
int snapBoxHeight = drawContext.getScaledWindowHeight() / snapSize;

// Calculate the index of the snap box that the new position would be in
int snapBoxX = newX / snapBoxWidth;
Expand Down Expand Up @@ -496,7 +494,7 @@ public void loadFromFile(Map<String, Object> MAP) {
}

public static void setSnapSize(int snapSize){
HudElement.snapSize = MathHelper.clamp(snapSize,0,mc.getWindow().getScaledWidth() * mc.getWindow().getScaledHeight());
HudElement.snapSize = MathHelper.clamp(snapSize,1,mc.getWindow().getScaledWidth() * mc.getWindow().getScaledHeight());
}

public static int getSnapSize() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/heliosclient/hud/HudElementList.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public HudElementList() {
registerElement(ClientTag.DATA);
registerElement(ModuleList.DATA);
registerElement(Radar.DATA);
registerElement(ArmorHud.DATA);
registerElement(CompassHud.DATA);
registerElement(CompactData.DATA);
registerElement(PlayerModel.DATA);
Expand Down
167 changes: 167 additions & 0 deletions src/main/java/dev/heliosclient/hud/hudelements/ArmorHud.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package dev.heliosclient.hud.hudelements;

import dev.heliosclient.hud.HudElement;
import dev.heliosclient.hud.HudElementData;
import dev.heliosclient.module.settings.BooleanSetting;
import dev.heliosclient.module.settings.CycleSetting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.util.fontutils.FontRenderers;
import dev.heliosclient.util.player.PlayerUtils;
import dev.heliosclient.util.render.Renderer2D;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;

import java.util.List;

import static dev.heliosclient.hud.hudelements.ArmorHud.DamageMode.Bar;

public class ArmorHud extends HudElement {
public SettingGroup sgSettings = new SettingGroup("Settings");

public static HudElementData<ArmorHud> DATA = new HudElementData<>("ArmorHUD","Displays your armor and its damage",ArmorHud::new);

private final CycleSetting damageMode = sgSettings.add(new CycleSetting.Builder()
.name("DamageMode")
.description("Mode to show the armor's damage in")
.value(List.of(DamageMode.values()))
.onSettingChange(this)
.defaultListOption(Bar)
.build()
);
private final BooleanSetting damageModeAbove = sgSettings.add(new BooleanSetting.Builder()
.name("DamageMode Above")
.description("Shows damage of the armor above the item")
.defaultValue(false)
.onSettingChange(this)
.build()
);
private final BooleanSetting vertical = sgSettings.add(new BooleanSetting.Builder()
.name("Vertical")
.description("Shows the armor in a vertical manner")
.defaultValue(false)
.onSettingChange(this)
.build()
);

public ArmorHud() {
super(DATA);
addSettingGroup(sgSettings);

this.width = 20;
this.height = 20 * 4 + 4;
this.renderBg.setValue(true);
this.rounded.setValue(true);
}
@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
super.renderElement(drawContext, textRenderer);
ItemStack helmet, chestplate, leggings, boots;

if(isInHudEditor || mc.player == null){
helmet = Items.NETHERITE_HELMET.getDefaultStack();
chestplate = Items.NETHERITE_CHESTPLATE.getDefaultStack();
leggings = Items.NETHERITE_LEGGINGS.getDefaultStack();
boots = Items.NETHERITE_BOOTS.getDefaultStack();
}else{
helmet = mc.player.getEquippedStack(EquipmentSlot.HEAD);
chestplate = mc.player.getEquippedStack(EquipmentSlot.CHEST);
leggings = mc.player.getEquippedStack(EquipmentSlot.LEGS);
boots = mc.player.getEquippedStack(EquipmentSlot.FEET);
}

int x = this.x + 2;
int y = this.y;

if(this.damageModeAbove.value){
y = y + 3;
}

drawContext.drawItem(helmet,x,y);
drawDamageBar(drawContext,helmet,x,getDamageBarY(y));

if(vertical.value){
y += 20;
}else{
x += 20;
}

drawContext.drawItem(chestplate,x,y);
drawDamageBar(drawContext,chestplate,x,getDamageBarY(y));

if(vertical.value){
y += 20;
}else{
x += 20;
}

drawContext.drawItem(leggings,x,y);
drawDamageBar(drawContext,leggings,x,getDamageBarY(y));

if(vertical.value){
y += 20;
}else{
x += 20;
}

drawContext.drawItem(boots,x,y);
drawDamageBar(drawContext,boots,x,getDamageBarY(y));

// + 18 for the first item.
this.width = x - this.x + 18;
this.height = y - this.y + 20;
}

private int getDamageBarY(int orgY){
if(damageModeAbove.value){
return orgY - 2;
} else{
return orgY + 16;
}
}

public void drawDamageBar(DrawContext context, ItemStack stack, int x, int y){
//Gives percentage between 0 and 1
double durabilityPercentage = ((double) stack.getMaxDamage() - (double) stack.getDamage()) / (double) stack.getMaxDamage();
int barWidth = Math.round((float)durabilityPercentage * 16);
int color = PlayerUtils.getDurabilityColor(durabilityPercentage);

switch ((DamageMode)damageMode.getOption()){
case Percentage -> {
drawText(context, String.format("%.0f",durabilityPercentage * 100) + "%",x,y,color);
}
case Number -> {
drawText(context,String.valueOf(stack.getMaxDamage() - stack.getDamage()),x,y,color);
}
case Bar -> {
Renderer2D.drawRectangle(context.getMatrices().peek().getPositionMatrix(), x,y + 0.1f,barWidth,1,color);
}
}

}

private void drawText(DrawContext context,String text, int x, int y,int color){
if(!Renderer2D.isVanillaRenderer()){
x += (int) (18 - FontRenderers.Super_Small_fxfontRenderer.getStringWidth(text))/2f;
FontRenderers.Super_Small_fxfontRenderer.drawString(context.getMatrices(),text,x,y,color);
}else{
context.getMatrices().push();
context.getMatrices().scale(0.5f,0.5f,1);
x += (18 - (mc.textRenderer.getWidth(text) * 0.5f))/2f;

float scaledX = (x / 0.5f);
float scaledY = (y / 0.5f);
context.drawText(mc.textRenderer,text,(int)scaledX,(int)scaledY - 1,color,false);
context.getMatrices().pop();
}
}

public enum DamageMode {
Bar,
Percentage,
Number
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.modules.render.Xray;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.render.VertexConsumerProvider;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/dev/heliosclient/mixin/MixinPlayerEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.modules.movement.Sprint;
import dev.heliosclient.module.modules.world.SpeedMine;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.player.FreeCamEntity;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
Expand All @@ -18,13 +18,11 @@
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.stat.Stat;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
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.Redirect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import dev.heliosclient.module.settings.BooleanSetting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.system.HeliosExecutor;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.ChunkUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.blocks.ChunkUtils;
import dev.heliosclient.util.player.RotationSimulator;
import dev.heliosclient.util.player.RotationUtils;
import net.minecraft.block.entity.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import dev.heliosclient.event.events.TickEvent;
import dev.heliosclient.module.Categories;
import dev.heliosclient.module.Module_;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.EntityUtils;
import net.minecraft.util.math.BlockPos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.settings.*;
import dev.heliosclient.system.mixininterface.IVec3d;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.ChatUtils;
import dev.heliosclient.util.player.DamageUtils;
import dev.heliosclient.util.player.InventoryUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.settings.*;
import dev.heliosclient.module.settings.lists.BlockListSetting;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.player.InventoryUtils;
import dev.heliosclient.util.player.PlayerUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import dev.heliosclient.module.settings.BooleanSetting;
import dev.heliosclient.module.settings.DoubleSetting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import net.minecraft.item.BlockItem;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import dev.heliosclient.module.settings.DropDownSetting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.module.settings.lists.ItemListSetting;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.ChatUtils;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.player.InventoryUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.module.settings.lists.BlockListSetting;
import dev.heliosclient.system.HeliosExecutor;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.ChunkChecker;
import dev.heliosclient.util.ChunkUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.blocks.ChunkChecker;
import dev.heliosclient.util.blocks.ChunkUtils;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.render.Renderer3D;
import dev.heliosclient.util.render.color.LineColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.settings.*;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.HoleUtils;
import dev.heliosclient.util.blocks.HoleUtils;
import dev.heliosclient.util.render.Renderer3D;
import dev.heliosclient.util.render.color.QuadColor;
import net.minecraft.util.math.Box;
Expand All @@ -15,7 +15,7 @@
import java.awt.*;
import java.util.List;

import static dev.heliosclient.util.HoleUtils.HoleType.*;
import static dev.heliosclient.util.blocks.HoleUtils.HoleType.*;

public class HoleESP extends Module_ {
static Color TRANSPARENT_BLUE = new Color(0, 30, 175, 179);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import dev.heliosclient.module.settings.DoubleSetting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.player.BlockIterator;
import dev.heliosclient.util.render.FrustumUtils;
import dev.heliosclient.util.blocks.BlockIterator;
import dev.heliosclient.util.render.Renderer3D;
import dev.heliosclient.util.render.color.QuadColor;
import net.minecraft.util.math.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.settings.BooleanSetting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.util.ChunkUtils;
import dev.heliosclient.util.blocks.ChunkUtils;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.render.Renderer3D;
import dev.heliosclient.util.render.color.LineColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import dev.heliosclient.module.modules.render.hiteffect.particles.TextParticle;
import dev.heliosclient.module.settings.*;
import dev.heliosclient.module.settings.lists.ParticleListSetting;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.InputBox;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import dev.heliosclient.event.listener.Listener;
import dev.heliosclient.managers.EventManager;
import dev.heliosclient.module.modules.render.hiteffect.HitEffectParticle;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.render.Renderer3D;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dev.heliosclient.module.settings.BooleanSetting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.util.TimerUtils;
import dev.heliosclient.util.player.BlockIterator;
import dev.heliosclient.util.blocks.BlockIterator;
import net.minecraft.block.Blocks;
import net.minecraft.network.packet.c2s.play.TeleportConfirmC2SPacket;
import net.minecraft.util.math.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import dev.heliosclient.module.settings.RGBASetting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.system.HeliosExecutor;
import dev.heliosclient.util.ChunkChecker;
import dev.heliosclient.util.blocks.ChunkChecker;
import dev.heliosclient.util.render.Renderer3D;
import dev.heliosclient.util.render.color.QuadColor;
import net.minecraft.block.BlockState;
Expand Down
Loading

0 comments on commit c486f77

Please sign in to comment.