Jump to content

Recommended Posts

Posted

Hi, recently i started with minecraft mod development and i was trying to lit my block but for some reason it does not seem to work. I might have forgot something but im pretty sure it was suppose to work with the piece of code below right? I know that for some of you this might seem a dumb post but i really would appreciate if someone could help me. Thanks in advance.

public class AerialLight extends Block {

    public static final BooleanProperty LIT = BlockStateProperties.LIT;

    public AerialLight(Properties properties){
        super(properties.sound(SoundType.WOOL).noCollission());
        this.registerDefaultState(this.stateDefinition.any().setValue(LIT, Boolean.valueOf(true)));
    }

    public void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_48928_) {
        p_48928_.add(LIT);
    }
}
Posted
7 hours ago, diesieben07 said:
  • Use @Override when overriding methods.
  • You added a block state property to your block. It can now store whether it should be lit or not. You have not told the game to actually make your block light up. Use the lightLevel method of the Properties class.

I thought LIT would actually light my block but apparently is just a way to verify its state my bad haha, but if lightlevel is defined in the constructor how would i then turn it off with use()? Becaus right now i can change my block state with LIT but not the lightlevel. 

Posted

That boolean property could be called MADE_OF_GOLD for all the relevance it has to its name.

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.

Posted
36 minutes ago, Draco18s said:

That boolean property could be called MADE_OF_GOLD for all the relevance it has to its name.

Got it, that was really confusing me haha but how do i update my block lightlevel?

Posted
36 minutes ago, diesieben07 said:

 

But that would be in my block class constructor. I was wondering if i could update the lightLevel after defining it in the constructor for example:

public AerialLight(Properties properties){
        super(properties.sound(SoundType.WOOL).noCollission().lightLevel((p_60954_) -> {
            return 15;
        }));
        this.registerDefaultState(this.stateDefinition.any().setValue(LIT, Boolean.valueOf(true)));
}

public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit){
	//Update the lightLevel here for 0
	return InteractionResult.SUCCESS;
}

I don't know if I explained myself well😅 but is it possible?

Posted
1 hour ago, diesieben07 said:

lightLevel takes a ToIntFunction as its parameter. You can return different results based on the BlockState.

I have tried that before but my problem is that because my class constructor will always be called first i don't know how would i be returning different values with the blockstate from use(). I have tried the following, but obviously it would never work

public static final BooleanProperty LIT = BlockStateProperties.LIT;
private static int LightUp = 15;    

public AerialLight(Properties properties){
        super(properties.sound(SoundType.WOOL).noCollission().lightLevel((p_60954_) -> {
            return LightUp; 
        }));
        this.registerDefaultState(this.stateDefinition.any().setValue(LIT, Boolean.valueOf(true)));
    }

@Override
  public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit){
        if(state.getValue(LIT)){
            level.setBlock(pos, state.setValue(LIT, Boolean.valueOf(false)), 3);
            LightUp = 0;
            return InteractionResult.SUCCESS;
        }else{
            LightUp = 15;
            level.setBlock(pos, state.setValue(LIT, Boolean.valueOf(true)), 3);
            return InteractionResult.SUCCESS;
        }
    }

I even tried with a verification inside lightLevel as it is a function

Posted
37 minutes ago, diesieben07 said:

You have to check the LIT property inside the lambda passed to lightLevel.

Bruh, nevermind i am just dumb because when i did the verification for some reason my brain completely erased the fact that "p_60954_" was a parameter for the lambda expression being the reason why nothing was working. Well i appreciate alot your patience, really, thank you.

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.