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

Item right clicked on block function only partially works, only 1 out of 2 blockstates is updated at a time


Recommended Posts

PasteBin Code

Item PasteBin Code

 

So I have an item that when right clicked on a block (when shift is held) sets it's NBTdata up by one, and loops back around to 0 when the max value is reached. It works fine.

When I right click any block (not shift held down) it places a default state Road Marking block.

 

My intended behavior is to grab the item's NBTdata and player facing position and apply it to the Road Marking block in the world when it is placed.

 

My code partially works, but only 1 of the 2 blockstates is ever updated on the block that is placed. If the "type" blockstate is changed first, only the "facing" blockstate is changed based on which way the player is facing, but if "type" is second, the "facing" blockstate is overwritten by the "type" blockstate, causing the block to only face it's default direction.

I'm using the method setBlock() from the LevelAccessor to do this behavior.

 

I'm not sure what I'm doing wrong here, because both blockstates are setup properly. I've included the function in a pastebin link. The pastebin code shows the code if "type" is applied to the block at the current block location after the "facing" blockstate is applied.

Also, there is a pastebin for the Item that does the right click actions.

Edited by CreativeMasterBonin
Link to comment
Share on other sites

Posted (edited)

I understand that part, I get the position and states of the block from the Level... and that only 1 state can be changed at a time... but...

The main problem is that I want the block to not only face the player when placed, but also be the correct state based on the Item's NBTdata.

 

I want the setBlock() method to basically Place a block that faces the player and make's it's 'TYPE' property correspond to the Item's 'marking_type' nbt data.

 

I've looked through Level & Block methods and none seem to really do what I want them to do.

If I cannot change 2 properties of a block at the same time, without resetting one of the blockstates, then I'm stumped.

Edited by CreativeMasterBonin
Link to comment
Share on other sites

A quote from your code:

Quote

 // get property of marking_type then apply to current block being put in world

This is not what the following code does. The code takes _bs (which is the block state that was in the world at the beginning of the method, before setting the facing or axis property), sets the TYPE property and then places that in the world (in line 34). This makes the previous setBlock calls (line 29 and 25) redundant, because you are overwriting the block state that you placed there. You need to apply both properties to the BlockState (note that setValue returns a new BlockState instance, BlockState is immutable!). Then place the resulting BlockState value in the world. You only need one setBlock call.

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