Jump to content

Recommended Posts

Posted

Hello there,

Was just wondering if anyone could explain to me how to give a block its own light level in 1.16 Forge. I read that in previous versions you could use:

.setLightLevel(0.5f);

with the float being a value between 0 and 1.

 

Though in 1.16 you have to use:

.setLightLevel(ToIntFunction<BlockState>);

which I frankly don't understand. I'm fairly new to Java, and after reading up on block states for a while, I've come to the conclusion that I have no idea what to do here.

 

Any help would be much appreciated :)

Posted
15 minutes ago, JoeAteTheBeans said:

Though in 1.16 you have to use:

use the methode:

	@Override
	public int getLightValue(BlockState state, IBlockReader world, BlockPos pos) {
		
		return super.getLightValue(state, world, pos);
		
	}

and retun the light level you want (1-15)

Posted (edited)
1 hour ago, Luis_ST said:

use the methode:


	@Override
	public int getLightValue(BlockState state, IBlockReader world, BlockPos pos) {
		
		return super.getLightValue(state, world, pos);
		
	}

and retun the light level you want (1-15)

Forgive me if I'm wrong, but to me this looks like a method to get the light level of a block, not to set it.

 

1 hour ago, diesieben07 said:

You have to pass in an implementation of ToIntFunction, most likely you'll want to use a lambda expression. It will get the block state passed in and needs to return the light value for that state. If you want all states of your block to have the same light value, you can just return the value.

Thanks for explaining this to me, working off of what you said I managed to get it working and also learned what a lambda expression was in the process. So thank you :)

 

To anyone wanted a code example of this, I'll share my working code with you (though there is probably a better way to do it):

public class BlockInit {
	
	// Light level (Change the 5 to whatever light level you want).
	public static ToIntFunction<BlockState> lightLevel = BlockState -> 5;
	
	// Register creation.
	public static final DeferredRegister<Block> block = DeferredRegister.create(ForgeRegistries.BLOCKS, Mineite.modid);
	
	// Block creation.
	public static final Block testBlock = new Block(AbstractBlock.Properties
			.create(Material.IRON)
			.hardnessAndResistance(100f, 1200f)
			.harvestTool(ToolType.PICKAXE)
			.harvestLevel(4)
			.setLightLevel(lightLevel)
			.sound(SoundType.ANCIENT_DEBRIS));
	
	// Adding block to register.
	public static final RegistryObject<Block> testBlock_registered = block.register("test_block", () -> testBlock);	
}

 

Edited by JoeAteTheBeans
Posted (edited)
7 minutes ago, JoeAteTheBeans said:

Forgive me if I'm wrong, but to me this looks like a method to get the light level of a block, not to set it.

i wasn't sure either but i tested it and when i used the method the block has a light level

Edited by Luis_ST
  • 2 months later...
  • 2 years later...
Posted

I'm sure it's been solved already, but I had luck using:

.setLightLevel(s -> 15);

instead of:

.setLightLevel(0.5f);

on 1.16.5.

(replace numbers with the value you want)

Just add this to your block register class with the other properties.

This worked for me on 1.16.5 using Forge MCP mappings. It will likely be different on Mojang official mappings. Hopefully this helps somebody out there who might come across this thread.

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.