Mark sequence position when block placing

Fixes some instances between 1.19 and 1.20.5 when block ghosting could occur
This commit is contained in:
Camotoy 2024-07-23 15:43:57 -04:00
parent 1dd9ba3fb6
commit b113a6b185
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 5 additions and 4 deletions

View file

@ -201,4 +201,4 @@ public final class WorldCache {
public String removeActiveRecord(Vector3i pos) { public String removeActiveRecord(Vector3i pos) {
return this.activeRecords.remove(pos); return this.activeRecords.remove(pos);
} }
} }

View file

@ -247,8 +247,6 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
} }
// As of 1.21, Paper does not have any additional range checks that would inconvenience normal players. // As of 1.21, Paper does not have any additional range checks that would inconvenience normal players.
// Note that, before these changes, I could replicate on Paper 1.20.4 and iPad 1.21.2 an instance of block ghosting
// that we had not previously implemented. Might be some sort of ray tracing that is currently unimplemented.
Vector3f playerPosition = session.getPlayerEntity().getPosition(); Vector3f playerPosition = session.getPlayerEntity().getPosition();
playerPosition = playerPosition.down(EntityDefinitions.PLAYER.offset() - session.getEyeHeight()); playerPosition = playerPosition.down(EntityDefinitions.PLAYER.offset() - session.getEyeHeight());
@ -284,13 +282,16 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
} }
} }
// Storing the block position allows inconsistencies in block place checking from post-1.19 - pre-1.20.5 to be resolved.
int sequence = session.getWorldCache().nextPredictionSequence();
session.getWorldCache().markPositionInSequence(blockPos);
ServerboundUseItemOnPacket blockPacket = new ServerboundUseItemOnPacket( ServerboundUseItemOnPacket blockPacket = new ServerboundUseItemOnPacket(
packet.getBlockPosition(), packet.getBlockPosition(),
Direction.VALUES[packet.getBlockFace()], Direction.VALUES[packet.getBlockFace()],
Hand.MAIN_HAND, Hand.MAIN_HAND,
packet.getClickPosition().getX(), packet.getClickPosition().getY(), packet.getClickPosition().getZ(), packet.getClickPosition().getX(), packet.getClickPosition().getY(), packet.getClickPosition().getZ(),
false, false,
session.getWorldCache().nextPredictionSequence()); sequence);
session.sendDownstreamGamePacket(blockPacket); session.sendDownstreamGamePacket(blockPacket);
Item item = session.getPlayerInventory().getItemInHand().asItem(); Item item = session.getPlayerInventory().getItemInHand().asItem();