From 9fe2c5b5dc4e248097233860967fbf807a88a8d4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 20 Jul 2025 02:02:03 +0000 Subject: [PATCH 1/4] Initial plan From 34645acaf5fc5200a0bb279c6cdc5a4ffe6afdf6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 20 Jul 2025 02:10:36 +0000 Subject: [PATCH 2/4] Implement riding entity teleportation feature with localization support Co-authored-by: icceey <33692766+icceey@users.noreply.github.com> --- .../onlytp/command/TeleportCommand.java | 45 ++++++++++++++----- .../resources/assets/onlytp/lang/en_us.json | 1 + .../resources/assets/onlytp/lang/ja_jp.json | 1 + .../resources/assets/onlytp/lang/lzh.json | 1 + .../resources/assets/onlytp/lang/zh_cn.json | 1 + .../resources/assets/onlytp/lang/zh_hk.json | 1 + .../resources/assets/onlytp/lang/zh_tw.json | 1 + 7 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/icceey/onlytp/command/TeleportCommand.java b/src/main/java/com/icceey/onlytp/command/TeleportCommand.java index 6845462..c3ff521 100644 --- a/src/main/java/com/icceey/onlytp/command/TeleportCommand.java +++ b/src/main/java/com/icceey/onlytp/command/TeleportCommand.java @@ -17,6 +17,7 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.Entity; import java.util.stream.IntStream; @@ -74,6 +75,10 @@ private static int execute(CommandContext context) throws Co return 0; } + // 检查玩家是否正在骑乘生物 + Entity ridingEntity = executor.getVehicle(); + boolean wasRiding = ridingEntity != null; + // 在原位置播放下界传送门音效 executor.level().playSound( null, // 发送给所有玩家,无需特定玩家 @@ -89,18 +94,38 @@ private static int execute(CommandContext 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 (wasRiding) { + // 让玩家下马(但保持引用) + executor.stopRiding(); + + // 传送骑乘生物到目标位置 + ridingEntity.teleportTo(targetLevel, targetX, targetY, targetZ, targetYRot, targetXRot); + } + + // 执行玩家传送 + executor.teleportTo(targetLevel, targetX, targetY, targetZ, targetYRot, targetXRot); + + // 如果之前在骑乘状态,重新让玩家骑上生物 + if (wasRiding && ridingEntity.isAlive()) { + // 确保骑乘生物在同一个世界且位置正确后,让玩家重新骑上 + executor.startRiding(ridingEntity, true); + } // 发送成功消息 - source.sendSuccess(() -> translatableWithFallback("commands.onlytp.success", targetPlayer.getGameProfile().getName()), true); + if (wasRiding && ridingEntity != null && ridingEntity.isAlive()) { + source.sendSuccess(() -> translatableWithFallback("commands.onlytp.success_with_mount", targetPlayer.getGameProfile().getName()), true); + } else { + source.sendSuccess(() -> translatableWithFallback("commands.onlytp.success", targetPlayer.getGameProfile().getName()), true); + } // 通知目标玩家有人传送到了他那里 targetPlayer.sendSystemMessage(translatableWithFallback("commands.onlytp.notify_target", executor.getGameProfile().getName())); diff --git a/src/main/resources/assets/onlytp/lang/en_us.json b/src/main/resources/assets/onlytp/lang/en_us.json index fad025f..6d0d48a 100644 --- a/src/main/resources/assets/onlytp/lang/en_us.json +++ b/src/main/resources/assets/onlytp/lang/en_us.json @@ -4,6 +4,7 @@ "commands.onlytp.target_dead_offline": "Target player is dead or offline", "commands.onlytp.executor_dead_offline": "You are dead or offline, cannot teleport", "commands.onlytp.success": "Teleported to %s", + "commands.onlytp.success_with_mount": "Teleported to %s with your mount", "commands.onlytp.notify_target": "%s teleported to you" } diff --git a/src/main/resources/assets/onlytp/lang/ja_jp.json b/src/main/resources/assets/onlytp/lang/ja_jp.json index de67203..9b86b6d 100644 --- a/src/main/resources/assets/onlytp/lang/ja_jp.json +++ b/src/main/resources/assets/onlytp/lang/ja_jp.json @@ -4,6 +4,7 @@ "commands.onlytp.target_dead_offline": "対象プレイヤーが死亡またはオフラインです", "commands.onlytp.executor_dead_offline": "あなたは死亡またはオフラインのため、瞬間移動できません", "commands.onlytp.success": "%s にテレポートしました", + "commands.onlytp.success_with_mount": "乗り物と一緒に %s にテレポートしました", "commands.onlytp.notify_target": "%s があなたのところにテレポートしました" } diff --git a/src/main/resources/assets/onlytp/lang/lzh.json b/src/main/resources/assets/onlytp/lang/lzh.json index 20b35ed..0ef1ebf 100644 --- a/src/main/resources/assets/onlytp/lang/lzh.json +++ b/src/main/resources/assets/onlytp/lang/lzh.json @@ -4,5 +4,6 @@ "commands.onlytp.target_dead_offline": "彼身已殁,或形未現", "commands.onlytp.executor_dead_offline": "子身已殁,焉能徙形", "commands.onlytp.success": "已現 %s 之側", + "commands.onlytp.success_with_mount": "攜座騎而現 %s 之側", "commands.onlytp.notify_target": "%s 已臨君側" } \ No newline at end of file diff --git a/src/main/resources/assets/onlytp/lang/zh_cn.json b/src/main/resources/assets/onlytp/lang/zh_cn.json index 4850621..4ba66e5 100644 --- a/src/main/resources/assets/onlytp/lang/zh_cn.json +++ b/src/main/resources/assets/onlytp/lang/zh_cn.json @@ -4,6 +4,7 @@ "commands.onlytp.target_dead_offline": "目标玩家已死亡或已离线", "commands.onlytp.executor_dead_offline": "你已死亡或已离线,无法传送", "commands.onlytp.success": "已传送到 %s", + "commands.onlytp.success_with_mount": "已与坐骑一同传送到 %s", "commands.onlytp.notify_target": "%s 传送到了你这里" } diff --git a/src/main/resources/assets/onlytp/lang/zh_hk.json b/src/main/resources/assets/onlytp/lang/zh_hk.json index dac38e7..1f7568c 100644 --- a/src/main/resources/assets/onlytp/lang/zh_hk.json +++ b/src/main/resources/assets/onlytp/lang/zh_hk.json @@ -4,6 +4,7 @@ "commands.onlytp.target_dead_offline": "目標玩家已死亡或已離線", "commands.onlytp.executor_dead_offline": "你已死亡或已離線,無法傳送", "commands.onlytp.success": "已傳送到 %s", + "commands.onlytp.success_with_mount": "已與坐騎一同傳送到 %s", "commands.onlytp.notify_target": "%s 傳送到了你這裏" } diff --git a/src/main/resources/assets/onlytp/lang/zh_tw.json b/src/main/resources/assets/onlytp/lang/zh_tw.json index d2be29d..b718910 100644 --- a/src/main/resources/assets/onlytp/lang/zh_tw.json +++ b/src/main/resources/assets/onlytp/lang/zh_tw.json @@ -4,6 +4,7 @@ "commands.onlytp.target_dead_offline": "目標玩家已死亡或已離線", "commands.onlytp.executor_dead_offline": "你已死亡或已離線,無法傳送", "commands.onlytp.success": "已傳送到 %s", + "commands.onlytp.success_with_mount": "已與坐騎一同傳送到 %s", "commands.onlytp.notify_target": "%s 傳送到了你這裡" } From d1d99e169e5ec134848bb69dd649c78057cb4ce1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 20 Jul 2025 02:41:39 +0000 Subject: [PATCH 3/4] Fix riding entity teleportation to only teleport living entities and update README Co-authored-by: icceey <33692766+icceey@users.noreply.github.com> --- README.md | 12 ++++++++++++ .../com/icceey/onlytp/command/TeleportCommand.java | 12 +++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4c6ee5d..f1d8cb8 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ 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 @@ -12,6 +13,17 @@ A Minecraft Forge mod that provides enhanced teleportation functionality. Easily Run the following commands in-game: - `/tlp `: 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 diff --git a/src/main/java/com/icceey/onlytp/command/TeleportCommand.java b/src/main/java/com/icceey/onlytp/command/TeleportCommand.java index c3ff521..375090c 100644 --- a/src/main/java/com/icceey/onlytp/command/TeleportCommand.java +++ b/src/main/java/com/icceey/onlytp/command/TeleportCommand.java @@ -18,6 +18,7 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import java.util.stream.IntStream; @@ -78,6 +79,7 @@ private static int execute(CommandContext context) throws Co // 检查玩家是否正在骑乘生物 Entity ridingEntity = executor.getVehicle(); boolean wasRiding = ridingEntity != null; + boolean isRidingLivingEntity = ridingEntity instanceof LivingEntity; // 在原位置播放下界传送门音效 executor.level().playSound( @@ -102,8 +104,8 @@ private static int execute(CommandContext context) throws Co float targetYRot = targetPlayer.getYRot(); float targetXRot = targetPlayer.getXRot(); - // 如果玩家在骑乘状态,先处理骑乘生物的传送 - if (wasRiding) { + // 如果玩家在骑乘状态且骑乘的是生物,先处理骑乘生物的传送 + if (wasRiding && isRidingLivingEntity) { // 让玩家下马(但保持引用) executor.stopRiding(); @@ -114,14 +116,14 @@ private static int execute(CommandContext context) throws Co // 执行玩家传送 executor.teleportTo(targetLevel, targetX, targetY, targetZ, targetYRot, targetXRot); - // 如果之前在骑乘状态,重新让玩家骑上生物 - if (wasRiding && ridingEntity.isAlive()) { + // 如果之前在骑乘生物状态,重新让玩家骑上生物 + if (wasRiding && isRidingLivingEntity && ridingEntity.isAlive()) { // 确保骑乘生物在同一个世界且位置正确后,让玩家重新骑上 executor.startRiding(ridingEntity, true); } // 发送成功消息 - if (wasRiding && ridingEntity != null && ridingEntity.isAlive()) { + if (wasRiding && isRidingLivingEntity && ridingEntity != null && ridingEntity.isAlive()) { source.sendSuccess(() -> translatableWithFallback("commands.onlytp.success_with_mount", targetPlayer.getGameProfile().getName()), true); } else { source.sendSuccess(() -> translatableWithFallback("commands.onlytp.success", targetPlayer.getGameProfile().getName()), true); From 957840bd5fad85a8951ca334ad84a234ebfe58c5 Mon Sep 17 00:00:00 2001 From: icceey Date: Sun, 20 Jul 2025 11:55:44 +0800 Subject: [PATCH 4/4] fix build issue --- .../onlytp/command/TeleportCommand.java | 30 ++++++++----------- .../resources/assets/onlytp/lang/en_us.json | 1 - .../resources/assets/onlytp/lang/ja_jp.json | 1 - .../resources/assets/onlytp/lang/lzh.json | 1 - .../resources/assets/onlytp/lang/zh_cn.json | 1 - .../resources/assets/onlytp/lang/zh_hk.json | 1 - .../resources/assets/onlytp/lang/zh_tw.json | 1 - 7 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/icceey/onlytp/command/TeleportCommand.java b/src/main/java/com/icceey/onlytp/command/TeleportCommand.java index 375090c..f9edb9e 100644 --- a/src/main/java/com/icceey/onlytp/command/TeleportCommand.java +++ b/src/main/java/com/icceey/onlytp/command/TeleportCommand.java @@ -17,8 +17,8 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.RelativeMovement; import java.util.stream.IntStream; @@ -77,9 +77,10 @@ private static int execute(CommandContext context) throws Co } // 检查玩家是否正在骑乘生物 - Entity ridingEntity = executor.getVehicle(); - boolean wasRiding = ridingEntity != null; - boolean isRidingLivingEntity = ridingEntity instanceof LivingEntity; + LivingEntity livingRidingEntity = null; + if (executor.getVehicle() instanceof LivingEntity ridingEntity) { + livingRidingEntity = ridingEntity; + } // 在原位置播放下界传送门音效 executor.level().playSound( @@ -105,29 +106,24 @@ private static int execute(CommandContext context) throws Co float targetXRot = targetPlayer.getXRot(); // 如果玩家在骑乘状态且骑乘的是生物,先处理骑乘生物的传送 - if (wasRiding && isRidingLivingEntity) { + if (livingRidingEntity != null && livingRidingEntity.isAlive()) { // 让玩家下马(但保持引用) executor.stopRiding(); - + // 传送骑乘生物到目标位置 - ridingEntity.teleportTo(targetLevel, targetX, targetY, targetZ, targetYRot, targetXRot); + livingRidingEntity.teleportTo(targetLevel, targetX, targetY, targetZ, RelativeMovement.ALL, targetYRot, targetXRot); } // 执行玩家传送 executor.teleportTo(targetLevel, targetX, targetY, targetZ, targetYRot, targetXRot); - // 如果之前在骑乘生物状态,重新让玩家骑上生物 - if (wasRiding && isRidingLivingEntity && ridingEntity.isAlive()) { + if (livingRidingEntity != null && livingRidingEntity.isAlive()) { // 确保骑乘生物在同一个世界且位置正确后,让玩家重新骑上 - executor.startRiding(ridingEntity, true); + executor.startRiding(livingRidingEntity, true); } // 发送成功消息 - if (wasRiding && isRidingLivingEntity && ridingEntity != null && ridingEntity.isAlive()) { - source.sendSuccess(() -> translatableWithFallback("commands.onlytp.success_with_mount", targetPlayer.getGameProfile().getName()), true); - } else { - source.sendSuccess(() -> translatableWithFallback("commands.onlytp.success", targetPlayer.getGameProfile().getName()), true); - } + source.sendSuccess(() -> translatableWithFallback("commands.onlytp.success", targetPlayer.getGameProfile().getName()), true); // 通知目标玩家有人传送到了他那里 targetPlayer.sendSystemMessage(translatableWithFallback("commands.onlytp.notify_target", executor.getGameProfile().getName())); @@ -153,8 +149,8 @@ private static int execute(CommandContext context) throws Co /** * 在玩家周围生成传送粒子效果 * - * @param player 作为粒子生成中心的玩家 - * @param level 要在其中生成粒子的世界 + * @param player 作为粒子生成中心的玩家 + * @param level 要在其中生成粒子的世界 * @param particleType 要生成的粒子类型 */ private static void spawnTeleportParticles(ServerPlayer player, ServerLevel level, ParticleOptions particleType) { diff --git a/src/main/resources/assets/onlytp/lang/en_us.json b/src/main/resources/assets/onlytp/lang/en_us.json index 6d0d48a..fad025f 100644 --- a/src/main/resources/assets/onlytp/lang/en_us.json +++ b/src/main/resources/assets/onlytp/lang/en_us.json @@ -4,7 +4,6 @@ "commands.onlytp.target_dead_offline": "Target player is dead or offline", "commands.onlytp.executor_dead_offline": "You are dead or offline, cannot teleport", "commands.onlytp.success": "Teleported to %s", - "commands.onlytp.success_with_mount": "Teleported to %s with your mount", "commands.onlytp.notify_target": "%s teleported to you" } diff --git a/src/main/resources/assets/onlytp/lang/ja_jp.json b/src/main/resources/assets/onlytp/lang/ja_jp.json index 9b86b6d..de67203 100644 --- a/src/main/resources/assets/onlytp/lang/ja_jp.json +++ b/src/main/resources/assets/onlytp/lang/ja_jp.json @@ -4,7 +4,6 @@ "commands.onlytp.target_dead_offline": "対象プレイヤーが死亡またはオフラインです", "commands.onlytp.executor_dead_offline": "あなたは死亡またはオフラインのため、瞬間移動できません", "commands.onlytp.success": "%s にテレポートしました", - "commands.onlytp.success_with_mount": "乗り物と一緒に %s にテレポートしました", "commands.onlytp.notify_target": "%s があなたのところにテレポートしました" } diff --git a/src/main/resources/assets/onlytp/lang/lzh.json b/src/main/resources/assets/onlytp/lang/lzh.json index 0ef1ebf..20b35ed 100644 --- a/src/main/resources/assets/onlytp/lang/lzh.json +++ b/src/main/resources/assets/onlytp/lang/lzh.json @@ -4,6 +4,5 @@ "commands.onlytp.target_dead_offline": "彼身已殁,或形未現", "commands.onlytp.executor_dead_offline": "子身已殁,焉能徙形", "commands.onlytp.success": "已現 %s 之側", - "commands.onlytp.success_with_mount": "攜座騎而現 %s 之側", "commands.onlytp.notify_target": "%s 已臨君側" } \ No newline at end of file diff --git a/src/main/resources/assets/onlytp/lang/zh_cn.json b/src/main/resources/assets/onlytp/lang/zh_cn.json index 4ba66e5..4850621 100644 --- a/src/main/resources/assets/onlytp/lang/zh_cn.json +++ b/src/main/resources/assets/onlytp/lang/zh_cn.json @@ -4,7 +4,6 @@ "commands.onlytp.target_dead_offline": "目标玩家已死亡或已离线", "commands.onlytp.executor_dead_offline": "你已死亡或已离线,无法传送", "commands.onlytp.success": "已传送到 %s", - "commands.onlytp.success_with_mount": "已与坐骑一同传送到 %s", "commands.onlytp.notify_target": "%s 传送到了你这里" } diff --git a/src/main/resources/assets/onlytp/lang/zh_hk.json b/src/main/resources/assets/onlytp/lang/zh_hk.json index 1f7568c..dac38e7 100644 --- a/src/main/resources/assets/onlytp/lang/zh_hk.json +++ b/src/main/resources/assets/onlytp/lang/zh_hk.json @@ -4,7 +4,6 @@ "commands.onlytp.target_dead_offline": "目標玩家已死亡或已離線", "commands.onlytp.executor_dead_offline": "你已死亡或已離線,無法傳送", "commands.onlytp.success": "已傳送到 %s", - "commands.onlytp.success_with_mount": "已與坐騎一同傳送到 %s", "commands.onlytp.notify_target": "%s 傳送到了你這裏" } diff --git a/src/main/resources/assets/onlytp/lang/zh_tw.json b/src/main/resources/assets/onlytp/lang/zh_tw.json index b718910..d2be29d 100644 --- a/src/main/resources/assets/onlytp/lang/zh_tw.json +++ b/src/main/resources/assets/onlytp/lang/zh_tw.json @@ -4,7 +4,6 @@ "commands.onlytp.target_dead_offline": "目標玩家已死亡或已離線", "commands.onlytp.executor_dead_offline": "你已死亡或已離線,無法傳送", "commands.onlytp.success": "已傳送到 %s", - "commands.onlytp.success_with_mount": "已與坐騎一同傳送到 %s", "commands.onlytp.notify_target": "%s 傳送到了你這裡" }