Decrease Block count when Placed
This commit is contained in:
parent
0ab4b5daed
commit
65cb0b52b4
@ -120,6 +120,16 @@ impl PlayerInventory {
|
|||||||
self.items[self.selected + 36 - 9].as_ref()
|
self.items[self.selected + 36 - 9].as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn held_item_mut(&mut self) -> Option<&mut ItemStack> {
|
||||||
|
debug_assert!((0..9).contains(&self.selected));
|
||||||
|
self.items[self.selected + 36 - 9].as_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn empty_held_item(&mut self) {
|
||||||
|
debug_assert!((0..9).contains(&self.selected));
|
||||||
|
self.items[self.selected + 36 - 9] = None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn slots(&self) -> Vec<Option<&ItemStack>> {
|
pub fn slots(&self) -> Vec<Option<&ItemStack>> {
|
||||||
let mut slots = vec![self.crafting_output.as_ref()];
|
let mut slots = vec![self.crafting_output.as_ref()];
|
||||||
slots.extend(self.crafting.iter().map(|c| c.as_ref()));
|
slots.extend(self.crafting.iter().map(|c| c.as_ref()));
|
||||||
|
|||||||
@ -560,13 +560,23 @@ impl Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(face) = BlockFace::from_i32(use_item_on.face.0) {
|
if let Some(face) = BlockFace::from_i32(use_item_on.face.0) {
|
||||||
if let Some(item) = self.inventory.lock().await.held_item() {
|
let mut inventory = self.inventory.lock().await;
|
||||||
|
if let Some(item) = inventory.held_item_mut() {
|
||||||
let block = get_block_by_item(item.item_id);
|
let block = get_block_by_item(item.item_id);
|
||||||
// check if item is a block, Because Not every item can be placed :D
|
// check if item is a block, Because Not every item can be placed :D
|
||||||
if let Some(block) = block {
|
if let Some(block) = block {
|
||||||
let entity = &self.living_entity.entity;
|
let entity = &self.living_entity.entity;
|
||||||
let world = &entity.world;
|
let world = &entity.world;
|
||||||
|
|
||||||
|
// TODO: Config
|
||||||
|
// Decrease Block count
|
||||||
|
if self.gamemode.load() != GameMode::Creative {
|
||||||
|
item.item_count -= 1;
|
||||||
|
if item.item_count == 0 {
|
||||||
|
inventory.empty_held_item();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
world
|
world
|
||||||
.set_block(
|
.set_block(
|
||||||
WorldPosition(location.0 + face.to_offset()),
|
WorldPosition(location.0 + face.to_offset()),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user