From f104a3d4caee12c86e49cd7e8cda26e6573b7e0b Mon Sep 17 00:00:00 2001 From: oryxel Date: Thu, 5 Jun 2025 01:34:41 +0700 Subject: [PATCH] Fix non-vanilla block breaking (#5575) * Keep track of non-vanilla block break. * Just use simple BitSet registry. --- .../java/org/geysermc/geyser/registry/BlockRegistries.java | 5 +++++ .../registry/populator/CustomBlockRegistryPopulator.java | 1 + .../bedrock/entity/player/input/BedrockBlockActions.java | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java b/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java index b7316605b..2c04930be 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java @@ -82,6 +82,11 @@ public class BlockRegistries { */ public static final MappedRegistry> JAVA_IDENTIFIER_TO_ID = MappedRegistry.create(RegistryLoaders.empty(Object2IntOpenHashMap::new)); + /** + * A registry containing non-vanilla block IDS. + */ + public static final SimpleRegistry NON_VANILLA_BLOCK_IDS = SimpleRegistry.create(RegistryLoaders.empty(BitSet::new)); + /** * A registry containing all the waterlogged blockstates. * Properties.WATERLOGGED should not be relied on for two reasons: diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java index 46bfcb45e..d672d1732 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java @@ -303,6 +303,7 @@ public class CustomBlockRegistryPopulator { BlockRegistries.JAVA_BLOCKS.registerWithAnyIndex(javaBlockState.stateGroupId(), block, Blocks.AIR); BlockRegistries.JAVA_IDENTIFIER_TO_ID.register(javaId, stateRuntimeId); + BlockRegistries.NON_VANILLA_BLOCK_IDS.register(set -> set.set(stateRuntimeId)); // TODO register different collision types? BoundingBox[] geyserCollisions = Arrays.stream(javaBlockState.collision()) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockBlockActions.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockBlockActions.java index 4fed313ad..633562c4d 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockBlockActions.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockBlockActions.java @@ -33,6 +33,7 @@ import org.cloudburstmc.protocol.bedrock.data.PlayerBlockActionData; import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.geysermc.geyser.api.block.custom.CustomBlockState; +import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.ItemFrameEntity; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -101,7 +102,7 @@ final class BedrockBlockActions { SkullCache.Skull skull = session.getSkullCache().getSkulls().get(vector); session.setBlockBreakStartTime(0); - if (blockStateOverride != null || customItem != null || (skull != null && skull.getBlockDefinition() != null)) { + if (BlockRegistries.NON_VANILLA_BLOCK_IDS.get().get(blockState) || blockStateOverride != null || customItem != null || (skull != null && skull.getBlockDefinition() != null)) { session.setBlockBreakStartTime(System.currentTimeMillis()); } startBreak.setData((int) (65535 / breakTime));