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 09:18:01 -06:00
parent 5e553f2e72
commit 13045618ec

View File

@@ -58,6 +58,8 @@ public class EventBus
*/
@SubscribeEvent
public static void onClick(final PlayerInteractEvent event)
{
try
{
DistExecutor.safeRunWhenOn(Dist.CLIENT,
(DistExecutor.SafeSupplier<DistExecutor.SafeRunnable>) () -> new DistExecutor.SafeRunnable()
@@ -73,6 +75,14 @@ public class EventBus
}
});
}
catch (Exception e)
{
LOGGER.error(
"Error in running markil3.immersive_hud.EventBus#onClick " +
"event",
e);
}
}
/**
* Run whenever the player mounts something. This brings the mount's health
@@ -85,6 +95,8 @@ public class EventBus
*/
@SubscribeEvent
public static void onMount(final EntityMountEvent event)
{
try
{
DistExecutor.safeRunWhenOn(Dist.CLIENT,
(DistExecutor.SafeSupplier<DistExecutor.SafeRunnable>) () -> new DistExecutor.SafeRunnable()
@@ -96,6 +108,14 @@ public class EventBus
}
});
}
catch (Exception e)
{
LOGGER.error(
"Error in running markil3.immersive_hud.EventBus#onMount " +
"event",
e);
}
}
/**
* Run whenever a hand is rendered in 1st person. This brings the player
@@ -106,11 +126,23 @@ public class EventBus
@SubscribeEvent
public static void onRenderHand(final RenderHandEvent event)
{
if (TimerUtils.onRenderHand(event.getHand(), event.getMatrixStack(), event.getPartialTicks()))
try
{
if (TimerUtils.onRenderHand(event.getHand(),
event.getMatrixStack(),
event.getPartialTicks()))
{
event.setCanceled(true);
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running markil3.immersive_hud" +
".EventBus#onRenderHand event",
e);
}
}
/**
* Called whenever we are drawing a part of the GUI. This is where most of
@@ -120,6 +152,8 @@ public class EventBus
*/
@SubscribeEvent
public static void onGUIDraw(final RenderGameOverlayEvent event)
{
try
{
Minecraft mc = Minecraft.getInstance();
boolean fadeIn = false;
@@ -168,7 +202,8 @@ public class EventBus
case HEALTH:
if (event instanceof RenderGameOverlayEvent.Pre)
{
if (TimerUtils.drawHealth(event.getMatrixStack(), event.getPartialTicks()))
if (TimerUtils.drawHealth(event.getMatrixStack(),
event.getPartialTicks()))
{
event.setCanceled(true);
}
@@ -182,7 +217,8 @@ public class EventBus
case FOOD:
if (event instanceof RenderGameOverlayEvent.Pre)
{
if (TimerUtils.drawHunger(event.getMatrixStack(), event.getPartialTicks()))
if (TimerUtils.drawHunger(event.getMatrixStack(),
event.getPartialTicks()))
{
event.setCanceled(true);
}
@@ -199,7 +235,8 @@ public class EventBus
case ARMOR:
if (event instanceof RenderGameOverlayEvent.Pre)
{
if (TimerUtils.drawArmor(event.getMatrixStack(), event.getPartialTicks()))
if (TimerUtils.drawArmor(event.getMatrixStack(),
event.getPartialTicks()))
{
event.setCanceled(true);
}
@@ -216,7 +253,8 @@ public class EventBus
case AIR:
if (event instanceof RenderGameOverlayEvent.Pre)
{
if (TimerUtils.drawAir(event.getMatrixStack(), event.getPartialTicks()))
if (TimerUtils.drawAir(event.getMatrixStack(),
event.getPartialTicks()))
{
event.setCanceled(true);
}
@@ -233,7 +271,8 @@ public class EventBus
case HEALTHMOUNT:
if (event instanceof RenderGameOverlayEvent.Pre)
{
if (TimerUtils.drawMountHealth(event.getMatrixStack(), event.getPartialTicks()))
if (TimerUtils.drawMountHealth(event.getMatrixStack(),
event.getPartialTicks()))
{
event.setCanceled(true);
}
@@ -250,8 +289,11 @@ public class EventBus
event.setCanceled(true);
if (!TimerUtils.drawJumpbar(event.getPartialTicks()))
{
RenderUtils.renderHorseJumpBar(mc, mc.ingameGUI,
event.getMatrixStack(), event.getPartialTicks(), TimerUtils.jumpTime);
RenderUtils.renderHorseJumpBar(mc,
mc.ingameGUI,
event.getMatrixStack(),
event.getPartialTicks(),
TimerUtils.jumpTime);
}
}
break;
@@ -261,11 +303,21 @@ public class EventBus
event.setCanceled(true);
if (!TimerUtils.drawExperience(event.getPartialTicks()))
{
RenderUtils.renderExperience(mc, mc.ingameGUI,
event.getMatrixStack(), event.getPartialTicks(), TimerUtils.experienceTime);
RenderUtils.renderExperience(mc,
mc.ingameGUI,
event.getMatrixStack(),
event.getPartialTicks(),
TimerUtils.experienceTime);
}
}
break;
}
}
catch (Exception e)
{
LOGGER.error(
"Error in running markil3.immersive_hud.EventBus#onGUIDraw event",
e);
}
}
}