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

[ECS] Add Inventory component, re-implement player inventories #187

Merged
merged 9 commits into from
Jan 14, 2023

Conversation

dyc3
Copy link
Collaborator

@dyc3 dyc3 commented Jan 12, 2023

  • add missing field preventing build, format
  • add Inventory ECS component
  • add cursor_item fields, getters, setters to Client
  • add new_with_title to Inventory instead of using an Option
  • add Inventory component to client entities when they connect
  • add system update_player_inventories

This does not implement opening other inventories yet, planning to do that in a follow up PR.

The idea here is to have an Inventory component that can be used for all inventories. If you want a chest to have an inventory, give the corresponding block entity an Inventory. If you don't want any inventory update systems to run, simply don't give clients a player inventory.

Code used to test
use bevy_ecs::prelude::*;
use bevy_ecs::schedule::ShouldRun;
use valence_new::client::Client;
use valence_new::config::Config;
use valence_new::dimension::DimensionId;
use valence_new::protocol::types::GameMode;
use valence_new::server::Server;

#[derive(Resource)]
struct GameState {
    instance: Entity,
}

fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt().init();

    valence_new::run_server(
        Config::default(),
        SystemStage::parallel()
            .with_system(setup.with_run_criteria(ShouldRun::once))
            .with_system(init_clients),
        (),
    )
}

fn setup(world: &mut World) {
    let instance = world
        .resource::<Server>()
        .new_instance(DimensionId::default());

    let id = world.spawn(instance).id();
    world.insert_resource(GameState { instance: id })
}

fn init_clients(mut clients: Query<&mut Client, Added<Client>>, state: Res<GameState>) {
    for mut client in &mut clients {
        client.set_instance(state.instance);
        client.set_game_mode(GameMode::Creative);
    }
}

crates/valence_new/src/inventory.rs Outdated Show resolved Hide resolved
crates/valence_new/src/inventory.rs Outdated Show resolved Hide resolved
crates/valence_protocol/src/inventory.rs Show resolved Hide resolved
@dyc3 dyc3 requested a review from rj00a January 13, 2023 16:19
@rj00a rj00a merged commit e3c43a7 into valence-rs:ecs_rewrite Jan 14, 2023
@dyc3 dyc3 deleted the ecs-inventory branch January 14, 2023 15:00
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