Compare commits
No commits in common. "1ebe7dd0b97381733c4f966acb3ccbedc25faa12" and "4d3947c4ef4970d13b17fc9674a6d0e8c5d16c9d" have entirely different histories.
1ebe7dd0b9
...
4d3947c4ef
@ -64,21 +64,16 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
||||
|
||||
call_listeners(&state, "chat", formatted_message.to_string()).await;
|
||||
}
|
||||
Event::Death(packet) => {
|
||||
if let Some(packet) = packet {
|
||||
Event::Death(Some(packet)) => {
|
||||
let table = state.lua.create_table()?;
|
||||
table.set("message", packet.message.to_string())?;
|
||||
table.set("player_id", packet.player_id.0)?;
|
||||
call_listeners(&state, "death", table).await;
|
||||
} else {
|
||||
call_listeners(&state, "death", ()).await;
|
||||
}
|
||||
}
|
||||
Event::Disconnect(message) => {
|
||||
call_listeners(&state, "disconnect", message.map(|m| m.to_string())).await;
|
||||
exit(0)
|
||||
}
|
||||
Event::KeepAlive(id) => call_listeners(&state, "keep_alive", id).await,
|
||||
Event::Login => call_listeners(&state, "login", ()).await,
|
||||
Event::RemovePlayer(player_info) => {
|
||||
call_listeners(&state, "remove_player", Player::from(player_info)).await;
|
||||
@ -175,6 +170,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
||||
});
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -22,7 +22,6 @@ pub fn held_slot(_lua: &Lua, client: &Client) -> Result<u8> {
|
||||
Ok(client.component::<Inventory>().selected_hotbar_slot)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub fn menu(lua: &Lua, client: &Client) -> Result<Table> {
|
||||
fn from_slot_list<const N: usize>(s: SlotList<N>) -> Vec<ItemStack> {
|
||||
s.iter()
|
||||
@ -46,46 +45,11 @@ pub fn menu(lua: &Lua, client: &Client) -> Result<Table> {
|
||||
table.set("inventory", from_slot_list(inventory))?;
|
||||
table.set("offhand", ItemStack::from(offhand))?;
|
||||
}
|
||||
Menu::Generic9x3 { contents, player } => {
|
||||
table.set("type", 3)?;
|
||||
table.set("contents", from_slot_list(contents))?;
|
||||
table.set("player", from_slot_list(player))?;
|
||||
}
|
||||
Menu::Generic9x6 { contents, player } => {
|
||||
table.set("type", 6)?;
|
||||
table.set("contents", from_slot_list(contents))?;
|
||||
table.set("player", from_slot_list(player))?;
|
||||
}
|
||||
Menu::Crafting {
|
||||
result,
|
||||
grid,
|
||||
player,
|
||||
} => {
|
||||
table.set("type", 13)?;
|
||||
table.set("result", ItemStack::from(result))?;
|
||||
table.set("grid", from_slot_list(grid))?;
|
||||
table.set("player", from_slot_list(player))?;
|
||||
}
|
||||
Menu::Hopper { contents, player } => {
|
||||
table.set("type", 17)?;
|
||||
table.set("contents", from_slot_list(contents))?;
|
||||
table.set("player", from_slot_list(player))?;
|
||||
}
|
||||
Menu::Merchant {
|
||||
payments,
|
||||
result,
|
||||
player,
|
||||
} => {
|
||||
table.set("type", 20)?;
|
||||
table.set("payments", from_slot_list(payments))?;
|
||||
table.set("result", ItemStack::from(result))?;
|
||||
table.set("player", from_slot_list(player))?;
|
||||
}
|
||||
Menu::ShulkerBox { contents, player } => {
|
||||
table.set("type", 21)?;
|
||||
table.set("contents", from_slot_list(contents))?;
|
||||
table.set("player", from_slot_list(player))?;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
Ok(table)
|
||||
|
@ -1,55 +0,0 @@
|
||||
use azalea::inventory::operations::{
|
||||
ClickOperation, CloneClick, PickupAllClick, PickupClick, QuickCraftClick, QuickCraftKind,
|
||||
QuickCraftStatus, QuickMoveClick, SwapClick, ThrowClick,
|
||||
};
|
||||
use mlua::{Result, Table};
|
||||
|
||||
pub fn operation_from_table(op: Table, op_type: Option<u8>) -> Result<ClickOperation> {
|
||||
Ok(match op_type.unwrap_or_default() {
|
||||
0 => ClickOperation::Pickup(PickupClick::Left {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
1 => ClickOperation::Pickup(PickupClick::Right {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
2 => ClickOperation::Pickup(PickupClick::LeftOutside),
|
||||
3 => ClickOperation::Pickup(PickupClick::RightOutside),
|
||||
5 => ClickOperation::QuickMove(QuickMoveClick::Right {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
6 => ClickOperation::Swap(SwapClick {
|
||||
source_slot: op.get("source_slot")?,
|
||||
target_slot: op.get("target_slot")?,
|
||||
}),
|
||||
7 => ClickOperation::Clone(CloneClick {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
8 => ClickOperation::Throw(ThrowClick::Single {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
9 => ClickOperation::Throw(ThrowClick::All {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
10 => ClickOperation::QuickCraft(QuickCraftClick {
|
||||
kind: match op.get("kind").unwrap_or_default() {
|
||||
1 => QuickCraftKind::Right,
|
||||
2 => QuickCraftKind::Middle,
|
||||
_ => QuickCraftKind::Left,
|
||||
},
|
||||
status: match op.get("status").unwrap_or_default() {
|
||||
1 => QuickCraftStatus::Add {
|
||||
slot: op.get("slot")?,
|
||||
},
|
||||
2 => QuickCraftStatus::End,
|
||||
_ => QuickCraftStatus::Start,
|
||||
},
|
||||
}),
|
||||
11 => ClickOperation::PickupAll(PickupAllClick {
|
||||
slot: op.get("slot")?,
|
||||
reversed: op.get("reversed").unwrap_or_default(),
|
||||
}),
|
||||
_ => ClickOperation::QuickMove(QuickMoveClick::Left {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
})
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
pub mod click;
|
||||
pub mod item_stack;
|
||||
|
||||
use azalea::container::{ContainerHandle, ContainerHandleRef};
|
||||
use click::operation_from_table;
|
||||
use azalea::{
|
||||
container::{ContainerHandle, ContainerHandleRef},
|
||||
inventory::operations::{
|
||||
ClickOperation, CloneClick, PickupAllClick, PickupClick, QuickCraftClick, QuickCraftKind,
|
||||
QuickCraftStatus, QuickMoveClick, SwapClick, ThrowClick,
|
||||
},
|
||||
};
|
||||
use item_stack::ItemStack;
|
||||
use mlua::{Table, UserData, UserDataFields, UserDataMethods};
|
||||
use mlua::{Result, Table, UserData, UserDataFields, UserDataMethods};
|
||||
|
||||
pub struct Container {
|
||||
pub inner: ContainerHandle,
|
||||
@ -32,7 +36,7 @@ impl UserData for Container {
|
||||
"click",
|
||||
|_, this, (operation, operation_type): (Table, Option<u8>)| {
|
||||
this.inner
|
||||
.click(operation_from_table(operation, operation_type)?);
|
||||
.click(click_operation_from_table(operation, operation_type)?);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
@ -70,9 +74,59 @@ impl UserData for ContainerRef {
|
||||
"click",
|
||||
|_, this, (operation, operation_type): (Table, Option<u8>)| {
|
||||
this.inner
|
||||
.click(operation_from_table(operation, operation_type)?);
|
||||
.click(click_operation_from_table(operation, operation_type)?);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn click_operation_from_table(op: Table, op_type: Option<u8>) -> Result<ClickOperation> {
|
||||
Ok(match op_type.unwrap_or_default() {
|
||||
0 => ClickOperation::Pickup(PickupClick::Left {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
1 => ClickOperation::Pickup(PickupClick::Right {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
2 => ClickOperation::Pickup(PickupClick::LeftOutside),
|
||||
3 => ClickOperation::Pickup(PickupClick::RightOutside),
|
||||
5 => ClickOperation::QuickMove(QuickMoveClick::Right {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
6 => ClickOperation::Swap(SwapClick {
|
||||
source_slot: op.get("source_slot")?,
|
||||
target_slot: op.get("target_slot")?,
|
||||
}),
|
||||
7 => ClickOperation::Clone(CloneClick {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
8 => ClickOperation::Throw(ThrowClick::Single {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
9 => ClickOperation::Throw(ThrowClick::All {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
10 => ClickOperation::QuickCraft(QuickCraftClick {
|
||||
kind: match op.get("kind").unwrap_or_default() {
|
||||
1 => QuickCraftKind::Right,
|
||||
2 => QuickCraftKind::Middle,
|
||||
_ => QuickCraftKind::Left,
|
||||
},
|
||||
status: match op.get("status").unwrap_or_default() {
|
||||
1 => QuickCraftStatus::Add {
|
||||
slot: op.get("slot")?,
|
||||
},
|
||||
2 => QuickCraftStatus::End,
|
||||
_ => QuickCraftStatus::Start,
|
||||
},
|
||||
}),
|
||||
11 => ClickOperation::PickupAll(PickupAllClick {
|
||||
slot: op.get("slot")?,
|
||||
reversed: op.get("reversed").unwrap_or_default(),
|
||||
}),
|
||||
_ => ClickOperation::QuickMove(QuickMoveClick::Left {
|
||||
slot: op.get("slot")?,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
@ -76,14 +76,14 @@ async fn main() -> anyhow::Result<()> {
|
||||
} else {
|
||||
DefaultPlugins.set(LogPlugin {
|
||||
custom_layer: |_| {
|
||||
env::var("LOG_FILE").ok().map(|path| {
|
||||
env::var("LOG_FILE").ok().map(|log_file| {
|
||||
layer()
|
||||
.with_writer(
|
||||
OpenOptions::new()
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(&path)
|
||||
.expect(&(path + " should be accessible")),
|
||||
.open(&log_file)
|
||||
.expect(&(log_file + " should be accessible")),
|
||||
)
|
||||
.boxed()
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user