refactor!: replace setters with fields
This commit is contained in:
+1
-1
@@ -99,7 +99,7 @@ function attack_entities(target_kind, minimum)
|
|||||||
pos.y = pos.y + 1.5
|
pos.y = pos.y + 1.5
|
||||||
|
|
||||||
hold_sword()
|
hold_sword()
|
||||||
client:look_at(pos)
|
client.looking_at = pos
|
||||||
client:attack(e.id)
|
client:attack(e.id)
|
||||||
while client.has_attack_cooldown do
|
while client.has_attack_cooldown do
|
||||||
sleep(100)
|
sleep(100)
|
||||||
|
|||||||
+2
-2
@@ -6,7 +6,7 @@ function hold_items_in_hotbar(target_kinds, inventory)
|
|||||||
if index >= 37 and index <= 45 and table.contains(target_kinds, item.kind) then
|
if index >= 37 and index <= 45 and table.contains(target_kinds, item.kind) then
|
||||||
inventory = nil
|
inventory = nil
|
||||||
sleep(500)
|
sleep(500)
|
||||||
client:set_held_slot(index - 37)
|
client.held_slot = index - 37
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -35,7 +35,7 @@ end
|
|||||||
function steal(item_name)
|
function steal(item_name)
|
||||||
for _, chest_pos in ipairs(client:find_blocks(client.position, get_block_states({ "chest" }))) do
|
for _, chest_pos in ipairs(client:find_blocks(client.position, get_block_states({ "chest" }))) do
|
||||||
client:go_to({ position = chest_pos, radius = 3 }, { type = RADIUS_GOAL })
|
client:go_to({ position = chest_pos, radius = 3 }, { type = RADIUS_GOAL })
|
||||||
client:look_at(chest_pos)
|
client.looking_at = chest_pos
|
||||||
|
|
||||||
local container = client:open_container_at(chest_pos)
|
local container = client:open_container_at(chest_pos)
|
||||||
for index, item in ipairs(container.contents) do
|
for index, item in ipairs(container.contents) do
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ function look_at_player(name)
|
|||||||
local player = get_player(name)
|
local player = get_player(name)
|
||||||
if player then
|
if player then
|
||||||
player.position.y = player.position.y + 1
|
player.position.y = player.position.y + 1
|
||||||
client:look_at(player.position)
|
client.looking_at = player.position
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -141,7 +141,7 @@ function interact_bed()
|
|||||||
end
|
end
|
||||||
|
|
||||||
client:go_to({ position = bed, radius = 2 }, { type = RADIUS_GOAL, options = { without_mining = true } })
|
client:go_to({ position = bed, radius = 2 }, { type = RADIUS_GOAL, options = { without_mining = true } })
|
||||||
client:look_at(bed)
|
client.looking_at = bed
|
||||||
client:block_interact(bed)
|
client:block_interact(bed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub fn held_item(_lua: &Lua, client: &Client) -> Result<ItemStack> {
|
|||||||
Ok(ItemStack(client.get_held_item()))
|
Ok(ItemStack(client.get_held_item()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn held_slot(_lua: &Lua, client: &Client) -> Result<u8> {
|
pub fn get_held_slot(_lua: &Lua, client: &Client) -> Result<u8> {
|
||||||
Ok(client.component::<Inventory>().selected_hotbar_slot)
|
Ok(client.component::<Inventory>().selected_hotbar_slot)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ pub fn open_inventory(_lua: &Lua, client: &Client, (): ()) -> Result<Option<Cont
|
|||||||
Ok(client.open_inventory().map(Container))
|
Ok(client.open_inventory().map(Container))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_held_slot(_lua: &Lua, client: &Client, slot: u8) -> Result<()> {
|
pub fn set_held_slot(_lua: &Lua, client: &mut Client, slot: u8) -> Result<()> {
|
||||||
if slot > 8 {
|
if slot > 8 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,11 @@ pub async fn mine(_lua: Lua, client: UserDataRef<Client>, position: Vec3) -> Res
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_mining(_lua: &Lua, client: &Client, state: bool) -> Result<()> {
|
pub fn get_mining(_lua: &Lua, client: &Client) -> Result<bool> {
|
||||||
|
Ok(client.is_mining())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_mining(_lua: &Lua, client: &mut Client, state: bool) -> Result<()> {
|
||||||
client.left_click_mine(state);
|
client.left_click_mine(state);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-11
@@ -33,20 +33,30 @@ impl UserData for Client {
|
|||||||
f.add_field_method_get("air_supply", state::air_supply);
|
f.add_field_method_get("air_supply", state::air_supply);
|
||||||
f.add_field_method_get("container", container::container);
|
f.add_field_method_get("container", container::container);
|
||||||
f.add_field_method_get("dimension", world::dimension);
|
f.add_field_method_get("dimension", world::dimension);
|
||||||
f.add_field_method_get("direction", movement::direction);
|
f.add_field_method_get("direction", movement::get_direction);
|
||||||
|
f.add_field_method_set("direction", movement::set_direction);
|
||||||
f.add_field_method_get("experience", state::experience);
|
f.add_field_method_get("experience", state::experience);
|
||||||
f.add_field_method_get("eye_position", movement::eye_position);
|
f.add_field_method_get("eye_position", movement::eye_position);
|
||||||
f.add_field_method_get("go_to_reached", movement::go_to_reached);
|
f.add_field_method_get("go_to_reached", movement::go_to_reached);
|
||||||
f.add_field_method_get("has_attack_cooldown", interaction::has_attack_cooldown);
|
f.add_field_method_get("has_attack_cooldown", interaction::has_attack_cooldown);
|
||||||
f.add_field_method_get("health", state::health);
|
f.add_field_method_get("health", state::health);
|
||||||
f.add_field_method_get("held_item", container::held_item);
|
f.add_field_method_get("held_item", container::held_item);
|
||||||
f.add_field_method_get("held_slot", container::held_slot);
|
f.add_field_method_get("held_slot", container::get_held_slot);
|
||||||
|
f.add_field_method_set("held_slot", container::set_held_slot);
|
||||||
f.add_field_method_get("hunger", state::hunger);
|
f.add_field_method_get("hunger", state::hunger);
|
||||||
f.add_field_method_get("id", id);
|
f.add_field_method_get("id", id);
|
||||||
f.add_field_method_get("looking_at", movement::looking_at);
|
f.add_field_method_get("jumping", movement::get_jumping);
|
||||||
|
f.add_field_method_set("jumping", movement::set_jumping);
|
||||||
|
f.add_field_method_get("looking_at", movement::get_looking_at);
|
||||||
|
f.add_field_method_set("looking_at", movement::set_looking_at);
|
||||||
f.add_field_method_get("menu", container::menu);
|
f.add_field_method_get("menu", container::menu);
|
||||||
|
f.add_field_method_get("mining", interaction::get_mining);
|
||||||
|
f.add_field_method_set("mining", interaction::set_mining);
|
||||||
f.add_field_method_get("pathfinder", movement::pathfinder);
|
f.add_field_method_get("pathfinder", movement::pathfinder);
|
||||||
f.add_field_method_get("position", movement::position);
|
f.add_field_method_get("position", movement::get_position);
|
||||||
|
f.add_field_method_set("position", movement::set_position);
|
||||||
|
f.add_field_method_get("sneaking", movement::get_sneaking);
|
||||||
|
f.add_field_method_set("sneaking", movement::set_sneaking);
|
||||||
f.add_field_method_get("tab_list", tab_list);
|
f.add_field_method_get("tab_list", tab_list);
|
||||||
f.add_field_method_get("username", username);
|
f.add_field_method_get("username", username);
|
||||||
f.add_field_method_get("uuid", uuid);
|
f.add_field_method_get("uuid", uuid);
|
||||||
@@ -72,15 +82,8 @@ impl UserData for Client {
|
|||||||
m.add_method("get_block_state", world::get_block_state);
|
m.add_method("get_block_state", world::get_block_state);
|
||||||
m.add_method("get_fluid_state", world::get_fluid_state);
|
m.add_method("get_fluid_state", world::get_fluid_state);
|
||||||
m.add_method("jump", movement::jump);
|
m.add_method("jump", movement::jump);
|
||||||
m.add_method("look_at", movement::look_at);
|
|
||||||
m.add_method("open_inventory", container::open_inventory);
|
m.add_method("open_inventory", container::open_inventory);
|
||||||
m.add_method("set_component", state::set_component);
|
m.add_method("set_component", state::set_component);
|
||||||
m.add_method("set_direction", movement::set_direction);
|
|
||||||
m.add_method("set_held_slot", container::set_held_slot);
|
|
||||||
m.add_method("set_jumping", movement::set_jumping);
|
|
||||||
m.add_method("set_mining", interaction::set_mining);
|
|
||||||
m.add_method("set_position", movement::set_position);
|
|
||||||
m.add_method("set_sneaking", movement::set_sneaking);
|
|
||||||
m.add_method("sprint", movement::sprint);
|
m.add_method("sprint", movement::sprint);
|
||||||
m.add_method("start_mining", interaction::start_mining);
|
m.add_method("start_mining", interaction::start_mining);
|
||||||
m.add_method("start_use_item", interaction::start_use_item);
|
m.add_method("start_use_item", interaction::start_use_item);
|
||||||
|
|||||||
+18
-10
@@ -125,7 +125,7 @@ pub async fn start_go_to(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn direction(_lua: &Lua, client: &Client) -> Result<Direction> {
|
pub fn get_direction(_lua: &Lua, client: &Client) -> Result<Direction> {
|
||||||
let direction = client.direction();
|
let direction = client.direction();
|
||||||
Ok(Direction {
|
Ok(Direction {
|
||||||
y: direction.y_rot(),
|
y: direction.y_rot(),
|
||||||
@@ -133,6 +133,11 @@ pub fn direction(_lua: &Lua, client: &Client) -> Result<Direction> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_direction(_lua: &Lua, client: &mut Client, direction: Direction) -> Result<()> {
|
||||||
|
client.set_direction(direction.y, direction.x);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn eye_position(_lua: &Lua, client: &Client) -> Result<Vec3> {
|
pub fn eye_position(_lua: &Lua, client: &Client) -> Result<Vec3> {
|
||||||
Ok(Vec3::from(client.eye_position()))
|
Ok(Vec3::from(client.eye_position()))
|
||||||
}
|
}
|
||||||
@@ -142,7 +147,7 @@ pub fn jump(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> {
|
pub fn get_looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> {
|
||||||
Ok(
|
Ok(
|
||||||
if let HitResult::Block(ref result) = **client.component::<HitResultComponent>() {
|
if let HitResult::Block(ref result) = **client.component::<HitResultComponent>() {
|
||||||
let table = lua.create_table()?;
|
let table = lua.create_table()?;
|
||||||
@@ -158,7 +163,7 @@ pub fn looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn look_at(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
|
pub fn set_looking_at(_lua: &Lua, client: &mut Client, position: Vec3) -> Result<()> {
|
||||||
client.look_at(azalea::Vec3::new(position.x, position.y, position.z));
|
client.look_at(azalea::Vec3::new(position.x, position.y, position.z));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -189,21 +194,20 @@ pub fn pathfinder(lua: &Lua, client: &Client) -> Result<Table> {
|
|||||||
Ok(table)
|
Ok(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn position(_lua: &Lua, client: &Client) -> Result<Vec3> {
|
pub fn get_position(_lua: &Lua, client: &Client) -> Result<Vec3> {
|
||||||
Ok(Vec3::from(*client.component::<Position>()))
|
Ok(Vec3::from(*client.component::<Position>()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_direction(_lua: &Lua, client: &Client, direction: Direction) -> Result<()> {
|
pub fn get_jumping(_lua: &Lua, client: &Client) -> Result<bool> {
|
||||||
client.set_direction(direction.y, direction.x);
|
Ok(client.jumping())
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_jumping(_lua: &Lua, client: &Client, jumping: bool) -> Result<()> {
|
pub fn set_jumping(_lua: &Lua, client: &mut Client, jumping: bool) -> Result<()> {
|
||||||
client.set_jumping(jumping);
|
client.set_jumping(jumping);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_position(_lua: &Lua, client: &Client, new_pos: Vec3) -> Result<()> {
|
pub fn set_position(_lua: &Lua, client: &mut Client, new_pos: Vec3) -> Result<()> {
|
||||||
client.query_self::<&mut Position, _>(|mut pos| {
|
client.query_self::<&mut Position, _>(|mut pos| {
|
||||||
pos.x = new_pos.x;
|
pos.x = new_pos.x;
|
||||||
pos.y = new_pos.y;
|
pos.y = new_pos.y;
|
||||||
@@ -212,7 +216,11 @@ pub fn set_position(_lua: &Lua, client: &Client, new_pos: Vec3) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
|
pub fn get_sneaking(_lua: &Lua, client: &Client) -> Result<bool> {
|
||||||
|
Ok(client.crouching())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_sneaking(_lua: &Lua, client: &mut Client, sneaking: bool) -> Result<()> {
|
||||||
client.set_crouching(sneaking);
|
client.set_crouching(sneaking);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user