Posted January 7, 20223 yr 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 January 7, 20223 yr by CreativeMasterBonin
January 7, 20223 yr 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 January 7, 20223 yr by CreativeMasterBonin
January 7, 20223 yr I changed the definition to "BlockState _bs = world.getBlockState(_pos).setValue(WhiteRoadMarking.TYPE,marking_type);" and it worked! Thanks!
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.