Skip to content

Commit 1013bf6

Browse files
committed
Implement camera facing target.
While at it, fix passing on of command args.
1 parent 0b649a2 commit 1013bf6

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

src/minecraft/bedrock_edition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod camera;
55
use std::future::Future;
66

77
use crate::minecraft::java_edition::TargetSelector;
8-
use crate::minecraft::{parse_response, Entity, Error};
8+
use crate::minecraft::{parse_response, Entity, Error, Serialize};
99
use crate::Minecraft;
1010

1111
/// Extension trait for `Source RCON` clients for the `Minecraft: Bedrock Edition`.
@@ -41,6 +41,6 @@ where
4141
}
4242

4343
fn camera(&mut self, target: Entity<TargetSelector>) -> camera::Proxy<'_, Self> {
44-
camera::Proxy::new(self, target)
44+
camera::Proxy::new(self, vec![target.serialize()])
4545
}
4646
}

src/minecraft/bedrock_edition/camera.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::borrow::Cow;
33
pub use color::Color;
44
pub use time::Time;
55

6-
use crate::minecraft::java_edition::TargetSelector;
7-
use crate::minecraft::{Entity, Error, Serialize};
6+
use crate::minecraft::{Error, Serialize};
87
use crate::RCon;
98

109
mod color;
@@ -15,17 +14,18 @@ mod time;
1514
#[derive(Debug)]
1615
pub struct Proxy<'client, T> {
1716
client: &'client mut T,
18-
target: Entity<TargetSelector>,
17+
args: Vec<Cow<'client, str>>,
1918
}
2019

2120
impl<'client, T> Proxy<'client, T> {
22-
pub(crate) const fn new(client: &'client mut T, target: Entity<TargetSelector>) -> Self {
23-
Self { client, target }
21+
pub(crate) fn new(client: &'client mut T, args: Vec<Cow<'client, str>>) -> Self {
22+
Self { client, args }
2423
}
2524

2625
/// Return a proxy with available set options.
27-
pub fn set<'preset>(self, preset: Cow<'preset, str>) -> set::Proxy<'client, 'preset, T> {
28-
set::Proxy::new(self.client, preset)
26+
pub fn set(mut self, preset: Cow<'client, str>) -> set::Proxy<'client, T> {
27+
self.args.extend([Cow::Borrowed("set"), preset]);
28+
set::Proxy::new(self.client, self.args)
2929
}
3030
}
3131

@@ -34,9 +34,10 @@ where
3434
T: RCon + Send,
3535
{
3636
/// Clear the camera view.
37-
pub async fn clear(self) -> Result<String, Error> {
37+
pub async fn clear(mut self) -> Result<String, Error> {
38+
self.args.push(Cow::Borrowed("clear"));
3839
self.client
39-
.run_utf8(format!("{} clear", self.target.serialize()))
40+
.run_utf8(self.args.join(" "))
4041
.await
4142
.map_err(Into::into)
4243
}

src/minecraft/bedrock_edition/camera/set.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
use std::borrow::Cow;
2-
3-
use crate::minecraft::util::EscapeString;
41
use crate::minecraft::Error;
52
use crate::RCon;
3+
use std::borrow::Cow;
4+
5+
mod target;
66

77
/// Camera actions proxy.
88
#[derive(Debug)]
9-
pub struct Proxy<'client, 'preset, T> {
9+
pub struct Proxy<'client, T> {
1010
client: &'client mut T,
11-
preset: Cow<'preset, str>,
11+
args: Vec<Cow<'client, str>>,
1212
}
1313

14-
impl<'client, 'preset, T> Proxy<'client, 'preset, T> {
15-
pub(crate) const fn new(client: &'client mut T, preset: Cow<'preset, str>) -> Self {
16-
Self { client, preset }
14+
impl<'client, T> Proxy<'client, T> {
15+
pub(crate) const fn new(client: &'client mut T, args: Vec<Cow<'client, str>>) -> Self {
16+
Self { client, args }
1717
}
1818
}
1919

20-
impl<T> Proxy<'_, '_, T>
20+
impl<T> Proxy<'_, T>
2121
where
2222
T: RCon + Send,
2323
{
@@ -26,15 +26,15 @@ where
2626
/// TODO: investigate what this actually is. The wiki is quite sparse on this.
2727
///
2828
/// See: <https://minecraft.fandom.com/wiki/Commands/camera>
29-
pub async fn default(self, default: Option<Cow<'_, str>>) -> Result<String, Error> {
30-
let mut args = vec![Cow::Borrowed("set"), self.preset];
29+
pub async fn default(mut self, default: Option<Cow<'_, str>>) -> Result<String, Error> {
30+
self.args.push(Cow::Borrowed("default"));
3131

3232
if let Some(default) = default {
33-
args.push(default.quote().into());
33+
self.args.push(default);
3434
}
3535

3636
self.client
37-
.run_utf8(args.join(" "))
37+
.run_utf8(self.args.join(" "))
3838
.await
3939
.map_err(Into::into)
4040
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use crate::minecraft::java_edition::TargetSelector;
2+
use crate::minecraft::Entity;
3+
4+
/// Facing target.
5+
#[derive(Clone, Debug, PartialEq)]
6+
pub enum Target {
7+
/// Facing an entity.
8+
Entity(Entity<TargetSelector>),
9+
/// Facing a position. Parameters in order are `x`, `y` and `z`.
10+
Position(f32, f32, f32),
11+
}

0 commit comments

Comments
 (0)