Catches any errors that occur when triggering events.

It is pretty annoying for the game to crash because of a GUI mod. This should reduce that.
This commit is contained in:
Markil3
2021-03-26 10:08:16 -06:00
parent 6daf696e01
commit e3c0f1d533
3 changed files with 372 additions and 79 deletions

View File

@@ -21,6 +21,8 @@ import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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;
@@ -38,6 +40,9 @@ import markil3.immersive_hud.TimerUtils;
@Mixin(ClientPlayerEntity.class) @Mixin(ClientPlayerEntity.class)
public class ClientPlayerHook public class ClientPlayerHook
{ {
private static final Logger LOGGER =
LogManager.getLogger(ClientPlayerHook.class);
/** /**
* Updates hand timing every time an attack is initiated. * Updates hand timing every time an attack is initiated.
* *
@@ -49,7 +54,18 @@ public class ClientPlayerHook
@Inject(method = "swingHand", at = @At(value = "TAIL")) @Inject(method = "swingHand", at = @At(value = "TAIL"))
public void swingHand(Hand hand, CallbackInfo callbackInfo) public void swingHand(Hand hand, CallbackInfo callbackInfo)
{ {
TimerUtils.onClick(hand, hand == null); try
{
TimerUtils.onClick(hand, hand == null);
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.network" +
".ClientPlayerEntity#swingHand " +
"event",
e);
}
} }
/** /**
@@ -63,7 +79,18 @@ public class ClientPlayerHook
@Inject(method = "setCurrentHand", at = @At(value = "TAIL")) @Inject(method = "setCurrentHand", at = @At(value = "TAIL"))
public void setCurrentHand(Hand hand, CallbackInfo callbackInfo) public void setCurrentHand(Hand hand, CallbackInfo callbackInfo)
{ {
TimerUtils.onClick(hand, hand == null); try
{
TimerUtils.onClick(hand, hand == null);
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.network" +
".ClientPlayerEntity#setCurrentHand " +
"event",
e);
}
} }
/** /**
@@ -76,10 +103,21 @@ public class ClientPlayerHook
@Inject(method = "clearActiveItem", at = @At(value = "HEAD")) @Inject(method = "clearActiveItem", at = @At(value = "HEAD"))
public void clearActiveItem(CallbackInfo callbackInfo) public void clearActiveItem(CallbackInfo callbackInfo)
{ {
if (MinecraftClient.getInstance().cameraEntity instanceof LivingEntity) try
{ {
TimerUtils.onClick(((LivingEntity) MinecraftClient.getInstance().cameraEntity) if (MinecraftClient.getInstance().cameraEntity instanceof LivingEntity)
.getActiveHand(), true); {
TimerUtils.onClick(((LivingEntity) MinecraftClient.getInstance().cameraEntity)
.getActiveHand(), true);
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.network" +
".ClientPlayerEntity#clearActiveItem " +
"event",
e);
} }
} }
} }

View File

@@ -23,6 +23,8 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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;
@@ -40,6 +42,9 @@ import markil3.immersive_hud.TimerUtils;
@Mixin(HeldItemRenderer.class) @Mixin(HeldItemRenderer.class)
public class HeldItemHook public class HeldItemHook
{ {
private static final Logger LOGGER =
LogManager.getLogger(HeldItemHook.class);
/** /**
* Determines whether or not to render a certain hand. * Determines whether or not to render a certain hand.
* *
@@ -72,9 +77,20 @@ public class HeldItemHook
int light, int light,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
if (TimerUtils.onRenderHand(hand, matrices, tickDelta)) try
{ {
callbackInfo.cancel(); if (TimerUtils.onRenderHand(hand, matrices, tickDelta))
{
callbackInfo.cancel();
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.render.item" +
".HeldItemRenderer#renderFirstPersonItem " +
"event",
e);
} }
} }

View File

@@ -24,6 +24,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.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectInstance;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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;
@@ -43,6 +45,8 @@ import markil3.immersive_hud.TimerUtils;
@Mixin(InGameHud.class) @Mixin(InGameHud.class)
public class HudHook public class HudHook
{ {
private static final Logger LOGGER = LogManager.getLogger(HudHook.class);
private StatusEffectInstance currentEffect; private StatusEffectInstance currentEffect;
/** /**
@@ -58,10 +62,21 @@ 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() try
.getTickDelta()))
{ {
callbackInfo.cancel(); if (TimerUtils.drawCrosshair(MinecraftClient.getInstance()
.getTickDelta()))
{
callbackInfo.cancel();
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#startCrosshair " +
"event",
e);
} }
} }
@@ -77,10 +92,21 @@ public class HudHook
@Inject(method = "renderCrosshair", at = @At(value = "TAIL")) @Inject(method = "renderCrosshair", at = @At(value = "TAIL"))
public void finishCrosshair(MatrixStack stack, CallbackInfo callbackInfo) public void finishCrosshair(MatrixStack stack, CallbackInfo callbackInfo)
{ {
/* try
* Resets the color so that nothing else is bothered. {
*/ /*
TimerUtils.resetAlpha(); * Resets the color so that nothing else is bothered.
*/
TimerUtils.resetAlpha();
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderCrosshair " +
"event",
e);
}
} }
/** /**
@@ -98,10 +124,21 @@ public class HudHook
int x, int x,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
if (TimerUtils.drawJumpbar(stack, try
MinecraftClient.getInstance().getTickDelta()))
{ {
callbackInfo.cancel(); if (TimerUtils.drawJumpbar(stack,
MinecraftClient.getInstance().getTickDelta()))
{
callbackInfo.cancel();
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderMountJumpBar " +
"event",
e);
} }
} }
@@ -119,11 +156,22 @@ public class HudHook
int x, int x,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
stack.pop(); try
/* {
* Resets the color so that nothing else is bothered. stack.pop();
*/ /*
TimerUtils.resetAlpha(); * Resets the color so that nothing else is bothered.
*/
TimerUtils.resetAlpha();
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderMountJumpBar " +
"event",
e);
}
} }
/** /**
@@ -141,10 +189,21 @@ public class HudHook
int x, int x,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
if (TimerUtils.drawExperience(stack, try
MinecraftClient.getInstance().getTickDelta()))
{ {
callbackInfo.cancel(); if (TimerUtils.drawExperience(stack,
MinecraftClient.getInstance().getTickDelta()))
{
callbackInfo.cancel();
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderExperienceBar " +
"event",
e);
} }
} }
@@ -162,11 +221,22 @@ public class HudHook
int x, int x,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
stack.pop(); try
/* {
* Resets the color so that nothing else is bothered. stack.pop();
*/ /*
TimerUtils.resetAlpha(); * Resets the color so that nothing else is bothered.
*/
TimerUtils.resetAlpha();
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderExperienceBar " +
"event",
e);
}
} }
/** /**
@@ -181,8 +251,19 @@ public class HudHook
"/math/MatrixStack;)V", at = @At("HEAD")) "/math/MatrixStack;)V", at = @At("HEAD"))
public MatrixStack startStatus(MatrixStack stack) public MatrixStack startStatus(MatrixStack stack)
{ {
stack.push(); try
stack.translate(0F, TimerUtils.getHealthTranslation(), 0F); {
stack.push();
stack.translate(0F, TimerUtils.getHealthTranslation(), 0F);
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderStatusBars " +
"event",
e);
}
return stack; return stack;
} }
@@ -197,9 +278,20 @@ public class HudHook
"/minecraft/util/profiler/Profiler;push(Ljava/lang/String;)V")) "/minecraft/util/profiler/Profiler;push(Ljava/lang/String;)V"))
public void renderArmor(MatrixStack matrices, CallbackInfo callbackInfo) public void renderArmor(MatrixStack matrices, CallbackInfo callbackInfo)
{ {
if (TimerUtils.drawArmor()) try
{ {
TimerUtils.setAlpha(0F); if (TimerUtils.drawArmor())
{
TimerUtils.setAlpha(0F);
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderStatusBars " +
"event",
e);
} }
} }
@@ -215,13 +307,25 @@ public class HudHook
ordinal = 0)) ordinal = 0))
public void renderHealth(MatrixStack matrices, CallbackInfo callbackInfo) public void renderHealth(MatrixStack matrices, CallbackInfo callbackInfo)
{ {
/* try
* Resets the transparency from the previous call.
*/
TimerUtils.setAlpha(1F);
if (TimerUtils.drawHealth(MinecraftClient.getInstance().getTickDelta()))
{ {
TimerUtils.setAlpha(0F); /*
* Resets the transparency from the previous call.
*/
TimerUtils.setAlpha(1F);
if (TimerUtils.drawHealth(MinecraftClient.getInstance()
.getTickDelta()))
{
TimerUtils.setAlpha(0F);
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderStatusBars " +
"event",
e);
} }
} }
@@ -237,13 +341,25 @@ public class HudHook
ordinal = 1)) ordinal = 1))
public void renderFood(MatrixStack matrices, CallbackInfo callbackInfo) public void renderFood(MatrixStack matrices, CallbackInfo callbackInfo)
{ {
/* try
* Resets the transparency from the previous call.
*/
TimerUtils.setAlpha(1F);
if (TimerUtils.drawHunger(MinecraftClient.getInstance().getTickDelta()))
{ {
TimerUtils.setAlpha(0F); /*
* Resets the transparency from the previous call.
*/
TimerUtils.setAlpha(1F);
if (TimerUtils.drawHunger(MinecraftClient.getInstance()
.getTickDelta()))
{
TimerUtils.setAlpha(0F);
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderStatusBars " +
"event",
e);
} }
} }
@@ -259,17 +375,39 @@ public class HudHook
ordinal = 2)) ordinal = 2))
public void renderAir(MatrixStack matrices, CallbackInfo callbackInfo) public void renderAir(MatrixStack matrices, CallbackInfo callbackInfo)
{ {
/* try
* Resets the color so that nothing else is bothered. {
*/ /*
TimerUtils.setAlpha(1F); * Resets the color so that nothing else is bothered.
*/
TimerUtils.setAlpha(1F);
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderStatusBars " +
"event",
e);
}
} }
@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)
{ {
stack.pop(); try
{
stack.pop();
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderStatusBars " +
"event",
e);
}
return stack; return stack;
} }
@@ -286,10 +424,21 @@ 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, try
MinecraftClient.getInstance().getTickDelta()))
{ {
callbackInfo.cancel(); if (TimerUtils.drawMountHealth(stack,
MinecraftClient.getInstance().getTickDelta()))
{
callbackInfo.cancel();
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderMountHealth " +
"event",
e);
} }
} }
@@ -305,11 +454,22 @@ public class HudHook
@Inject(method = "renderMountHealth", at = @At(value = "TAIL")) @Inject(method = "renderMountHealth", at = @At(value = "TAIL"))
public void finishMountHealth(MatrixStack stack, CallbackInfo callbackInfo) public void finishMountHealth(MatrixStack stack, CallbackInfo callbackInfo)
{ {
/* try
* Resets the color so that nothing else is bothered. {
*/ /*
stack.pop(); * Resets the color so that nothing else is bothered.
TimerUtils.resetAlpha(); */
stack.pop();
TimerUtils.resetAlpha();
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderMountHealth " +
"event",
e);
}
} }
/** /**
@@ -323,9 +483,20 @@ public class HudHook
@At(value = "HEAD", shift = At.Shift.AFTER)) @At(value = "HEAD", shift = At.Shift.AFTER))
public void startPotion(MatrixStack effect, CallbackInfo info) public void startPotion(MatrixStack effect, CallbackInfo info)
{ {
TimerUtils.updatePotions(MinecraftClient.getInstance().cameraEntity instanceof ClientPlayerEntity ? try
((ClientPlayerEntity) MinecraftClient.getInstance().cameraEntity) : {
null); TimerUtils.updatePotions(MinecraftClient.getInstance().cameraEntity instanceof ClientPlayerEntity ?
((ClientPlayerEntity) MinecraftClient.getInstance().cameraEntity) :
null);
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderStatusEffectOverlay " +
"event",
e);
}
} }
/** /**
@@ -342,9 +513,21 @@ public class HudHook
"shouldShowIcon()Z")) "shouldShowIcon()Z"))
public boolean shouldRenderPotion(StatusEffectInstance effect) public boolean shouldRenderPotion(StatusEffectInstance effect)
{ {
currentEffect = effect; try
return TimerUtils.updatePotion(effect, {
MinecraftClient.getInstance().getTickDelta()); currentEffect = effect;
return TimerUtils.updatePotion(effect,
MinecraftClient.getInstance().getTickDelta());
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderStatusEffectOverlay " +
"event",
e);
}
return true;
} }
/** /**
@@ -362,7 +545,19 @@ public class HudHook
public float updatePotion(float f, public float updatePotion(float f,
MatrixStack stack) MatrixStack stack)
{ {
return TimerUtils.getPotionAlpha(currentEffect); try
{
return TimerUtils.getPotionAlpha(currentEffect);
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderStatusEffectOverlay " +
"event",
e);
}
return 1F;
} }
/** /**
@@ -378,10 +573,21 @@ public class HudHook
public void finishPotion(MatrixStack matrices, public void finishPotion(MatrixStack matrices,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
/* try
* Resets the color so that nothing else is bothered. {
*/ /*
TimerUtils.resetAlpha(); * Resets the color so that nothing else is bothered.
*/
TimerUtils.resetAlpha();
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderStatusEffectOverlay " +
"event",
e);
}
} }
/** /**
@@ -400,9 +606,20 @@ public class HudHook
MatrixStack matrices, MatrixStack matrices,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
if (TimerUtils.updateHotbar(tickDelta)) try
{ {
callbackInfo.cancel(); if (TimerUtils.updateHotbar(tickDelta))
{
callbackInfo.cancel();
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderHotbar " +
"event",
e);
} }
} }
@@ -423,7 +640,18 @@ public class HudHook
MatrixStack matrices, MatrixStack matrices,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
TimerUtils.recolorHotbar(matrices); try
{
TimerUtils.recolorHotbar(matrices);
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderHotbar " +
"event",
e);
}
} }
/** /**
@@ -441,11 +669,22 @@ public class HudHook
MatrixStack stack, MatrixStack stack,
CallbackInfo callbackInfo) CallbackInfo callbackInfo)
{ {
RenderSystem.popMatrix(); try
stack.pop(); {
/* RenderSystem.popMatrix();
* Resets the color so that nothing else is bothered. stack.pop();
*/ /*
TimerUtils.resetAlpha(); * Resets the color so that nothing else is bothered.
*/
TimerUtils.resetAlpha();
}
catch (Exception e)
{
LOGGER.error(
"Error in running net.minecraft.client.gui.hud" +
".InGameHud#renderHotbar " +
"event",
e);
}
} }
} }