Jump to content

[1.6.4][SOLVED-ISH] GENERATED STRUCTURES HAVE MESSED UP LIGHTING


epicsquare

Recommended Posts

Hi everyone,

 

I'll get right to the point:

 

I'm generating a structure and it has the weird blacked out areas lighting bug:

 

 

lQeVK.jpg

 

 

 

I don't know what causes it, and for the life of me I can't get rid of it.

The black bits are all over the place and are really annoying to look at.

 

I've tried running

 

world.markBlockForUpdate(x, y, z);
world.updateAllLightTypes(x, y, z);

 

on every block inside the structure (both air and solid) after generating the structure, and it still happens.

 

Also, when generating the structure, I'm passing 3 as a flag to set block -

world.setBlock(x, y, z, id, meta, 3);

Any advice?

Link to comment
Share on other sites

Hi

 

No obvious cause springs to mind, I would suggest troubleshooting it by setting a breakpoint just before performing the updateAllLightTypes on one of the black blocks, then tracing in to see why it stays dark.

 

This link might give useful background info too (even if it probably doesn't contain a direct answer to your problem...)

 

http://greyminecraftcoder.blogspot.com.au/2013/08/lighting.html

 

-TGG

 

Link to comment
Share on other sites

Thanks for the suggestion, I don't know why I did not think of stepping into updateLightByType lol

 

Turns out this check (the first check in the method) fails :

 

if (this.doChunksNearChunkExist(par2, par3, par4, 17))
{

 

Which makes sense because the structure is being generated with the chunks. TECHNICALLY, I'm generating it on

 

onPopulateChunkPost(PopulateChunkEvent.Post event)

 

because I read that for large structures generating them on that event (rather than registering an IWoldGenerator) prevents them from getting cut off.

 

None the less, that event is called after the IWoldGenerator would have been so the problem remains. If I can't update my lights here, where can I (so that all the chunks would already be generated)?

 

EDIT: I tried force generating all the nearby chunks before updating lights - did not help (.doChunksNearChunkExist is true and the update lights code runs, but dark blocks remain).

 

Not only can I not debug the blocks that are dark (I don't know which ones hey are until I see them in-game, and update lights gets run on every solid block I generate),

but

this.computeLightValue(par2, par3, par4, par1EnumSkyBlock);

 

seems to return 0, and I don't know whether it it supposed to or not (is that block naturally unlit or is it the bug).

 

The link did prove quite interesting, thank you, but I'm still unsure as to the specific cause in my case.

Link to comment
Share on other sites

Well, I seem to have found an extremely sketchy, but somewhat effective fix. Basically when creating the structure, I put a single custom block with a tile entity. Each second (20 ticks) the tile entity checks for players within 100 blocks, and if one is found it updates all the lights in a 50 block radius around it, then replaces itself with a grass block.

 

I know this is very inefficient and somewhat lag inducing, but the performance impact has been tolerable (as far as I can tell, its just a single 500 - 600 millisecond stutter when approaching the structure), and it does solve the problem.

 

Here is the code for the tile entity:

 

 

public class TileEntityLightLoader extends TileEntity {

boolean defunct = false;
int tickCount = 0;
@Override
public void readFromNBT(NBTTagCompound par1nbtTagCompound) {

	super.readFromNBT(par1nbtTagCompound);
}

@Override
public void writeToNBT(NBTTagCompound par1nbtTagCompound) {

	super.writeToNBT(par1nbtTagCompound);
}

@Override
public void updateEntity() {
	if (defunct)
		return;

	tickCount++;
	if (tickCount < 20)
		return;

	tickCount = 0;

	if (worldObj.getClosestPlayer(xCoord, yCoord, zCoord, 100) != null)
	{
		defunct = true;
		updateLights();
	}


}

public void updateLights() {
	if (worldObj.isRemote)
	{
		updateLights_do(xCoord-50, xCoord+50, yCoord-50, yCoord+50, zCoord-50, zCoord+50);
	}
	else
	{
		worldObj.removeBlockTileEntity(xCoord, yCoord, zCoord);
		worldObj.setBlock(xCoord, yCoord, zCoord, Block.grass.blockID);
	}
}

public void updateLights_do(int startX, int endX, int startY, int endY, int startZ, int endZ) {
	int minX = Math.min(startX, endX);
	int maxX = Math.max(startX, endX);

	int minY = Math.min(startY, endY);
	int maxY = Math.max(startY, endY);

	int minZ = Math.min(startZ, endZ);
	int maxZ = Math.max(startZ, endZ);

	for (int x = minX; x <= maxX; x++)
	{
		for (int y = minY; y <= maxY; y++)
		{
			for (int z = minZ; z <= maxZ; z++)
			{
				updateLights_do_do(x, y, z);
			}
		}
	}
}

public void updateLights_do_do(int x, int y, int z)
{
	this.worldObj.markBlockForUpdate(x, y, z);

	this.worldObj.markBlockRangeForRenderUpdate(x, y, z, 5, 5, 5);
	this.worldObj.updateLightByType(EnumSkyBlock.Sky, x, y, z);

}
}

 

 

 

If anyone has a better suggestion, please post!

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.