Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.18.1] [Bug] Forge 39.0.10 The chunk load event fires before the light is calculated.

Featured Replies

Posted

I am trying to do this:

@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public void onChunkLoaded(ChunkEvent.Load event) {
	if (event.getWorld().isClientSide()) {
		if (event.getWorld() instanceof Level) {
			Level world = (Level) event.getWorld();
			DataLayer sky = world.getLightEngine().getLayerListener(LightLayer.SKY).getDataLayerData(SectionPos.of(event.getChunk().getPos().x, 64 >> 4, event.getChunk().getPos().z));
			if (sky != null) System.out.println(sky.get(8, 8, 8));
		}
	}
}

But I get zero all the time.

If I try to do this at any other time after loading the chunk, the result will be correct.

In addition, everything worked correctly on version 1.17.x

Edited by Liahim

Sorry, I don't speak English very well...

  • Author

No, that doesn't work either.

@SubscribeEvent
public void onChunkLoaded(ChunkEvent.Load event) {
	if (event.getWorld().isClientSide()) {
		if (event.getWorld() instanceof Level) {
			Level world = (Level) event.getWorld();
			LayerLightEventListener sky = world.getLightEngine().getLayerListener(LightLayer.SKY);
			BlockPos pos = new BlockPos(event.getChunk().getPos().getWorldPosition().above(70)); //Tried at different heights
			MutableBlockPos mPos = BlockPos.ZERO.mutable();
			for (int x = 0; x < 16; ++x) {
				for (int z = 0; z < 16; ++z) {
					int s = sky.getLightValue(mPos.set(pos).move(x, 0, z));
					System.out.println(pos + "_" + s);
				}
			}
		}
	}
}

Location?
I've tried this in a lot of locations.
It outputs either zero or 15 (obviously in empty chunk sections) to the console...

Edited by Liahim

Sorry, I don't speak English very well...

  • Liahim changed the title to [1.18.1] [Bug] Forge 39.0.10 The chunk load event fires before the light is calculated.
  • Author
1 minute ago, diesieben07 said:

It's not what I told you to do.

This is exactly what you said.
If we look into the Level#getBrightness method, we can see the same thing.

default int getBrightness(LightLayer type, BlockPos pos) {
	return this.getLightEngine().getLayerListener(type).getLightValue(pos);
}

 

5 minutes ago, diesieben07 said:

I meant show this code:

For example:

@SubscribeEvent
public void playerTick(PlayerTickEvent event) {
	if (event.side == LogicalSide.CLIENT && event.phase == Phase.START ) {
		if (event.player.tickCount % 20 == 0) {
			Level world = event.player.level;
			LayerLightEventListener sky = world.getLightEngine().getLayerListener(LightLayer.SKY);
			BlockPos pos = new BlockPos(event.player.blockPosition());
			MutableBlockPos mPos = BlockPos.ZERO.mutable();
			for (int x = 0; x < 16; ++x) {
				for (int z = 0; z < 16; ++z) {
					int s = sky.getLightValue(mPos.set(pos).move(x, 0, z));
					System.out.println(pos + "_" + s);
				}
			}
		}
	}
}

It doesn't matter where and how to do it. I see incorrect data only during the chunk load event. And this happens only at 1.18.x

Sorry, I don't speak English very well...

  • Author
16 minutes ago, diesieben07 said:

Then why did you copy it instead of calling getBrightness?

In order not to receive the LayerLightEventListener 256 times, but to receive it only once.

16 minutes ago, diesieben07 said:

Then Mojang changed something about the chunk loading. And if you look into the code then you will see that chunk loading and light update are now two separate packets (as opposed to 1.17 and earlier). So first the chunk is loaded and then it later receives its light data. Not much you can do about this.

Could you point me to where the light data is being retrieved?
Perhaps I can somehow intercept this packet or add a mixin call to it.
I really need to know this exactly at the time of loading the chunk, since I am making a lightmap.

Maybe I should ask the forge team to add a special event for this?

Or is it easier for me to add my own ticker for each chunk and retrieve data one tick after loading? 😄

Edited by Liahim

Sorry, I don't speak English very well...

  • Author

Thanks! I'll see what I can do about it.

Sorry, I don't speak English very well...

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.