mojira.dev
MC-10480

Blindness + Night-vision Effects Create Complete Blindness

I was messing around with the effects and I found that the blindness effect and the night vision effect cause you to see nothing but the sun and the light in the sky.
Commands to test:

/effect @p minecraft:night_vision 1000000 0
/effect @p minecraft:blindness 1000000 0

Code analysis by @unknown in this comment.

Linked issues

Attachments

Comments 17

Anon Ymus

Confirmed.

Michael Cooper

Still in the game as of 13w09c.

Craig McKinley

and as of the 1.5 pre-release

Ethan Brown

AND as of 13w25b

Erik Broes

Not really sure what the issue is, this works as intended.

'nightvision' doesn't override blindness and removes its effect.

You can also still see the floor beneath you without any issues.

7 more comments
Sonicwave

Fixed in 15w31b. What makes regular blindness + Moody brightness not enough? 🙂

user-f2760

no it's not, also this is resolved as intended
and I agree with Martin, it's very usefull for map makers

Jacob Larsen

It is breaking one of my maps though. I want to limit a players ability to see (distance wise) but light up he area around said player i.e. Holding a torch. It makes no sense that a torch could light up areas 160 m away. Instead, they are completely blinded. Bug still in 1.9

Possible fix:
Blindness has 256 levels, but only one effect. Why not allow blindness II create complete blindness and blindness I created normal blindness. Night vision + blindness 1 creates the lighted limited area. Blindness II under any circumstances is complete darkness.

Everybody wins.

Sonicwave

Based on @unknown's comment, I actually think that he misunderstood this issue since he said that you can see the floor without issues, while this bug is describing the exact opposite. There are discussions on Reddit about this issue here and here.

In any case, this behavior is inconsistent between computers: it didn't occur to me in 17w17b or 1.11.2 on a Windows 10 with NVIDIA (seen in attachment 2017-04-27_16.13.25.png), but when I tested it on another computer in the same versions it did occur (will get screenshots/specs when I get access to that computer again).

Edit: This seems to have the same cause as MC-4647, which describes blackness when in the Void with Night Vision.

Ben Staddon

Having had a chance to look at this earlier, here's an explanation of the bug.

The issue is in EntityRenderer.updateFogColor() and is the cause of both MC-4647 and MC-10480.

Looking at the relevant section of code there (based on MC 1.12.1):

double d1 = (entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks) * world.provider.getVoidFogYFactor();

if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPotionActive(MobEffects.BLINDNESS))
{
	int i = ((EntityLivingBase)entity).getActivePotionEffect(MobEffects.BLINDNESS).getDuration();

	if (i < 20)
	{
		d1 *= (double)(1.0F - (float)i / 20.0F);
	}
	else
	{
		d1 = 0.0D;
	}
}

if (d1 < 1.0D)
{
	if (d1 < 0.0D)
	{
		d1 = 0.0D;
	}

	d1 = d1 * d1;
	this.fogColorRed = (float)((double)this.fogColorRed * d1);
	this.fogColorGreen = (float)((double)this.fogColorGreen * d1);
	this.fogColorBlue = (float)((double)this.fogColorBlue * d1);
}

if (this.bossColorModifier > 0.0F)
{
	float f14 = this.bossColorModifierPrev + (this.bossColorModifier - this.bossColorModifierPrev) * partialTicks;
	this.fogColorRed = this.fogColorRed * (1.0F - f14) + this.fogColorRed * 0.7F * f14;
	this.fogColorGreen = this.fogColorGreen * (1.0F - f14) + this.fogColorGreen * 0.6F * f14;
	this.fogColorBlue = this.fogColorBlue * (1.0F - f14) + this.fogColorBlue * 0.6F * f14;
}

if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPotionActive(MobEffects.NIGHT_VISION))
{
	float f15 = this.getNightVisionBrightness((EntityLivingBase)entity, partialTicks);
	float f6 = 1.0F / this.fogColorRed;

	if (f6 > 1.0F / this.fogColorGreen)
	{
		f6 = 1.0F / this.fogColorGreen;
	}

	if (f6 > 1.0F / this.fogColorBlue)
	{
		f6 = 1.0F / this.fogColorBlue;
	}

	this.fogColorRed = this.fogColorRed * (1.0F - f15) + this.fogColorRed * f6 * f15;
	this.fogColorGreen = this.fogColorGreen * (1.0F - f15) + this.fogColorGreen * f6 * f15;
	this.fogColorBlue = this.fogColorBlue * (1.0F - f15) + this.fogColorBlue * f6 * f15;
}

After some calculations, the fog colour values are multiplied by the value d1. If this value is zero, which can occur both due to being subject to the blindness effect and also a negative y position, then all three colour components of the fog will be zero upon entering the block of code applying the night-vision effect. This is what triggers the bug.

Within the night-vision code, the value f6 is calculated as the minimum of the reciprocal of the red, green, blue colour values. For the case where these are all 0, this value will be infinity.

The colour values are then linearly interpolated (based on the night-vision intensity value, f15) between their original values, and the value multiplied by the calculated factor f6. In the case described above, this multiplication will be 0 * infinity, which has no defined value, and will evaluate to NaN (Not a Number). The NaN value will propagate here, leading to a final NaN value being assigned as the fog colours.

These invalid values are then passed to various OpenGL fog functions, which is what seems to be causing the effects described. As NVidia cards do have alternative fog rendering methods (that are used by Minecraft - the optional "GL_NV_fog_distance" extension) it's likely that the implementation used handling this differently is the reason why it's hardware dependent.

The night-vision code needs to handle this edge case, to avoid passing invalid values here. If the developers do intend on having the end result, it should be coded specifically, rather than relying on implementation quirks.

Notes:
See the OpenGL spec (section 2.3.4.1: Floating-Point Computation) for some info about how various floating-point values are to be handled.

Michael Cooper

(Unassigned)

Confirmed

Snapshot 13w09b, Snapshot 13w09c, Snapshot 13w10b, Minecraft 1.5, Snapshot 13w11a, ..., Snapshot 13w24a, Snapshot 13w24b, Snapshot 13w25a, Snapshot 13w25b, Minecraft 15w31a

1.15.2

Retrieved