Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
panItem.setToolTipWithNewLine("key.lemclienthelper.serverconfig.panscale.tooltip");


//Hud
//Armor Hud
HudConfig clientGUI = HudMod.getConfig();
ConfigSection clientGUISection = new ConfigSection(configScreen, Text.translatable("key.lemclienthelper.clientgui"));

Expand All @@ -104,6 +104,16 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {

//clientGUISection.addConfigItem(new ArmorHudPreviewItem(Text.translatable("key.lemclienthelper.clientgui.displaypreview"), clientGUI.enabled, false));

// Damage Indicator
ConfigSection damageIndicatorSection = new ConfigSection(configScreen, Text.translatable("key.lemclienthelper.damageindicator"));

damageIndicatorSection.addConfigItem(new BooleanItem(Text.translatable("key.lemclienthelper.damageindicator.enabled"), clientGUI.enableDamageIndicator, true).setSaveConsumer(val -> clientGUI.enableDamageIndicator = val));

IntegerItem damageIndicatorFadeOut = (IntegerItem) damageIndicatorSection.addConfigItem(new IntegerItem(Text.translatable("key.lemclienthelper.damageindicator.fadeout"), clientGUI.damageIndicatorFadeOut, 16));
damageIndicatorFadeOut.setMinMax(0, 200);
damageIndicatorFadeOut.setSaveConsumer(val -> clientGUI.damageIndicatorFadeOut = val);
damageIndicatorFadeOut.setToolTipWithNewLine("key.lemclienthelper.damageindicator.fadeout.tooltip");


//Small Inv
ConfigSection smallInvSection = new ConfigSection(configScreen, Text.translatable("key.lemclienthelper.smallinv"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package net.kyrptonaught.lemclienthelper.hud;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.*;
import net.minecraft.util.Identifier;
import org.joml.Matrix4f;

import java.util.List;

public class DamageIndicatorHudRenderer {
private static final Identifier[] INDICATORS = new Identifier[]{
new Identifier("lemclienthelper", "textures/hud/damage_indicator_0.png"),
new Identifier("lemclienthelper", "textures/hud/damage_indicator_1.png"),
new Identifier("lemclienthelper", "textures/hud/damage_indicator_2.png"),
new Identifier("lemclienthelper", "textures/hud/damage_indicator_3.png"),
new Identifier("lemclienthelper", "textures/hud/damage_indicator_4.png"),
new Identifier("lemclienthelper", "textures/hud/damage_indicator_5.png"),
new Identifier("lemclienthelper", "textures/hud/damage_indicator_6.png"),
new Identifier("lemclienthelper", "textures/hud/damage_indicator_7.png")
};

public static void onHudRender(DrawContext context, float v) {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player != null && HudMod.shouldDisplayDmgIndicator()) {
int height = client.getWindow().getScaledHeight();
int width = client.getWindow().getScaledWidth();

context.getMatrices().push();
context.getMatrices().translate(width / 2f, height / 2f, 0);
context.getMatrices().scale(1f, 1f, 1f);
context.getMatrices().translate(-8.5, -8, 0);
context.setShaderColor(1f, 1f, 1f, 1f);

if (HudMod.shouldDisplayDmgIndicator()) {
int[] time = HudMod.getDMGTimeAngle();
draw(context, INDICATORS[0], 0, 0, Math.max(1 - (time[0] / ((float) HudMod.getConfig().damageIndicatorFadeOut)), 0));
draw(context, INDICATORS[1], 0, 0, Math.max(1 - (time[1] / ((float) HudMod.getConfig().damageIndicatorFadeOut)), 0));
draw(context, INDICATORS[2], 0, 0, Math.max(1 - (time[2] / ((float) HudMod.getConfig().damageIndicatorFadeOut)), 0));
draw(context, INDICATORS[3], 0, 0, Math.max(1 - (time[3] / ((float) HudMod.getConfig().damageIndicatorFadeOut)), 0));
draw(context, INDICATORS[4], 0, 0, Math.max(1 - (time[4] / ((float) HudMod.getConfig().damageIndicatorFadeOut)), 0));
draw(context, INDICATORS[5], 0, 0, Math.max(1 - (time[5] / ((float) HudMod.getConfig().damageIndicatorFadeOut)), 0));
draw(context, INDICATORS[6], 0, 0, Math.max(1 - (time[6] / ((float) HudMod.getConfig().damageIndicatorFadeOut)), 0));
draw(context, INDICATORS[7], 0, 0, Math.max(1 - (time[7] / ((float) HudMod.getConfig().damageIndicatorFadeOut)), 0));
}
context.setShaderColor(1f, 1f, 1f, 1f);
context.getMatrices().pop();
}
}

private static void draw(DrawContext context, Identifier texture, float x, float y, float alpha) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.setShader(GameRenderer::getPositionColorTexProgram);
RenderSystem.enableBlend();
Matrix4f matrix4f = context.getMatrices().peek().getPositionMatrix();
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE);
bufferBuilder.vertex(matrix4f, x, y, 0f).color(1f, 1f, 1f, alpha).texture(0f, 0f).next();
bufferBuilder.vertex(matrix4f, x, y + 16, 0f).color(1, 1f, 1f, alpha).texture(0f, 1f).next();
bufferBuilder.vertex(matrix4f, x + 16, y + 16, 0f).color(1f, 1f, 1f, alpha).texture(1f, 1f).next();
bufferBuilder.vertex(matrix4f, x + 16, y, 0f).color(1f, 1f, 1f, alpha).texture(1f, 0f).next();
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
RenderSystem.disableBlend();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ public class HudConfig implements AbstractConfigFile {
public float xOffset = 20;

public float transparency =.75f;

public boolean enableDamageIndicator = true;

public int damageIndicatorFadeOut = 16;
}
85 changes: 84 additions & 1 deletion src/main/java/net/kyrptonaught/lemclienthelper/hud/HudMod.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package net.kyrptonaught.lemclienthelper.hud;

import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.kyrptonaught.lemclienthelper.LEMClientHelperMod;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.Identifier;
import java.util.Arrays;

public class HudMod {
public static String MOD_ID = "hud";
Expand All @@ -13,24 +16,104 @@ public class HudMod {
private static final Identifier ARMOR_HUD_DISABLE = new Identifier("armorhud", "armor_hud_render_disable");

public static boolean SHOULD_RENDER_ARMOR = false;

public static int[] DMG_TIME_ANGLE = {100, 100, 100, 100, 100, 100, 100, 100};

public static void onInitialize() {
LEMClientHelperMod.configManager.registerFile(MOD_ID, new HudConfig());
LEMClientHelperMod.configManager.load(MOD_ID);
//register hud's here
HudRenderCallback.EVENT.register(ArmorHudRenderer::onHudRender);
HudRenderCallback.EVENT.register(DamageIndicatorHudRenderer::onHudRender);

for (int i = 0; i < DMG_TIME_ANGLE.length; i++) {
DMG_TIME_ANGLE[i] = getConfig().damageIndicatorFadeOut;
}

ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> SHOULD_RENDER_ARMOR = false);

ClientPlayNetworking.registerGlobalReceiver(ARMOR_HUD_ENABLE, (client, handler, buf, responseSender) -> SHOULD_RENDER_ARMOR = true);
ClientPlayNetworking.registerGlobalReceiver(ARMOR_HUD_DISABLE, (client, handler, buf, responseSender) -> SHOULD_RENDER_ARMOR = false);
ClientTickEvents.END_CLIENT_TICK.register(client -> {onClientTick();});
}

public static void onClientTick() {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player != null) {
// new dmg taken
if (client.player.hurtTime == 9) {
//check if it's a directional damage before resetting all angles
boolean reset = true;
int[] times = getDMGTimeAngle();
for (int i = 0; i < times.length; i++) {
if (times[i] == 0) {
reset = false;
break;
}
}
if (reset) {
resetAllTimes();
}
}
}

for (int i = 0; i < DMG_TIME_ANGLE.length; i++) {
if (DMG_TIME_ANGLE[i] < getConfig().damageIndicatorFadeOut) {
DMG_TIME_ANGLE[i]++;
}
}
}

public static boolean shouldDisplay() {
return getConfig().alwaysEnabled || SHOULD_RENDER_ARMOR;
}

public static boolean shouldDisplayDmgIndicator() {
return getConfig().enableDamageIndicator;
}

public static void resetTimeForAngle(float angle) {
if (Math.abs(angle) <= (45.0/2.0)) {
DMG_TIME_ANGLE[1] = 0;
}
else if (Math.abs(angle) <= 45.0 + (45.0/2.0)) {
if (angle > 0) {
DMG_TIME_ANGLE[2] = 0;
}
else {
DMG_TIME_ANGLE[0] = 0;
}
}
else if (Math.abs(angle) <= 90.0 + (45.0/2.0)) {
if (angle > 0) {
DMG_TIME_ANGLE[4] = 0;
}
else {
DMG_TIME_ANGLE[3] = 0;
}
}
else if (Math.abs(angle) <= 180.0 - (45.0/2.0)) {
if (angle > 0) {
DMG_TIME_ANGLE[7] = 0;
}
else {
DMG_TIME_ANGLE[5] = 0;
}
}
else {
DMG_TIME_ANGLE[6] = 0;
}
}

public static void resetAllTimes() {
for (int i = 0; i < DMG_TIME_ANGLE.length; i++) {
DMG_TIME_ANGLE[i] = 0;
}
}

public static int[] getDMGTimeAngle() {
return Arrays.copyOf(DMG_TIME_ANGLE, DMG_TIME_ANGLE.length);
}

public static HudConfig getConfig() {
return (HudConfig) LEMClientHelperMod.configManager.getConfig(MOD_ID);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.kyrptonaught.lemclienthelper.mixin.DamageIndicator;

import net.kyrptonaught.lemclienthelper.hud.HudMod;
import net.minecraft.entity.LivingEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.math.MathHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(LivingEntity.class)
public abstract class DamageAngleMixin {
@Inject(method = "animateDamage", at = @At("HEAD"))
private void onAnimateDamage(float yaw, CallbackInfo ci) {
// Ensure this logic only runs for the local player on the client
if ((Object)this instanceof ClientPlayerEntity player) {
// Fix MC related stupidity:
float angle = MathHelper.wrapDegrees(yaw - 90);
HudMod.resetTimeForAngle(angle);
}
}
}
10 changes: 9 additions & 1 deletion src/main/resources/assets/lemclienthelper/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@
"key.lemclienthelper.clientgui.xOffset.tooltip": "Sets the X Offset the Armor HUD will be rendered at.\nValues between 0-100.",
"key.lemclienthelper.clientgui.transparency": "Armor HUD Transparency",
"key.lemclienthelper.clientgui.transparency.tooltip": "Sets the transparency the Armor HUD will be rendered at.\nValues between 0.0-1.0.",
"key.lemclienthelper.damageindicator": "Damage Direction Indicator",
"key.lemclienthelper.damageindicator.enabled":"Enable Damage Direction Indicator",
"key.lemclienthelper.damageindicator.fadeout": "Fadeout Time",
"key.lemclienthelper.damageindicator.fadeout.tooltip": "Sets the fade out time (in ticks) for the damage direction indicator.\nValues between 0-200.",
"key.lemclienthelper.syncedkeybinds": "Synced Keybinds",
"key.lemclienthelper.syncedkeys": "Synced Keys",
"key.lemclienthelper.syncedkeys.tooltip": "These are keybindings synced from a LEM server\nOnly functional on LEM servers",
"key.lemclienthelper.serverconfig": "Local Server Config",
"key.lemclienthelper.serverconfig.guiscale": "GUI Scale",
"key.lemclienthelper.serverconfig.panscale": "Panorama Scale",
"key.lemclienthelper.serverconfig.guiscale.tooltip": "Sets your GUI Scale 1-4 on official LEM servers.\nSetting this value to 0 will use your option set on the server",
"key.lemclienthelper.serverconfig.panscale.tooltip": "Sets your Panorama Scale 1-4 on official LEM servers.\nSetting this value to 0 will use your option set on the server"
"key.lemclienthelper.serverconfig.panscale.tooltip": "Sets your Panorama Scale 1-4 on official LEM servers.\nSetting this value to 0 will use your option set on the server",
"key.lemclienthelper.autogg": "Auto GG",
"key.lemclienthelper.autogg.enabled": "Enabled",
"key.lemclienthelper.autogg.message": "Message",
"key.lemclienthelper.autogg.delay": "Delay (in ticks)"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"contributors": [
"Virusnest",
"S_N00B",
"DBTDerpbox"
"DBTDerpbox",
"Awsome_Creeper9"
],
"contact": {
"homepage": "https://github.com/Legacy-Edition-Minigames/lemclienthelper",
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/lemclienthelper.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"SmallInv.invs.MultipleScreenMixin",
"SpectateSquaker.MinecraftClientMixin",
"SyncedKeybinds.GameOptionsMixin",
"TakeEverything.ScreenHandlerMixin"
"TakeEverything.ScreenHandlerMixin",
"DamageIndicator.DamageAngleMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down