diff --git a/src/main/java/net/kyrptonaught/lemclienthelper/config/ModMenuIntegration.java b/src/main/java/net/kyrptonaught/lemclienthelper/config/ModMenuIntegration.java index 6a67a80..be2ae6f 100644 --- a/src/main/java/net/kyrptonaught/lemclienthelper/config/ModMenuIntegration.java +++ b/src/main/java/net/kyrptonaught/lemclienthelper/config/ModMenuIntegration.java @@ -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")); @@ -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")); diff --git a/src/main/java/net/kyrptonaught/lemclienthelper/hud/DamageIndicatorHudRenderer.java b/src/main/java/net/kyrptonaught/lemclienthelper/hud/DamageIndicatorHudRenderer.java new file mode 100644 index 0000000..f26ec9f --- /dev/null +++ b/src/main/java/net/kyrptonaught/lemclienthelper/hud/DamageIndicatorHudRenderer.java @@ -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(); + } +} diff --git a/src/main/java/net/kyrptonaught/lemclienthelper/hud/HudConfig.java b/src/main/java/net/kyrptonaught/lemclienthelper/hud/HudConfig.java index bcc740d..ba41314 100644 --- a/src/main/java/net/kyrptonaught/lemclienthelper/hud/HudConfig.java +++ b/src/main/java/net/kyrptonaught/lemclienthelper/hud/HudConfig.java @@ -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; } diff --git a/src/main/java/net/kyrptonaught/lemclienthelper/hud/HudMod.java b/src/main/java/net/kyrptonaught/lemclienthelper/hud/HudMod.java index 47679cc..840662e 100644 --- a/src/main/java/net/kyrptonaught/lemclienthelper/hud/HudMod.java +++ b/src/main/java/net/kyrptonaught/lemclienthelper/hud/HudMod.java @@ -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"; @@ -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); } diff --git a/src/main/java/net/kyrptonaught/lemclienthelper/mixin/DamageIndicator/DamageAngleMixin.java b/src/main/java/net/kyrptonaught/lemclienthelper/mixin/DamageIndicator/DamageAngleMixin.java new file mode 100644 index 0000000..96c7f1d --- /dev/null +++ b/src/main/java/net/kyrptonaught/lemclienthelper/mixin/DamageIndicator/DamageAngleMixin.java @@ -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); + } + } +} diff --git a/src/main/resources/assets/lemclienthelper/lang/en_us.json b/src/main/resources/assets/lemclienthelper/lang/en_us.json index dba56c1..941e66e 100644 --- a/src/main/resources/assets/lemclienthelper/lang/en_us.json +++ b/src/main/resources/assets/lemclienthelper/lang/en_us.json @@ -30,6 +30,10 @@ "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", @@ -37,5 +41,9 @@ "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)" } \ No newline at end of file diff --git a/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_0.png b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_0.png new file mode 100644 index 0000000..fd39f19 Binary files /dev/null and b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_0.png differ diff --git a/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_1.png b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_1.png new file mode 100644 index 0000000..f7c3827 Binary files /dev/null and b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_1.png differ diff --git a/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_2.png b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_2.png new file mode 100644 index 0000000..8a4c7b6 Binary files /dev/null and b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_2.png differ diff --git a/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_3.png b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_3.png new file mode 100644 index 0000000..9554389 Binary files /dev/null and b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_3.png differ diff --git a/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_4.png b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_4.png new file mode 100644 index 0000000..628a485 Binary files /dev/null and b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_4.png differ diff --git a/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_5.png b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_5.png new file mode 100644 index 0000000..c0e9894 Binary files /dev/null and b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_5.png differ diff --git a/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_6.png b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_6.png new file mode 100644 index 0000000..ade3e13 Binary files /dev/null and b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_6.png differ diff --git a/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_7.png b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_7.png new file mode 100644 index 0000000..f2f27b6 Binary files /dev/null and b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_7.png differ diff --git a/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_full.png b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_full.png new file mode 100644 index 0000000..c36420e Binary files /dev/null and b/src/main/resources/assets/lemclienthelper/textures/hud/damage_indicator_full.png differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 0b30aef..6357a50 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -10,7 +10,8 @@ "contributors": [ "Virusnest", "S_N00B", - "DBTDerpbox" + "DBTDerpbox", + "Awsome_Creeper9" ], "contact": { "homepage": "https://github.com/Legacy-Edition-Minigames/lemclienthelper", diff --git a/src/main/resources/lemclienthelper.mixins.json b/src/main/resources/lemclienthelper.mixins.json index 51e5dae..00ec891 100644 --- a/src/main/resources/lemclienthelper.mixins.json +++ b/src/main/resources/lemclienthelper.mixins.json @@ -15,7 +15,8 @@ "SmallInv.invs.MultipleScreenMixin", "SpectateSquaker.MinecraftClientMixin", "SyncedKeybinds.GameOptionsMixin", - "TakeEverything.ScreenHandlerMixin" + "TakeEverything.ScreenHandlerMixin", + "DamageIndicator.DamageAngleMixin" ], "injectors": { "defaultRequire": 1