Skip to content

Commit b26e3c6

Browse files
committed
TeleportCommand.java updated.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 0d9b6af commit b26e3c6

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

src/main/java/com/mairwunnx/projectessentials/core/impl/vanilla/commands/TeleportCommand.java

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
import net.minecraft.command.Commands;
1919
import net.minecraft.command.arguments.*;
2020
import net.minecraft.entity.Entity;
21+
import net.minecraft.entity.LivingEntity;
2122
import net.minecraft.entity.player.ServerPlayerEntity;
2223
import net.minecraft.network.play.server.SPlayerPositionLookPacket;
23-
import net.minecraft.util.math.Vec2f;
24-
import net.minecraft.util.math.Vec3d;
24+
import net.minecraft.util.math.*;
2525
import net.minecraft.util.text.TranslationTextComponent;
2626
import net.minecraft.world.server.ServerWorld;
27+
import net.minecraft.world.server.TicketType;
2728
import org.jetbrains.annotations.NotNull;
2829

2930
import javax.annotation.Nullable;
@@ -100,9 +101,9 @@ private static int teleportToPos(CommandSource source, Collection<? extends Enti
100101

101102
for (Entity entity : targets) {
102103
if (rotationIn == null) {
103-
net.minecraft.command.impl.TeleportCommand.teleport(source, entity, worldIn, vec3d.x, vec3d.y, vec3d.z, set, entity.rotationYaw, entity.rotationPitch, facing);
104+
teleport(source, entity, worldIn, vec3d.x, vec3d.y, vec3d.z, set, entity.rotationYaw, entity.rotationPitch, facing);
104105
} else {
105-
net.minecraft.command.impl.TeleportCommand.teleport(source, entity, worldIn, vec3d.x, vec3d.y, vec3d.z, set, vec2f.y, vec2f.x, facing);
106+
teleport(source, entity, worldIn, vec3d.x, vec3d.y, vec3d.z, set, vec2f.y, vec2f.x, facing);
106107
}
107108
}
108109

@@ -115,6 +116,56 @@ private static int teleportToPos(CommandSource source, Collection<? extends Enti
115116
return targets.size();
116117
}
117118

119+
public static void teleport(CommandSource source, Entity entityIn, ServerWorld worldIn, double x, double y, double z, Set<SPlayerPositionLookPacket.Flags> relativeList, float yaw, float pitch, @Nullable Facing facing) {
120+
if (entityIn instanceof ServerPlayerEntity) {
121+
ChunkPos chunkpos = new ChunkPos(new BlockPos(x, y, z));
122+
worldIn.getChunkProvider().func_217228_a(TicketType.POST_TELEPORT, chunkpos, 1, entityIn.getEntityId());
123+
entityIn.stopRiding();
124+
if (((ServerPlayerEntity) entityIn).isSleeping()) {
125+
((ServerPlayerEntity) entityIn).wakeUpPlayer(true, true, false);
126+
}
127+
128+
if (worldIn == entityIn.world) {
129+
((ServerPlayerEntity) entityIn).connection.setPlayerLocation(x, y, z, yaw, pitch, relativeList);
130+
} else {
131+
((ServerPlayerEntity) entityIn).teleport(worldIn, x, y, z, yaw, pitch);
132+
}
133+
134+
entityIn.setRotationYawHead(yaw);
135+
} else {
136+
float f1 = MathHelper.wrapDegrees(yaw);
137+
float f = MathHelper.wrapDegrees(pitch);
138+
f = MathHelper.clamp(f, -90.0F, 90.0F);
139+
if (worldIn == entityIn.world) {
140+
entityIn.setLocationAndAngles(x, y, z, f1, f);
141+
entityIn.setRotationYawHead(f1);
142+
} else {
143+
entityIn.detach();
144+
entityIn.dimension = worldIn.dimension.getType();
145+
Entity entity = entityIn;
146+
entityIn = entityIn.getType().create(worldIn);
147+
if (entityIn == null) {
148+
return;
149+
}
150+
151+
entityIn.copyDataFromOld(entity);
152+
entityIn.setLocationAndAngles(x, y, z, f1, f);
153+
entityIn.setRotationYawHead(f1);
154+
worldIn.func_217460_e(entityIn);
155+
}
156+
}
157+
158+
if (facing != null) {
159+
facing.updateLook(source, entityIn);
160+
}
161+
162+
if (!(entityIn instanceof LivingEntity) || !((LivingEntity) entityIn).isElytraFlying()) {
163+
entityIn.setMotion(entityIn.getMotion().mul(1.0D, 0.0D, 1.0D));
164+
entityIn.onGround = true;
165+
}
166+
167+
}
168+
118169
static class Facing {
119170
private final Vec3d position;
120171
private final Entity entity;

0 commit comments

Comments
 (0)