Prevent 2x placement due to extended collision box

Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
This commit is contained in:
Joshua Castle 2023-05-13 20:22:06 -07:00
parent 4e88a7fb9a
commit 41d7d8e3a3
No known key found for this signature in database
GPG Key ID: F674F38216C35D5D
1 changed files with 22 additions and 0 deletions

View File

@ -173,6 +173,27 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
}
}
// Check if this is a double placement due to an extended collision block
if (!session.getBlockMappings().getExtendedCollisionBoxes().isEmpty()) {
Vector3i belowBlockPos = null;
switch (packet.getBlockFace()) {
case 1 -> belowBlockPos = blockPos.add(0, -2, 0);
case 2 -> belowBlockPos = blockPos.add(0, -1, 1);
case 3 -> belowBlockPos = blockPos.add(0, -1, -1);
case 4 -> belowBlockPos = blockPos.add(1, -1, 0);
case 5 -> belowBlockPos = blockPos.add(-1, -1, 0);
}
if (belowBlockPos != null) {
int belowBlock = session.getGeyser().getWorldManager().getBlockAt(session, belowBlockPos);
BlockDefinition extendedCollisionDefinition = session.getBlockMappings().getExtendedCollisionBoxes().get(belowBlock);
if (extendedCollisionDefinition != null && (System.currentTimeMillis() - session.getLastInteractionTime()) < 200) {
restoreCorrectBlock(session, blockPos, packet);
return;
}
}
}
// Check to make sure the client isn't spamming interaction
// Based on Nukkit 1.0, with changes to ensure holding down still works
boolean hasAlreadyClicked = System.currentTimeMillis() - session.getLastInteractionTime() < 110.0 &&
@ -257,6 +278,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
restoreCorrectBlock(session, blockPos, packet);
return;
}
/*
Block place checks end - client is good to go
*/