Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] i cant figure out how to make the block light up when its night time and turn off when day


FREyebeans2506
 Share

Recommended Posts

i have tried several things to get it to change when the day changes to night i can only get it to be lit up if i place it at night

package com.freyebeans2506.faltthethe.contentfeatures.blocks;

import net.minecraft.block.BedBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.LightType;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;

import javax.annotation.Nullable;
import java.util.Random;

public class ABBlock extends Block {
    public static final BooleanProperty LIT = BlockStateProperties.LIT;
    public ABBlock(Properties properties) {
        super(properties);
        this.registerDefaultState(this.stateDefinition.any().setValue(LIT, Boolean.valueOf(false)));
    }

    @Nullable
    public BlockState getStateForPlacement(BlockItemUseContext p_196258_1_) {
        return this.defaultBlockState().setValue(LIT, Boolean.valueOf(p_196258_1_.getLevel().isNight()));
    }

    protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> p_206840_1_) {
        p_206840_1_.add(LIT);
    }
}

this has been causing me pain for the past 3 hours

Link to comment
Share on other sites

Hint: take a look at the daylight sensor.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

This block surely has code you can look at, yeah?

Go look at it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

10 hours ago, FREyebeans2506 said:

could you elaborate

On your IDE you probably have a folder called "External Libraries" on your project tree. In there you can find among a whole lot of other things, one folder that in particular may come handy. For example for 1.17.1 (Should be similar if not the same for 1.16.5)

Gradle: net.minecraftforge:forge:1.17.1:37.1.1_mapped_official_1.17.1 (For 1.16.5 the name will change a little bit of course)

When you open this tree you will find net > minecraft > level > world > block > DaylightDetectorBlock

In there you can take a look at it's code to see what this block is doing in order to detect when it's daylight and when it's not. Haven't been doing MC modding in a time, but I guess this block been that it extends an entity block, it "ticks" and so has this method where the "magic" happens. tickEntity

Link to comment
Share on other sites

3 minutes ago, American2050 said:

On your IDE you probably have a folder called "External Libraries" on your project tree. In there you can find among a whole lot of other things, one folder that in particular may come handy. For example for 1.17.1 (Should be similar if not the same for 1.16.5)

Gradle: net.minecraftforge:forge:1.17.1:37.1.1_mapped_official_1.17.1 (For 1.16.5 the name will change a little bit of course)

When you open this tree you will find net > minecraft > level > world > block > DaylightDetectorBlock

Or... you know... Use the "go to class" feature that any IDE has.

Link to comment
Share on other sites

I tend to forget that one, but do remember F4, which opens the type hierarchy for a focused Type, and if I know that I'm looking for a block (or PlayerEvent, or whatever), I can quickly make a variable and F4 it and browse.

  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

  • 3 weeks later...

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
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.

 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.