Compare commits

...

4 Commits

Author SHA1 Message Date
Markil3
5219932076 Changes:
+ Adds the ability to determine whether hands and crosshairs disappear or not. This can be changed in the mod configuration.
* Reduces the chance of the mod crashing the game for ordinary events (any errors will be reported to the console, though).
Bug Fixes
* Fixes crash when mounting boat or minecart (#1 thanks, @theFuzzyWarble!)
2021-04-01 13:09:55 -06:00
Markil3
bb18357bfe Adds the ability to always show hands and crosshairs.
Apparently, @rflambert doesn't want the hands to fade. It seemed like a good idea, so I added a configurable option to the main repo.
2021-03-26 11:00:18 -06:00
Markil3
5e3b714190 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.
2021-03-26 09:27:07 -06:00
Markil3
5059774b34 Fixes a ClassCastException (#1) 2021-03-25 17:15:36 -06:00
5 changed files with 309 additions and 207 deletions

View File

@@ -10,6 +10,6 @@ forge_version=26.0.63
# Mod Properties # Mod Properties
mod_version = 1.0 mod_version = 1.1
maven_group = markil3 maven_group = markil3
archives_base_name = immersive_hud archives_base_name = immersive_hud

View File

@@ -154,7 +154,9 @@ public class ConfigManager
private final TimeValues hungerTime; private final TimeValues hungerTime;
private final TimeValues effectTime; private final TimeValues effectTime;
private final ForgeConfigSpec.IntValue crosshairTime; private final ForgeConfigSpec.IntValue crosshairTime;
private final ForgeConfigSpec.BooleanValue hideCrosshair;
private final ForgeConfigSpec.IntValue handTime; private final ForgeConfigSpec.IntValue handTime;
private final ForgeConfigSpec.BooleanValue hideHands;
private final ForgeConfigSpec.BooleanValue showArmor; private final ForgeConfigSpec.BooleanValue showArmor;
private final ForgeConfigSpec.DoubleValue minHealth; private final ForgeConfigSpec.DoubleValue minHealth;
private final ForgeConfigSpec.IntValue minHunger; private final ForgeConfigSpec.IntValue minHunger;
@@ -181,6 +183,10 @@ public class ConfigManager
6 * TICKS_PER_SECOND, 6 * TICKS_PER_SECOND,
0, 0,
10 * 60 * TICKS_PER_SECOND); 10 * 60 * TICKS_PER_SECOND);
this.hideCrosshair =
configSpecBuilder.translation(
"immersive_hud.configGui.hideCrosshair.title")
.define("hideCrosshair", true);
this.handTime = this.handTime =
configSpecBuilder.translation( configSpecBuilder.translation(
"immersive_hud.configGui.handTime.title") "immersive_hud.configGui.handTime.title")
@@ -188,6 +194,10 @@ public class ConfigManager
30 * TICKS_PER_SECOND, 30 * TICKS_PER_SECOND,
0, 0,
10 * 60 * TICKS_PER_SECOND); 10 * 60 * TICKS_PER_SECOND);
this.hideHands =
configSpecBuilder.translation(
"immersive_hud.configGui.hideHands.title")
.define("hideHands", true);
this.showArmor = configSpecBuilder.translation( this.showArmor = configSpecBuilder.translation(
"immersive_hud.configGui.showArmor.title") "immersive_hud.configGui.showArmor.title")
.define("showArmor", true); .define("showArmor", true);
@@ -281,6 +291,16 @@ public class ConfigManager
return this.crosshairTime.get(); return this.crosshairTime.get();
} }
/**
* Checks whether the crosshairs should be hidden after a period of time.
*
* @return - Whether or not crosshairs will be hidden.
*/
public boolean hideCrosshair()
{
return this.hideCrosshair.get();
}
/** /**
* Obtains the time that the hands are allowed to display. * Obtains the time that the hands are allowed to display.
* *
@@ -291,6 +311,16 @@ public class ConfigManager
return this.handTime.get(); return this.handTime.get();
} }
/**
* Checks whether hands should be hidden after a period of time.
*
* @return - Whether or not hands will be hidden.
*/
public boolean hideHands()
{
return this.hideHands.get();
}
/** /**
* Checks whether the armor bar should render. * Checks whether the armor bar should render.
* *
@@ -334,6 +364,16 @@ public class ConfigManager
// } // }
// //
// /** // /**
// * Sets whether the crosshairs should be hidden after a period of time.
// *
// * @param hide - Whether or not crosshairs will be hidden.
// */
// public void hideCrosshair(boolean hide)
// {
// this.hideCrosshair.set(hide);
// }
//
// /**
// * Sets the time that the hands are allowed to display. // * Sets the time that the hands are allowed to display.
// * // *
// * @param time - The hand display time values. // * @param time - The hand display time values.
@@ -344,6 +384,16 @@ public class ConfigManager
// } // }
// //
// /** // /**
// * Sets whether hands should be hidden after a period of time.
// *
// * @param hide - Whether or not hands will be hidden.
// */
// public void hideHands(boolean hide)
// {
// this.hideHands.set(hide);
// }
//
// /**
// * Determines whether the armor bar should render. // * Determines whether the armor bar should render.
// * // *
// * @param show - Whether or not armor shows on the HUD. // * @param show - Whether or not armor shows on the HUD.

View File

@@ -23,7 +23,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderSpecificHandEvent; import net.minecraftforge.client.event.RenderSpecificHandEvent;
import net.minecraftforge.event.entity.EntityMountEvent; import net.minecraftforge.event.entity.EntityMountEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
@@ -61,6 +60,8 @@ public class EventBus
*/ */
@SubscribeEvent @SubscribeEvent
public static void onClick(final PlayerInteractEvent event) public static void onClick(final PlayerInteractEvent event)
{
try
{ {
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () ->
{ {
@@ -71,6 +72,14 @@ public class EventBus
TimerUtils.onClick(event.getHand(), item); TimerUtils.onClick(event.getHand(), item);
}); });
} }
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 * Run whenever the player mounts something. This brings the mount's health
@@ -83,12 +92,22 @@ public class EventBus
*/ */
@SubscribeEvent @SubscribeEvent
public static void onMount(final EntityMountEvent event) public static void onMount(final EntityMountEvent event)
{
try
{ {
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () ->
{ {
TimerUtils.resetMountHealth(); TimerUtils.resetMountHealth();
}); });
} }
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 * Run whenever a hand is rendered in 1st person. This brings the player
@@ -98,6 +117,8 @@ public class EventBus
*/ */
@SubscribeEvent @SubscribeEvent
public static void onRenderHand(final RenderSpecificHandEvent event) public static void onRenderHand(final RenderSpecificHandEvent event)
{
try
{ {
if (TimerUtils.onRenderHand(event.getHand(), if (TimerUtils.onRenderHand(event.getHand(),
event.getPartialTicks())) event.getPartialTicks()))
@@ -105,6 +126,14 @@ public class EventBus
event.setCanceled(true); 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 * Called whenever we are drawing a part of the GUI. This is where most of
@@ -114,6 +143,8 @@ public class EventBus
*/ */
@SubscribeEvent @SubscribeEvent
public static void onGUIDraw(final RenderGameOverlayEvent event) public static void onGUIDraw(final RenderGameOverlayEvent event)
{
try
{ {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
boolean fadeIn = false; boolean fadeIn = false;
@@ -264,4 +295,11 @@ public class EventBus
break; break;
} }
} }
catch (Exception e)
{
LOGGER.error(
"Error in running markil3.immersive_hud.EventBus#onGUIDraw event",
e);
}
}
} }

View File

@@ -294,6 +294,10 @@ public class TimerUtils
{ {
float HAND_UP_TIME = 20F; float HAND_UP_TIME = 20F;
boolean hideHands =
ConfigManager.getInstance().hideHands();
if (hideHands)
{
switch (hand) switch (hand)
{ {
case OFF_HAND: case OFF_HAND:
@@ -344,6 +348,7 @@ public class TimerUtils
} }
break; break;
} }
}
return false; return false;
} }
@@ -378,6 +383,10 @@ public class TimerUtils
boolean changed = false; boolean changed = false;
boolean canceled = false; boolean canceled = false;
boolean hideCrosshair =
ConfigManager.getInstance().hideCrosshair();
if (hideCrosshair)
{
if (mc.objectMouseOver != null && mc.objectMouseOver.getType() != RayTraceResult.Type.MISS) if (mc.objectMouseOver != null && mc.objectMouseOver.getType() != RayTraceResult.Type.MISS)
{ {
if (mc.objectMouseOver.getType() == RayTraceResult.Type.ENTITY) if (mc.objectMouseOver.getType() == RayTraceResult.Type.ENTITY)
@@ -407,6 +416,7 @@ public class TimerUtils
{ {
crosshairTime -= ticks; crosshairTime -= ticks;
} }
}
return canceled; return canceled;
} }
@@ -923,7 +933,7 @@ public class TimerUtils
Entity tmp = mc.player.getRidingEntity(); Entity tmp = mc.player.getRidingEntity();
boolean changed = false; boolean changed = false;
if (tmp == null) if (tmp == null || !(tmp instanceof LivingEntity))
{ {
mountHealth = -1; mountHealth = -1;
mountMaxHealth = -1; mountMaxHealth = -1;

View File

@@ -19,7 +19,9 @@
"option.immersive_hud.effectFadeIn": "Potion Fade In Time", "option.immersive_hud.effectFadeIn": "Potion Fade In Time",
"option.immersive_hud.effectFadeOut": "Potion Fade Out Time", "option.immersive_hud.effectFadeOut": "Potion Fade Out Time",
"option.immersive_hud.crosshairTime": "Crosshair Display Time", "option.immersive_hud.crosshairTime": "Crosshair Display Time",
"option.immersive_hud.hideCrosshair": "Hide Crosshair",
"option.immersive_hud.handTime": "Hand Display Time", "option.immersive_hud.handTime": "Hand Display Time",
"option.immersive_hud.hideHands": "Hide Hands",
"option.immersive_hud.minHealth": "Minimum Health Fade", "option.immersive_hud.minHealth": "Minimum Health Fade",
"option.immersive_hud.minHunger": "Minimum Hunger Fade", "option.immersive_hud.minHunger": "Minimum Hunger Fade",
"option.immersive_hud.showArmor": "Show Armor", "option.immersive_hud.showArmor": "Show Armor",
@@ -42,7 +44,9 @@
"tooltip.immersive_hud.effectFadeIn": "How many seconds it takes for potion icons to fade in", "tooltip.immersive_hud.effectFadeIn": "How many seconds it takes for potion icons to fade in",
"tooltip.immersive_hud.effectFadeOut": "How many seconds it takes for potion icons to fade out", "tooltip.immersive_hud.effectFadeOut": "How many seconds it takes for potion icons to fade out",
"tooltip.immersive_hud.crosshairTime": "How many seconds the crosshairs can be on screen", "tooltip.immersive_hud.crosshairTime": "How many seconds the crosshairs can be on screen",
"tooltip.immersive_hud.hideCrosshair": "Whether or not the crosshairs should be hidden after a period of time",
"tooltip.immersive_hud.handTime": "How many seconds the hands can be on screen", "tooltip.immersive_hud.handTime": "How many seconds the hands can be on screen",
"tooltip.immersive_hud.hideHands": "Whether or not hands should be hidden after a period of time",
"tooltip.immersive_hud.minHealth": "When the percentage of health goes below this level, the health bar won't fade away", "tooltip.immersive_hud.minHealth": "When the percentage of health goes below this level, the health bar won't fade away",
"tooltip.immersive_hud.minHunger": "When the hunger level goes below this level, the hunger bar won't fade away", "tooltip.immersive_hud.minHunger": "When the hunger level goes below this level, the hunger bar won't fade away",
"tooltip.immersive_hud.showArmor": "Whether or not the armor bar should display on the HUD" "tooltip.immersive_hud.showArmor": "Whether or not the armor bar should display on the HUD"