Skip to content

Survival fly block breaking#6227

Draft
valaphee wants to merge 1 commit intoGeyserMC:masterfrom
valaphee:survival-fly-block-breaking
Draft

Survival fly block breaking#6227
valaphee wants to merge 1 commit intoGeyserMC:masterfrom
valaphee:survival-fly-block-breaking

Conversation

@valaphee
Copy link
Contributor

@valaphee valaphee commented Mar 9, 2026

This simulates the mining speed for survival fly on Bedrock by using effects.

There is no restore yet, as it the penalty would be x11.1 and we certainly have to tick the effects, as the duration might be less and other calculations ignore this fact anyway.

Copilot AI review requested due to automatic review settings March 9, 2026 10:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to better match Java Edition’s reduced block breaking speed while flying in Survival by applying a temporary Bedrock Mining Fatigue effect during block break start.

Changes:

  • Send a MobEffectPacket (Mining Fatigue) when starting to break a block while flying in Survival.
  • Compute the effect duration based on the expected break time derived from BlockUtils.getBlockMiningProgressPerTick(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +335 to +339
if (session.getGameMode() == GameMode.SURVIVAL && session.isFlying()) {
MobEffectPacket mobEffectPacket = new MobEffectPacket();
mobEffectPacket.setAmplifier(0);
mobEffectPacket.setDuration((int) (1 / BlockUtils.getBlockMiningProgressPerTick(session, state.block(), item)));
mobEffectPacket.setEvent(session.getEffectCache().getEntityEffects().contains(Effect.MINING_FATIGUE) ? MobEffectPacket.Event.MODIFY : MobEffectPacket.Event.ADD);
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sends a MINING_FATIGUE packet with amplifier 0 and uses MODIFY when the Java effect cache already contains mining fatigue. If the server has applied Mining Fatigue (often at higher amplifiers), this will overwrite the client-side effect and effectively weaken/replace the server-intended debuff. Consider skipping this logic when the player already has mining fatigue, or preserving the existing amplifier/duration rather than forcing amplifier 0.

Suggested change
if (session.getGameMode() == GameMode.SURVIVAL && session.isFlying()) {
MobEffectPacket mobEffectPacket = new MobEffectPacket();
mobEffectPacket.setAmplifier(0);
mobEffectPacket.setDuration((int) (1 / BlockUtils.getBlockMiningProgressPerTick(session, state.block(), item)));
mobEffectPacket.setEvent(session.getEffectCache().getEntityEffects().contains(Effect.MINING_FATIGUE) ? MobEffectPacket.Event.MODIFY : MobEffectPacket.Event.ADD);
if (session.getGameMode() == GameMode.SURVIVAL && session.isFlying()
&& !session.getEffectCache().getEntityEffects().contains(Effect.MINING_FATIGUE)) {
MobEffectPacket mobEffectPacket = new MobEffectPacket();
mobEffectPacket.setAmplifier(0);
mobEffectPacket.setDuration((int) (1 / BlockUtils.getBlockMiningProgressPerTick(session, state.block(), item)));
mobEffectPacket.setEvent(MobEffectPacket.Event.ADD);

Copilot uses AI. Check for mistakes.
@valaphee valaphee force-pushed the survival-fly-block-breaking branch 2 times, most recently from 5f3628e to 20d4c0f Compare March 9, 2026 10:43
Copilot AI review requested due to automatic review settings March 9, 2026 10:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

import org.geysermc.geyser.translator.protocol.bedrock.BedrockInventoryTransactionTranslator;
import org.geysermc.geyser.translator.protocol.java.level.JavaBlockDestructionTranslator;
import org.geysermc.geyser.util.BlockUtils;
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

org.geysermc.mcprotocollib.protocol.data.game.entity.Effect is imported but not used in this class. Unused imports cause compilation failures in Java; please remove it (or use it if intended).

Suggested change
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;

Copilot uses AI. Check for mistakes.
Comment on lines +334 to +344
// Survival fly in Bedrock doesn't come with a mining speed penalty, but we can use effects to lower the mining speed to match Java's one
if (session.getGameMode() == GameMode.SURVIVAL && session.isFlying() && breakProgress > 0) {
MobEffectPacket mobEffectPacket = new MobEffectPacket();
mobEffectPacket.setAmplifier(0);
mobEffectPacket.setDuration((int) BlockUtils.reciprocal(breakProgress));
mobEffectPacket.setEvent(MobEffectPacket.Event.ADD);
mobEffectPacket.setRuntimeEntityId(session.getPlayerEntity().geyserId());
mobEffectPacket.setEffectId(EffectType.MINING_FATIGUE.getBedrockId());
session.sendUpstreamPacket(mobEffectPacket);
}

Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The injected MINING_FATIGUE effect is added when starting to break a block while flying, but it is never removed when the block is successfully broken (destroyBlock path). This can leave the Bedrock client with mining fatigue after the break completes (until the duration expires), affecting subsequent gameplay. Consider explicitly removing the effect when breaking finishes (and when state is cleared) instead of relying on duration.

Suggested change
// Survival fly in Bedrock doesn't come with a mining speed penalty, but we can use effects to lower the mining speed to match Java's one
if (session.getGameMode() == GameMode.SURVIVAL && session.isFlying() && breakProgress > 0) {
MobEffectPacket mobEffectPacket = new MobEffectPacket();
mobEffectPacket.setAmplifier(0);
mobEffectPacket.setDuration((int) BlockUtils.reciprocal(breakProgress));
mobEffectPacket.setEvent(MobEffectPacket.Event.ADD);
mobEffectPacket.setRuntimeEntityId(session.getPlayerEntity().geyserId());
mobEffectPacket.setEffectId(EffectType.MINING_FATIGUE.getBedrockId());
session.sendUpstreamPacket(mobEffectPacket);
}

Copilot uses AI. Check for mistakes.
Comment on lines +437 to +444
// Remove effect again which is applied to simulate survival fly block breaking
if (session.getGameMode() == GameMode.SURVIVAL && session.isFlying()) {
MobEffectPacket mobEffectPacket = new MobEffectPacket();
mobEffectPacket.setEvent(MobEffectPacket.Event.REMOVE);
mobEffectPacket.setRuntimeEntityId(session.getPlayerEntity().geyserId());
mobEffectPacket.setEffectId(EffectType.MINING_FATIGUE.getBedrockId());
session.sendUpstreamPacket(mobEffectPacket);
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The effect removal is conditional on session.isFlying(). If the player starts breaking while flying (effect applied) but lands before ABORT_BREAK (or a forced abort), this condition will skip removal and leave mining fatigue applied. Track whether the temporary effect was applied and remove it based on that flag (or remove unconditionally when aborting/clearing), rather than checking the current flying state.

Copilot uses AI. Check for mistakes.
@valaphee valaphee marked this pull request as draft March 9, 2026 11:49
@valaphee
Copy link
Contributor Author

Also seem to have issues with tools

@valaphee valaphee force-pushed the survival-fly-block-breaking branch from 20d4c0f to 8832df4 Compare March 12, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants