Skip to content

Commit

Permalink
Maintenance stuff. ArmorHud has scalable text.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Sep 8, 2024
1 parent d66b0a9 commit 16c34fb
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 35 deletions.
64 changes: 50 additions & 14 deletions src/main/java/dev/heliosclient/hud/hudelements/ArmorHud.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dev.heliosclient.hud.hudelements;

import dev.heliosclient.event.SubscribeEvent;
import dev.heliosclient.event.events.heliosclient.FontChangeEvent;
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.managers.FontManager;
import dev.heliosclient.module.settings.*;
import dev.heliosclient.util.fontutils.fxFontRenderer;
import dev.heliosclient.util.player.PlayerUtils;
import dev.heliosclient.util.render.Renderer2D;
import net.minecraft.client.font.TextRenderer;
Expand All @@ -31,6 +32,17 @@ public class ArmorHud extends HudElement {
.defaultListOption(Bar)
.build()
);
private final DoubleSetting textSize = sgSettings.add(new DoubleSetting.Builder()
.name("Text Size")
.description("Size of the durability shown")
.min(1)
.max(10)
.defaultValue(4d)
.onSettingChange(this)
.roundingPlace(1)
.shouldRender(()-> !damageMode.isOption(Bar))
.build()
);
private final BooleanSetting damageModeAbove = sgSettings.add(new BooleanSetting.Builder()
.name("DamageMode Above")
.description("Shows damage of the armor above the item")
Expand All @@ -46,6 +58,8 @@ public class ArmorHud extends HudElement {
.build()
);

fxFontRenderer cFontRenderer;

public ArmorHud() {
super(DATA);
addSettingGroup(sgSettings);
Expand All @@ -54,10 +68,31 @@ public ArmorHud() {
this.height = 20 * 4 + 4;
this.renderBg.setValue(true);
this.rounded.setValue(true);

}

@Override
public void onSettingChange(Setting<?> setting) {
super.onSettingChange(setting);

if(setting == textSize){
this.cFontRenderer = new fxFontRenderer(FontManager.fonts,textSize.getFloat());
}
}
@SubscribeEvent
public void onFontChange(FontChangeEvent e){
if(mc.getWindow() == null) return;

this.cFontRenderer = new fxFontRenderer(e.getFonts(),textSize.getFloat());
}

@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
super.renderElement(drawContext, textRenderer);
if(cFontRenderer == null){
this.cFontRenderer = new fxFontRenderer(FontManager.fonts,textSize.getFloat());
}

ItemStack helmet, chestplate, leggings, boots;

if(isInHudEditor && mc.player == null){
Expand All @@ -74,11 +109,11 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
return;
}

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

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

drawContext.drawItem(helmet,x,y);
Expand Down Expand Up @@ -118,9 +153,9 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {

private int getDamageBarY(int orgY){
if(damageModeAbove.value){
return orgY - 2;
return damageMode.isOption(Bar) ? orgY - 2 : orgY - (int) Renderer2D.getCustomStringHeight(cFontRenderer);
} else{
return orgY + 16;
return damageMode.isOption(Bar) ? orgY + 16 : orgY + 12 + (int) Renderer2D.getCustomStringHeight(cFontRenderer);
}
}

Expand All @@ -147,15 +182,16 @@ public void drawDamageBar(DrawContext context, ItemStack stack, int x, int y){

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

float scaledX = (x / 0.5f);
float scaledY = (y / 0.5f);
float scaledX = (x / scale);
float scaledY = (y / scale);
context.drawText(mc.textRenderer,text,(int)scaledX,(int)scaledY - 1,color,false);
context.getMatrices().pop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class AutoTotem extends Module_ {

int totemCount = 0;
private final TickTimer timer = new TickTimer();
boolean lastNoTotemNotified = false;
boolean lastNoTotemNotified = false, didTotemPop = false;

public AutoTotem() {
super("AutoTotem","Automatically holds a totem in your hand", Categories.COMBAT);
Expand Down Expand Up @@ -103,16 +103,16 @@ public void onKey(KeyPressedEvent e){
public void onTick(TickEvent.WORLD event) {
if(!HeliosClient.shouldUpdate()) return;


totemCount = InventoryUtils.getItemCountInInventory(Items.TOTEM_OF_UNDYING);
if(totemCount > 0){
lastNoTotemNotified = false;
timer.incrementAndEvery(delay.getInt(),()->{
if(mc.player.getOffHandStack().getItem() == Items.TOTEM_OF_UNDYING || mc.player.playerScreenHandler != mc.player.currentScreenHandler){
return;
}
if(always.value || isPlayerLow()) {
if(always.value || isPlayerLow() || didTotemPop) {
doAutoTotem();
didTotemPop = false;

if(log.value){
ChatUtils.sendHeliosMsg("Restocked Totem, Totems left: " + InventoryUtils.getItemCountInInventory(Items.TOTEM_OF_UNDYING));
Expand All @@ -132,7 +132,7 @@ public void doAutoTotem(){
return;
}

//if is hotbar then swap item with offhand super fast.
//if is hotbar then swap item with offhand super-fast.
if(itemSlot >= 0 && itemSlot < 9){
InventoryUtils.swapToSlot(itemSlot,true);
mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN));
Expand All @@ -151,6 +151,7 @@ public void packetReceive(PacketEvent.RECEIVE e){
if(e.packet instanceof EntityStatusS2CPacket packet){
if(packet.getStatus() != 35 || packet.getEntity(mc.world) != mc.player) return;

didTotemPop = true;
timer.setTicks(delay.getInt());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ private boolean isInvisible(LivingEntity entity) {
}

public boolean shouldAttack() {
float baseTimer = (!smartDelay.value) ? attackDelay.getFloat() : 0.5f;
float baseTimer = (!smartDelay.value) ? attackDelay.getInt() : 0.5f;
if (tpsSync.get()) baseTimer = baseTimer / (TickRate.INSTANCE.getTPS() / 20);

if (smartDelay.value) {
return mc.player.getAttackCooldownProgress(baseTimer) >= 1;
} else {
return timer.incrementAndEvery((int) baseTimer);
return baseTimer == 0 || timer.incrementAndEvery((int) baseTimer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.heliosclient.util.render.Renderer3D;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.text.Text;

import java.awt.*;

Expand All @@ -22,8 +23,19 @@ public EntityOwner() {
public void onRender3d(Render3DEvent event) {
for (Entity entity : MC.world.getEntities()) {
if (entity instanceof TameableEntity tameableEntity) {
if (tameableEntity.getOwner() != null) {
String text = tameableEntity.getOwner().getDisplayName().getString();
if (tameableEntity.isTamed()) {
String text;
if(tameableEntity.getOwner() == null) {
text = "Failed to get Owner";
}else{
Text displayName = tameableEntity.getOwner().getDisplayName();
if(displayName == null){
text = "Owner UUID: " + tameableEntity.getOwner().getUuidAsString();
Renderer3D.drawText(FontRenderers.Mid_fxfontRenderer, "Owner name not found", (float) entity.getPos().x, (float) entity.getEyeY() + 0.5f, (float) entity.getPos().z, -(FontRenderers.Mid_fxfontRenderer.getStringWidth("Owner name not found") / 2.0f) + 0.1f, -FontRenderers.Mid_fxfontRenderer.getStringHeight(text) - 2, 1f, Color.RED.getRGB());
}else {
text = displayName.getString();
}
}
Renderer3D.drawText(FontRenderers.Mid_fxfontRenderer, text, (float) entity.getPos().x, (float) entity.getEyeY() + 0.5f, (float) entity.getPos().z, -(FontRenderers.Mid_fxfontRenderer.getStringWidth(text) / 2.0f) + 0.1f, 0, 1f, Color.WHITE.getRGB());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ private void updateScale(float speed, boolean close) {
if (ModuleManager.get(GUI.class).bounceAnimation.value) {
long currentTime = System.currentTimeMillis();
if (close) {
this.scale -= speed * Easing.ease(EasingType.BOUNCE_OUT, MathHelper.clamp((currentTime - timeOnOpen) / 1500f, 0, 1));
this.scale -= speed * Easing.ease(EasingType.BOUNCE_OUT, MathHelper.clamp((currentTime - timeOnOpen) / 2000f, 0, 1));
if (this.scale <= 0.0) {
super.close();
shouldClose = false;
}
} else {
this.scale += speed * Easing.ease(EasingType.CUBIC_IN, MathHelper.clamp((currentTime - timeOnOpen) / 1000f, 0, 1));
this.scale += speed * Easing.ease(EasingType.QUADRATIC_IN, MathHelper.clamp((currentTime - timeOnOpen) / 1000f, 0, 1));
}
this.scale = MathHelper.clamp(this.scale, 0.0f, 1f);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public <T extends HudElement> void addInstanceToList(Class<? extends T> clazz) {
HudManager.INSTANCE.addHudElement(instance);
HudElement lastHudElement = HudManager.INSTANCE.hudElements.get(HudManager.INSTANCE.hudElements.size() - 1);

lastHudElement.posX = HudElement.NUMBER_OF_LINES/2 - 1;
lastHudElement.posY = HudElement.NUMBER_OF_LINES/2 - 1;
lastHudElement.posX = (HeliosClient.MC.getWindow().getScaledWidth()/2) % HudElement.NUMBER_OF_LINES;
lastHudElement.posY = (HeliosClient.MC.getWindow().getScaledHeight()/2) % HudElement.NUMBER_OF_LINES;
lastHudElement.distanceX = (HeliosClient.MC.getWindow().getScaledWidth() - lastHudElement.width)/2;
lastHudElement.distanceY = (HeliosClient.MC.getWindow().getScaledHeight() - lastHudElement.height)/2;
lastHudElement.x = (HeliosClient.MC.getWindow().getScaledWidth() - lastHudElement.width)/2;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/heliosclient/util/TickTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public void increment(){

// Checks if ticks have passed since the last reset
public boolean every(int ticks) {
boolean didTimerLapse = getElapsedTicks() >= ticks;
if (didTimerLapse) {
if (getElapsedTicks() >= ticks) {
restartTimer();
return true;
}
return didTimerLapse;
return false;
}


Expand Down
15 changes: 13 additions & 2 deletions src/main/java/dev/heliosclient/util/animation/Easing.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.heliosclient.util.animation;

import net.minecraft.util.math.MathHelper;

public class Easing {
public static float ease(EasingType type, float t) {
return switch (type) {
Expand Down Expand Up @@ -103,6 +101,7 @@ public static float bounceIn(float t) {
public static float bounceOut(float t) {
float n1 = 7.5625f;
float d1 = 2.75f;

if (t < 1 / d1) {
return n1 * t * t;
} else if (t < 2 / d1) {
Expand All @@ -117,6 +116,18 @@ public static float bounceOut(float t) {
}
}

public static float bounceOutWithOvershoot(float t) {
float overshoot = 1.4f; // Adjust this value to control the overshoot

float bounce = bounceOut(t);
if (t < 0.5f) {
return bounce * overshoot;
} else {
return bounce * (2 - overshoot);
}
}


public static float bounceInOut(float t) {
if (t < 0.5) {
return bounceIn(t * 2) * 0.5f;
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/dev/heliosclient/util/player/DamageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.registry.tag.EntityTypeTags;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.explosion.Explosion;
import net.minecraft.world.explosion.ExplosionBehavior;
Expand Down Expand Up @@ -47,16 +46,23 @@ public static double calculateBedBlastDamage(Vec3d bedLocation, LivingEntity tar
* @see LivingEntity#computeFallDamage(float, float)
*/
public static float calcFallDamage(LivingEntity entity){
return calcFallDamage(entity,entity.fallDistance);
}
/**
* Directly taken from with some changes:
* @see LivingEntity#computeFallDamage(float, float)
*/
public static float calcFallDamage(LivingEntity entity, float fallDistance){
if (entity.hasStatusEffect(StatusEffects.SLOW_FALLING) || entity.hasStatusEffect(StatusEffects.LEVITATION)) return 0;

if (entity.getType().isIn(EntityTypeTags.FALL_DAMAGE_IMMUNE)) {
return 0;
} else {
StatusEffectInstance statusEffectInstance = entity.getStatusEffect(StatusEffects.JUMP_BOOST);
float f = statusEffectInstance == null ? 0.0F : (float)(statusEffectInstance.getAmplifier() + 1);
float fallDamageBeforeRedu = HeliosClient.MC.player.fallDistance - 3.0F - f;

float fallDamageBeforeRedu = fallDistance - 3.0F - f;

return (float) Math.ceil(calculateReductions(fallDamageBeforeRedu,entity,entity.getDamageSources().fall()));
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/heliosclient/util/render/Renderer2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,12 @@ public static void drawRoundedGradientRectangle(Matrix4f matrix, Color color1, C
* @param radius Radius of the quadrants / the rounded gradient rectangle
*/
public static void drawRoundedGradientRectangle(Matrix4f matrix, Color color1, Color color2, Color color3, Color color4, float x, float y, float width, float height, float radius, boolean TL, boolean TR, boolean BL, boolean BR) {
//Draw a single rounded rectangle for same colors
if(color1 == color2 && color2 == color3 && color3 == color4){
drawRoundedRectangle(matrix, x, y, TL, TR, BL, BR, width, height, radius, color1.getRGB());
return;
}

RenderSystem.enableBlend();
RenderSystem.colorMask(false, false, false, true);
RenderSystem.clearColor(0.0F, 0.0F, 0.0F, 0.0F);
Expand Down

0 comments on commit 16c34fb

Please sign in to comment.