Jump to content

Block light emission in 1.16


JoeAteTheBeans

Recommended Posts

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 :)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 months later...
  • 2 years later...

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.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • AGENSLOT77 dikenal sebagai salah satu situs judi slot gacor terpercaya. Istilah "gacor" merujuk pada mesin slot yang sering memberikan kemenangan kepada pemainnya. Dengan koleksi permainan slot yang beragam dan canggih, AGENSLOT77 memberikan kesempatan besar bagi para pemain untuk meraih kemenangan yang menggiurkan. 2. Slot88 Terpercaya Slot88 merupakan salah satu permainan slot paling populer di AGENSLOT77. Dengan desain yang menawan dan pembayaran yang besar, Slot88 menjadi favorit di antara pemain judi online. Malam ini, para pemain dapat menikmati berbagai permainan Slot88 yang menarik dan menguntungkan di AGENSLOT77. 3. Peluang Maxwin Malam Ini AGENSLOT77 menawarkan peluang Maxwin yang menarik, terutama malam ini. Dengan fitur yang mudah dimengerti dan diakses, pemain memiliki kesempatan besar untuk meraih kemenangan maksimum dalam setiap permainan yang mereka mainkan. Jadi, jangan lewatkan kesempatan untuk memenangkan hadiah besar di AGENSLOT77 malam ini!   ❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰  
    • Javatogel: Agen BO Terpercaya, Anti Sedot WC, 100% Real, Gampang Menang Dalam dunia perjudian online, menemukan agen yang dapat dipercaya adalah langkah penting untuk pen galaman berjudi yang aman dan menguntungkan. Salah satu agen yang mendapat kepercayaan tinggi dari para pemain adalah Javatogel. Mari kita telusuri lebih dalam mengenai apa yang membuat Javatogel menjadi pilihan utama bagi para pecinta togel. Javatogel: Agen BO Terpercaya                                   DAFTAR SEKARANG AKUN VIP MAXWIN
    • S1288POKER Rasakan sensasi bertaruh Mix Parlay yang tak terlupakan dengan bonus fantastis di situs judi terpercaya kami! Kami menawarkan bonus Mix Parlay terbesar di Asia dengan berbagai pilihan taruhan dan minimal deposit rendah. Dapatkan bonus hingga jutaan rupiah untuk taruhan Mix Parlay Anda dan nikmati keuntungan berlipat ganda.
    • Situs Akun Pro Peru adalah pilihan terbaik bagi Anda yang mencari situs terpercaya untuk bermain slot dan taruhan bola. Berikut adalah beberapa alasan mengapa Anda harus memilih Situs Akun Pro Peru: Slot Populer Kami menyajikan koleksi slot yang populer dan menarik dengan berbagai tema yang beragam. Dari slot klasik hingga slot video modern, setiap pemain dapat menemukan permainan favorit mereka dengan mudah. Taruhan Bola Terpercaya Selain slot, kami juga menyediakan taruhan bola dengan pasaran terlengkap dan odds yang kompetitif. Dengan berbagai pertandingan dan liga yang tersedia, Anda dapat menikmati pengalaman taruhan bola yang seru dan menguntungkan. Transaksi Mudah dengan Bank BTN Kami menyediakan layanan transaksi yang mudah dan aman melalui Bank BTN. Dengan dukungan dari sistem pembayaran yang terpercaya, Anda dapat melakukan deposit dan penarikan dana dengan cepat dan tanpa hambatan.  
    • Ngamenslot adalah pilihan terbaik bagi Anda yang mencari situs terpercaya untuk bermain slot dan taruhan bola. Berikut adalah beberapa alasan mengapa Anda harus memilih Ngamenslot: Kombinasi Slot & Bola Kami menyajikan kombinasi terbaik antara permainan slot yang seru dan taruhan bola yang menegangkan. Dengan pilihan permainan yang beragam, setiap pemain dapat menikmati pengalaman bermain yang unik dan menyenangkan. Transaksi Mudah melalui Bank Ekonomi Kami menyediakan layanan transaksi yang mudah dan aman melalui Bank Ekonomi. Dengan dukungan dari sistem pembayaran yang terpercaya, Anda dapat melakukan deposit dan penarikan dana dengan cepat dan tanpa hambatan. Terpercaya dan Terjamin Ngamenslot telah terbukti sebagai situs terpercaya dengan ribuan pemain yang puas. Kami mengutamakan keamanan dan kenyamanan para pemain, sehingga Anda dapat bermain dengan tenang dan fokus pada permainan.  
  • Topics

×
×
  • Create New...

Important Information

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