Allows some items to not trigger a hand/crosshair update.

This is helpful if one is using Firework rockets to fly around the landscape
This commit is contained in:
Markil3
2021-08-30 21:21:59 -06:00
parent 2403546896
commit 50fad9acfd
2 changed files with 66 additions and 39 deletions

View File

@@ -1,11 +1,19 @@
package markil3.immersive_hud;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.Registry;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import static markil3.immersive_hud.Main.TICKS_PER_SECOND;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Configuration manager of this mod, which reads from and writes to this mod's
* configuration file.
@@ -88,6 +96,7 @@ public class ConfigManager
private boolean showArmor = true;
private double minHealth = 0.5;
private int minHunger = 17;
private Identifier[] ignoredItems = new Identifier[]{Registry.ITEM.getId(Items.FIREWORK_ROCKET)};
/**
* Returns the instance of this class.
@@ -248,6 +257,16 @@ public class ConfigManager
return this.minHunger;
}
/**
* Obtains a collection of items that won't cause hands and crosshairs to show when used.
*
* @return A set of ignored items.
*/
public Set<Item> getIgnoredItems()
{
return Arrays.stream(ignoredItems).map(Registry.ITEM::get).collect(Collectors.toSet());
}
/**
* Sets the time that the hands are allowed to display.
*
@@ -319,6 +338,16 @@ public class ConfigManager
{
this.minHunger = MathHelper.clamp(boundary, 0, 20);
}
/**
* Sets which items won't cause the hands and crosshairs to show when used.
*
* @param items - A set of ignored items.
*/
public void setIgnoredItems(Item... items)
{
this.ignoredItems = Arrays.stream(items).map(Registry.ITEM::getId).toArray(Identifier[]::new);
}
/**
* Saves changes to this mod's configuration.
*/

View File

@@ -49,6 +49,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Optional;
import java.util.Set;
/**
* Contains the logic for changing the HUD.
@@ -287,9 +288,8 @@ public class TimerUtils
* view, and briefly brings the health and hunger into view if the held item
* is food.
*
* @param hand - The hand being triggered
* @param hand - The hand being triggered
* @param clear - Whether the hand it being enabled or disabled.
*
* @since 0.1-1.16.4-fabric
*/
public static void onClick(Hand hand, boolean clear)
@@ -304,6 +304,7 @@ public class TimerUtils
LivingEntity entity;
Item item;
Iterator<ItemStack> hands;
Set<Item> ignored;
if (mc.getCameraEntity() instanceof LivingEntity)
{
entity = (LivingEntity) mc.getCameraEntity();
@@ -329,6 +330,14 @@ public class TimerUtils
.map(ItemStack::getItem)
.orElse(null);
}
if (item != null)
{
ignored = ConfigManager.getInstance().getIgnoredItems();
if (ignored.contains(item))
{
return;
}
}
crosshairTime = ConfigManager.getInstance().getCrosshairTime();
if (hand == Hand.MAIN_HAND)
{
@@ -345,11 +354,11 @@ public class TimerUtils
if (item.isFood())
{
healthTime = health.getMaxTime() - (healthTime > 0 ?
health.getFadeInTime() :
0);
health.getFadeInTime() :
0);
hungerTime = hunger.getMaxTime() - (hungerTime > 0 ?
hunger.getFadeInTime() :
0);
hunger.getFadeInTime() :
0);
}
}
}
@@ -358,11 +367,9 @@ public class TimerUtils
* Run whenever a hand is rendered in 1st person. This brings the player
* hands into and out of view as needed.
*
* @param hand - The hand being rendered.
* @param hand - The hand being rendered.
* @param matrixStack - The rendering stack.
*
* @return If true, then don't render this hand at all.
*
* @since 0.1-1.16.4-fabric
*/
public static boolean onRenderHand(Hand hand,
@@ -428,7 +435,6 @@ public class TimerUtils
* needed.
*
* @return If true, then cancel drawing the crosshair.
*
* @since 0.1-1.16.4-fabric
*/
public static boolean drawCrosshair(float ticks)
@@ -465,8 +471,8 @@ public class TimerUtils
> 0)
{
setAlpha(Main.getAlpha(crosshairTime > 0 ?
crosshairTime :
CROSSHAIR_TIME, CROSSHAIR_TIME, 0, 0));
crosshairTime :
CROSSHAIR_TIME, CROSSHAIR_TIME, 0, 0));
}
else
{
@@ -485,7 +491,6 @@ public class TimerUtils
* as needed.
*
* @return If true, then cancel drawing the mount health bar.
*
* @since 0.1-1.16.4-fabric
*/
public static boolean drawMountHealth(float ticks)
@@ -529,8 +534,8 @@ public class TimerUtils
if (changed)
{
mountTime = healthTimes.getMaxTime() - (mountTime > 0 ?
healthTimes.getFadeInTime() :
0);
healthTimes.getFadeInTime() :
0);
}
else if (mountTime > 0)
{
@@ -617,7 +622,6 @@ public class TimerUtils
* Obtains how transparent
*
* @param effectinstance
*
* @return
*/
public static float getPotionAlpha(StatusEffectInstance effectinstance)
@@ -629,7 +633,8 @@ public class TimerUtils
if (effectinstance.getDuration() <= BLINK_TIME)
{
effectAlpha =
MathHelper.sin(7000F / (effectinstance.getDuration() + 16F * (float) Math.PI)) * 50F / (effectinstance
MathHelper.sin(7000F / (effectinstance
.getDuration() + 16F * (float) Math.PI)) * 50F / (effectinstance
.getDuration() + 100F) + 0.5F;
}
else if (effectinstance.getDuration() <= BLINK_TIME + potion.getFadeInTime())
@@ -654,7 +659,6 @@ public class TimerUtils
* needed.
*
* @return If true, then cancel drawing the armor bar.
*
* @since 0.1-1.16.4-fabric
*/
public static boolean drawArmor()
@@ -682,7 +686,6 @@ public class TimerUtils
* needed.
*
* @return If true, then cancel drawing the health.
*
* @since 0.1-1.16.4-fabric
*/
public static boolean drawHealth(float ticks)
@@ -726,8 +729,8 @@ public class TimerUtils
if (changed)
{
healthTime = healthTimes.getMaxTime() - (healthTime > 0 ?
healthTimes.getFadeInTime() :
0);
healthTimes.getFadeInTime() :
0);
}
else if (healthTime > 0)
{
@@ -758,7 +761,6 @@ public class TimerUtils
* needed.
*
* @return If true, then cancel drawing the hunger bar.
*
* @since 0.1-1.16.4-fabric
*/
public static boolean drawHunger(float ticks)
@@ -805,8 +807,8 @@ public class TimerUtils
if (changed)
{
hungerTime = hungerTimes.getMaxTime() - (hungerTime > 0 ?
hungerTimes.getFadeInTime() :
0);
hungerTimes.getFadeInTime() :
0);
}
else if (hungerTime > 0)
{
@@ -837,7 +839,6 @@ public class TimerUtils
* as needed.
*
* @return If true, then cancel drawing the jump bar.
*
* @since 0.1-1.16.4-fabric
*/
public static boolean drawJumpbar(float ticks)
@@ -859,8 +860,8 @@ public class TimerUtils
if (entity.method_3151() > 0)
{
jumpTime = jump.getMaxTime() - (jumpTime > 0 ?
jump.getFadeInTime() :
0);
jump.getFadeInTime() :
0);
}
else if (jumpTime > 0)
{
@@ -884,7 +885,6 @@ public class TimerUtils
* as needed.
*
* @return If true, then cancel drawing the experience bar.
*
* @since 0.1-1.16.4-fabric
*/
public static boolean drawExperience(float ticks)
@@ -913,8 +913,8 @@ public class TimerUtils
if (changed)
{
experienceTime = experience.getMaxTime() - (experienceTime > 0 ?
experience.getFadeInTime() :
0);
experience.getFadeInTime() :
0);
}
else if (experienceTime > 0)
{
@@ -941,7 +941,6 @@ public class TimerUtils
* or not to draw it.
*
* @return If true, then cancel drawing the hotbar.
*
* @see #recolorHotbar()
* @since 0.1-1.16.4-fabric
*/
@@ -1050,7 +1049,7 @@ public class TimerUtils
{
if (entity.isUsingItem() && entity
.getActiveHand() != null && entity.getActiveHand()
.ordinal() == i)
.ordinal() == i)
{
switch (i)
{
@@ -1113,11 +1112,11 @@ public class TimerUtils
if (item.isFood())
{
healthTime = health.getMaxTime() - (healthTime > 0 ?
health.getFadeInTime() :
0);
health.getFadeInTime() :
0);
hungerTime = hunger.getMaxTime() - (hungerTime > 0 ?
hunger.getFadeInTime() :
0);
hunger.getFadeInTime() :
0);
}
if (i == 0)
{
@@ -1146,8 +1145,8 @@ public class TimerUtils
if (changed)
{
hotbarTime = hotbar.getMaxTime() - (hotbarTime > 0 ?
hotbar.getFadeInTime() :
0);
hotbar.getFadeInTime() :
0);
}
else if (hotbarTime > 0)
{
@@ -1162,7 +1161,6 @@ public class TimerUtils
* needed.
*
* @return If true, then cancel drawing the crosshair.
*
* @since 0.1-1.16.4-fabric
*/
public static void recolorHotbar()