mirror of
				https://github.com/TheWhiteDog9487/RandomTeleporter.git
				synced 2025-11-05 00:05:03 +08:00 
			
		
		
		
	0.2.2
例行更新Fabric API的版本。 用Krita给模组画了个图标。 然后为了发版本更新不只是更新图标,所以继续完善了功能,增加了一大堆新命令格式。 我确实就是为了这碟醋而包了这盘饺子。
This commit is contained in:
		
							
								
								
									
										27
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								README.md
									
									
									
									
									
								
							@@ -7,6 +7,11 @@
 | 
			
		||||
- /rtp <被传送玩家名(PlayerID)>
 | 
			
		||||
- /rtp <Radius(半径)> <被传送玩家名(PlayerID)>
 | 
			
		||||
- /rtp <被传送玩家名(PlayerID)> <Radius(半径)>
 | 
			
		||||
- /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
 | 
			
		||||
- /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginEntity(随机中心,实体)>
 | 
			
		||||
- /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
 | 
			
		||||
- /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginEntity(随机中心,实体)>
 | 
			
		||||
- /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)>
 | 
			
		||||
 | 
			
		||||
## 命令示例
 | 
			
		||||
- /rtp  
 | 
			
		||||
@@ -25,6 +30,28 @@
 | 
			
		||||
- /rtp 1000 TheWhiteDog9487  
 | 
			
		||||
将TheWhiteDog9487随机传送到以(0,0)为中心点,1000作为随机半径的范围内的随机一点  
 | 
			
		||||
 | 
			
		||||
- /rtp 1000 10000 ~ 10000  
 | 
			
		||||
将执行命令的玩家随机传送到以(10000,10000)为中心点,1000作为随机半径的范围内的随机一点  
 | 
			
		||||
提示:按照道理来说中心坐标是不需要高度(Y轴)的,但由于坐标的类型是Vec3d,所以还是要写高度的。  
 | 
			
		||||
至于高度的具体数值,随便写,代码里也没用到过。  
 | 
			
		||||
 | 
			
		||||
- /rtp 1000 TheWhiteDog9487 TheWhiteDog_CN  
 | 
			
		||||
将TheWhiteDog9487随机传送到以TheWhiteDog_CN所在位置为中心点,1000作为随机半径的范围内的随机一点  
 | 
			
		||||
 | 
			
		||||
- /rtp 1000 TheWhiteDog9487 10000 ~ 10000  
 | 
			
		||||
将TheWhiteDog9487随机传送到以(10000,10000)为中心点,1000作为随机半径的范围内的随机一点  
 | 
			
		||||
 | 
			
		||||
- /rtp TheWhiteDog9487 1000 TheWhiteDog_CN  
 | 
			
		||||
将TheWhiteDog9487随机传送到以TheWhiteDog_CN所在位置为中心点,1000作为随机半径的范围内的随机一点  
 | 
			
		||||
 | 
			
		||||
- /rtp TheWhiteDog9487 1000 10000 ~ 10000  
 | 
			
		||||
将TheWhiteDog9487随机传送到以(10000,10000)为中心点,1000作为随机半径的范围内的随机一点  
 | 
			
		||||
 | 
			
		||||
### 特别提示
 | 
			
		||||
/rtp <Radius(半径)> <Origin(随机中心,实体)> 这种格式不存在。  
 | 
			
		||||
因为第二个参数可能是被传送玩家名,也可能是做随机中心点的实体。  
 | 
			
		||||
这两种都是实体类型,无法区分到底是哪一种,存在歧义。  
 | 
			
		||||
 | 
			
		||||
# 依赖项
 | 
			
		||||
由于我使用了fabric.api.command.v2中的CommandRegistrationCallback.EVENT来向游戏注册命令,所以这个模组需要依赖Fabric API
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,12 +9,12 @@ yarn_mappings=1.20.4+build.3
 | 
			
		||||
loader_version=0.15.6
 | 
			
		||||
 | 
			
		||||
# Mod Properties
 | 
			
		||||
mod_version=0.2.1
 | 
			
		||||
mod_version=0.2.2
 | 
			
		||||
maven_group=xyz.thewhitedog9487
 | 
			
		||||
archives_base_name=randomteleporter
 | 
			
		||||
 | 
			
		||||
# Dependencies
 | 
			
		||||
fabric_version=0.95.0+1.20.4
 | 
			
		||||
fabric_version=0.95.4+1.20.4
 | 
			
		||||
 | 
			
		||||
loom_libraries_base=https://bmclapi2.bangbang93.com/maven/
 | 
			
		||||
loom_resources_base=https://bmclapi2.bangbang93.com/assets/
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,8 @@ import com.mojang.brigadier.arguments.LongArgumentType;
 | 
			
		||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
 | 
			
		||||
import net.minecraft.block.Blocks;
 | 
			
		||||
import net.minecraft.command.argument.EntityArgumentType;
 | 
			
		||||
import net.minecraft.command.argument.Vec3ArgumentType;
 | 
			
		||||
import net.minecraft.entity.Entity;
 | 
			
		||||
import net.minecraft.server.command.ServerCommandSource;
 | 
			
		||||
import net.minecraft.server.network.ServerPlayerEntity;
 | 
			
		||||
import net.minecraft.text.Text;
 | 
			
		||||
@@ -21,62 +23,162 @@ public class CommandRegister {
 | 
			
		||||
    final static long WorldBorder = (long) 2.9e7;
 | 
			
		||||
    static byte Retry = 0;
 | 
			
		||||
    public static void Register(String Name){
 | 
			
		||||
        // /rtp
 | 
			
		||||
        CommandRegistrationCallback.EVENT
 | 
			
		||||
                .register((dispatcher, registryAccess, environment) ->{
 | 
			
		||||
                    dispatcher.register(literal(Name)
 | 
			
		||||
                            .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
                            .executes(context -> execute_command_radius(
 | 
			
		||||
                                    context.getSource(),null,null)));});
 | 
			
		||||
                            .executes(context -> execute_command(
 | 
			
		||||
                                    context.getSource(),null,null, null)));});
 | 
			
		||||
 | 
			
		||||
        // /rtp <Radius(半径)>
 | 
			
		||||
        CommandRegistrationCallback.EVENT
 | 
			
		||||
                .register((dispatcher, registryAccess, environment) -> {
 | 
			
		||||
                    dispatcher.register(literal(Name)
 | 
			
		||||
                            .then(argument("Radius(半径)", LongArgumentType.longArg())
 | 
			
		||||
                                    .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
                                    .executes(context -> execute_command_radius(
 | 
			
		||||
                                    .executes(context -> execute_command(
 | 
			
		||||
                                            context.getSource(),
 | 
			
		||||
                                            LongArgumentType.getLong(context, "Radius(半径)"),
 | 
			
		||||
                                            null,
 | 
			
		||||
                                            null))));});
 | 
			
		||||
 | 
			
		||||
        // /rtp <被传送玩家名(PlayerID)>
 | 
			
		||||
        CommandRegistrationCallback.EVENT
 | 
			
		||||
                .register((dispatcher, registryAccess, environment) -> {
 | 
			
		||||
                    dispatcher.register(literal(Name)
 | 
			
		||||
                            .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.player())
 | 
			
		||||
                            .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
 | 
			
		||||
                                    .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
                                    .executes(context -> execute_command_player(
 | 
			
		||||
                                    .executes(context -> execute_command(
 | 
			
		||||
                                            context.getSource(),
 | 
			
		||||
                                            null,
 | 
			
		||||
                                            EntityArgumentType.getPlayer(context,"被传送玩家名(PlayerID)")))));});
 | 
			
		||||
                                            EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
 | 
			
		||||
                                            null))));});
 | 
			
		||||
 | 
			
		||||
        // /rtp <Radius(半径)> <被传送玩家名(PlayerID)>
 | 
			
		||||
        CommandRegistrationCallback.EVENT
 | 
			
		||||
                .register((dispatcher, registryAccess, environment) -> {
 | 
			
		||||
                    dispatcher.register(literal(Name)
 | 
			
		||||
                            .then(argument("Radius(半径)", LongArgumentType.longArg())
 | 
			
		||||
                                    .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.player())
 | 
			
		||||
                                    .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
 | 
			
		||||
                                            .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
                                            .executes(context -> execute_command_player(
 | 
			
		||||
                                            .executes(context -> execute_command(
 | 
			
		||||
                                                    context.getSource(),
 | 
			
		||||
                                                    LongArgumentType.getLong(context, "Radius(半径)"),
 | 
			
		||||
                                                    EntityArgumentType.getPlayer(context,"被传送玩家名(PlayerID)"))))));});
 | 
			
		||||
                                                    EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
 | 
			
		||||
                                                    null)))));});
 | 
			
		||||
 | 
			
		||||
        // /rtp <被传送玩家名(PlayerID)> <Radius(半径)>
 | 
			
		||||
        CommandRegistrationCallback.EVENT
 | 
			
		||||
                .register((dispatcher, registryAccess, environment) -> {
 | 
			
		||||
                    dispatcher.register(literal(Name)
 | 
			
		||||
                            .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.player())
 | 
			
		||||
                            .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
 | 
			
		||||
                                .then(argument("Radius(半径)", LongArgumentType.longArg())
 | 
			
		||||
                                            .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
                                            .executes(context -> execute_command_player(
 | 
			
		||||
                                            .executes(context -> execute_command(
 | 
			
		||||
                                                    context.getSource(),
 | 
			
		||||
                                                    LongArgumentType.getLong(context, "Radius(半径)"),
 | 
			
		||||
                                                    EntityArgumentType.getPlayer(context,"被传送玩家名(PlayerID)"))))));});}
 | 
			
		||||
                                                    EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
 | 
			
		||||
                                                    null)))));});
 | 
			
		||||
 | 
			
		||||
//        // /rtp <Radius(半径)> <Origin(随机中心)>
 | 
			
		||||
//        CommandRegistrationCallback.EVENT
 | 
			
		||||
//                .register((dispatcher, registryAccess, environment) -> {
 | 
			
		||||
//                    dispatcher.register(literal(Name)
 | 
			
		||||
//                            .then(argument("Radius(半径)", LongArgumentType.longArg())
 | 
			
		||||
//                                    .then(argument("Origin(随机中心)",EntityArgumentType.player())
 | 
			
		||||
//                                        .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
//                                        .executes(context -> execute_command_origin(
 | 
			
		||||
//                                                context.getSource(),
 | 
			
		||||
//                                                LongArgumentType.getLong(context, "Radius(半径)"),
 | 
			
		||||
//                                                null,
 | 
			
		||||
//                                                EntityArgumentType.getEntity(context,"Origin(随机中心)"))))));});
 | 
			
		||||
        // /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
 | 
			
		||||
        CommandRegistrationCallback.EVENT
 | 
			
		||||
                .register((dispatcher, registryAccess, environment) -> {
 | 
			
		||||
                    dispatcher.register(literal(Name)
 | 
			
		||||
                            .then(argument("Radius(半径)", LongArgumentType.longArg())
 | 
			
		||||
                                    .then(argument("OriginPos(随机中心,坐标)",Vec3ArgumentType.vec3())
 | 
			
		||||
                                            .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
                                            .executes(context -> execute_command(
 | 
			
		||||
                                                    context.getSource(),
 | 
			
		||||
                                                    LongArgumentType.getLong(context, "Radius(半径)"),
 | 
			
		||||
                                                    null,
 | 
			
		||||
                                                    Vec3ArgumentType.getVec3(context,"OriginPos(随机中心,坐标)"))))));});
 | 
			
		||||
 | 
			
		||||
        // /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginEntity(随机中心,实体)>
 | 
			
		||||
        CommandRegistrationCallback.EVENT
 | 
			
		||||
                .register((dispatcher, registryAccess, environment) -> {
 | 
			
		||||
                    dispatcher.register(literal(Name)
 | 
			
		||||
                            .then(argument("Radius(半径)", LongArgumentType.longArg())
 | 
			
		||||
                                    .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
 | 
			
		||||
                                            .then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity())
 | 
			
		||||
                                                    .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
                                                    .executes(context -> execute_command_origin(
 | 
			
		||||
                                                            context.getSource(),
 | 
			
		||||
                                                            LongArgumentType.getLong(context, "Radius(半径)"),
 | 
			
		||||
                                                            EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
 | 
			
		||||
                                                            EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)")))))));});
 | 
			
		||||
 | 
			
		||||
        // /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
 | 
			
		||||
        CommandRegistrationCallback.EVENT
 | 
			
		||||
                .register((dispatcher, registryAccess, environment) -> {
 | 
			
		||||
                    dispatcher.register(literal(Name)
 | 
			
		||||
                            .then(argument("Radius(半径)", LongArgumentType.longArg())
 | 
			
		||||
                                    .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
 | 
			
		||||
                                            .then(argument("OriginPos(随机中心,坐标)",Vec3ArgumentType.vec3())
 | 
			
		||||
                                                    .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
                                                    .executes(context -> execute_command(
 | 
			
		||||
                                                            context.getSource(),
 | 
			
		||||
                                                            LongArgumentType.getLong(context, "Radius(半径)"),
 | 
			
		||||
                                                            EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
 | 
			
		||||
                                                            Vec3ArgumentType.getVec3(context,"OriginPos(随机中心,坐标)")))))));});
 | 
			
		||||
 | 
			
		||||
        // /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginEntity(随机中心,实体)>
 | 
			
		||||
        CommandRegistrationCallback.EVENT
 | 
			
		||||
                .register((dispatcher, registryAccess, environment) -> {
 | 
			
		||||
                    dispatcher.register(literal(Name)
 | 
			
		||||
                            .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
 | 
			
		||||
                                    .then(argument("Radius(半径)", LongArgumentType.longArg())
 | 
			
		||||
                                            .then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity())
 | 
			
		||||
                                                    .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
                                                    .executes(context -> execute_command_origin(
 | 
			
		||||
                                                            context.getSource(),
 | 
			
		||||
                                                            LongArgumentType.getLong(context, "Radius(半径)"),
 | 
			
		||||
                                                            EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
 | 
			
		||||
                                                            EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)")))))));});
 | 
			
		||||
 | 
			
		||||
        // /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)>
 | 
			
		||||
        CommandRegistrationCallback.EVENT
 | 
			
		||||
                .register((dispatcher, registryAccess, environment) -> {
 | 
			
		||||
                    dispatcher.register(literal(Name)
 | 
			
		||||
                            .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
 | 
			
		||||
                                    .then(argument("Radius(半径)", LongArgumentType.longArg())
 | 
			
		||||
                                            .then(argument("OriginPos(随机中心,坐标)",Vec3ArgumentType.vec3())
 | 
			
		||||
                                                    .requires(source -> source.hasPermissionLevel(4))
 | 
			
		||||
                                                    .executes(context -> execute_command(
 | 
			
		||||
                                                            context.getSource(),
 | 
			
		||||
                                                            LongArgumentType.getLong(context, "Radius(半径)"),
 | 
			
		||||
                                                            EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
 | 
			
		||||
                                                            Vec3ArgumentType.getVec3(context,"OriginPos(随机中心,坐标)")))))));});}
 | 
			
		||||
    public static void Register(){
 | 
			
		||||
        Register("随机传送");
 | 
			
		||||
        Register("rtp");}
 | 
			
		||||
    static int execute_command_radius(ServerCommandSource Source, @Nullable Long Radius, @Nullable ServerPlayerEntity Player){
 | 
			
		||||
        ServerPlayerEntity player = Player == null ? Source.getPlayer() : Player;
 | 
			
		||||
        if (player == null) {
 | 
			
		||||
    static int execute_command(ServerCommandSource Source, @Nullable Long Radius, @Nullable Entity Player, @Nullable Vec3d Origin){
 | 
			
		||||
        Entity entity = Player == null ? Source.getPlayer() : Player;
 | 
			
		||||
        if (entity == null) {
 | 
			
		||||
            Source.sendFeedback(()->{ return  Text.translatable("error.twd.rtp.not_player"); }, true);
 | 
			
		||||
            return -1;}
 | 
			
		||||
        if (Radius == null){Radius = WorldBorder - (long) 1e4;}
 | 
			
		||||
        Radius = Math.abs(Radius);
 | 
			
		||||
        long Coordinate_X = new SplittableRandom().nextLong(-Radius, Radius);
 | 
			
		||||
        long Coordinate_Z = new SplittableRandom().nextLong(-Radius, Radius);
 | 
			
		||||
        long Coordinate_X;
 | 
			
		||||
        long Coordinate_Z;
 | 
			
		||||
        if (Origin == null){
 | 
			
		||||
            Coordinate_X = new SplittableRandom().nextLong(-Radius, Radius);
 | 
			
		||||
            Coordinate_Z = new SplittableRandom().nextLong(-Radius, Radius);}
 | 
			
		||||
        else{
 | 
			
		||||
            Coordinate_X = new SplittableRandom().nextLong(Math.round(Origin.getX() - Radius), Math.round(Origin.getX() + Radius));
 | 
			
		||||
            Coordinate_Z = new SplittableRandom().nextLong(Math.round(Origin.getZ() - Radius), Math.round(Origin.getZ() + Radius));}
 | 
			
		||||
        int Coordinate_Y = 320;
 | 
			
		||||
        for (;
 | 
			
		||||
             Blocks.AIR == Source.getWorld().getBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getBlock() ||
 | 
			
		||||
@@ -85,16 +187,16 @@ public class CommandRegister {
 | 
			
		||||
                ;Coordinate_Y--){}
 | 
			
		||||
        Coordinate_Y++;
 | 
			
		||||
        Vec3d Coordinate = new Vec3d(Coordinate_X, Coordinate_Y, Coordinate_Z);
 | 
			
		||||
        if (Radius == WorldBorder && Retry < 126 && Distance(player.getPos(), Coordinate) < 1e5){
 | 
			
		||||
        if (Radius == WorldBorder && Retry < 126 && Distance(entity.getPos(), Coordinate) < 1e5){
 | 
			
		||||
            Retry++;
 | 
			
		||||
            execute_command_radius(Source, Radius,null);
 | 
			
		||||
            execute_command(Source, Radius,null, Origin);
 | 
			
		||||
            return 0;}
 | 
			
		||||
        if (Retry >= 126){
 | 
			
		||||
            Source.sendFeedback(()->{ return  Text.translatable("warning.twd.rtp.retry"); }, true);}
 | 
			
		||||
        player.teleport(Source.getWorld(), Coordinate_X, Coordinate_Y, Coordinate_Z, 0, 0);
 | 
			
		||||
        entity.teleport(Coordinate_X, Coordinate_Y, Coordinate_Z);
 | 
			
		||||
        final int FinalCoordinate_Y = Coordinate_Y;
 | 
			
		||||
        Source.sendFeedback(()->{ return  Text.translatable("info.twd.rtp.success", player.getName(), Coordinate_X, FinalCoordinate_Y, Coordinate_Z); },true);
 | 
			
		||||
        Source.sendFeedback(()->{ return  Text.translatable("info.twd.rtp.success", entity.getName(), Coordinate_X, FinalCoordinate_Y, Coordinate_Z); },true);
 | 
			
		||||
        return 0;}
 | 
			
		||||
    static int execute_command_player(ServerCommandSource Source, Long Radius, ServerPlayerEntity Player){
 | 
			
		||||
        return execute_command_radius(Source, Radius, Player);}
 | 
			
		||||
    static int execute_command_origin(ServerCommandSource Source, @Nullable Long Radius, @Nullable Entity Player, Entity Origin){
 | 
			
		||||
        return execute_command(Source, Radius, Player, Origin.getPos());}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								src/main/resources/assets/randomteleporter/icon.kra
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/main/resources/assets/randomteleporter/icon.kra
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 453 B After Width: | Height: | Size: 11 KiB  | 
		Reference in New Issue
	
	Block a user