Jump to content

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


Liahim

Recommended Posts

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...

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

  • Liahim changed the title to [1.18.1] [Bug] Forge 39.0.10 The chunk load event fires before the light is calculated.
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...

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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