From 13aaacad822c416795bc65c27d7a7683750935b6 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 25 Jul 2019 18:41:06 +0100 Subject: [PATCH] Fixed block-hopping on edges, added correct inventory slots --- client/src/lib.rs | 7 +++++-- common/src/comp/inventory/mod.rs | 6 +++++- common/src/sys/movement.rs | 2 +- common/src/sys/phys.rs | 5 +++-- server/src/lib.rs | 1 + voxygen/src/hud/bag.rs | 34 +++++++++++++++++--------------- voxygen/src/hud/mod.rs | 4 +--- 7 files changed, 34 insertions(+), 25 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 1a7b0479e6..c649a7c812 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -4,8 +4,7 @@ pub mod error; // Reexports pub use crate::error::Error; -pub use specs::join::Join; -pub use specs::Entity as EcsEntity; +pub use specs::{join::Join, Entity as EcsEntity, ReadStorage}; use common::{ comp, @@ -188,6 +187,10 @@ impl Client { self.state.terrain().get_key_arc(chunk_pos).cloned() } + pub fn inventories(&self) -> ReadStorage { + self.state.read_storage() + } + /// Send a chat message to the server. #[allow(dead_code)] pub fn send_chat(&mut self, msg: String) { diff --git a/common/src/comp/inventory/mod.rs b/common/src/comp/inventory/mod.rs index 8e850918cb..e11a2581c1 100644 --- a/common/src/comp/inventory/mod.rs +++ b/common/src/comp/inventory/mod.rs @@ -13,6 +13,10 @@ pub struct Inventory { } impl Inventory { + pub fn slots(&self) -> &[Option] { + &self.slots + } + // Get info about an item slot pub fn get(&self, cell: usize) -> Option { self.slots.get(cell).cloned().flatten() @@ -33,7 +37,7 @@ impl Inventory { impl Default for Inventory { fn default() -> Inventory { Inventory { - slots: vec![None; 24], + slots: vec![None; 8], } } } diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs index a1744d9fa6..f278655d72 100644 --- a/common/src/sys/movement.rs +++ b/common/src/sys/movement.rs @@ -11,7 +11,7 @@ const HUMANOID_ACCEL: f32 = 70.0; const HUMANOID_SPEED: f32 = 120.0; const HUMANOID_AIR_ACCEL: f32 = 10.0; const HUMANOID_AIR_SPEED: f32 = 100.0; -const HUMANOID_JUMP_ACCEL: f32 = 16.5; +const HUMANOID_JUMP_ACCEL: f32 = 18.0; const ROLL_ACCEL: f32 = 120.0; const ROLL_SPEED: f32 = 550.0; const GLIDE_ACCEL: f32 = 15.0; diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index f196a29f9c..7149fdcaaa 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -126,6 +126,7 @@ impl<'a> System<'a> for Sys { let increments = (pos_delta.map(|e| e.abs()).reduce_partial_max() / 0.3) .ceil() .max(1.0); + let old_pos = pos.0; for _ in 0..increments as usize { pos.0 += pos_delta / increments; @@ -196,13 +197,13 @@ impl<'a> System<'a> for Sys { // ...and the vertical resolution direction is sufficiently great... && -dir.z > 0.1 // ...and we're falling/standing OR there is a block *directly* beneath our current origin (note: not hitbox)... - && (vel.0.z <= 0.0 || terrain + && (vel.0.z <= 0.0 && terrain .get((pos.0 - Vec3::unit_z()).map(|e| e.floor() as i32)) .map(|vox| !vox.is_empty()) .unwrap_or(false)) // ...and there is a collision with a block beneath our current hitbox... && collision_with( - pos.0 + resolve_dir - Vec3::unit_z() * 1.05, + old_pos + resolve_dir - Vec3::unit_z() * 1.05, near_iter.clone(), ) { diff --git a/server/src/lib.rs b/server/src/lib.rs index 9ee66db5a4..09f43f2295 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -192,6 +192,7 @@ impl Server { state.write_component(entity, comp::Ori(Vec3::unit_y())); state.write_component(entity, comp::ActionState::default()); state.write_component(entity, comp::Inventory::default()); + state.write_component(entity, comp::InventoryUpdate); // Make sure physics are accepted. state.write_component(entity, comp::ForceUpdate); diff --git a/voxygen/src/hud/bag.rs b/voxygen/src/hud/bag.rs index c0a7f86188..9549bab947 100644 --- a/voxygen/src/hud/bag.rs +++ b/voxygen/src/hud/bag.rs @@ -1,4 +1,5 @@ use super::{img_ids::Imgs, Fonts, TEXT_COLOR}; +use client::Client; use conrod_core::{ color, position::Relative, @@ -25,8 +26,7 @@ widget_ids! { #[derive(WidgetCommon)] pub struct Bag<'a> { - inventory_space: usize, - + client: &'a Client, imgs: &'a Imgs, fonts: &'a Fonts, #[conrod(common_builder)] @@ -34,9 +34,9 @@ pub struct Bag<'a> { } impl<'a> Bag<'a> { - pub fn new(inventory_space: usize, imgs: &'a Imgs, fonts: &'a Fonts) -> Self { + pub fn new(client: &'a Client, imgs: &'a Imgs, fonts: &'a Fonts) -> Self { Self { - inventory_space, + client, imgs, fonts, common: widget::CommonBuilder::default(), @@ -72,16 +72,20 @@ impl<'a> Widget for Bag<'a> { fn update(self, args: widget::UpdateArgs) -> Self::Event { let widget::UpdateArgs { state, ui, .. } = args; + let inventory_slots = self + .client + .inventories() + .get(self.client.entity()) + .map(|inv| inv.slots().len()) + .unwrap_or(0); + // Bag parts Image::new(self.imgs.bag_bot) .w_h(61.0 * BAG_SCALE, 9.0 * BAG_SCALE) .bottom_right_with_margins_on(ui.window, 60.0, 5.0) .set(state.ids.bag_bot, ui); Image::new(self.imgs.bag_mid) - .w_h( - 61.0 * BAG_SCALE, - ((self.inventory_space + 4) / 5) as f64 * 44.0, - ) + .w_h(61.0 * BAG_SCALE, ((inventory_slots + 4) / 5) as f64 * 44.0) .up_from(state.ids.bag_bot, 0.0) .set(state.ids.bag_mid, ui); Image::new(self.imgs.bag_top) @@ -91,10 +95,7 @@ impl<'a> Widget for Bag<'a> { // Alignment for Grid Rectangle::fill_with( - [ - 54.0 * BAG_SCALE, - ((self.inventory_space + 4) / 5) as f64 * 44.0, - ], + [54.0 * BAG_SCALE, ((inventory_slots + 4) / 5) as f64 * 44.0], color::TRANSPARENT, ) .top_left_with_margins_on(state.ids.bag_top, 9.0 * BAG_SCALE, 3.0 * BAG_SCALE) @@ -117,16 +118,17 @@ impl<'a> Widget for Bag<'a> { .thickness(5.0) .rgba(0.33, 0.33, 0.33, 1.0) .set(state.ids.inv_scrollbar, ui);*/ + // Create available inventory slot widgets - if state.ids.inv_slot.len() < self.inventory_space { + if state.ids.inv_slot.len() < inventory_slots { state.update(|s| { s.ids .inv_slot - .resize(self.inventory_space, &mut ui.widget_id_generator()); + .resize(inventory_slots, &mut ui.widget_id_generator()); }); } // "Allowed" max. inventory space should be handled serverside and thus isn't limited in the UI - for i in 0..self.inventory_space { + for i in 0..inventory_slots { let x = i % 5; let y = i / 5; Button::image(self.imgs.inv_slot) @@ -140,7 +142,7 @@ impl<'a> Widget for Bag<'a> { .set(state.ids.inv_slot[i], ui); } // Test Item - if self.inventory_space > 0 { + if inventory_slots > 0 { Button::image(self.imgs.potion_red) // TODO: Insert variable image depending on the item displayed in that slot .w_h(4.0 * 4.4, 7.0 * 4.4) // TODO: Fix height and scale width correctly to that to avoid a stretched item image .middle_of(state.ids.inv_slot[0]) // TODO: Items need to be assigned to a certain slot and then placed like in this example diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 689f1f5668..c3d3b50a25 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -588,9 +588,7 @@ impl Hud { // Bag contents if self.show.bag { - match Bag::new(self.inventory_space, &self.imgs, &self.fonts) - .set(self.ids.bag, ui_widgets) - { + match Bag::new(client, &self.imgs, &self.fonts).set(self.ids.bag, ui_widgets) { Some(bag::Event::Close) => { self.show.bag(false); self.force_ungrab = true;