mirror of
				https://github.com/TheWhiteDog9487/RandomTeleporter.git
				synced 2025-10-28 19:21:06 +08:00 
			
		
		
		
	Compare commits
	
		
			10 Commits
		
	
	
		
			1.21.3
			...
			d47907cdf4
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d47907cdf4 | |||
| 8c55311f27 | |||
| 35ac4dd842 | |||
| 34ea09dfd9 | |||
| ad014a2b1b | |||
| 4de867d6aa | |||
| 9770b72448 | |||
| 66a1529132 | |||
| 96a69f3262 | |||
| da6802f605 | 
							
								
								
									
										9
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| # | ||||
| # https://help.github.com/articles/dealing-with-line-endings/ | ||||
| # | ||||
| # Linux start script should use lf | ||||
| /gradlew        text eol=lf | ||||
|  | ||||
| # These are Windows script files and should use crlf | ||||
| *.bat           text eol=crlf | ||||
|  | ||||
							
								
								
									
										37
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| # Automatically build the project and run any configured tests for every push | ||||
| # and submitted pull request. This can help catch issues that only occur on | ||||
| # certain platforms or Java versions, and provides a first line of defence | ||||
| # against bad commits. | ||||
|  | ||||
| name: build | ||||
| on: [pull_request, push] | ||||
|  | ||||
| jobs: | ||||
|   build: | ||||
|     strategy: | ||||
|       matrix: | ||||
|         # Use these Java versions | ||||
|         java: [ | ||||
|           21,    # Current Java LTS | ||||
|         ] | ||||
|     runs-on: ubuntu-22.04 | ||||
|     steps: | ||||
|       - name: checkout repository | ||||
|         uses: actions/checkout@v4 | ||||
|       - name: validate gradle wrapper | ||||
|         uses: gradle/wrapper-validation-action@v2 | ||||
|       - name: setup jdk ${{ matrix.java }} | ||||
|         uses: actions/setup-java@v4 | ||||
|         with: | ||||
|           java-version: ${{ matrix.java }} | ||||
|           distribution: 'microsoft' | ||||
|       - name: make gradle wrapper executable | ||||
|         run: chmod +x ./gradlew | ||||
|       - name: build | ||||
|         run: ./gradlew build | ||||
|       - name: capture build artifacts | ||||
|         if: ${{ matrix.java == '21' }} # Only upload artifacts built from latest java | ||||
|         uses: actions/upload-artifact@v4 | ||||
|         with: | ||||
|           name: Artifacts | ||||
|           path: build/libs/ | ||||
| @@ -71,9 +71,8 @@ | ||||
|     1. 服务器需要安装 | ||||
|     2. 客户端不需要 | ||||
|  | ||||
| **注意:情况2和3,虽然其他玩家不需要安装本模组就能使用功能。但是由于命令执行后的反馈结果文字使用了翻译,如果其他玩家没有安装模组会导致显示不正常,玩家会直接看到翻译键而不是对应的文字。   | ||||
| 因此,虽然可以但不建议其他人不安装。   | ||||
| 能安装的话还是都装一下吧。**   | ||||
| **注意:情况2和3,如果其他玩家不安装本模组,他们看到的命令执行反馈就无法正确使用翻译,而在这种情况下默认显示中文文本。   | ||||
| 如果有查看多语言翻译文本的需求 ,那建议还是都装一下吧。**   | ||||
|  | ||||
| # 一些小彩蛋 | ||||
| 你可以使用 /随机传送 来替代 /rtp   | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| plugins { | ||||
|     id("fabric-loom") version "1.8-SNAPSHOT" | ||||
|     id("fabric-loom") version "1.11-SNAPSHOT" | ||||
|     id("maven-publish") | ||||
| } | ||||
|  | ||||
| version = "${project.extra["mod_version"]}" | ||||
| version = project.extra["mod_version"] as String | ||||
| group = project.extra["maven_group"] as String | ||||
|  | ||||
| base { | ||||
|   | ||||
| @@ -4,24 +4,18 @@ org.gradle.parallel=true | ||||
|  | ||||
| # Fabric Properties | ||||
| # check these on https://fabricmc.net/develop | ||||
| minecraft_version=1.21.3 | ||||
| yarn_mappings=1.21.3+build.2 | ||||
| loader_version=0.16.7 | ||||
| minecraft_version=1.21.8 | ||||
| yarn_mappings=1.21.8+build.1 | ||||
| loader_version=0.16.14 | ||||
|  | ||||
| # Mod Properties | ||||
| mod_version=0.3.4 | ||||
| mod_version=0.3.6 | ||||
| maven_group=xyz.thewhitedog9487 | ||||
| archives_base_name=RandomTeleporter | ||||
|  | ||||
| # Dependencies | ||||
| fabric_version=0.106.1+1.21.3 | ||||
| fabric_version=0.129.0+1.21.8 | ||||
|  | ||||
| # https://modrinth.com/mod/modmenu/versions | ||||
| # https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu | ||||
| modmenu_version=12.0.0-beta.1 | ||||
|  | ||||
| # loom_libraries_base=https://bmclapi2.bangbang93.com/maven/ | ||||
| # loom_resources_base=https://bmclapi2.bangbang93.com/assets/ | ||||
| # loom_version_manifests=https://bmclapi2.bangbang93.com/mc/game/version_manifest.json | ||||
| # loom_experimental_versions=https://maven.fabricmc.net/net/minecraft/experimental_versions.json | ||||
| # loom_fabric_repository=https://repository.hanbings.io/proxy/ | ||||
| modmenu_version=15.0.0-beta.3 | ||||
							
								
								
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| distributionBase=GRADLE_USER_HOME | ||||
| distributionPath=wrapper/dists | ||||
| distributionUrl=https://services.gradle.org/distributions/gradle-8.10-bin.zip | ||||
| distributionUrl=https://services.gradle.org/distributions/gradle-8.14-bin.zip | ||||
| networkTimeout=10000 | ||||
| validateDistributionUrl=true | ||||
| zipStoreBase=GRADLE_USER_HOME | ||||
|   | ||||
| @@ -19,11 +19,30 @@ import static net.minecraft.server.command.CommandManager.argument; | ||||
| import static net.minecraft.server.command.CommandManager.literal; | ||||
|  | ||||
| public class CommandRegister { | ||||
|  | ||||
|     /** | ||||
|      * 世界边界 | ||||
|      * <br> | ||||
|      * @see <a href="https://zh.minecraft.wiki/w/%E4%B8%96%E7%95%8C%E8%BE%B9%E7%95%8C#%E5%A4%A7%E5%B0%8F">Minecraft Wiki (中文)</a> | ||||
|      * @see <a href="https://minecraft.wiki/w/World_border#General_information">Minecraft Wiki (English)</a> | ||||
|      */ | ||||
|     final static Integer WorldBorder = (int) 2.9e7; | ||||
|     // ↑ | ||||
|     // https://zh.minecraft.wiki/w/%E4%B8%96%E7%95%8C%E8%BE%B9%E7%95%8C#%E5%A4%A7%E5%B0%8F | ||||
|     // https://minecraft.wiki/w/World_border#General_information | ||||
|  | ||||
|     /** | ||||
|      * 执行命令所需权限等级 | ||||
|      * @see net.minecraft.server.command.TeleportCommand | ||||
|      */ | ||||
|     final static byte PermissionLevel = 2; | ||||
|  | ||||
|     /** | ||||
|      * 使用Fabric API向游戏内注册命令 | ||||
|      * @param Name 根命令名 | ||||
|      * <br> | ||||
|      * @see <a href="https://docs.fabricmc.net/zh_cn/develop/commands/basics">Fabric Wiki (新样式,中文)</a> | ||||
|      * @see <a href="https://wiki.fabricmc.net/zh_cn:tutorial:commands">Fabric Wiki (旧样式,中文)</a> | ||||
|      * @see <a href="https://docs.fabricmc.net/develop/commands/basics">Fabric Wiki (New style,English)</a> | ||||
|      * @see <a href="https://wiki.fabricmc.net/tutorial:commands">Fabric Wiki (Old style,English)</a> | ||||
|      */ | ||||
|     public static void Register(String Name){ | ||||
|         // /rtp | ||||
|         CommandRegistrationCallback.EVENT | ||||
| @@ -95,6 +114,7 @@ public class CommandRegister { | ||||
| //                                                LongArgumentType.getLong(context, "Radius(半径)"), | ||||
| //                                                null, | ||||
| //                                                EntityArgumentType.getEntity(context,"Origin(随机中心)"))))));}); | ||||
|  | ||||
|         // /rtp <Radius(半径)> <OriginPos(随机中心,坐标)> | ||||
|         CommandRegistrationCallback.EVENT | ||||
|                 .register((dispatcher, registryAccess, environment) -> { | ||||
| @@ -121,7 +141,7 @@ public class CommandRegister { | ||||
|                                                             IntegerArgumentType.getInteger(context, "Radius(半径)"), | ||||
|                                                             EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), | ||||
|                                                             new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x, | ||||
|                                                                     (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().y )))))));}); | ||||
|                                                                     (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().z )))))));}); | ||||
|  | ||||
|         // /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)> | ||||
|         CommandRegistrationCallback.EVENT | ||||
| @@ -150,7 +170,7 @@ public class CommandRegister { | ||||
|                                                             IntegerArgumentType.getInteger(context, "Radius(半径)"), | ||||
|                                                             EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), | ||||
|                                                             new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x, | ||||
|                                                                     (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().y )))))));}); | ||||
|                                                                     (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().z )))))));}); | ||||
|  | ||||
|         // /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)> | ||||
|         CommandRegistrationCallback.EVENT | ||||
| @@ -166,25 +186,62 @@ public class CommandRegister { | ||||
|                                                             EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), | ||||
|                                                             Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});} | ||||
|  | ||||
|     /** | ||||
|      * 向游戏内注册命令 | ||||
|      * <br> | ||||
|      * 是 {@link CommandRegister#Register(String)} 的包装器 | ||||
|      * @see CommandRegister#Register(String) | ||||
|      */ | ||||
|     public static void Register(){ | ||||
|         Register("随机传送"); | ||||
|         Register("rtp");} | ||||
|         Register("rtp"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @param Source 命令执行者 | ||||
|      * @param Radius 随机选择的目的坐标距离参数 {@code Origin} 的最大距离 | ||||
|      * @param Player 被传送的玩家 | ||||
|      * @param Origin 随机选择的目的坐标的中心 | ||||
|      * @return 命令运行是否成功 | ||||
|      */ | ||||
|     static int execute_command(ServerCommandSource Source, @Nullable Integer Radius, @Nullable Entity Player, @Nullable Vec2f Origin){ | ||||
|         Entity entity = Player == null ? Source.getPlayer() : Player; | ||||
|         /* | ||||
|             ↑ | ||||
|             Entity entity = null; | ||||
|             if (Player == null){ | ||||
|                 entity = Source.getPlayer();} | ||||
|             else{ | ||||
|                 entity = Player;} | ||||
|          */ | ||||
|         if (entity == null) { | ||||
|             Source.sendFeedback(()->{ return  Text.translatable("error.not_player"); }, true); | ||||
|             Source.sendFeedback(()->{ return  Text.translatableWithFallback("error.no_target","不存在被传送目标,由非玩家物体执行命令时请显式指定被传送玩家ID"); }, true); | ||||
|             return -1;} | ||||
|         if (Radius == null){Radius = (int) (WorldBorder - 1e4);} | ||||
|         // ↑ 远离世界边界 | ||||
|         Radius = Math.abs(Radius); | ||||
|         int Coordinate_X; | ||||
|         int Coordinate_Z; | ||||
|         if (Origin == null){ | ||||
|             Coordinate_X = new SplittableRandom().nextInt(-Radius, Radius); | ||||
|             Coordinate_Z = new SplittableRandom().nextInt(-Radius, Radius);} | ||||
|         else{ | ||||
|             Coordinate_X = new SplittableRandom().nextInt((int) Origin.x - Radius, (int) Origin.x + Radius); | ||||
|             Coordinate_Z = new SplittableRandom().nextInt((int) Origin.y - Radius, (int) Origin.y + Radius);} | ||||
|         int Coordinate_X = 0; | ||||
|         int Coordinate_Z = 0; | ||||
|         try { | ||||
|             if (Origin == null){ | ||||
|                 Coordinate_X = new SplittableRandom().nextInt(-Radius, Radius); | ||||
|                 Coordinate_Z = new SplittableRandom().nextInt(-Radius, Radius);} | ||||
|             else{ | ||||
|                 Coordinate_X = new SplittableRandom().nextInt((int) Origin.x - Radius, (int) Origin.x + Radius); | ||||
|                 Coordinate_Z = new SplittableRandom().nextInt((int) Origin.y - Radius, (int) Origin.y + Radius);}} | ||||
|         catch (IllegalArgumentException e) { | ||||
|             // 半径为零 | ||||
|             if (Origin == null) { | ||||
|                 Source.sendFeedback(()->{ return Text.translatableWithFallback("warning.radius_equal_zero_no_target", "由于你设置的随机半径为0,并且未设置随机中心点坐标,因此什么都不会发生"); },true); | ||||
|                 return -1;} | ||||
|             else { | ||||
|                 Coordinate_X = (int) Origin.x; | ||||
|                 Coordinate_Z = (int) Origin.y; | ||||
|                 int finalCoordinate_X1 = Coordinate_X; | ||||
|                 int finalCoordinate_Z1 = Coordinate_Z; | ||||
|                 // ↑ "lambda 表达式中使用的变量应为 final 或有效 final" | ||||
|                 Source.sendFeedback(()->{ return Text.translatableWithFallback("warning.radius_equal_zero", "警告:由于你设置的随机半径为0,因此在选择出合适高度之后将直接把你传送至%d %d", finalCoordinate_X1, finalCoordinate_Z1); },true);}} | ||||
|         int Coordinate_Y = 320; | ||||
|         for (var CurrentBlock = Source.getWorld().getBlockState(new BlockPos(Coordinate_X, Coordinate_Y, Coordinate_Z)).getBlock(); | ||||
|              // 从世界顶层往下找,直到遇到一个非空气方块 | ||||
| @@ -210,7 +267,11 @@ public class CommandRegister { | ||||
|         Coordinate_Y++; | ||||
|         // ↑ 高一层,人别站在土里了 | ||||
|         entity.teleport(Source.getWorld(),Coordinate_X + 0.5, Coordinate_Y, Coordinate_Z + 0.5, new HashSet<>(), entity.getYaw(), entity.getPitch(), false); | ||||
|         int finalCoordinate_X = Coordinate_X; | ||||
|         int finalCoordinate_Y = Coordinate_Y; | ||||
|         Source.sendFeedback(()->{ return  Text.translatable("info.success", entity.getName(), Coordinate_X, finalCoordinate_Y, Coordinate_Z); },true); | ||||
|         return 0;} | ||||
|         int finalCoordinate_Z = Coordinate_Z; | ||||
|         // ↑ "lambda 表达式中使用的变量应为 final 或有效 final" | ||||
|         final var FeedbackFallbackString = String.format("已将玩家%s传送到%d %d %d", entity.getName().getString(), Coordinate_X, finalCoordinate_Y, Coordinate_Z); | ||||
|         Source.sendFeedback(()->{ return  Text.translatableWithFallback("info.success", FeedbackFallbackString, entity.getName(), finalCoordinate_X, finalCoordinate_Y, finalCoordinate_Z); },true); | ||||
|         return 16;} | ||||
| } | ||||
| @@ -16,7 +16,10 @@ public class RandomTeleporter implements ModInitializer { | ||||
| 		// This code runs as soon as Minecraft is in a mod-load-ready state. | ||||
| 		// However, some things (like resources) may still be uninitialized. | ||||
| 		// Proceed with mild caution. | ||||
| 		CommandRegister.Register(); | ||||
| 		LOGGER.info("RandomTeleporter Loading!"); | ||||
|  | ||||
| 		CommandRegister.Register(); | ||||
|  | ||||
| 		LOGGER.info("RandomTeleporter Loaded!"); | ||||
| 	} | ||||
| } | ||||
| @@ -1,6 +1,9 @@ | ||||
| { | ||||
|   "modmenu.nameTranslation.randomteleporter": "RandomTeleporter", | ||||
|   "modmenu.descriptionTranslation.randomteleporter": "Added two commands for random teleportation", | ||||
|   "bilibili": "Bilibili", | ||||
|   "blog": "Blog" | ||||
|   "info.success": "Teleported %s to %d %d %d", | ||||
|   "error.no_target": "There is no teleported target, and the teleported player ID is explicitly specified when executed by a non-player object", | ||||
|   "warning.radius_equal_zero": "Warning: Since you set a random radius of 0, selecting the right height will teleport you directly to %d %d", | ||||
|   "warning.radius_equal_zero_no_target": "Warning: Since you set a random radius of 0 and you don't set a random center point coordinates, nothing happens", | ||||
|   "bilibili": "Bilibili" | ||||
| } | ||||
| @@ -2,7 +2,8 @@ | ||||
|   "modmenu.nameTranslation.randomteleporter": "随机传送", | ||||
|   "modmenu.descriptionTranslation.randomteleporter": "增加了两个用于随机传送的命令", | ||||
|   "info.success": "已将玩家%s传送到%d %d %d", | ||||
|   "error.not_player": "执行命令的不是玩家", | ||||
|   "bilibili": "TheWhiteDog9487的哔哩哔哩主页", | ||||
|   "blog": "TheWhiteDog9487的博客" | ||||
|   "error.no_target": "不存在被传送目标,由非玩家物体执行命令时请显式指定被传送玩家ID", | ||||
|   "warning.radius_equal_zero": "警告:由于你设置的随机半径为0,因此在选择出合适高度之后将直接把你传送至%d %d", | ||||
|   "warning.radius_equal_zero_no_target": "警告:由于你设置的随机半径为0,并且未设置随机中心点坐标,因此什么都不会发生", | ||||
|   "bilibili": "TheWhiteDog9487的哔哩哔哩主页" | ||||
| } | ||||
| @@ -27,10 +27,10 @@ | ||||
| 		} | ||||
| 	], | ||||
| 	"depends": { | ||||
| 		"fabricloader": ">=0.16.7", | ||||
| 		"minecraft": "1.21.3", | ||||
| 		"fabricloader": ">=0.16.14", | ||||
| 		"minecraft": "1.21.8", | ||||
| 		"java": ">=21", | ||||
| 		"fabric-api": "*" | ||||
| 		"fabric-api": ">=0.129.0" | ||||
| 	}, | ||||
| 	"suggests": { | ||||
| 		"another-mod": "*" | ||||
| @@ -38,7 +38,6 @@ | ||||
| 	"custom": { | ||||
| 		"modmenu": { | ||||
| 			"links": { | ||||
| 				"bilibili": "https://space.bilibili.com/401746666", | ||||
| 				"blog": "www.thewhitedog9487.xyz"}, | ||||
| 				"bilibili": "https://space.bilibili.com/401746666"}, | ||||
| 			"update_checker": true}} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user