From 4188bd71bb31fa734b0cb2a8628cffae08ec452d Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sat, 10 Dec 2022 21:08:32 -0500 Subject: [PATCH] re-implement inventory_piano example (#166) # Test plan ``` cargo r -r --example inventory_piano ``` Co-authored-by: Ryan Johnson --- examples/inventory_piano.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/examples/inventory_piano.rs b/examples/inventory_piano.rs index 665c07d..656e7d1 100644 --- a/examples/inventory_piano.rs +++ b/examples/inventory_piano.rs @@ -1,8 +1,3 @@ -pub fn main() { - todo!("reimplement when inventories are re-added"); -} - -/* use std::net::SocketAddr; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -39,8 +34,8 @@ const MAX_PLAYERS: usize = 10; const SIZE_X: usize = 100; const SIZE_Z: usize = 100; -const SLOT_MIN: SlotId = 36; -const SLOT_MAX: SlotId = 43; +const SLOT_MIN: i16 = 36; +const SLOT_MAX: i16 = 43; const PITCH_MIN: f32 = 0.5; const PITCH_MAX: f32 = 1.0; @@ -184,19 +179,19 @@ impl Config for Game { client.teleport(spawn_pos, client.yaw(), client.pitch()); } - while let Some(event) = handle_event_default(client, player) { + while let Some(event) = client.next_event() { match event { - ClientEvent::CloseScreen { .. } => { + ClientEvent::CloseContainer { .. } => { client.send_message("Done already?"); } - ClientEvent::SetSlotCreative { slot_id, .. } => { - client.send_message(format!("{:#?}", event)); + ClientEvent::SetCreativeModeSlot { slot, .. } => { + client.send_message(format!("{event:#?}")); // If the user does a double click, 3 notes will be played. // This is not possible to fix :( - play_note(client, player, slot_id); + play_note(client, player, slot); } ClientEvent::ClickContainer { slot_id, mode, .. } => { - client.send_message(format!("{:#?}", event)); + client.send_message(format!("{event:#?}")); if mode != ClickContainerMode::Click { // Prevent notes from being played twice if the user clicks quickly continue; @@ -212,7 +207,7 @@ impl Config for Game { } } -fn play_note(client: &mut Client, player: &mut Entity, clicked_slot: SlotId) { +fn play_note(client: &mut Client, player: &mut Entity, clicked_slot: i16) { if (SLOT_MIN..=SLOT_MAX).contains(&clicked_slot) { let pitch = (clicked_slot - SLOT_MIN) as f32 * (PITCH_MAX - PITCH_MIN) / (SLOT_MAX - SLOT_MIN) as f32 @@ -233,4 +228,3 @@ fn play_note(client: &mut Client, player: &mut Entity, clicked_slot: }); } } -*/