Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Digging EventReader has incorrect state when block is instant mined #333

Open
Wyatt-Stanke opened this issue May 17, 2023 · 2 comments
Open
Labels
bug Something isn't working

Comments

@Wyatt-Stanke
Copy link

Valence Version

8897eea (latest as of date of issue)

What You Did

I have code to listen for when a block is mined. It works fine for blocks take time to mine, but if a block instant mines (for example, wheat), the Stop event is not fired. This problem also happens in this example:
https://github.com/valence-rs/valence/blob/main/crates/valence/examples/building.rs

Playground
use valence::client::despawn_disconnected_clients;
use valence::network::ConnectionMode;
use valence::prelude::*;

#[allow(unused_imports)]
use crate::extras::*;

const SPAWN_Y: i32 = 64;

pub fn build_app(app: &mut App) {
    app.insert_resource(NetworkSettings {
        connection_mode: ConnectionMode::Offline,
        ..Default::default()
    })
    .add_plugins(DefaultPlugins)
    .add_startup_system(setup)
    .add_system(init_clients)
    .add_system(listener)
    .add_system(despawn_disconnected_clients)
    .add_system(toggle_gamemode_on_sneak.in_schedule(EventLoopSchedule));
}

fn setup(
    mut commands: Commands,
    server: Res<Server>,
    biomes: Query<&Biome>,
    dimensions: Query<&DimensionType>,
) {
    let mut instance = Instance::new(ident!("overworld"), &dimensions, &biomes, &server);

    for z in -5..5 {
        for x in -5..5 {
            instance.insert_chunk([x, z], Chunk::default());
        }
    }

    for z in -25..25 {
        for x in -25..25 {
            // Insta-break block
            instance.set_block([x, SPAWN_Y, z], BlockState::TNT);
        }
    }

    commands.spawn(instance);
}

fn init_clients(
    mut clients: Query<(&mut Location, &mut Position), Added<Client>>,
    instances: Query<Entity, With<Instance>>,
) {
    for (mut loc, mut pos) in &mut clients {
        loc.0 = instances.single();
        pos.set([0.5, SPAWN_Y as f64 + 1.0, 0.5]);
    }
}

fn listener(mut instances: Query<&mut Instance>, mut events: EventReader<Digging>) {
    let mut instance = instances.single_mut();

    for event in events.iter() {
        if event.state == DiggingState::Stop {
            instance.set_block(event.position, BlockState::AIR);
        }
    }
}

What Went Wrong

I expected for when a block is insta-broken for it to fire an event with the state DiggingState::Stop.

Additional Information

The reason why this is happening is because the DiggingState::Stop event is not firing. https://github.com/valence-rs/valence/blob/main/crates/valence/examples/building.rs has this bug. A quick workaround I used is to check if the block is an insta-breakable block or the event state is DiggingState::Stop Screen recording: https://github.com/valence-rs/valence/assets/47758296/524e9b88-a039-488a-8956-406b417b9641

@Wyatt-Stanke Wyatt-Stanke added bug Something isn't working triage Bug has not been confirmed as real issue yet labels May 17, 2023
@rj00a rj00a removed the triage Bug has not been confirmed as real issue yet label May 18, 2023
@rj00a
Copy link
Member

rj00a commented May 18, 2023

This is actually a bug in the Minecraft client and is out of our control unfortunately. I would leave a link to the issue in the Minecraft bug tracker here, but I can't find it right now.

We can leave this issue open until it's fixed by Mojang.

@Wyatt-Stanke
Copy link
Author

Related: PrismarineJS/mineflayer#2208

@rj00a rj00a linked a pull request Feb 11, 2024 that will close this issue
11 tasks
@rj00a rj00a removed a link to a pull request Feb 11, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants