Night vision toggling with HUD

This commit is contained in:
Toshayo 2025-02-07 12:47:43 +01:00
parent b60db5b911
commit b462b30156
No known key found for this signature in database
GPG Key ID: 7DC46644B561B1B4
2 changed files with 21 additions and 4 deletions

View File

@ -1,7 +1,8 @@
## Changed
* Particle detectors now print an error for when the recipe could not be completed
* Night Vision Goggles toggles with armor HUD
## Fixed
* Fixed items being annihilated when shift clicking them into the particle source
* 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 particle detectors not always using power when they should

View File

@ -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);
}
}
}