Makes some changes to make the methods here resemble that of the Forge implementation more.
This commit is contained in:
@@ -178,6 +178,26 @@ public class EventBus
|
||||
*/
|
||||
private static float experienceProgress = -1;
|
||||
|
||||
/**
|
||||
* Sets the transparency level of the next drawn element.
|
||||
*
|
||||
* @param alpha - The transparency, from 0 to 1.
|
||||
*/
|
||||
public static void setAlpha(float alpha)
|
||||
{
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the transparency level.
|
||||
*
|
||||
* @see #setAlpha(float)
|
||||
*/
|
||||
public static void resetAlpha()
|
||||
{
|
||||
setAlpha(1.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run whenever the player clicks a mouse button. This brings the hands into
|
||||
* view, and briefly brings the health and hunger into view if the held item
|
||||
@@ -314,6 +334,8 @@ public class EventBus
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
Entity entity = mc.getCameraEntity();
|
||||
boolean changed = false;
|
||||
boolean canceled = false;
|
||||
|
||||
if (mc.crosshairTarget != null && mc.crosshairTarget
|
||||
.getType() != HitResult.Type.MISS)
|
||||
{
|
||||
@@ -334,25 +356,19 @@ public class EventBus
|
||||
if (changed || mainHandLock || offHandLock || crosshairTime
|
||||
> 0)
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(crosshairTime > 0 ?
|
||||
setAlpha(Main.getAlpha(crosshairTime > 0 ?
|
||||
crosshairTime :
|
||||
VISUAL_TIME));
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
0F);
|
||||
canceled = true;
|
||||
}
|
||||
if (crosshairTime > 0)
|
||||
{
|
||||
crosshairTime--;
|
||||
}
|
||||
return false;
|
||||
return canceled;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -405,15 +421,10 @@ public class EventBus
|
||||
{
|
||||
mountTime--;
|
||||
}
|
||||
|
||||
if (mountTime > 0)
|
||||
{
|
||||
/*
|
||||
* Renders it along with health.
|
||||
*/
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(mountTime));
|
||||
setAlpha(Main.getAlpha(mountTime));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -436,20 +447,11 @@ public class EventBus
|
||||
*/
|
||||
if (healthTime > 0)
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(healthTime));
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
0.0F);
|
||||
}
|
||||
setAlpha(Main.getAlpha(healthTime));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the health bar, adjusting the alpha as
|
||||
@@ -466,7 +468,7 @@ public class EventBus
|
||||
* health bar won't disappear, allowing the player to be constantly
|
||||
* reminded of their low health.
|
||||
*/
|
||||
final float CONST_BOUNDARY = 0.5F;
|
||||
final float HEALTH_BOUNDARY = 0.5F;
|
||||
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
LivingEntity entity;
|
||||
@@ -479,14 +481,8 @@ public class EventBus
|
||||
return true;
|
||||
}
|
||||
boolean changed = false;
|
||||
|
||||
/*
|
||||
* Resets the transparency from the armor call.
|
||||
*/
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
1F);
|
||||
boolean canceled =
|
||||
healthTime == 0 && health / maxHealth > HEALTH_BOUNDARY;
|
||||
|
||||
/**
|
||||
* Checks for a change in current or max health.
|
||||
@@ -513,14 +509,11 @@ public class EventBus
|
||||
* Only makes a change if the player is healthy. Otherwise,
|
||||
* the bar is shown.
|
||||
*/
|
||||
if (health / maxHealth > CONST_BOUNDARY)
|
||||
if (health / maxHealth > HEALTH_BOUNDARY)
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(healthTime));
|
||||
setAlpha(Main.getAlpha(healthTime));
|
||||
}
|
||||
return false;
|
||||
return canceled;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -542,15 +535,9 @@ public class EventBus
|
||||
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
PlayerEntity entity;
|
||||
boolean canceled;
|
||||
boolean changed = false;
|
||||
|
||||
/*
|
||||
* Resets the transparency from last time.
|
||||
*/
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
1F);
|
||||
if (mc.getCameraEntity() instanceof PlayerEntity)
|
||||
{
|
||||
entity = (PlayerEntity) mc.getCameraEntity();
|
||||
@@ -584,15 +571,13 @@ public class EventBus
|
||||
{
|
||||
hungerTime--;
|
||||
}
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(hungerTime));
|
||||
/*
|
||||
* Only makes a change if the player is satisfied. Otherwise,
|
||||
* the bar is shown.
|
||||
*/
|
||||
return false;
|
||||
|
||||
canceled = hungerTime == 0 && hunger > HUNGER_BOUNDARY;
|
||||
if (!canceled)
|
||||
{
|
||||
setAlpha(Main.getAlpha(hungerTime));
|
||||
}
|
||||
return canceled;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -607,8 +592,6 @@ public class EventBus
|
||||
{
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
ClientPlayerEntity entity;
|
||||
boolean changed = false;
|
||||
|
||||
if (mc.getCameraEntity() instanceof ClientPlayerEntity)
|
||||
{
|
||||
entity = (ClientPlayerEntity) mc.getCameraEntity();
|
||||
@@ -626,12 +609,9 @@ public class EventBus
|
||||
{
|
||||
jumpTime--;
|
||||
}
|
||||
if (experienceTime > 0)
|
||||
if (jumpTime > 0)
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(jumpTime));
|
||||
setAlpha(Main.getAlpha(jumpTime));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -675,10 +655,7 @@ public class EventBus
|
||||
}
|
||||
if (experienceTime > 0)
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(experienceTime));
|
||||
setAlpha(Main.getAlpha(experienceTime));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -902,9 +879,6 @@ public class EventBus
|
||||
*/
|
||||
public static void recolorHotbar()
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(hotbarTime));
|
||||
setAlpha(Main.getAlpha(hotbarTime));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,12 +45,17 @@ public class HudHook
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderCrosshair", at = @At(value = "HEAD"))
|
||||
@Inject(method = "renderCrosshair", at = @At(value = "HEAD"),
|
||||
cancellable = true)
|
||||
public void startCrosshair(MatrixStack stack, CallbackInfo callbackInfo)
|
||||
{
|
||||
EventBus.drawCrosshair();
|
||||
if (EventBus.drawCrosshair())
|
||||
{
|
||||
callbackInfo.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,6 +64,7 @@ public class HudHook
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderCrosshair", at = @At(value = "TAIL"))
|
||||
@@ -67,7 +73,7 @@ public class HudHook
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
EventBus.resetAlpha();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,14 +82,20 @@ public class HudHook
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderMountJumpBar", at = @At(value = "HEAD"))
|
||||
@Inject(method = "renderMountJumpBar", at = @At(value = "HEAD"),
|
||||
cancellable =
|
||||
true)
|
||||
public void startJumpbar(MatrixStack stack,
|
||||
int x,
|
||||
CallbackInfo callbackInfo)
|
||||
{
|
||||
EventBus.drawJumpbar();
|
||||
if (EventBus.drawJumpbar())
|
||||
{
|
||||
callbackInfo.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,6 +104,7 @@ public class HudHook
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderMountJumpBar", at = @At(value = "TAIL"))
|
||||
@@ -102,7 +115,7 @@ public class HudHook
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
EventBus.resetAlpha();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,6 +124,7 @@ public class HudHook
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderExperienceBar", at = @At(value = "HEAD"),
|
||||
@@ -131,6 +145,7 @@ public class HudHook
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderExperienceBar", at = @At(value = "TAIL"))
|
||||
@@ -141,7 +156,7 @@ public class HudHook
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
EventBus.resetAlpha();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,12 +165,18 @@ public class HudHook
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderMountHealth", at = @At(value = "HEAD"))
|
||||
@Inject(method = "renderMountHealth", at = @At(value = "HEAD"),
|
||||
cancellable =
|
||||
true)
|
||||
public void startMountHealth(MatrixStack stack, CallbackInfo callbackInfo)
|
||||
{
|
||||
EventBus.drawMountHealth();
|
||||
if (EventBus.drawMountHealth())
|
||||
{
|
||||
callbackInfo.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,6 +185,7 @@ public class HudHook
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderMountHealth", at = @At(value = "TAIL"))
|
||||
@@ -172,7 +194,7 @@ public class HudHook
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
EventBus.resetAlpha();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,6 +204,7 @@ public class HudHook
|
||||
* @param matrices - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderHotbar", at = @At(value = "HEAD"), cancellable =
|
||||
@@ -203,6 +226,7 @@ public class HudHook
|
||||
* @param matrices - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderHotbar", at = @At(value = "INVOKE", target =
|
||||
@@ -222,6 +246,7 @@ public class HudHook
|
||||
* @param matrices - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @version 0.2-1.16.4-fabric
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderHotbar", at = @At(value = "TAIL"))
|
||||
@@ -232,6 +257,6 @@ public class HudHook
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
EventBus.resetAlpha();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import markil3.immersive_hud.EventBus;
|
||||
import markil3.immersive_hud.Main;
|
||||
|
||||
/**
|
||||
* This class hooks into the profiler to trigger color changes for the status
|
||||
@@ -50,7 +51,10 @@ public class ProfilerHook
|
||||
{
|
||||
if (section.equals("armor"))
|
||||
{
|
||||
EventBus.drawArmor();
|
||||
if (EventBus.drawArmor())
|
||||
{
|
||||
EventBus.setAlpha(0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,16 +73,30 @@ public class ProfilerHook
|
||||
switch (section)
|
||||
{
|
||||
case "health":
|
||||
EventBus.drawHealth();
|
||||
/*
|
||||
* Resets the transparency from the previous call.
|
||||
*/
|
||||
EventBus.setAlpha(1F);
|
||||
if (EventBus.drawHealth())
|
||||
{
|
||||
EventBus.setAlpha(0F);
|
||||
}
|
||||
break;
|
||||
case "food":
|
||||
EventBus.drawHunger();
|
||||
/*
|
||||
* Resets the transparency from the previous call.
|
||||
*/
|
||||
EventBus.setAlpha(1F);
|
||||
if (EventBus.drawHunger())
|
||||
{
|
||||
EventBus.setAlpha(0F);
|
||||
}
|
||||
break;
|
||||
case "air":
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
EventBus.setAlpha(1F);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user