Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ A Minecraft Forge mod that provides enhanced teleportation functionality. Easily
## Features

- **Simple Commands**: Easy-to-use commands for teleporting players
- **Riding Entity Teleportation**: When teleporting while riding a living entity (horse, pig, etc.), both player and mount are teleported together
- **No Dependencies**: This mod does not require any additional libraries or mods to function

## Usage

Run the following commands in-game:
- `/tlp <player>`: Teleports you to the specified player.

### Riding Entity Teleportation
When you use `/tlp` while riding a living entity (such as a horse, pig, donkey, mule, llama, camel, or strider), both you and your mount will be teleported together to the destination. The riding relationship is maintained after teleportation.

**Supported Living Entities:**
- Horses, Donkeys, Mules
- Pigs, Striders
- Llamas, Camels
- Any other rideable living entities

**Note:** Non-living vehicles like boats and minecarts are not teleported - only the player will be teleported in these cases.

**Note**: This mod is not recommended for use on PvP servers as it may provide unfair advantages.

## Compatibility
Expand Down
45 changes: 34 additions & 11 deletions src/main/java/com/icceey/onlytp/command/TeleportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.RelativeMovement;

import java.util.stream.IntStream;

Expand Down Expand Up @@ -74,6 +76,12 @@ private static int execute(CommandContext<CommandSourceStack> context) throws Co
return 0;
}

// 检查玩家是否正在骑乘生物
LivingEntity livingRidingEntity = null;
if (executor.getVehicle() instanceof LivingEntity ridingEntity) {
livingRidingEntity = ridingEntity;
}

// 在原位置播放下界传送门音效
executor.level().playSound(
null, // 发送给所有玩家,无需特定玩家
Expand All @@ -89,15 +97,30 @@ private static int execute(CommandContext<CommandSourceStack> context) throws Co
// 在出发点生成末影人粒子效果
spawnTeleportParticles(executor, executor.serverLevel(), ParticleTypes.PORTAL);

// 执行传送
executor.teleportTo(
targetPlayer.serverLevel(),
targetPlayer.getX(),
targetPlayer.getY(),
targetPlayer.getZ(),
targetPlayer.getYRot(),
targetPlayer.getXRot()
);
// 目标坐标
ServerLevel targetLevel = targetPlayer.serverLevel();
double targetX = targetPlayer.getX();
double targetY = targetPlayer.getY();
double targetZ = targetPlayer.getZ();
float targetYRot = targetPlayer.getYRot();
float targetXRot = targetPlayer.getXRot();

// 如果玩家在骑乘状态且骑乘的是生物,先处理骑乘生物的传送
if (livingRidingEntity != null && livingRidingEntity.isAlive()) {
// 让玩家下马(但保持引用)
executor.stopRiding();

// 传送骑乘生物到目标位置
livingRidingEntity.teleportTo(targetLevel, targetX, targetY, targetZ, RelativeMovement.ALL, targetYRot, targetXRot);
}

// 执行玩家传送
executor.teleportTo(targetLevel, targetX, targetY, targetZ, targetYRot, targetXRot);

if (livingRidingEntity != null && livingRidingEntity.isAlive()) {
// 确保骑乘生物在同一个世界且位置正确后,让玩家重新骑上
executor.startRiding(livingRidingEntity, true);
}

// 发送成功消息
source.sendSuccess(() -> translatableWithFallback("commands.onlytp.success", targetPlayer.getGameProfile().getName()), true);
Expand Down Expand Up @@ -126,8 +149,8 @@ private static int execute(CommandContext<CommandSourceStack> context) throws Co
/**
* 在玩家周围生成传送粒子效果
*
* @param player 作为粒子生成中心的玩家
* @param level 要在其中生成粒子的世界
* @param player 作为粒子生成中心的玩家
* @param level 要在其中生成粒子的世界
* @param particleType 要生成的粒子类型
*/
private static void spawnTeleportParticles(ServerPlayer player, ServerLevel level, ParticleOptions particleType) {
Expand Down