Fix inventories with block state overrides not opening

This commit is contained in:
davchoo 2023-01-16 15:22:05 -05:00
parent 4d78503b7c
commit 0f0308b6ef
No known key found for this signature in database
GPG key ID: 501B6F4FD961CF9A
2 changed files with 34 additions and 29 deletions

View file

@ -76,7 +76,9 @@ public class BlockInventoryHolder extends InventoryHolder {
// (This could be a virtual inventory that the player is opening)
if (checkInteractionPosition(session)) {
// Then, check to see if the interacted block is valid for this inventory by ensuring the block state identifier is valid
// and the bedrock block is vanilla
int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) {
String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
if (isValidBlock(javaBlockString)) {
// We can safely use this block
@ -87,6 +89,7 @@ public class BlockInventoryHolder extends InventoryHolder {
return true;
}
}
}
Vector3i position = InventoryUtils.findAvailableWorldSpace(session);
if (position == null) {
@ -96,7 +99,7 @@ public class BlockInventoryHolder extends InventoryHolder {
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(position);
blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState));
blockPacket.setRuntimeId(session.getBlockMappings().getVanillaBedrockBlockId(defaultJavaBlockState));
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket);
inventory.setHolderPosition(position);

View file

@ -55,6 +55,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
// See BlockInventoryHolder - same concept there except we're also dealing with a specific block state
if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) {
int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) {
String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest"))
&& !javaBlockString[1].contains("type=single")) {
@ -81,6 +82,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
return true;
}
}
}
Vector3i position = InventoryUtils.findAvailableWorldSpace(session);
if (position == null) {
@ -88,7 +90,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
}
Vector3i pairPosition = position.add(Vector3i.UNIT_X);
int bedrockBlockId = session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState);
int bedrockBlockId = session.getBlockMappings().getVanillaBedrockBlockId(defaultJavaBlockState);
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);