Prevent crafting without station

This commit is contained in:
Joshua Barretto 2021-04-17 23:27:42 +01:00 committed by Monty Marz
parent a1fe7c12c3
commit 1a0f6f03ef
4 changed files with 43 additions and 8 deletions

View File

@ -584,10 +584,33 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
let craft_result = recipe_book let craft_result = recipe_book
.get(&recipe) .get(&recipe)
.filter(|r| { .filter(|r| {
let sprite = craft_sprite if let Some(needed_sprite) = r.craft_sprite {
.and_then(|pos| state.terrain().get(pos).ok().copied()) let sprite = craft_sprite
.and_then(|block| block.get_sprite()); .filter(|pos| {
r.craft_sprite.map_or(true, |cs| Some(cs) == sprite) let entity_cylinder = get_cylinder(state, entity);
if !within_pickup_range(entity_cylinder, || {
Some(find_dist::Cube {
min: pos.as_(),
side_length: 1.0,
})
}) {
debug!(
?entity_cylinder,
"Failed to pick up block as not within range, block pos: \
{}",
pos
);
false
} else {
true
}
})
.and_then(|pos| state.terrain().get(pos).ok().copied())
.and_then(|block| block.get_sprite());
Some(needed_sprite) == sprite
} else {
false
}
}) })
.and_then(|r| { .and_then(|r| {
r.perform( r.perform(

View File

@ -699,6 +699,7 @@ impl<'a> Widget for Crafting<'a> {
.resize(recipe.inputs().len(), &mut ui.widget_id_generator()) .resize(recipe.inputs().len(), &mut ui.widget_id_generator())
}); });
}; };
// Widget generation for every ingredient // Widget generation for every ingredient
for (i, (recipe_input, amount)) in recipe.inputs.iter().enumerate() { for (i, (recipe_input, amount)) in recipe.inputs.iter().enumerate() {
let item_def = match recipe_input { let item_def = match recipe_input {

View File

@ -74,6 +74,7 @@ use common::{
skills::{Skill, SkillGroupKind}, skills::{Skill, SkillGroupKind},
BuffKind, Item, BuffKind, Item,
}, },
consts::MAX_PICKUP_RANGE,
outcome::Outcome, outcome::Outcome,
terrain::{SpriteKind, TerrainChunk}, terrain::{SpriteKind, TerrainChunk},
trade::{ReducedInventory, TradeAction}, trade::{ReducedInventory, TradeAction},
@ -3361,6 +3362,16 @@ impl Hud {
.handle_event(conrod_core::event::Input::Text("\t".to_string())); .handle_event(conrod_core::event::Input::Text("\t".to_string()));
} }
// Stop selecting a sprite to perform crafting with when out of range
self.show.craft_sprite = self.show.craft_sprite.filter(|(pos, _)| {
self.show.crafting
&& if let Some(player_pos) = client.position() {
pos.map(|e| e as f32 + 0.5).distance(player_pos) < MAX_PICKUP_RANGE
} else {
false
}
});
// Optimization: skip maintaining UI when it's off. // Optimization: skip maintaining UI when it's off.
if !self.show.ui { if !self.show.ui {
return std::mem::take(&mut self.events); return std::mem::take(&mut self.events);

View File

@ -530,13 +530,13 @@ impl Archetype for House {
center_offset.x, center_offset.x,
center_offset.y, center_offset.y,
z + 100, z + 100,
)) % 8 )) % 7
{ {
0..=1 => SpriteKind::Crate, 0..=1 => SpriteKind::Crate,
2 => SpriteKind::Bench, 2 => SpriteKind::Bench,
3 => SpriteKind::Anvil, 3 => SpriteKind::Anvil,
4 => SpriteKind::Cauldron, 4 => SpriteKind::Cauldron,
5 => SpriteKind::CraftingBench, 5 => SpriteKind::CraftingBench,
6 => SpriteKind::FireBowlGround, 6 => SpriteKind::FireBowlGround,
//8 => SpriteKind::Forge, //8 => SpriteKind::Forge,
_ => unreachable!(), _ => unreachable!(),
@ -621,7 +621,7 @@ impl Archetype for House {
0 => SpriteKind::HangingSign, 0 => SpriteKind::HangingSign,
1 | 2 | 3 => SpriteKind::HangingBasket, 1 | 2 | 3 => SpriteKind::HangingBasket,
4 => SpriteKind::WallSconce, 4 => SpriteKind::WallSconce,
5 => SpriteKind::WallLampSmall, 5 => SpriteKind::WallLampSmall,
_ => SpriteKind::DungeonWallDecor, _ => SpriteKind::DungeonWallDecor,
}; };