diff --git a/changelog b/changelog index 9c2a128f4..45700092f 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ ## Changed * Particle detectors now print an error for when the recipe could not be completed +* Night Vision Goggles toggles with armor HUD * Removed "no ore dict data" line from tooltips with extended view enabled * Added a client config called `GUN_ANIMATION_SPEED` which allows the speed of gun animations to be changed * Mostly for debugging, since it only applies to the bus animation system, things like smoke trails and muzzle flashes are unaffected @@ -9,4 +10,4 @@ * Fixed packet optimization not allowing packets to be sent when the day night cycle is halted * Fixed particle detectors not always using power when they should * Fixed rotary furnace voiding low pressure steam when dealing with input numbers not divisible by 100 -* Fixed state leak causing smoke from the right akimbo weapon to glow when the first one is fired \ No newline at end of file +* Fixed state leak causing smoke from the right akimbo weapon to glow when the first one is fired diff --git a/src/main/java/com/hbm/items/armor/ItemModNightVision.java b/src/main/java/com/hbm/items/armor/ItemModNightVision.java index 6418a88bc..305819aaf 100644 --- a/src/main/java/com/hbm/items/armor/ItemModNightVision.java +++ b/src/main/java/com/hbm/items/armor/ItemModNightVision.java @@ -1,10 +1,12 @@ package com.hbm.items.armor; +import com.hbm.extprop.HbmPlayerProps; import com.hbm.handler.ArmorModHandler; import net.minecraft.client.resources.I18n; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.EnumChatFormatting; @@ -12,6 +14,8 @@ import net.minecraft.util.EnumChatFormatting; import java.util.List; public class ItemModNightVision extends ItemArmorMod { + private static final String NIGHT_VISION_ACTIVE_NBT_KEY = "ITEM_MOD_NV_ACTIVE"; + public ItemModNightVision() { super(ArmorModHandler.helmet_only, true, false, false, false); } @@ -31,10 +35,22 @@ public class ItemModNightVision extends ItemArmorMod { @Override public void modUpdate(EntityLivingBase entity, ItemStack armor) { if(!entity.worldObj.isRemote && entity instanceof EntityPlayer && armor.getItem() instanceof ArmorFSBPowered && ArmorFSBPowered.hasFSBArmor((EntityPlayer) entity)) { - entity.addPotionEffect(new PotionEffect(Potion.nightVision.id, 15 * 20, 0)); + if(HbmPlayerProps.getData(((EntityPlayer) entity)).enableHUD) { + // 15 seconds to make less flickering if the client lags + entity.addPotionEffect(new PotionEffect(Potion.nightVision.id, 15 * 20, 0)); + if(!armor.hasTagCompound()) { + armor.setTagCompound(new NBTTagCompound()); + } + if(!armor.getTagCompound().hasKey(NIGHT_VISION_ACTIVE_NBT_KEY)) { + armor.getTagCompound().setBoolean(NIGHT_VISION_ACTIVE_NBT_KEY, true); // Value does not matter, it's just a flag + } - if(entity.getRNG().nextInt(100) == 0) { - armor.damageItem(1, entity); + if (entity.getRNG().nextInt(100) == 0) { + armor.damageItem(1, entity); + } + } else if(armor.hasTagCompound() && armor.getTagCompound().hasKey(NIGHT_VISION_ACTIVE_NBT_KEY)) { // Disable night vision if it was the armor mod that applied it to avoid removing other night vision sources. + entity.removePotionEffect(Potion.nightVision.id); + armor.getTagCompound().removeTag(NIGHT_VISION_ACTIVE_NBT_KEY); } } }