Makes potion icons fade over time
This commit is contained in:
@@ -23,6 +23,8 @@ import net.minecraft.client.network.ClientPlayerEntity;
|
|||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
import net.minecraft.entity.effect.StatusEffect;
|
||||||
|
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||||
import net.minecraft.entity.effect.StatusEffects;
|
import net.minecraft.entity.effect.StatusEffects;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.BowItem;
|
import net.minecraft.item.BowItem;
|
||||||
@@ -41,7 +43,13 @@ import net.minecraft.item.TridentItem;
|
|||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.hit.EntityHitResult;
|
import net.minecraft.util.hit.EntityHitResult;
|
||||||
import net.minecraft.util.hit.HitResult;
|
import net.minecraft.util.hit.HitResult;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -92,6 +100,8 @@ public class TimerUtils
|
|||||||
*/
|
*/
|
||||||
private static int mapLock;
|
private static int mapLock;
|
||||||
|
|
||||||
|
private static HashMap<StatusEffect, Integer> effectTime = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many more ticks the hotbar will be onscreen. Every tick is 1/20th of
|
* How many more ticks the hotbar will be onscreen. Every tick is 1/20th of
|
||||||
* a second.
|
* a second.
|
||||||
@@ -427,6 +437,75 @@ public class TimerUtils
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the timings of some of the potions currently affecting the
|
||||||
|
* player.
|
||||||
|
*
|
||||||
|
* @param player - The player being affected.
|
||||||
|
*/
|
||||||
|
public static void updatePotions(ClientPlayerEntity player)
|
||||||
|
{
|
||||||
|
for (StatusEffect effect :
|
||||||
|
new HashSet<>(effectTime.keySet()))
|
||||||
|
{
|
||||||
|
if (!player.hasStatusEffect(effect))
|
||||||
|
{
|
||||||
|
effectTime.remove(effect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the timings of some of the potions currently affecting the
|
||||||
|
* player.
|
||||||
|
*
|
||||||
|
* @param effectinstance - The effect to update
|
||||||
|
*/
|
||||||
|
public static boolean updatePotion(StatusEffectInstance effectinstance)
|
||||||
|
{
|
||||||
|
Integer time = effectTime.get(effectinstance.getEffectType());
|
||||||
|
if (time == null)
|
||||||
|
{
|
||||||
|
effectTime.put(effectinstance.getEffectType(),
|
||||||
|
(time = VISUAL_TIME));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
effectTime.put(effectinstance.getEffectType(), (time -= 1));
|
||||||
|
}
|
||||||
|
return Main.getAlpha(time) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains how transparent
|
||||||
|
*
|
||||||
|
* @param effectinstance
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static float getPotionAlpha(StatusEffectInstance effectinstance)
|
||||||
|
{
|
||||||
|
final int BLINK_TIME = 200;
|
||||||
|
float effectAlpha = 0.0F;
|
||||||
|
if (effectinstance.getDuration() <= BLINK_TIME)
|
||||||
|
{
|
||||||
|
effectAlpha =
|
||||||
|
MathHelper.sin(7000F / (effectinstance.getDuration() + 16F * (float) Math.PI)) * 50F / (effectinstance
|
||||||
|
.getDuration() + 100F) + 0.5F;
|
||||||
|
}
|
||||||
|
else if (effectinstance.getDuration() <= BLINK_TIME + 10)
|
||||||
|
{
|
||||||
|
effectAlpha = -(effectinstance.getDuration() - 200) / 22F + 0.454F;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
effectAlpha =
|
||||||
|
Main.getAlpha(effectTime.getOrDefault(effectinstance.getEffectType(),
|
||||||
|
0));
|
||||||
|
}
|
||||||
|
return effectAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|||||||
@@ -16,12 +16,17 @@
|
|||||||
*/
|
*/
|
||||||
package markil3.immersive_hud.mixin;
|
package markil3.immersive_hud.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.hud.InGameHud;
|
import net.minecraft.client.gui.hud.InGameHud;
|
||||||
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import markil3.immersive_hud.TimerUtils;
|
import markil3.immersive_hud.TimerUtils;
|
||||||
@@ -36,6 +41,8 @@ import markil3.immersive_hud.TimerUtils;
|
|||||||
@Mixin(InGameHud.class)
|
@Mixin(InGameHud.class)
|
||||||
public class HudHook
|
public class HudHook
|
||||||
{
|
{
|
||||||
|
private StatusEffectInstance currentEffect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether or not to draw the crosshair.
|
* Determines whether or not to draw the crosshair.
|
||||||
*
|
*
|
||||||
@@ -83,8 +90,7 @@ public class HudHook
|
|||||||
* @since 0.1-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 =
|
cancellable = true)
|
||||||
true)
|
|
||||||
public void startJumpbar(MatrixStack stack,
|
public void startJumpbar(MatrixStack stack,
|
||||||
int x,
|
int x,
|
||||||
CallbackInfo callbackInfo)
|
CallbackInfo callbackInfo)
|
||||||
@@ -166,8 +172,7 @@ public class HudHook
|
|||||||
* @since 0.1-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 =
|
cancellable = true)
|
||||||
true)
|
|
||||||
public void startMountHealth(MatrixStack stack, CallbackInfo callbackInfo)
|
public void startMountHealth(MatrixStack stack, CallbackInfo callbackInfo)
|
||||||
{
|
{
|
||||||
if (TimerUtils.drawMountHealth())
|
if (TimerUtils.drawMountHealth())
|
||||||
@@ -194,6 +199,77 @@ public class HudHook
|
|||||||
TimerUtils.resetAlpha();
|
TimerUtils.resetAlpha();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes the actual adjustment to the hotbar as needed.
|
||||||
|
*
|
||||||
|
* @version 0.2-1.16.4-fabric
|
||||||
|
* @since 0.1-1.16.4-fabric
|
||||||
|
*/
|
||||||
|
@Inject(method = "renderStatusEffectOverlay" +
|
||||||
|
"(Lnet/minecraft/client/util/math/MatrixStack;)V", at =
|
||||||
|
@At(value = "HEAD", shift = At.Shift.AFTER))
|
||||||
|
public void startPotion(MatrixStack effect, CallbackInfo info)
|
||||||
|
{
|
||||||
|
TimerUtils.updatePotions(MinecraftClient.getInstance().cameraEntity instanceof ClientPlayerEntity ?
|
||||||
|
((ClientPlayerEntity) MinecraftClient.getInstance().cameraEntity) :
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes the actual adjustment to the hotbar as needed.
|
||||||
|
*
|
||||||
|
* @version 0.2-1.16.4-fabric
|
||||||
|
* @since 0.1-1.16.4-fabric
|
||||||
|
*/
|
||||||
|
@Redirect(method = "renderStatusEffectOverlay" +
|
||||||
|
"(Lnet/minecraft/client/util/math/MatrixStack;)V", at =
|
||||||
|
@At(value = "INVOKE",
|
||||||
|
target =
|
||||||
|
"Lnet/minecraft/entity/effect/StatusEffectInstance;" +
|
||||||
|
"shouldShowIcon()Z"))
|
||||||
|
public boolean shouldRenderPotion(StatusEffectInstance effect)
|
||||||
|
{
|
||||||
|
currentEffect = effect;
|
||||||
|
return TimerUtils.updatePotion(effect);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes the actual adjustment to the hotbar as needed.
|
||||||
|
*
|
||||||
|
* @param matrices - The matrix drawing stack.
|
||||||
|
* @param callbackInfo
|
||||||
|
*
|
||||||
|
* @version 0.2-1.16.4-fabric
|
||||||
|
* @since 0.1-1.16.4-fabric
|
||||||
|
*/
|
||||||
|
@ModifyVariable(method = "renderStatusEffectOverlay" +
|
||||||
|
"(Lnet/minecraft/client/util/math/MatrixStack;)V", at =
|
||||||
|
@At(value = "STORE"), ordinal = 1)
|
||||||
|
public float updatePotion(float f,
|
||||||
|
MatrixStack stack)
|
||||||
|
{
|
||||||
|
return TimerUtils.getPotionAlpha(currentEffect);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets any changes from drawing the potion effects.
|
||||||
|
*
|
||||||
|
* @param matrices - The matrix drawing stack.
|
||||||
|
* @param callbackInfo
|
||||||
|
*
|
||||||
|
* @version 0.2-1.16.4-fabric
|
||||||
|
* @since 0.2-1.16.4-fabric
|
||||||
|
*/
|
||||||
|
@Inject(method = "renderStatusEffectOverlay", at = @At(value = "TAIL"))
|
||||||
|
public void finishPotion(MatrixStack matrices,
|
||||||
|
CallbackInfo callbackInfo)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Resets the color so that nothing else is bothered.
|
||||||
|
*/
|
||||||
|
TimerUtils.resetAlpha();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether or not to draw the hotbar.
|
* Determines whether or not to draw the hotbar.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user