Skip to content

Commit 5474fcb

Browse files
authored
fix: use command sender dimension when tp (#1690)
* fix: use target dismention * use from command sender * vanilla accurate --------- Co-authored-by: chocodev11 <chocodev11@users.noreply.github.com>
1 parent 3f4cdd0 commit 5474fcb

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

pumpkin/src/command/commands/teleport.rs

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ fn yaw_pitch_facing_position(
5252
(yaw_degrees as f32, pitch_degrees as f32)
5353
}
5454

55+
fn resolve_sender_world(
56+
sender: &CommandSender,
57+
server: &crate::server::Server,
58+
) -> std::sync::Arc<World> {
59+
sender
60+
.world()
61+
.unwrap_or_else(|| server.worlds.load().first().unwrap().clone())
62+
}
63+
5564
struct EntitiesToEntityExecutor;
5665

5766
impl CommandExecutor for EntitiesToEntityExecutor {
@@ -65,21 +74,21 @@ impl CommandExecutor for EntitiesToEntityExecutor {
6574
let targets = EntitiesArgumentConsumer::find_arg(args, ARG_TARGETS)?;
6675

6776
let destination = EntityArgumentConsumer::find_arg(args, ARG_DESTINATION)?;
68-
let pos = destination.get_entity().pos.load();
77+
let destination = destination.get_entity();
78+
let pos = destination.pos.load();
79+
let yaw = destination.yaw.load();
80+
let pitch = destination.pitch.load();
81+
let world = destination.world.load_full();
6982
if !World::is_valid(BlockPos(pos.floor_to_i32())) {
7083
return Err(CommandError::CommandFailed(TextComponent::translate(
7184
"commands.teleport.invalidPosition",
7285
[],
7386
)));
7487
}
7588
for target in targets {
76-
let base_entity = target.get_entity();
77-
let yaw = base_entity.yaw.load();
78-
let pitch = base_entity.pitch.load();
79-
let world = base_entity.world.load_full();
8089
target
8190
.clone()
82-
.teleport(pos, yaw.into(), pitch.into(), world)
91+
.teleport(pos, Some(yaw), Some(pitch), world.clone())
8392
.await;
8493
}
8594

@@ -109,14 +118,7 @@ impl CommandExecutor for EntitiesToPosFacingPosExecutor {
109118
}
110119
let facing_pos = Position3DArgumentConsumer::find_arg(args, ARG_FACING_LOCATION)?;
111120
let (yaw, pitch) = yaw_pitch_facing_position(&pos, &facing_pos);
112-
//todo
113-
let world = match sender {
114-
CommandSender::Rcon(_) | CommandSender::Console | CommandSender::Dummy => {
115-
server.worlds.load().first().unwrap().clone()
116-
}
117-
CommandSender::Player(player) => player.world().clone(),
118-
CommandSender::CommandBlock(_, w) => w.clone(),
119-
};
121+
let world = resolve_sender_world(sender, server);
120122

121123
for target in targets {
122124
target
@@ -135,8 +137,8 @@ struct EntitiesToPosFacingEntityExecutor;
135137
impl CommandExecutor for EntitiesToPosFacingEntityExecutor {
136138
fn execute<'a>(
137139
&'a self,
138-
_sender: &'a CommandSender,
139-
_server: &'a crate::server::Server,
140+
sender: &'a CommandSender,
141+
server: &'a crate::server::Server,
140142
args: &'a ConsumedArgs<'a>,
141143
) -> CommandResult<'a> {
142144
Box::pin(async move {
@@ -152,16 +154,12 @@ impl CommandExecutor for EntitiesToPosFacingEntityExecutor {
152154
let facing_entity = EntityArgumentConsumer::find_arg(args, ARG_FACING_ENTITY)?;
153155
let (yaw, pitch) =
154156
yaw_pitch_facing_position(&pos, &facing_entity.get_entity().pos.load());
157+
let world = resolve_sender_world(sender, server);
155158

156159
for target in targets {
157160
target
158161
.clone()
159-
.teleport(
160-
pos,
161-
Some(yaw),
162-
Some(pitch),
163-
facing_entity.get_entity().world.load_full(),
164-
)
162+
.teleport(pos, Some(yaw), Some(pitch), world.clone())
165163
.await;
166164
}
167165

@@ -175,7 +173,7 @@ struct EntitiesToPosWithRotationExecutor;
175173
impl CommandExecutor for EntitiesToPosWithRotationExecutor {
176174
fn execute<'a>(
177175
&'a self,
178-
_sender: &'a CommandSender,
176+
sender: &'a CommandSender,
179177
server: &'a crate::server::Server,
180178
args: &'a ConsumedArgs<'a>,
181179
) -> CommandResult<'a> {
@@ -192,9 +190,8 @@ impl CommandExecutor for EntitiesToPosWithRotationExecutor {
192190
// Note: Rotation returns (yaw, is_yaw_relative, pitch, is_pitch_relative)
193191
// For teleport, we use absolute values only (ignore relative flags)
194192
let (yaw, _, pitch, _) = RotationArgumentConsumer::find_arg(args, ARG_ROTATION)?;
193+
let world = resolve_sender_world(sender, server);
195194

196-
// todo command context
197-
let world = server.worlds.load().first().unwrap().clone();
198195
for target in targets {
199196
target
200197
.clone()
@@ -226,14 +223,7 @@ impl CommandExecutor for EntitiesToPosExecutor {
226223
[],
227224
)));
228225
}
229-
// todo command context
230-
let world = match sender {
231-
CommandSender::Rcon(_) | CommandSender::Console | CommandSender::Dummy => {
232-
server.worlds.load().first().unwrap().clone()
233-
}
234-
CommandSender::Player(player) => player.world().clone(),
235-
CommandSender::CommandBlock(_, w) => w.clone(),
236-
};
226+
let world = resolve_sender_world(sender, server);
237227
for target in targets {
238228
let yaw = target.get_entity().yaw.load();
239229
let pitch = target.get_entity().pitch.load();
@@ -259,13 +249,14 @@ impl CommandExecutor for SelfToEntityExecutor {
259249
) -> CommandResult<'a> {
260250
Box::pin(async move {
261251
let destination = EntityArgumentConsumer::find_arg(args, ARG_DESTINATION)?;
262-
let pos = destination.get_entity().pos.load();
263-
let world = destination.get_entity().world.load_full();
252+
let destination = destination.get_entity();
253+
let pos = destination.pos.load();
254+
let yaw = destination.yaw.load();
255+
let pitch = destination.pitch.load();
256+
let world = destination.world.load_full();
264257

265258
match sender {
266259
CommandSender::Player(player) => {
267-
let yaw = player.living_entity.entity.yaw.load();
268-
let pitch = player.living_entity.entity.pitch.load();
269260
if !World::is_valid(BlockPos(pos.floor_to_i32())) {
270261
return Err(CommandError::CommandFailed(TextComponent::translate(
271262
"commands.teleport.invalidPosition",

0 commit comments

Comments
 (0)