Compare commits

..

5 Commits

Author SHA1 Message Date
Markil3
9d955b3f81 Fixes a crash on some computers where the configuration file can't always be made. 2021-04-01 18:19:08 -06:00
Markil3
711e6121d4 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 10:47:38 -06:00
Markil3
13045618ec 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:18:01 -06:00
Markil3
5e553f2e72 Fixes a ClassCastException (#1) 2021-03-25 17:14:47 -06:00
Markil3
2fe4ec56f8 Fixes the hand not properly sliding out of view. 2021-03-04 09:05:09 -07:00
6 changed files with 365 additions and 231 deletions

View File

@@ -11,6 +11,6 @@ forge_version=35.1.37
cloth_version=4.11.14 cloth_version=4.11.14
# Mod Properties # Mod Properties
mod_version = 1.0 mod_version = 1.1.1
maven_group = markil3 maven_group = markil3
archives_base_name = immersive_hud archives_base_name = immersive_hud

View File

@@ -3,6 +3,7 @@ package markil3.immersive_hud;
import com.electronwill.nightconfig.core.file.CommentedFileConfig; import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.io.WritingMode; import com.electronwill.nightconfig.core.io.WritingMode;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
@@ -50,7 +51,7 @@ public class ConfigManager
new ForgeConfigSpec.Builder().configure(ConfigManager::new); new ForgeConfigSpec.Builder().configure(ConfigManager::new);
INSTANCE = specPair.getLeft(); INSTANCE = specPair.getLeft();
SPEC = specPair.getRight(); SPEC = specPair.getRight();
CommentedFileConfig config = CommentedFileConfig.builder(CONFIG_PATH) CommentedFileConfig config = CommentedFileConfig.builder(Minecraft.getInstance().gameDir.toPath().toAbsolutePath().resolve(CONFIG_PATH))
.sync() .sync()
.autoreload() .autoreload()
.writingMode(WritingMode.REPLACE) .writingMode(WritingMode.REPLACE)
@@ -155,7 +156,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;
@@ -182,6 +185,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")
@@ -189,6 +196,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);
@@ -282,6 +293,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.
* *
@@ -292,6 +313,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 +365,16 @@ public class ConfigManager
this.crosshairTime.set(time); this.crosshairTime.set(time);
} }
/**
* 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.
* *
@@ -344,6 +385,16 @@ public class ConfigManager
this.handTime.set(time); this.handTime.set(time);
} }
/**
* 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.
* *

View File

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

View File

@@ -123,6 +123,15 @@ public class ModMenu
.setCrosshairTime((int) (val * TICKS_PER_SECOND))) .setCrosshairTime((int) (val * TICKS_PER_SECOND)))
.build()); .build());
general.addEntry(entryBuilder.startBooleanToggle(new TranslationTextComponent(
"option.immersive_hud.hideCrosshair"), ConfigManager.getInstance().hideCrosshair())
.setDefaultValue(true)
.setTooltip(new TranslationTextComponent(
"tooltip.immersive_hud.hideCrosshair"))
.setSaveConsumer(val -> ConfigManager.getInstance()
.hideCrosshair(val))
.build());
general.addEntry(entryBuilder.startDoubleField(new TranslationTextComponent( general.addEntry(entryBuilder.startDoubleField(new TranslationTextComponent(
"option.immersive_hud.handTime"), "option.immersive_hud.handTime"),
(float) ConfigManager.getInstance() (float) ConfigManager.getInstance()
@@ -134,6 +143,15 @@ public class ModMenu
.setHandTime((int) (val * TICKS_PER_SECOND))) .setHandTime((int) (val * TICKS_PER_SECOND)))
.build()); .build());
general.addEntry(entryBuilder.startBooleanToggle(new TranslationTextComponent(
"option.immersive_hud.hideHands"), ConfigManager.getInstance().hideHands())
.setDefaultValue(true)
.setTooltip(new TranslationTextComponent(
"tooltip.immersive_hud.hideHands"))
.setSaveConsumer(val -> ConfigManager.getInstance()
.hideHands(val))
.build());
general.addEntry(entryBuilder.startDoubleField(new TranslationTextComponent( general.addEntry(entryBuilder.startDoubleField(new TranslationTextComponent(
"option.immersive_hud.minHealth"), "option.immersive_hud.minHealth"),
ConfigManager.getInstance() ConfigManager.getInstance()

View File

@@ -24,7 +24,6 @@ import net.minecraft.potion.Effect;
import net.minecraft.potion.EffectInstance; import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects; import net.minecraft.potion.Effects;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
@@ -295,8 +294,12 @@ public class TimerUtils
MatrixStack matrixStack, MatrixStack matrixStack,
float ticks) float ticks)
{ {
float HAND_UP_TIME = 1F; float HAND_UP_TIME = 20F;
boolean hideHands =
ConfigManager.getInstance().hideHands();
if (hideHands)
{
switch (hand) switch (hand)
{ {
case OFF_HAND: case OFF_HAND:
@@ -350,6 +353,7 @@ public class TimerUtils
} }
break; break;
} }
}
return false; return false;
} }
@@ -384,6 +388,8 @@ public class TimerUtils
boolean changed = false; boolean changed = false;
boolean canceled = false; boolean canceled = false;
if (ConfigManager.getInstance().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)
@@ -413,6 +419,7 @@ public class TimerUtils
{ {
crosshairTime -= ticks; crosshairTime -= ticks;
} }
}
return canceled; return canceled;
} }
@@ -475,7 +482,8 @@ public class TimerUtils
} }
else if (effectinstance.getDuration() <= BLINK_TIME + potion.getFadeInTime()) else if (effectinstance.getDuration() <= BLINK_TIME + potion.getFadeInTime())
{ {
effectAlpha = -(effectinstance.getDuration() - BLINK_TIME) / 22F + 0.454F; effectAlpha =
-(effectinstance.getDuration() - BLINK_TIME) / 22F + 0.454F;
} }
else else
{ {
@@ -758,7 +766,8 @@ public class TimerUtils
* Only makes a change if the player is healthy. Otherwise, * Only makes a change if the player is healthy. Otherwise,
* the bar is shown. * the bar is shown.
*/ */
if (health / maxHealth > HEALTH_BOUNDARY && !mc.player.isPotionActive(Effects.WITHER) && !mc.player.isPotionActive(Effects.POISON)) if (health / maxHealth > HEALTH_BOUNDARY && !mc.player.isPotionActive(
Effects.WITHER) && !mc.player.isPotionActive(Effects.POISON))
{ {
if (healthTime > 0) if (healthTime > 0)
{ {
@@ -930,7 +939,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"