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:
if (event instanceof RenderGameOverlayEvent.Pre)
{
if (TimerUtils.drawHealth())
if (TimerUtils.drawHealth(event.getMatrixStack()))
{
event.setCanceled(true);
}
}
else if (event instanceof RenderGameOverlayEvent.Post)
{
event.getMatrixStack().pop();
resetAlpha();
}
break;
case FOOD:
if (event instanceof RenderGameOverlayEvent.Pre)
{
if (TimerUtils.drawHunger())
if (TimerUtils.drawHunger(event.getMatrixStack()))
{
event.setCanceled(true);
}
@@ -189,13 +190,14 @@ public class EventBus
*/
else if (event instanceof RenderGameOverlayEvent.Post)
{
event.getMatrixStack().pop();
resetAlpha();
}
break;
case ARMOR:
if (event instanceof RenderGameOverlayEvent.Pre)
{
if (TimerUtils.drawArmor())
if (TimerUtils.drawArmor(event.getMatrixStack()))
{
event.setCanceled(true);
}
@@ -205,19 +207,38 @@ public class EventBus
*/
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();
}
break;
case HEALTHMOUNT:
if (event instanceof RenderGameOverlayEvent.Pre)
{
if (TimerUtils.drawMountHealth())
if (TimerUtils.drawMountHealth(event.getMatrixStack()))
{
event.setCanceled(true);
}
}
else if (event instanceof RenderGameOverlayEvent.Post)
{
event.getMatrixStack().pop();
resetAlpha();
}
break;

View File

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

View File

@@ -178,6 +178,55 @@ public class TimerUtils
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)
{
crosshairTime = VISUAL_TIME;
@@ -327,14 +376,19 @@ public class TimerUtils
*/
public static void updatePotions(ClientPlayerEntity player)
{
ArrayList<Effect> toRemove = new ArrayList<>();
for (Effect effect : Collections.checkedSet(effectTime.keySet(),
Effect.class))
{
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
*/
public static boolean drawHealth()
public static boolean drawHealth(MatrixStack stack)
{
/*
* When the health percentage falls to this level or below, the
@@ -631,11 +685,19 @@ public class TimerUtils
{
if (healthTime > 0)
{
stack.push();
stack.translate(0F,
getHealthTranslation(),
0F);
setAlpha(Main.getAlpha(healthTime));
return false;
}
return true;
}
stack.push();
stack.translate(0F,
getHealthTranslation(),
0F);
return false;
}
@@ -647,7 +709,7 @@ public class TimerUtils
*
* @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
@@ -673,7 +735,6 @@ public class TimerUtils
if (changed || hunger <= HUNGER_BOUNDARY)
{
hungerTime = HEALTH_TIME;
setAlpha(Main.getAlpha(hungerTime));
}
else if (hungerTime > 0)
{
@@ -683,18 +744,32 @@ public class TimerUtils
* Only fade a change if the player is satisfied. Otherwise,
* 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
* needed.
*
* @param stack
*
* @return If true, then cancel drawing the armor bar.
*
* @since 0.2-1.16.4-forge
*/
public static boolean drawArmor()
public static boolean drawArmor(MatrixStack stack)
{
/*
* Renders armor along with health.
@@ -702,20 +777,44 @@ public class TimerUtils
if (healthTime > 0)
{
setAlpha(Main.getAlpha(healthTime));
stack.push();
stack.translate(0F,
getHealthTranslation(),
0F);
return false;
}
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
* as needed.
*
* @param stack
*
* @return If true, then cancel drawing the mount health bar.
*
* @since 0.2-1.16.4-forge
*/
public static boolean drawMountHealth()
public static boolean drawMountHealth(MatrixStack stack)
{
Minecraft mc = Minecraft.getInstance();
Entity tmp = mc.player.getRidingEntity();
@@ -750,6 +849,10 @@ public class TimerUtils
if (mountTime > 0)
{
stack.push();
stack.translate(0F,
getHealthTranslation(),
0F);
setAlpha(Main.getAlpha(mountTime));
return false;
}