Jump to content

Recommended Posts

Posted (edited)

I'm trying to make a simple analog lamp, where the light output equals the max redstone input. I thought this would be simple, but it's not working. This is the relevant code, inside the block class:

 

	@Override
	public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) {
		if (world instanceof World) {
			World theWorld = (World) world;
			return theWorld.isBlockIndirectlyGettingPowered(pos);
		}
		return 0;
	}

	@Override
	public void observedNeighborChange(IBlockState thisState, World world, BlockPos thisPos, Block changedBlock,
			BlockPos changedBlockPos) {
		world.setLightFor(EnumSkyBlock.BLOCK, thisPos, world.isBlockIndirectlyGettingPowered(thisPos));
		world.checkLight(thisPos);
	}

 

Some debug output shows that the observedNeighborChange() method is being called correctly, when there's a block state change next to the lamp, and that isBlockIndirectlyGettingPowered() is returning the appropriate redstone signal strength.

Yet the block never lights up. Why not?

 

*Update* After more testing, it seems like the block light *is* getting set properly, but only after I exit the world and reload it. I thought checkLight() was supposed to update the light levels; if it's not, what do I need to call to update the light levels without relogging?

*UPDATE 2* I fixed it! As it turns out, you need to change the block state for Minecraft to actually update the lighting. Even calling setBlockState with the current state won't work; it needs to be a new block state. So I added a "power" property and set power equal to the redstone input, then I change the blockstate whenever the neighbor changes and it all works fine.

Edited by IceMetalPunk
Solved it myself

Whatever Minecraft needs, it is most likely not yet another tool tier.

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.

Announcements



×
×
  • Create New...

Important Information

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