Posted February 17, 20214 yr 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
February 17, 20214 yr 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)
February 17, 20214 yr Author 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 February 17, 20214 yr by JoeAteTheBeans
February 17, 20214 yr 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 February 17, 20214 yr by Luis_ST
February 17, 20214 yr Author 2 minutes ago, Luis_ST said: i wasn't sure either but i have tested it and when i use the method i set the light level I'll make sure to refer back to that then if the current solution ever fails, thanks
May 15, 20214 yr Hi i have a question, i try the same but my block makes only light when a block update is:
August 15, 20232 yr 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.