Fix night vision deactivating after dimension change via portal (#262)

Co-authored-by: Caedis <[email protected]>
This commit is contained in:
Eldrinn ElanteyandCaedis authored and GitHub committed 2026-09-04 18:41:45 -05:00
1 parent caec163702
commit a4a40ee726
3 files changed
+28 -51

No files matched your search

@@ -337,32 +337,18 @@ public class KeyTracker {
}
private void handleNightVision() {
if (nightVisionKey.isPressed()) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (!DarkSteelController.instance.isNightVisionUpgradeOrEnchEquipped(player)) {
return;
}
boolean isActive = !DarkSteelController.instance.isNightVisionActive();
if (isActive) {
player.worldObj.playSound(
player.posX,
player.posY,
player.posZ,
EnderIO.DOMAIN + ":ds.nightvision.on",
0.1f,
player.worldObj.rand.nextFloat() * 0.4f - 0.2f + 1.0f,
false);
} else {
player.worldObj.playSound(
player.posX,
player.posY,
player.posZ,
EnderIO.DOMAIN + ":ds.nightvision.off",
0.1f,
1.0f,
false);
}
DarkSteelController.instance.setNightVisionActive(isActive);
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (nightVisionKey.isPressed() && DarkSteelController.instance.isNightVisionUpgradeOrEnchEquipped(player)) {
boolean turningOn = !DarkSteelController.instance.isActive(player, Type.NIGHT_VISION);
player.worldObj.playSound(
player.posX,
player.posY,
player.posZ,
EnderIO.DOMAIN + (turningOn ? ":ds.nightvision.on" : ":ds.nightvision.off"),
0.1f,
turningOn ? player.worldObj.rand.nextFloat() * 0.4f - 0.2f + 1.0f : 1.0f,
false);
toggleDarkSteelController(Type.NIGHT_VISION, "darksteel.upgrade.nightVision");
}
}
@@ -107,9 +107,6 @@ public class DarkSteelController {
private final Map<UUID, EnumSet<Type>> allActive = new HashMap<>();
private boolean nightVisionActive = false;
private boolean removeNightvision = false;
private DarkSteelController() {
PacketHandler.INSTANCE.registerMessage(
PacketDarkSteelPowerPacket.class,
@@ -196,6 +193,8 @@ public class DarkSteelController {
updateSwim(player);
updateSolar(player);
updateNightvision(player);
}
}
@@ -447,7 +446,6 @@ public class DarkSteelController {
if (player == null) {
return;
}
updateNightvision(player);
if (player.capabilities.isFlying) {
return;
}
@@ -569,16 +567,20 @@ public class DarkSteelController {
}
private void updateNightvision(EntityPlayer player) {
if (isNightVisionUpgradeOrEnchEquipped(player) && nightVisionActive) {
player.addPotionEffect(new PotionEffect(Potion.nightVision.getId(), 210, 0, true));
if (player.worldObj.isRemote) {
return;
}
if (!isNightVisionUpgradeOrEnchEquipped(player) && nightVisionActive) {
nightVisionActive = false;
removeNightvision = true;
}
if (removeNightvision) {
PotionEffect effect = player.getActivePotionEffect(Potion.nightVision);
boolean hasNVUpgrade = isNightVisionUpgradeOrEnchEquipped(player);
boolean isNVUpgradeEnabled = isActive(player, Type.NIGHT_VISION);
if (hasNVUpgrade && isNVUpgradeEnabled) {
// only (re)apply effect if ours is missing or about to expire
if (effect == null || (effect.getIsAmbient() && effect.getDuration() < 220)) {
player.addPotionEffect(new PotionEffect(Potion.nightVision.getId(), 400, 0, true));
}
} else if (effect != null && effect.getIsAmbient() && (hasNVUpgrade || isNVUpgradeEnabled)) {
// if our effect exists and the player removed the upgrade item or toggled it off (both can't be true here)
player.removePotionEffect(Potion.nightVision.getId());
removeNightvision = false;
}
}
@@ -613,21 +615,9 @@ public class DarkSteelController {
return false;
}
// ---
public boolean isNightVisionUpgradeOrEnchEquipped(EntityPlayer player) {
ItemStack helmet = player.getEquipmentInSlot(4);
return (NightVisionUpgrade.loadFromItem(helmet) != null || isNightVisionEnch(helmet));
}
public void setNightVisionActive(boolean isNightVisionActive) {
if (nightVisionActive && !isNightVisionActive) {
removeNightvision = true;
}
this.nightVisionActive = isNightVisionActive;
}
public boolean isNightVisionActive() {
return nightVisionActive;
}
}
@@ -15,7 +15,8 @@ public class PacketUpgradeState implements IMessage, IMessageHandler<PacketUpgra
GLIDE,
SPEED,
STEP_ASSIST,
JUMP
JUMP,
NIGHT_VISION
}
public PacketUpgradeState() {}