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

replace a block onItemUse


Recommended Posts

 

how to check what block gets right clicked by your item, and then replace it to another block, but with the same blockstate as the first block?

 

I know I have to use the "onItemUse" method but don't know what to put after the 'if'

 

this is what I got so far....

public ActionResultType onItemUse(ItemUseContext context) {
World world = context.getWorld();
    BlockPos blockpos = context.getPos();
    BlockState blockstate = world.getBlockState(blockpos);
    BlockState block = blockstate.getBlockState();
    if (block != null) {

 

Link to post
Share on other sites
5 minutes ago, JoppeGames3 said:

if (block != null) {

This check is pointless.

 

5 minutes ago, JoppeGames3 said:

but with the same blockstate as the first block?

What do you mean by this? The blockstate includes the block, so if you want the same blockstate that also means its the same block. Please elaborate.

In general, to set the block state at a position use World#setBlockState.

Link to post
Share on other sites
1 minute ago, diesieben07 said:

What do you mean by this? The blockstate includes the block, so if you want the same blockstate that also means its the same block.

I meant same rotation..

2 minutes ago, diesieben07 said:

This check is pointless.

what do I have to check

and how to replace it with another block

Link to post
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.

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.



×
×
  • Create New...

Important Information

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