Jump to content

When must I set block state in world(call setBlockState).


AntonBespoiasov

Recommended Posts

49 minutes ago, AntonBespoiasov said:

Creating block I override methods that take block state as parameter and do something with it(for example onBlockPlacedBy). But I don't know must I call setBlockState from World to update block state?

Post your code. And explain what you are trying to do.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

23 minutes ago, Animefan8888 said:

Post your code. And explain what you are trying to do.

@Override
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
    {
        state.withProperty(BlockBed.FACING, placer.getHorizontalFacing());
        calculateBedTileBorders(worldIn, pos, state);
        calculateBedTilePillow(worldIn, pos, state, placer.getHorizontalFacing());
        notifyNeighborsOfBorderRecalculation(worldIn, pos);    
        worldIn.setBlockState(pos, state);
    }

calculateBedTileBorders(...) and calculateBedTilePillows(...) are functions that affect state, they don't set blcok state in world. notifyNeighborsOfBorderRecalculation(...) is a function that tells blocks around that they must call calculateBedTileBorders(...). TillingBed(block where this method is overridden) is a bed with connected textures.

 

What I think happens there? All these methods that are called in onBlockPlacedBy(...) don't copy state but just change("mutate") it and then this block state is set in world in onBlockPlacedBy(...). Why methods that are called in onBlockPlacedBy(...) just change it and don't copy? Each of these methods has its own parameter state in it that refer to single instance of block state due to IBlockState is mutable.

Link to comment
Share on other sites

5 minutes ago, AntonBespoiasov said:

Each of these methods has its own parameter state in it that refer to single instance of block state due to IBlockState is mutable.

They might exist because there are two BlockStates for a bed. The pillow part of the bed and foot part of the bed. However, I don't know because you are looking at rather old code.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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



×
×
  • Create New...

Important Information

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