Prefers picking up the highlighted item to the closest item

This commit is contained in:
Ryan Baker 2020-08-21 14:09:48 +00:00 committed by Marcel
parent e382e992bd
commit 712152740f
2 changed files with 17 additions and 13 deletions

View File

@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Animation and terrain math were switched to use SIMD where possible, improving performance. - Animation and terrain math were switched to use SIMD where possible, improving performance.
- The way we cache glyphs was refactored, fixed, and optimized. - The way we cache glyphs was refactored, fixed, and optimized.
- Colors for models and figures were adjusted to account for the saturation hack. - Colors for models and figures were adjusted to account for the saturation hack.
- Fixed a bug where the closest item would be picked up instead of a selected item
### Removed ### Removed

View File

@ -496,19 +496,22 @@ impl PlayState for SessionState {
.copied(); .copied();
if let Some(player_pos) = player_pos { if let Some(player_pos) = player_pos {
let entity = ( let entity = self.target_entity.or_else(|| {
&client.state().ecs().entities(), (
&client.state().ecs().read_storage::<comp::Pos>(), &client.state().ecs().entities(),
&client.state().ecs().read_storage::<comp::Item>(), &client.state().ecs().read_storage::<comp::Pos>(),
) &client.state().ecs().read_storage::<comp::Item>(),
.join() )
.filter(|(_, pos, _)| { .join()
pos.0.distance_squared(player_pos.0) < MAX_PICKUP_RANGE_SQR .filter(|(_, pos, _)| {
}) pos.0.distance_squared(player_pos.0)
.min_by_key(|(_, pos, _)| { < MAX_PICKUP_RANGE_SQR
(pos.0.distance_squared(player_pos.0) * 1000.0) as i32 })
}) .min_by_key(|(_, pos, _)| {
.map(|(entity, _, _)| entity); (pos.0.distance_squared(player_pos.0) * 1000.0) as i32
})
.map(|(entity, _, _)| entity)
});
if let Some(entity) = entity { if let Some(entity) = entity {
client.pick_up(entity); client.pick_up(entity);