3030import org .geysermc .geyser .session .GeyserSession ;
3131import org .geysermc .geyser .util .ChunkUtils ;
3232
33+ import java .util .Objects ;
34+
3335public class DoorBlock extends Block {
3436 public DoorBlock (String javaIdentifier , Builder builder ) {
3537 super (javaIdentifier , builder );
@@ -40,7 +42,10 @@ public void updateBlock(GeyserSession session, BlockState state, Vector3i positi
4042 // Needed to check whether we must force the client to update the door state.
4143 String doubleBlockHalf = state .getValue (Properties .DOUBLE_BLOCK_HALF );
4244
43- if (!session .getGeyser ().getWorldManager ().hasOwnChunkCache () && doubleBlockHalf .equals ("lower" )) {
45+ Vector3i lastLowerDoor = session .getLastLowerDoorPosition ();
46+ session .setLastLowerDoorPosition (null );
47+
48+ if (Objects .equals (lastLowerDoor , position ) && doubleBlockHalf .equals ("lower" )) {
4449 BlockState oldBlockState = session .getGeyser ().getWorldManager ().blockAt (session , position );
4550 // If these are the same, it means that we already updated the lower door block (manually in the workaround below),
4651 // and we do not need to update the block in the cache/on the client side using the super.updateBlock() method again.
@@ -55,9 +60,14 @@ public void updateBlock(GeyserSession session, BlockState state, Vector3i positi
5560 if (doubleBlockHalf .equals ("upper" )) {
5661 // Update the lower door block as Bedrock client doesn't like door to be closed from the top
5762 // See https://github.com/GeyserMC/Geyser/issues/4358
58- Vector3i belowDoorPosition = position .sub ( 0 , 1 , 0 );
63+ Vector3i belowDoorPosition = position .down ( 1 );
5964 BlockState belowDoorBlockState = session .getGeyser ().getWorldManager ().blockAt (session , belowDoorPosition .getX (), belowDoorPosition .getY (), belowDoorPosition .getZ ());
60- ChunkUtils .updateBlock (session , belowDoorBlockState , belowDoorPosition );
65+ // better safe than sorry - withValue can throw
66+ if (belowDoorBlockState .block () instanceof DoorBlock ) {
67+ belowDoorBlockState = belowDoorBlockState .withValue (Properties .OPEN , state .getValue (Properties .OPEN ));
68+ ChunkUtils .updateBlock (session , belowDoorBlockState , belowDoorPosition );
69+ session .setLastLowerDoorPosition (belowDoorPosition );
70+ }
6171 }
6272 }
6373}
0 commit comments