Skip to content

Commit dbed595

Browse files
committed
Fix: WorldGuard protected doors being openable for Bedrock players
Some doors just aren't open Fixes #6001
1 parent 2241472 commit dbed595

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

core/src/main/java/org/geysermc/geyser/level/block/type/DoorBlock.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.geysermc.geyser.session.GeyserSession;
3131
import org.geysermc.geyser.util.ChunkUtils;
3232

33+
import java.util.Objects;
34+
3335
public 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
}

core/src/main/java/org/geysermc/geyser/session/GeyserSession.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
590590
@Setter
591591
private boolean placedBucket;
592592

593+
/**
594+
* Stores whether we've updated a lower door block
595+
*/
596+
@Setter
597+
private @Nullable Vector3i lastLowerDoorPosition = null;
598+
593599
/**
594600
* Counts how many ticks have occurred since an arm animation started.
595601
* -1 means there is no active arm swing

core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.geysermc.geyser.level.block.type.BlockState;
6464
import org.geysermc.geyser.level.block.type.ButtonBlock;
6565
import org.geysermc.geyser.level.block.type.CauldronBlock;
66+
import org.geysermc.geyser.level.block.type.DoorBlock;
6667
import org.geysermc.geyser.level.block.type.FlowerPotBlock;
6768
import org.geysermc.geyser.level.physics.Direction;
6869
import org.geysermc.geyser.registry.BlockRegistries;
@@ -281,6 +282,11 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet)
281282
return;
282283
}
283284

285+
if (blockState.block() instanceof DoorBlock) {
286+
// See DoorBlock#updateBlock: ensure server-side lower-half door updates are translated
287+
session.setLastLowerDoorPosition(null);
288+
}
289+
284290
if (packet.getItemInHand() != null && session.getItemMappings().getMapping(packet.getItemInHand()).getJavaItem() instanceof SpawnEggItem) {
285291
if (blockState.is(Blocks.WATER) && blockState.getValue(Properties.LEVEL) == 0) {
286292
// Otherwise causes multiple mobs to spawn - just send a use item packet

0 commit comments

Comments
 (0)