Hello everyone,
For a 1.14 mod,
I try to create an item that change the state of a block. To do that I'm using setBlockState method of World object. The code for doing this use a variable that confirmed that the rest of the code is working well.
As I search into setBlockState method I find these lines :
/**
* Sets a block state into this world.Flags are as follows:
* 1 will cause a block update.
* 2 will send the change to clients.
* 4 will prevent the block from being re-rendered.
* 8 will force any re-renders to run on the main thread instead
* 16 will prevent neighbor reactions (e.g. fences connecting, observers pulsing).
* 32 will prevent neighbor reactions from spawning drops.
* 64 will signify the block is being moved.
* Flags can be OR-ed
*/
I think this may change the behaviour but I try for the flag that match the best what I wanted and I trye for 7 and 11 but none of them changes the behaviour.
Here is the method where I use the method setBlockState :
private void updatePoweredState(World world, BlockState state,BlockPos pos,BlockState oldState) {
isPowered = !isPowered;
if (isPowered){
System.out.println("etat du block : turn");
world.setBlockState(pos,state.with(SWITCH_POSITION,Corners.TURN),flags);
}else {
System.out.println("etat du block : straight");
world.setBlockState(pos,state.with(SWITCH_POSITION,Corners.STRAIGHT),flags);
}
}
flags has the value 7 or 11.
what the code is doing is changing the state switchposition and then almost instantly changing the state to the previous one.