Makes the hotbar and experience/jump bars move in and out.

Its a nice effect.
This commit is contained in:
Markil3
2021-02-27 12:23:21 -07:00
parent 2deb8aa2b3
commit c7680888c1
3 changed files with 144 additions and 20 deletions

View File

@@ -166,20 +166,21 @@ public class EventBus
case HEALTH: case HEALTH:
if (event instanceof RenderGameOverlayEvent.Pre) if (event instanceof RenderGameOverlayEvent.Pre)
{ {
if (TimerUtils.drawHealth()) if (TimerUtils.drawHealth(event.getMatrixStack()))
{ {
event.setCanceled(true); event.setCanceled(true);
} }
} }
else if (event instanceof RenderGameOverlayEvent.Post) else if (event instanceof RenderGameOverlayEvent.Post)
{ {
event.getMatrixStack().pop();
resetAlpha(); resetAlpha();
} }
break; break;
case FOOD: case FOOD:
if (event instanceof RenderGameOverlayEvent.Pre) if (event instanceof RenderGameOverlayEvent.Pre)
{ {
if (TimerUtils.drawHunger()) if (TimerUtils.drawHunger(event.getMatrixStack()))
{ {
event.setCanceled(true); event.setCanceled(true);
} }
@@ -189,13 +190,14 @@ public class EventBus
*/ */
else if (event instanceof RenderGameOverlayEvent.Post) else if (event instanceof RenderGameOverlayEvent.Post)
{ {
event.getMatrixStack().pop();
resetAlpha(); resetAlpha();
} }
break; break;
case ARMOR: case ARMOR:
if (event instanceof RenderGameOverlayEvent.Pre) if (event instanceof RenderGameOverlayEvent.Pre)
{ {
if (TimerUtils.drawArmor()) if (TimerUtils.drawArmor(event.getMatrixStack()))
{ {
event.setCanceled(true); event.setCanceled(true);
} }
@@ -205,19 +207,38 @@ public class EventBus
*/ */
else if (event instanceof RenderGameOverlayEvent.Post) else if (event instanceof RenderGameOverlayEvent.Post)
{ {
event.getMatrixStack().pop();
resetAlpha();
}
break;
case AIR:
if (event instanceof RenderGameOverlayEvent.Pre)
{
if (TimerUtils.drawAir(event.getMatrixStack()))
{
event.setCanceled(true);
}
}
/*
* Reset the transparency.
*/
else if (event instanceof RenderGameOverlayEvent.Post)
{
event.getMatrixStack().pop();
resetAlpha(); resetAlpha();
} }
break; break;
case HEALTHMOUNT: case HEALTHMOUNT:
if (event instanceof RenderGameOverlayEvent.Pre) if (event instanceof RenderGameOverlayEvent.Pre)
{ {
if (TimerUtils.drawMountHealth()) if (TimerUtils.drawMountHealth(event.getMatrixStack()))
{ {
event.setCanceled(true); event.setCanceled(true);
} }
} }
else if (event instanceof RenderGameOverlayEvent.Post) else if (event instanceof RenderGameOverlayEvent.Post)
{ {
event.getMatrixStack().pop();
resetAlpha(); resetAlpha();
} }
break; break;

View File

@@ -189,7 +189,7 @@ public class RenderUtils
float f = mc.player.getHorseJumpPower(); float f = mc.player.getHorseJumpPower();
int i = 182; int i = 182;
int j = (int) (f * 183.0F); int j = (int) (f * 183.0F);
int k = scaledHeight - 32 + 3; int k = scaledHeight - TimerUtils.getJumpTranslation();
gui.blit(matrixStack, xPosition, k, 0, 84, 182, 5); gui.blit(matrixStack, xPosition, k, 0, 84, 182, 5);
if (j > 0) if (j > 0)
{ {
@@ -239,7 +239,7 @@ public class RenderUtils
{ {
int j = 182; int j = 182;
int k = (int) (mc.player.experience * 183.0F); int k = (int) (mc.player.experience * 183.0F);
int l = scaledHeight - 32 + 3; int l = scaledHeight - TimerUtils.getExperienceTranslation();
gui.blit(matrixStack, x, l, 0, 64, 182, 5); gui.blit(matrixStack, x, l, 0, 64, 182, 5);
if (k > 0) if (k > 0)
{ {
@@ -256,7 +256,7 @@ public class RenderUtils
String s = "" + mc.player.experienceLevel; String s = "" + mc.player.experienceLevel;
int i1 = (scaledWidth - gui.getFontRenderer() int i1 = (scaledWidth - gui.getFontRenderer()
.getStringWidth(s)) / 2; .getStringWidth(s)) / 2;
int j1 = scaledHeight - 31 - 4; int j1 = scaledHeight - (int) ((22F * Main.getAlpha(TimerUtils.hotbarTime) + 9F) * alpha) - (int) (4F * alpha);
gui.getFontRenderer() gui.getFontRenderer()
.drawString(matrixStack, .drawString(matrixStack,
s, s,
@@ -335,10 +335,10 @@ public class RenderUtils
int k = 182; int k = 182;
int l = 91; int l = 91;
gui.setBlitOffset(-90); gui.setBlitOffset(-90);
gui.blit(matrixStack, i - 91, scaledHeight - 22, 0, 0, 182, 22); gui.blit(matrixStack, i - 91, scaledHeight - TimerUtils.getHotbarTranslation(), 0, 0, 182, 22);
gui.blit(matrixStack, gui.blit(matrixStack,
i - 91 - 1 + playerentity.inventory.currentItem * 20, i - 91 - 1 + playerentity.inventory.currentItem * 20,
scaledHeight - 22 - 1, scaledHeight - (int) (22F * alpha) - 1,
0, 0,
22, 22,
24, 24,
@@ -349,7 +349,7 @@ public class RenderUtils
{ {
gui.blit(matrixStack, gui.blit(matrixStack,
i - 91 - 29, i - 91 - 29,
scaledHeight - 23, scaledHeight - (int) (23F * alpha),
24, 24,
22, 22,
29, 29,
@@ -359,7 +359,7 @@ public class RenderUtils
{ {
gui.blit(matrixStack, gui.blit(matrixStack,
i + 91, i + 91,
scaledHeight - 23, scaledHeight - (int) (23F * alpha),
53, 53,
22, 22,
29, 29,
@@ -375,7 +375,7 @@ public class RenderUtils
for (int i1 = 0; i1 < 9; ++i1) for (int i1 = 0; i1 < 9; ++i1)
{ {
int j1 = i - 90 + i1 * 20 + 2; int j1 = i - 90 + i1 * 20 + 2;
int k1 = scaledHeight - 16 - 3; int k1 = scaledHeight - (int) (16F * alpha) - 3;
renderHotbarItem(mc, alpha, j1, renderHotbarItem(mc, alpha, j1,
k1, k1,
partialTicks, partialTicks,
@@ -385,7 +385,7 @@ public class RenderUtils
if (!itemstack.isEmpty()) if (!itemstack.isEmpty())
{ {
int i2 = scaledHeight - 16 - 3; int i2 = scaledHeight - (int) (16F * alpha) - 3;
if (handside == HandSide.LEFT) if (handside == HandSide.LEFT)
{ {
renderHotbarItem(mc, alpha, i - 91 - 26, renderHotbarItem(mc, alpha, i - 91 - 26,

View File

@@ -178,6 +178,55 @@ public class TimerUtils
setAlpha(1.0F); setAlpha(1.0F);
} }
/**
* Obtains the offset from the bottom of the screen that the hotbar
* receives.
*
* @return The offset the hotbar uses.
*/
public static int getHotbarTranslation()
{
return (int) (22F * Main.getAlpha(hotbarTime));
}
/**
* Obtains the offset from the bottom of the screen that the experience bar
* receives.
*
* @return The offset the experience bar uses.
*/
public static int getExperienceTranslation()
{
return (int) ((getHotbarTranslation() + 10F) * Main.getAlpha(
experienceTime)) - 3;
}
/**
* Obtains the offset from the bottom of the screen that the jump bar
* receives.
*
* @return The offset the jump bar uses.
*/
public static int getJumpTranslation()
{
return (int) ((getHotbarTranslation() + 10F) * Main.getAlpha(jumpTime)) - 3;
}
/**
* Obtains the offset that the status bars (health, hunger, etc.) gets from
* their usual position.
*
* @return The offset.
*/
public static float getHealthTranslation()
{
return 29 - Math.max(Math.max(getExperienceTranslation(),
getJumpTranslation()), getHotbarTranslation());
}
public static void onClick(Hand hand, Item item) public static void onClick(Hand hand, Item item)
{ {
crosshairTime = VISUAL_TIME; crosshairTime = VISUAL_TIME;
@@ -327,14 +376,19 @@ public class TimerUtils
*/ */
public static void updatePotions(ClientPlayerEntity player) public static void updatePotions(ClientPlayerEntity player)
{ {
ArrayList<Effect> toRemove = new ArrayList<>();
for (Effect effect : Collections.checkedSet(effectTime.keySet(), for (Effect effect : Collections.checkedSet(effectTime.keySet(),
Effect.class)) Effect.class))
{ {
if (!player.isPotionActive(effect)) if (!player.isPotionActive(effect))
{ {
effectTime.remove(effect); toRemove.add(effect);
} }
} }
for (Effect effect : toRemove)
{
effectTime.remove(effect);
}
} }
/** /**
@@ -591,7 +645,7 @@ public class TimerUtils
* *
* @since 0.2-1.16.4-forge * @since 0.2-1.16.4-forge
*/ */
public static boolean drawHealth() public static boolean drawHealth(MatrixStack stack)
{ {
/* /*
* When the health percentage falls to this level or below, the * When the health percentage falls to this level or below, the
@@ -631,11 +685,19 @@ public class TimerUtils
{ {
if (healthTime > 0) if (healthTime > 0)
{ {
stack.push();
stack.translate(0F,
getHealthTranslation(),
0F);
setAlpha(Main.getAlpha(healthTime)); setAlpha(Main.getAlpha(healthTime));
return false; return false;
} }
return true; return true;
} }
stack.push();
stack.translate(0F,
getHealthTranslation(),
0F);
return false; return false;
} }
@@ -647,7 +709,7 @@ public class TimerUtils
* *
* @since 0.2-1.16.4-forge * @since 0.2-1.16.4-forge
*/ */
public static boolean drawHunger() public static boolean drawHunger(MatrixStack stack)
{ {
/* /*
* When hunger falls to this level or below, the hunger bar won't * When hunger falls to this level or below, the hunger bar won't
@@ -673,7 +735,6 @@ public class TimerUtils
if (changed || hunger <= HUNGER_BOUNDARY) if (changed || hunger <= HUNGER_BOUNDARY)
{ {
hungerTime = HEALTH_TIME; hungerTime = HEALTH_TIME;
setAlpha(Main.getAlpha(hungerTime));
} }
else if (hungerTime > 0) else if (hungerTime > 0)
{ {
@@ -683,18 +744,32 @@ public class TimerUtils
* Only fade a change if the player is satisfied. Otherwise, * Only fade a change if the player is satisfied. Otherwise,
* the bar is shown. * the bar is shown.
*/ */
return hungerTime == 0 && hunger > HUNGER_BOUNDARY; if (hungerTime == 0 && hunger > HUNGER_BOUNDARY)
{
return true;
}
else
{
setAlpha(Main.getAlpha(hungerTime));
stack.push();
stack.translate(0F,
getHealthTranslation(),
0F);
return false;
}
} }
/** /**
* Determines whether or not to draw the armor bar, adjusting the alpha as * Determines whether or not to draw the armor bar, adjusting the alpha as
* needed. * needed.
* *
* @param stack
*
* @return If true, then cancel drawing the armor bar. * @return If true, then cancel drawing the armor bar.
* *
* @since 0.2-1.16.4-forge * @since 0.2-1.16.4-forge
*/ */
public static boolean drawArmor() public static boolean drawArmor(MatrixStack stack)
{ {
/* /*
* Renders armor along with health. * Renders armor along with health.
@@ -702,20 +777,44 @@ public class TimerUtils
if (healthTime > 0) if (healthTime > 0)
{ {
setAlpha(Main.getAlpha(healthTime)); setAlpha(Main.getAlpha(healthTime));
stack.push();
stack.translate(0F,
getHealthTranslation(),
0F);
return false; return false;
} }
return true; return true;
} }
/**
* Repositions the oxygen bar.
*
* @param stack
*
* @return If true, then cancel drawing the oxygen bar.
*
* @since 0.2-1.16.4-forge
*/
public static boolean drawAir(MatrixStack stack)
{
stack.push();
stack.translate(0F,
getHealthTranslation(),
0F);
return false;
}
/** /**
* Determines whether or not to draw the mount's health, adjusting the alpha * Determines whether or not to draw the mount's health, adjusting the alpha
* as needed. * as needed.
* *
* @param stack
*
* @return If true, then cancel drawing the mount health bar. * @return If true, then cancel drawing the mount health bar.
* *
* @since 0.2-1.16.4-forge * @since 0.2-1.16.4-forge
*/ */
public static boolean drawMountHealth() public static boolean drawMountHealth(MatrixStack stack)
{ {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
Entity tmp = mc.player.getRidingEntity(); Entity tmp = mc.player.getRidingEntity();
@@ -750,6 +849,10 @@ public class TimerUtils
if (mountTime > 0) if (mountTime > 0)
{ {
stack.push();
stack.translate(0F,
getHealthTranslation(),
0F);
setAlpha(Main.getAlpha(mountTime)); setAlpha(Main.getAlpha(mountTime));
return false; return false;
} }