refactor away unnecessary abstraction
This commit is contained in:
parent
d1c4e59955
commit
28292439de
@ -1,17 +1,11 @@
|
|||||||
use pumpkin_world::item::ItemStack;
|
use pumpkin_world::item::ItemStack;
|
||||||
|
|
||||||
pub struct ClickMode {
|
pub struct Click {
|
||||||
pub slot: Slot,
|
pub slot: Slot,
|
||||||
pub click_type: ClickType,
|
pub click_type: ClickType,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Click {
|
impl Click {
|
||||||
pub mode: ClickMode,
|
|
||||||
pub changed_items: Vec<ItemChange>,
|
|
||||||
pub carried_item: Option<ItemStack>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ClickMode {
|
|
||||||
pub fn new(mode: u8, button: i8, slot: i16) -> Self {
|
pub fn new(mode: u8, button: i8, slot: i16) -> Self {
|
||||||
match mode {
|
match mode {
|
||||||
0 => Self::new_normal_click(button, slot),
|
0 => Self::new_normal_click(button, slot),
|
||||||
|
|||||||
@ -141,36 +141,22 @@ impl Player {
|
|||||||
dbg!("weird");
|
dbg!("weird");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let click = Click {
|
|
||||||
changed_items: packet
|
let click = Click::new(
|
||||||
.array_of_changed_slots
|
packet
|
||||||
.into_iter()
|
.mode
|
||||||
.map(|(slot, item)| {
|
.0
|
||||||
let slot = slot.try_into().unwrap();
|
.try_into()
|
||||||
if let Some(item) = item.to_item() {
|
.expect("Mode can only be between 0-6"),
|
||||||
ItemChange::Add { slot, item }
|
packet.button,
|
||||||
} else {
|
packet.slot,
|
||||||
ItemChange::Remove { slot }
|
);
|
||||||
}
|
match click.click_type {
|
||||||
})
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
carried_item: packet.carried_item.to_item(),
|
|
||||||
mode: ClickMode::new(
|
|
||||||
packet
|
|
||||||
.mode
|
|
||||||
.0
|
|
||||||
.try_into()
|
|
||||||
.expect("Mode can only be between 0-6"),
|
|
||||||
packet.button,
|
|
||||||
packet.slot,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
match click.mode.click_type {
|
|
||||||
ClickType::MouseClick(mouse_click) => {
|
ClickType::MouseClick(mouse_click) => {
|
||||||
self.mouse_click(opened_container, mouse_click, click.mode.slot)
|
self.mouse_click(opened_container, mouse_click, click.slot)
|
||||||
}
|
}
|
||||||
ClickType::ShiftClick => self.shift_mouse_click(opened_container, click.mode.slot),
|
ClickType::ShiftClick => self.shift_mouse_click(opened_container, click.slot),
|
||||||
ClickType::KeyClick(key_click) => match click.mode.slot {
|
ClickType::KeyClick(key_click) => match click.slot {
|
||||||
container_click::Slot::Normal(slot) => {
|
container_click::Slot::Normal(slot) => {
|
||||||
self.number_button_pressed(opened_container, key_click, slot)
|
self.number_button_pressed(opened_container, key_click, slot)
|
||||||
}
|
}
|
||||||
@ -179,12 +165,12 @@ impl Player {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ClickType::CreativePickItem => {
|
ClickType::CreativePickItem => {
|
||||||
if let container_click::Slot::Normal(slot) = click.mode.slot {
|
if let container_click::Slot::Normal(slot) = click.slot {
|
||||||
self.creative_pick_item(opened_container, slot)
|
self.creative_pick_item(opened_container, slot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ClickType::DoubleClick => {
|
ClickType::DoubleClick => {
|
||||||
if let container_click::Slot::Normal(slot) = click.mode.slot {
|
if let container_click::Slot::Normal(slot) = click.slot {
|
||||||
self.double_click(slot)
|
self.double_click(slot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user