Moves the status bar adjustments to HudHook

They really do belong there. Hooking into the profiler was just a crutch.
This commit is contained in:
Markil3
2021-03-02 10:27:29 -07:00
parent 37df8eef93
commit 8798691dc0
3 changed files with 90 additions and 108 deletions

View File

@@ -58,7 +58,8 @@ public class HudHook
cancellable = true) cancellable = true)
public void startCrosshair(MatrixStack stack, CallbackInfo callbackInfo) public void startCrosshair(MatrixStack stack, CallbackInfo callbackInfo)
{ {
if (TimerUtils.drawCrosshair(MinecraftClient.getInstance().getTickDelta())) if (TimerUtils.drawCrosshair(MinecraftClient.getInstance()
.getTickDelta()))
{ {
callbackInfo.cancel(); callbackInfo.cancel();
} }
@@ -97,7 +98,8 @@ public class HudHook
int x, int x,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
if (TimerUtils.drawJumpbar(stack, MinecraftClient.getInstance().getTickDelta())) if (TimerUtils.drawJumpbar(stack,
MinecraftClient.getInstance().getTickDelta()))
{ {
callbackInfo.cancel(); callbackInfo.cancel();
} }
@@ -139,7 +141,8 @@ public class HudHook
int x, int x,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
if (TimerUtils.drawExperience(stack, MinecraftClient.getInstance().getTickDelta())) if (TimerUtils.drawExperience(stack,
MinecraftClient.getInstance().getTickDelta()))
{ {
callbackInfo.cancel(); callbackInfo.cancel();
} }
@@ -183,6 +186,85 @@ public class HudHook
return stack; return stack;
} }
/**
* Adjusts the armor GUI.
*
* @param matrices
* @param callbackInfo
*/
@Inject(method = "renderStatusBars(Lnet/minecraft/client/util" +
"/math/MatrixStack;)V", at = @At(value = "INVOKE", target = "Lnet" +
"/minecraft/util/profiler/Profiler;push(Ljava/lang/String;)V"))
public void renderArmor(MatrixStack matrices, CallbackInfo callbackInfo)
{
if (TimerUtils.drawArmor())
{
TimerUtils.setAlpha(0F);
}
}
/**
* Adjusts the health GUI.
*
* @param matrices
* @param callbackInfo
*/
@Inject(method = "renderStatusBars(Lnet/minecraft/client/util" +
"/math/MatrixStack;)V", at = @At(value = "INVOKE", target = "Lnet" +
"/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V",
ordinal = 0))
public void renderHealth(MatrixStack matrices, CallbackInfo callbackInfo)
{
/*
* Resets the transparency from the previous call.
*/
TimerUtils.setAlpha(1F);
if (TimerUtils.drawHealth(MinecraftClient.getInstance().getTickDelta()))
{
TimerUtils.setAlpha(0F);
}
}
/**
* Adjusts the food GUI.
*
* @param matrices
* @param callbackInfo
*/
@Inject(method = "renderStatusBars(Lnet/minecraft/client/util" +
"/math/MatrixStack;)V", at = @At(value = "INVOKE", target = "Lnet" +
"/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V",
ordinal = 1))
public void renderFood(MatrixStack matrices, CallbackInfo callbackInfo)
{
/*
* Resets the transparency from the previous call.
*/
TimerUtils.setAlpha(1F);
if (TimerUtils.drawHunger(MinecraftClient.getInstance().getTickDelta()))
{
TimerUtils.setAlpha(0F);
}
}
/**
* Resets the air GUI.
*
* @param matrices
* @param callbackInfo
*/
@Inject(method = "renderStatusBars(Lnet/minecraft/client/util" +
"/math/MatrixStack;)V", at = @At(value = "INVOKE", target = "Lnet" +
"/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V",
ordinal = 2))
public void renderAir(MatrixStack matrices, CallbackInfo callbackInfo)
{
/*
* Resets the color so that nothing else is bothered.
*/
TimerUtils.setAlpha(1F);
}
@ModifyVariable(method = "renderStatusBars(Lnet/minecraft/client/util" + @ModifyVariable(method = "renderStatusBars(Lnet/minecraft/client/util" +
"/math/MatrixStack;)V", at = @At("TAIL")) "/math/MatrixStack;)V", at = @At("TAIL"))
public MatrixStack finishStatus(MatrixStack stack) public MatrixStack finishStatus(MatrixStack stack)
@@ -204,7 +286,8 @@ public class HudHook
cancellable = true) cancellable = true)
public void startMountHealth(MatrixStack stack, CallbackInfo callbackInfo) public void startMountHealth(MatrixStack stack, CallbackInfo callbackInfo)
{ {
if (TimerUtils.drawMountHealth(stack, MinecraftClient.getInstance().getTickDelta())) if (TimerUtils.drawMountHealth(stack,
MinecraftClient.getInstance().getTickDelta()))
{ {
callbackInfo.cancel(); callbackInfo.cancel();
} }
@@ -260,7 +343,8 @@ public class HudHook
public boolean shouldRenderPotion(StatusEffectInstance effect) public boolean shouldRenderPotion(StatusEffectInstance effect)
{ {
currentEffect = effect; currentEffect = effect;
return TimerUtils.updatePotion(effect, MinecraftClient.getInstance().getTickDelta()); return TimerUtils.updatePotion(effect,
MinecraftClient.getInstance().getTickDelta());
} }
/** /**

View File

@@ -1,101 +0,0 @@
/**
* Copyright (C) 2021 Markil 3
* <p>
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* <p>
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
package markil3.immersive_hud.mixin;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.profiler.DummyProfiler;
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;
import markil3.immersive_hud.TimerUtils;
/**
* This class hooks into the profiler to trigger color changes for the status
* indicators.
*
* @author Markil 3
* @version 0.1-1.16.4-fabric
*/
@Mixin(DummyProfiler.class)
public class ProfilerHook
{
/**
* Hooks into the profiler to add logic to drawing armor.
*
* @param section - The profiler section
* @param callbackInfo
*
* @since 0.1-1.16.4-fabric
*/
@Inject(method = "push", at = @At(value = "TAIL"))
public void renderArmor(String section, CallbackInfo callbackInfo)
{
if (section.equals("armor"))
{
if (TimerUtils.drawArmor())
{
TimerUtils.setAlpha(0F);
}
}
}
/**
* Hooks into the profiler to add logic to drawing status bars besides
* armor.
*
* @param section - The profiler section
* @param callbackInfo
*
* @since 0.1-1.16.4-fabric
*/
@Inject(method = "swap", at = @At(value = "TAIL"))
public void renderStatus(String section, CallbackInfo callbackInfo)
{
switch (section)
{
case "health":
/*
* Resets the transparency from the previous call.
*/
TimerUtils.setAlpha(1F);
if (TimerUtils.drawHealth(MinecraftClient.getInstance().getTickDelta()))
{
TimerUtils.setAlpha(0F);
}
break;
case "food":
/*
* Resets the transparency from the previous call.
*/
TimerUtils.setAlpha(1F);
if (TimerUtils.drawHunger(MinecraftClient.getInstance().getTickDelta()))
{
TimerUtils.setAlpha(0F);
}
break;
case "air":
/*
* Resets the color so that nothing else is bothered.
*/
TimerUtils.setAlpha(1F);
break;
}
}
}

View File

@@ -8,8 +8,7 @@
"client": [ "client": [
"ClientPlayerHook", "ClientPlayerHook",
"HeldItemHook", "HeldItemHook",
"HudHook", "HudHook"
"ProfilerHook"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1