mirror of
https://github.com/TheWhiteDog9487/RandomTeleporter.git
synced 2025-10-15 16:05:04 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e7f9ac069a | ||
![]() |
eb85fff326 | ||
![]() |
48a5027cce | ||
![]() |
62c3484c5e |
@@ -4,9 +4,9 @@ org.gradle.parallel=true
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/develop
|
||||
minecraft_version=1.21.8
|
||||
yarn_mappings=1.21.8+build.1
|
||||
loader_version=0.16.14
|
||||
minecraft_version=1.21.9
|
||||
yarn_mappings=1.21.9+build.1
|
||||
loader_version=0.17.2
|
||||
|
||||
# Mod Properties
|
||||
mod_version=0.3.6
|
||||
@@ -14,8 +14,8 @@ maven_group=xyz.thewhitedog9487
|
||||
archives_base_name=RandomTeleporter
|
||||
|
||||
# Dependencies
|
||||
fabric_version=0.129.0+1.21.8
|
||||
fabric_version=0.133.14+1.21.9
|
||||
|
||||
# https://modrinth.com/mod/modmenu/versions
|
||||
# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu
|
||||
modmenu_version=15.0.0-beta.3
|
||||
modmenu_version=16.0.0-rc.1
|
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.14-bin.zip
|
||||
distributionUrl=https://services.gradle.org/distributions/gradle-9.1.0-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package xyz.thewhitedog9487;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.minecraft.block.Blocks;
|
||||
@@ -13,6 +14,7 @@ import net.minecraft.util.math.Vec2f;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.SplittableRandom;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
@@ -20,6 +22,32 @@ import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
public class CommandRegister {
|
||||
|
||||
/**
|
||||
* 随机数生成器
|
||||
*/
|
||||
final static SplittableRandom SR = new SplittableRandom();
|
||||
|
||||
/**
|
||||
* 传送后用于生成保护平台的方块
|
||||
*/
|
||||
final static Block TargetBlock = Blocks.GLASS;
|
||||
|
||||
/**
|
||||
* 传送后会被 {@link CommandRegister#TargetBlock} 替换掉的方块
|
||||
* <br>
|
||||
* 替换中心:被传送目标脚下方块
|
||||
* <br>
|
||||
* 替换范围:替换中心周围半径为一的正方形区域
|
||||
*/
|
||||
final static Set<Block> ReplaceToTargetBlock = Set.of(
|
||||
Blocks.AIR,
|
||||
Blocks.VOID_AIR,
|
||||
Blocks.CAVE_AIR,
|
||||
Blocks.WATER,
|
||||
Blocks.LAVA,
|
||||
Blocks.SHORT_GRASS,
|
||||
Blocks.VINE );
|
||||
|
||||
/**
|
||||
* 世界边界
|
||||
* <br>
|
||||
@@ -44,147 +72,107 @@ public class CommandRegister {
|
||||
* @see <a href="https://wiki.fabricmc.net/tutorial:commands">Fabric Wiki (Old style,English)</a>
|
||||
*/
|
||||
public static void Register(String Name){
|
||||
// /rtp
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) ->{
|
||||
dispatcher.register(literal(Name)
|
||||
// /rtp
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> execute_command(
|
||||
context.getSource(),null,null, null)));});
|
||||
|
||||
// /rtp <Radius(半径)>
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) -> {
|
||||
dispatcher.register(literal(Name)
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
||||
.executes(context -> ExecuteCommand(
|
||||
context.getSource(),null,null, null))
|
||||
// /rtp <Radius(半径)>
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer(0))
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> execute_command(
|
||||
.executes(context -> ExecuteCommand(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
null,
|
||||
null))));});
|
||||
|
||||
// /rtp <被传送玩家名(PlayerID)>
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) -> {
|
||||
dispatcher.register(literal(Name)
|
||||
null)))
|
||||
// /rtp <被传送玩家名(PlayerID)>
|
||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> execute_command(
|
||||
.executes(context -> ExecuteCommand(
|
||||
context.getSource(),
|
||||
null,
|
||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||
null))));});
|
||||
|
||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)>
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) -> {
|
||||
dispatcher.register(literal(Name)
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
||||
null)))
|
||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)>
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer(0))
|
||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> execute_command(
|
||||
.executes(context -> ExecuteCommand(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||
null)))));});
|
||||
|
||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)>
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) -> {
|
||||
dispatcher.register(literal(Name)
|
||||
null))))
|
||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)>
|
||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer(0))
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> execute_command(
|
||||
.executes(context -> ExecuteCommand(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
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(PermissionLevel))
|
||||
// .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(半径)", IntegerArgumentType.integer())
|
||||
null))))
|
||||
// // /rtp <Radius(半径)> <Origin(随机中心)>
|
||||
// .then(argument("Radius(半径)", LongArgumentType.longArg())
|
||||
// .then(argument("Origin(随机中心)",EntityArgumentType.player())
|
||||
// .requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
// .executes(context -> execute_command_origin(
|
||||
// context.getSource(),
|
||||
// LongArgumentType.getLong(context, "Radius(半径)"),
|
||||
// null,
|
||||
// EntityArgumentType.getEntity(context,"Origin(随机中心)")))))
|
||||
// /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer(0))
|
||||
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> execute_command(
|
||||
.executes(context -> ExecuteCommand(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
null,
|
||||
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)"))))));});
|
||||
|
||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginEntity(随机中心,实体)>
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) -> {
|
||||
dispatcher.register(literal(Name)
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
||||
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))
|
||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginEntity(随机中心,实体)>
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer(0))
|
||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||
.then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity())
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> execute_command(
|
||||
.executes(context -> ExecuteCommand(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||
new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x,
|
||||
(float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().z )))))));});
|
||||
|
||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) -> {
|
||||
dispatcher.register(literal(Name)
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> execute_command(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});
|
||||
|
||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) -> {
|
||||
dispatcher.register(literal(Name)
|
||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
||||
.then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity())
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> execute_command(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||
new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x,
|
||||
(float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().z )))))));});
|
||||
|
||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) -> {
|
||||
dispatcher.register(literal(Name)
|
||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
||||
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> execute_command(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});}
|
||||
new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getEntityPos().x,
|
||||
(float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getEntityPos().z ))))))
|
||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer(0))
|
||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> ExecuteCommand(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)"))))))
|
||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer(0))
|
||||
.then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity())
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> ExecuteCommand(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||
new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getEntityPos().x,
|
||||
(float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getEntityPos().z ))))))
|
||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||
.then(argument("Radius(半径)", IntegerArgumentType.integer(0))
|
||||
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||
.executes(context -> ExecuteCommand(
|
||||
context.getSource(),
|
||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))) );});}
|
||||
|
||||
/**
|
||||
* 向游戏内注册命令
|
||||
@@ -220,16 +208,15 @@ public class CommandRegister {
|
||||
return -1;}
|
||||
if (Radius == null){Radius = (int) (WorldBorder - 1e4);}
|
||||
// ↑ 远离世界边界
|
||||
Radius = Math.abs(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);}
|
||||
Coordinate_X = SR.nextInt(-Radius, Radius + 1);
|
||||
Coordinate_Z = SR.nextInt(-Radius, Radius + 1); }
|
||||
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);}}
|
||||
Coordinate_X = SR.nextInt((int) Origin.x - Radius, (int) Origin.x + Radius + 1);
|
||||
Coordinate_Z = SR.nextInt((int) Origin.y - Radius, (int) Origin.y + Radius + 1); } }
|
||||
catch (IllegalArgumentException e) {
|
||||
// 半径为零
|
||||
if (Origin == null) {
|
||||
@@ -263,6 +250,9 @@ public class CommandRegister {
|
||||
// 只替换空气、水和岩浆,其余保留
|
||||
Source.getWorld().setBlockState(BlockPos, Blocks.GLASS.getDefaultState());}}}
|
||||
// if ( String.valueOf(entity.getWorld().getBiome(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getKey()).equals("minecraft:the_void") ) {
|
||||
if ( ReplaceToTargetBlock.contains(CurrentBlock) ) {
|
||||
// 只替换ReplaceToTargetBlock内的方块,其余保留
|
||||
EntityWorld.setBlockState(BlockPos, TargetBlock.getDefaultState());}}}
|
||||
// Coordinate_Y++;}
|
||||
Coordinate_Y++;
|
||||
// ↑ 高一层,人别站在土里了
|
||||
@@ -271,7 +261,7 @@ public class CommandRegister {
|
||||
int finalCoordinate_Y = Coordinate_Y;
|
||||
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;}
|
||||
final var FeedbackFallbackString = String.format("已将玩家%s传送到%d %d %d", TargetEntity.getName().getString(), Coordinate_X, Coordinate_Y, Coordinate_Z);
|
||||
Source.sendFeedback(()->{ return Text.translatableWithFallback("info.success", FeedbackFallbackString, TargetEntity.getName(), finalCoordinate_X, Coordinate_Y, finalCoordinate_Z); },true);
|
||||
return Command.SINGLE_SUCCESS;}
|
||||
}
|
@@ -27,10 +27,10 @@
|
||||
}
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.16.14",
|
||||
"minecraft": "1.21.8",
|
||||
"fabricloader": ">=0.17.2",
|
||||
"minecraft": "1.21.9",
|
||||
"java": ">=21",
|
||||
"fabric-api": ">=0.129.0"
|
||||
"fabric-api": ">=0.133.14"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
|
Reference in New Issue
Block a user