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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -32,3 +32,4 @@ bin/
|
|||||||
|
|
||||||
run/
|
run/
|
||||||
/logs/
|
/logs/
|
||||||
|
/remappedSrc/
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package markil3.immersive_hud;
|
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.math.MathHelper;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
//import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
//import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||||
|
|
||||||
@@ -8,6 +12,12 @@ import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
|||||||
|
|
||||||
import static markil3.immersive_hud.Main.TICKS_PER_SECOND;
|
import static markil3.immersive_hud.Main.TICKS_PER_SECOND;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration manager of this mod, which reads from and writes to this mod's
|
* Configuration manager of this mod, which reads from and writes to this mod's
|
||||||
* configuration file.
|
* configuration file.
|
||||||
@@ -90,6 +100,7 @@ public class ConfigManager
|
|||||||
private boolean showArmor = true;
|
private boolean showArmor = true;
|
||||||
private double minHealth = 0.5;
|
private double minHealth = 0.5;
|
||||||
private int minHunger = 17;
|
private int minHunger = 17;
|
||||||
|
private Identifier[] ignoredItems = new Identifier[]{Registry.ITEM.getId(Items.FIREWORK_ROCKET)};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the instance of this class.
|
* Returns the instance of this class.
|
||||||
@@ -250,6 +261,16 @@ public class ConfigManager
|
|||||||
return this.minHunger;
|
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.
|
* Sets the time that the hands are allowed to display.
|
||||||
*
|
*
|
||||||
@@ -321,6 +342,16 @@ public class ConfigManager
|
|||||||
{
|
{
|
||||||
this.minHunger = MathHelper.clamp(boundary, 0, 20);
|
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.
|
* Saves changes to this mod's configuration.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ import net.minecraft.util.math.MathHelper;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the logic for changing the HUD.
|
* Contains the logic for changing the HUD.
|
||||||
@@ -304,6 +306,7 @@ public class TimerUtils
|
|||||||
LivingEntity entity;
|
LivingEntity entity;
|
||||||
Item item;
|
Item item;
|
||||||
Iterator<ItemStack> hands;
|
Iterator<ItemStack> hands;
|
||||||
|
Set<Item> ignored;
|
||||||
if (mc.getCameraEntity() instanceof LivingEntity)
|
if (mc.getCameraEntity() instanceof LivingEntity)
|
||||||
{
|
{
|
||||||
entity = (LivingEntity) mc.getCameraEntity();
|
entity = (LivingEntity) mc.getCameraEntity();
|
||||||
@@ -329,6 +332,14 @@ public class TimerUtils
|
|||||||
.map(ItemStack::getItem)
|
.map(ItemStack::getItem)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
ignored = ConfigManager.getInstance().getIgnoredItems();
|
||||||
|
if (ignored.contains(item))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
crosshairTime = ConfigManager.getInstance().getCrosshairTime();
|
crosshairTime = ConfigManager.getInstance().getCrosshairTime();
|
||||||
if (hand == Hand.MAIN_HAND)
|
if (hand == Hand.MAIN_HAND)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user