Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite Night Vision Fix #2391

Open
wants to merge 1 commit into
base: 1.20.1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper;
import com.gregtechceu.gtceu.api.capability.IElectricItem;
import com.gregtechceu.gtceu.api.item.armor.ArmorLogicSuite;
import com.gregtechceu.gtceu.api.item.armor.ArmorUtils;
import com.gregtechceu.gtceu.utils.input.KeyBind;

import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -34,45 +35,45 @@ public void onArmorTick(Level world, @NotNull Player player, @NotNull ItemStack
if (item == null) {
return;
}
CompoundTag nbtData = itemStack.getOrCreateTag();
byte toggleTimer = nbtData.getByte("toggleTimer");
if (!player.getItemBySlot(EquipmentSlot.HEAD).is(itemStack.getItem())) {
disableNightVision(world, player, false);
}
CompoundTag data = itemStack.getOrCreateTag();
byte toggleTimer = data.contains("toggleTimer") ? data.getByte("toggleTimer") : 0;
int nightVisionTimer = data.contains("nightVisionTimer") ? data.getInt("nightVisionTimer") :
ArmorUtils.NIGHTVISION_DURATION;
if (type == ArmorItem.Type.HELMET) {
boolean nightvision = nbtData.getBoolean("nightVision");
boolean nightVision = data.contains("nightVision") && data.getBoolean("nightVision");
if (toggleTimer == 0 && KeyBind.ARMOR_MODE_SWITCH.isKeyDown(player)) {
nightVision = !nightVision;
toggleTimer = 5;
if (!nightvision && item.getCharge() >= energyPerUse) {
nightvision = true;
if (!world.isClientSide)
player.displayClientMessage(Component.translatable("metaarmor.message.nightvision.enabled"),
true);
} else if (nightvision) {
nightvision = false;
disableNightVision(world, player, true);
if (item.getCharge() < ArmorUtils.MIN_NIGHTVISION_CHARGE) {
nightVision = false;
player.displayClientMessage(Component.translatable("metaarmor.nms.nightvision.error"), true);
} else {
if (!world.isClientSide) {
player.displayClientMessage(Component.translatable("metaarmor.message.nightvision.error"),
true);
}
}

if (!world.isClientSide) {
nbtData.putBoolean("nightVision", nightvision);
player.displayClientMessage(Component
.translatable("metaarmor.nms.nightvision." + (nightVision ? "enabled" : "disabled")), true);
}
}

if (nightvision && !world.isClientSide && item.getCharge() >= energyPerUse) {
if (nightVision) {
player.removeEffect(MobEffects.BLINDNESS);
player.addEffect(new MobEffectInstance(MobEffects.NIGHT_VISION, 999999, 0, true, false));
item.discharge((energyPerUse), this.tier, true, false, false);
if (nightVisionTimer <= ArmorUtils.NIGHT_VISION_RESET) {
nightVisionTimer = ArmorUtils.NIGHTVISION_DURATION;
player.addEffect(
new MobEffectInstance(MobEffects.NIGHT_VISION, ArmorUtils.NIGHTVISION_DURATION, 0, true,
false));
item.discharge((4), this.tier, true, false, false);
}
} else {
player.removeEffect(MobEffects.NIGHT_VISION);
}
data.putBoolean("nightVision", nightVision);

if (toggleTimer > 0) --toggleTimer;

nbtData.putByte("toggleTimer", toggleTimer);
}

if (nightVisionTimer > 0) nightVisionTimer--;
if (toggleTimer > 0) toggleTimer--;

data.putInt("nightVisionTimer", nightVisionTimer);
data.putByte("toggleTimer", toggleTimer);
}

public static void disableNightVision(@NotNull Level world, Player player, boolean sendMsg) {
Expand Down