Posted July 8, 20214 yr I am trying to give a blinding effect to players who are in light level of 0 but I can't seem to get it to work. @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { PlayerEntity player = event.player; World world = event.player.level; BlockPos blockpos = player.blockPosition(); BlockState block = world.getBlockState(blockpos); if (block.getLightValue(world, blockpos) == 0 && block != null) { ((LivingEntity)event.player).addEffect(new EffectInstance(Effects.BLINDNESS, 20, 3)); } } Am I using getLightValue correctly? Also I am correctly feeding in the correct block position? Edited July 8, 20214 yr by Sinu
July 8, 20214 yr Author I see. What is the second int parameter in World#getRawBrightness for? I looked at the reference and it just seems to subtract it? Not sure why.. Also I believe I tried using World#getBrightness with LightType.BLOCK but I don't think it detected the light level properly. I am trying to give the Blindness effect to players who walk into caves with light levels of 0.
July 8, 20214 yr Author Sweet, that seems to have worked! The one issue is that, I had to check if the instance was client or server because for some reason the server kept thinking the light level of the player is always 0 (is it client-side only?). So my code looks like this now: PlayerEntity player = event.player; World world = event.player.level; BlockPos blockpos = player.blockPosition(); BlockState block = world.getBlockState(blockpos); if (world.isClientSide) { System.out.print(world.getMaxLocalRawBrightness(blockpos) + System.lineSeparator()); if (world.getMaxLocalRawBrightness(blockpos) == 0) { ((LivingEntity)event.player).addEffect(new EffectInstance(Effects.BLINDNESS, 20, 3)); } } But now once I walk out of the light level of 0, it still says that I have the Blindness effect even though I can see clearly. I am assuming that since I checked if the instance is client-side or not, it didn't actually give the potion effect according to the server (which makes sense) but I don't understand why Blindness goes away even after I walk into the light?
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.