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
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
# OnlyTP

A Minecraft Forge mod that provides enhanced teleportation functionality. Easily teleport to your friends to help them.
[English](README.md) | [中文](README_zh.md)

## Features
OnlyTP is a lightweight Minecraft Forge mod that enhances your gameplay with convenient teleportation features. Whether you're exploring vast worlds or helping friends in need, OnlyTP makes traveling across your Minecraft server simple and efficient.

- **Simple Commands**: Easy-to-use commands for teleporting players
- **No Dependencies**: This mod does not require any additional libraries or mods to function
## ✨ Features

## Usage
- **🎯 Simple Commands**: Intuitive teleportation with easy-to-remember commands
- **🌟 Enhanced Experience**: Teleport with elegant particle effects and sound feedback
- **⚡ Zero Dependencies**: No additional mods or libraries required - just install and play

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

**Note**: This mod is not recommended for use on PvP servers as it may provide unfair advantages.
### Basic Command
- **`/tlp <player>`**: Teleports you to the specified online player

## Compatibility
### Features in Action
- **Particle Effects**: Beautiful portal particles appear at both departure and arrival locations
- **Sound Feedback**: Immersive portal sounds enhance the teleportation experience
- **Player Notifications**: Both teleporter and target receive clear status messages

### 🔒 Safety Note
This mod is not recommended for competitive PvP servers as it may provide tactical advantages to players.

## 🔧 Compatibility

- **Minecraft Version**: 1.20.1
- **Forge Version**: 47.4.0+
- **Side**: Only server is required, client is optional.
- Install on client for localized messages, otherwise server language will be used.
- **Installation**: Server-side required, client-side optional
- Install on client for localized messages
- Server-only installation uses server language for all players

## License
## 📄 License

This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
36 changes: 36 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# OnlyTP

[English](README.md) | [中文](README_zh.md)

OnlyTP 是一个轻量级的 Minecraft Forge 模组,为您的游戏体验提供便捷的传送功能。无论您是在探索广阔的世界,还是要帮助有需要的朋友,OnlyTP 都能让您在 Minecraft 服务器中的旅行变得简单高效。

## ✨ 功能特色

- **🎯 简单命令**: 直观的传送命令,易于记忆和使用
- **🌟 增强体验**: 传送时带有精美的粒子效果和音效反馈
- **⚡ 零依赖**: 无需额外的模组或库 - 安装即可使用

## 🎮 使用方法

### 基础命令
- **`/tlp <玩家名>`**: 传送到指定的在线玩家位置

### 功能详情
- **粒子效果**: 在出发地和到达地都会出现美丽的传送门粒子效果
- **音效反馈**: 沉浸式的传送门音效增强传送体验
- **玩家通知**: 传送者和目标玩家都会收到清晰的状态消息

### 🔒 安全提示
不建议在竞技性 PvP 服务器上使用此模组,因为它可能为玩家提供战术优势。

## 🔧 兼容性

- **Minecraft 版本**: 1.20.1
- **Forge 版本**: 47.4.0+
- **安装要求**: 服务端必需,客户端可选
- 在客户端安装可获得本地化提示
- 仅服务端安装时所有玩家使用服务器语言

## 📄 许可证

本项目基于 MIT 许可证开源 - 详情请查看 [LICENSE.txt](LICENSE.txt) 文件。
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