From 29835a1b76013737bf716391c48fcadf08adc090 Mon Sep 17 00:00:00 2001 From: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> Date: Mon, 20 Feb 2023 21:52:46 -0800 Subject: [PATCH] Fix block break speeds thanks to @Camotoy Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> --- .../mappings/versions/MappingsReader_v1.java | 5 ++- .../geyser/session/GeyserSession.java | 6 ++++ .../player/BedrockActionTranslator.java | 31 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java index 052864656..6e5f3846e 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java @@ -313,9 +313,8 @@ public class MappingsReader_v1 extends MappingsReader { builder.collisionBox(collisionBox); } - // Ideally we would just be able to calculate the right value for this, but it seems that hardness value on bedrock does not follow Java - // As such this might as well just be configured for now if people so choose - float destructibleByMining = BlockRegistries.JAVA_BLOCKS.getOrDefault(id, BlockMapping.AIR).getHardness() * 3.25F; + // We set this to max value by default so that we may dictate the correct destroy time ourselves + float destructibleByMining = Float.MAX_VALUE; if (node.has("destructible_by_mining")) { destructibleByMining = node.get("destructible_by_mining").floatValue(); } diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index d481b68de..70c16a9db 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -437,6 +437,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { @Setter private long lastInteractionTime; + /** + * Stores when the player started to break a block. Used to allow correct break time for custom blocks. + */ + @Setter + private long blockBreakStartTime; + /** * Stores whether the player intended to place a bucket. */ diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java index c728390d6..28eaf9183 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java @@ -38,6 +38,7 @@ import com.nukkitx.protocol.bedrock.data.PlayerActionType; import com.nukkitx.protocol.bedrock.data.entity.EntityEventType; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.packet.*; +import org.geysermc.geyser.api.block.custom.CustomBlockState; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.ItemFrameEntity; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; @@ -147,6 +148,11 @@ public class BedrockActionTranslator extends PacketTranslator= breakTime * 50) { + // Play break sound and particle + LevelEventPacket effectPacket = new LevelEventPacket(); + effectPacket.setPosition(vectorFloat); + effectPacket.setType(LevelEventType.PARTICLE_DESTROY_BLOCK); + effectPacket.setData(session.getBlockMappings().getBedrockBlockId(breakingBlock)); + session.sendUpstreamPacket(effectPacket); + + // Break the block + ServerboundPlayerActionPacket finishBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.FINISH_DIGGING, + vector, Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence()); + session.sendDownstreamPacket(finishBreakingPacket); + session.setBlockBreakStartTime(0); + break; + } + } + } + updateBreak.setData((int) (65535 / breakTime)); session.sendUpstreamPacket(updateBreak); break;