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

View file

@ -55,30 +55,32 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
// See BlockInventoryHolder - same concept there except we're also dealing with a specific block state // See BlockInventoryHolder - same concept there except we're also dealing with a specific block state
if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) { if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) {
int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition()); int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\["); if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) {
if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest")) String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
&& !javaBlockString[1].contains("type=single")) { if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest"))
inventory.setHolderPosition(session.getLastInteractionBlockPosition()); && !javaBlockString[1].contains("type=single")) {
((Container) inventory).setUsingRealBlock(true, javaBlockString[0]); inventory.setHolderPosition(session.getLastInteractionBlockPosition());
((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
NbtMapBuilder tag = NbtMap.builder() NbtMapBuilder tag = NbtMap.builder()
.putString("id", "Chest") .putString("id", "Chest")
.putInt("x", session.getLastInteractionBlockPosition().getX()) .putInt("x", session.getLastInteractionBlockPosition().getX())
.putInt("y", session.getLastInteractionBlockPosition().getY()) .putInt("y", session.getLastInteractionBlockPosition().getY())
.putInt("z", session.getLastInteractionBlockPosition().getZ()) .putInt("z", session.getLastInteractionBlockPosition().getZ())
.putString("CustomName", inventory.getTitle()) .putString("CustomName", inventory.getTitle())
.putString("id", "Chest"); .putString("id", "Chest");
DoubleChestValue chestValue = BlockStateValues.getDoubleChestValues().get(javaBlockId); DoubleChestValue chestValue = BlockStateValues.getDoubleChestValues().get(javaBlockId);
DoubleChestBlockEntityTranslator.translateChestValue(tag, chestValue, DoubleChestBlockEntityTranslator.translateChestValue(tag, chestValue,
session.getLastInteractionBlockPosition().getX(), session.getLastInteractionBlockPosition().getZ()); session.getLastInteractionBlockPosition().getX(), session.getLastInteractionBlockPosition().getZ());
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket(); BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
dataPacket.setData(tag.build()); dataPacket.setData(tag.build());
dataPacket.setBlockPosition(session.getLastInteractionBlockPosition()); dataPacket.setBlockPosition(session.getLastInteractionBlockPosition());
session.sendUpstreamPacket(dataPacket); session.sendUpstreamPacket(dataPacket);
return true; return true;
}
} }
} }
@ -88,7 +90,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
} }
Vector3i pairPosition = position.add(Vector3i.UNIT_X); Vector3i pairPosition = position.add(Vector3i.UNIT_X);
int bedrockBlockId = session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState); int bedrockBlockId = session.getBlockMappings().getVanillaBedrockBlockId(defaultJavaBlockState);
UpdateBlockPacket blockPacket = new UpdateBlockPacket(); UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0); blockPacket.setDataLayer(0);