mirror of
https://github.com/TheWhiteDog9487/RandomTeleporter.git
synced 2025-12-17 12:32:05 +08:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a903dda82e | ||
|
|
8f40dddc2a | ||
|
|
327dd5d168 | ||
|
|
dca7fa256e | ||
|
|
74046be828 | ||
|
|
33e01b3d35 | ||
|
|
e7f9ac069a | ||
|
|
eb85fff326 | ||
|
|
48a5027cce | ||
|
|
62c3484c5e | ||
| d47907cdf4 | |||
| 8c55311f27 | |||
| 35ac4dd842 | |||
| 34ea09dfd9 | |||
| ad014a2b1b |
@@ -1,9 +1,9 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("fabric-loom") version "1.10-SNAPSHOT"
|
id("fabric-loom") version "1.14-SNAPSHOT"
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
}
|
}
|
||||||
|
|
||||||
version = "${project.extra["mod_version"]}"
|
version = project.extra["mod_version"] as String
|
||||||
group = project.extra["maven_group"] as String
|
group = project.extra["maven_group"] as String
|
||||||
|
|
||||||
base {
|
base {
|
||||||
@@ -25,17 +25,16 @@ loom {
|
|||||||
splitEnvironmentSourceSets()
|
splitEnvironmentSourceSets()
|
||||||
|
|
||||||
mods {
|
mods {
|
||||||
create("randomteleporter") {
|
val mod = create("randomteleporter")
|
||||||
sourceSet(sourceSets["main"])
|
mod.sourceSet("main")
|
||||||
sourceSet(sourceSets["client"])
|
mod.sourceSet("client")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// To change the versions see the gradle.properties file
|
// To change the versions see the gradle.properties file
|
||||||
minecraft("com.mojang:minecraft:${project.extra["minecraft_version"]}")
|
minecraft("com.mojang:minecraft:${project.extra["minecraft_version"]}")
|
||||||
mappings("net.fabricmc:yarn:${project.extra["yarn_mappings"]}:v2")
|
mappings(loom.officialMojangMappings())
|
||||||
modImplementation("net.fabricmc:fabric-loader:${project.extra["loader_version"]}")
|
modImplementation("net.fabricmc:fabric-loader:${project.extra["loader_version"]}")
|
||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
|
|||||||
@@ -4,18 +4,17 @@ org.gradle.parallel=true
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/develop
|
# check these on https://fabricmc.net/develop
|
||||||
minecraft_version=1.21.5
|
minecraft_version=1.21.11
|
||||||
yarn_mappings=1.21.5+build.1
|
loader_version=0.18.2
|
||||||
loader_version=0.16.10
|
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=0.3.5
|
mod_version=0.4.0
|
||||||
maven_group=xyz.thewhitedog9487
|
maven_group=xyz.thewhitedog9487
|
||||||
archives_base_name=RandomTeleporter
|
archives_base_name=RandomTeleporter
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_version=0.119.5+1.21.5
|
fabric_version=0.139.4+1.21.11
|
||||||
|
|
||||||
# https://modrinth.com/mod/modmenu/versions
|
# https://modrinth.com/mod/modmenu/versions
|
||||||
# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu
|
# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu
|
||||||
modmenu_version=14.0.0-rc.2
|
modmenu_version=17.0.0-alpha.1
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https://services.gradle.org/distributions/gradle-8.13-bin.zip
|
distributionUrl=https://services.gradle.org/distributions/gradle-9.2.0-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package xyz.thewhitedog9487.mixin.client;
|
package xyz.thewhitedog9487.mixin.client;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(MinecraftClient.class)
|
@Mixin(Minecraft.class)
|
||||||
public class ExampleClientMixin {
|
public class ExampleClientMixin {
|
||||||
@Inject(at = @At("HEAD"), method = "run")
|
@Inject(at = @At("HEAD"), method = "run")
|
||||||
private void run(CallbackInfo info) {
|
private void run(CallbackInfo info) {
|
||||||
|
|||||||
@@ -1,25 +1,62 @@
|
|||||||
package xyz.thewhitedog9487;
|
package xyz.thewhitedog9487;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.command.argument.EntityArgumentType;
|
import net.minecraft.server.commands.TeleportCommand;
|
||||||
import net.minecraft.command.argument.Vec2ArgumentType;
|
import net.minecraft.server.permissions.PermissionCheck;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.commands.arguments.EntityArgument;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.commands.arguments.coordinates.Vec2Argument;
|
||||||
import net.minecraft.util.math.Vec2f;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.phys.Vec2;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.SplittableRandom;
|
import java.util.SplittableRandom;
|
||||||
|
|
||||||
import static net.minecraft.server.command.CommandManager.argument;
|
import static net.minecraft.commands.Commands.argument;
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.commands.Commands.literal;
|
||||||
|
import static net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING_NO_LEAVES;
|
||||||
|
import static xyz.thewhitedog9487.ResourceReloaderListener.*;
|
||||||
|
|
||||||
public class CommandRegister {
|
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>
|
* <br>
|
||||||
@@ -30,9 +67,9 @@ public class CommandRegister {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行命令所需权限等级
|
* 执行命令所需权限等级
|
||||||
* @see net.minecraft.server.command.TeleportCommand
|
* @see TeleportCommand
|
||||||
*/
|
*/
|
||||||
final static byte PermissionLevel = 2;
|
final static PermissionCheck PermissionLevel = Commands.LEVEL_GAMEMASTERS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用Fabric API向游戏内注册命令
|
* 使用Fabric API向游戏内注册命令
|
||||||
@@ -44,147 +81,108 @@ public class CommandRegister {
|
|||||||
* @see <a href="https://wiki.fabricmc.net/tutorial:commands">Fabric Wiki (Old style,English)</a>
|
* @see <a href="https://wiki.fabricmc.net/tutorial:commands">Fabric Wiki (Old style,English)</a>
|
||||||
*/
|
*/
|
||||||
public static void Register(String Name){
|
public static void Register(String Name){
|
||||||
|
|
||||||
|
CommandRegistrationCallback.EVENT
|
||||||
|
.register((dispatcher, registryAccess, environment) ->{
|
||||||
|
dispatcher.register(literal(Name)
|
||||||
// /rtp
|
// /rtp
|
||||||
CommandRegistrationCallback.EVENT
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.register((dispatcher, registryAccess, environment) ->{
|
.executes(context -> ExecuteCommand(
|
||||||
dispatcher.register(literal(Name)
|
context.getSource(),null,null, null))
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
|
||||||
.executes(context -> execute_command(
|
|
||||||
context.getSource(),null,null, null)));});
|
|
||||||
|
|
||||||
// /rtp <Radius(半径)>
|
// /rtp <Radius(半径)>
|
||||||
CommandRegistrationCallback.EVENT
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.register((dispatcher, registryAccess, environment) -> {
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
dispatcher.register(literal(Name)
|
.executes(context -> ExecuteCommand(
|
||||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
|
||||||
.executes(context -> execute_command(
|
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
null,
|
null,
|
||||||
null))));});
|
null)))
|
||||||
|
|
||||||
// /rtp <被传送玩家名(PlayerID)>
|
// /rtp <被传送玩家名(PlayerID)>
|
||||||
CommandRegistrationCallback.EVENT
|
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||||
.register((dispatcher, registryAccess, environment) -> {
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
dispatcher.register(literal(Name)
|
.executes(context -> ExecuteCommand(
|
||||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
|
||||||
.executes(context -> execute_command(
|
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
null,
|
null,
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
||||||
null))));});
|
null)))
|
||||||
|
|
||||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)>
|
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)>
|
||||||
CommandRegistrationCallback.EVENT
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.register((dispatcher, registryAccess, environment) -> {
|
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||||
dispatcher.register(literal(Name)
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
.executes(context -> ExecuteCommand(
|
||||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
|
||||||
.executes(context -> execute_command(
|
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
||||||
null)))));});
|
null))))
|
||||||
|
|
||||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)>
|
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)>
|
||||||
CommandRegistrationCallback.EVENT
|
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||||
.register((dispatcher, registryAccess, environment) -> {
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
dispatcher.register(literal(Name)
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
.executes(context -> ExecuteCommand(
|
||||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
|
||||||
.executes(context -> execute_command(
|
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
||||||
null)))));});
|
null))))
|
||||||
|
|
||||||
// // /rtp <Radius(半径)> <Origin(随机中心)>
|
// // /rtp <Radius(半径)> <Origin(随机中心)>
|
||||||
// CommandRegistrationCallback.EVENT
|
|
||||||
// .register((dispatcher, registryAccess, environment) -> {
|
|
||||||
// dispatcher.register(literal(Name)
|
|
||||||
// .then(argument("Radius(半径)", LongArgumentType.longArg())
|
// .then(argument("Radius(半径)", LongArgumentType.longArg())
|
||||||
// .then(argument("Origin(随机中心)",EntityArgumentType.player())
|
// .then(argument("Origin(随机中心)",EntityArgumentType.player())
|
||||||
// .requires(source -> source.hasPermissionLevel(PermissionLevel))
|
// .requires(Commands.hasPermission(PermissionLevel))
|
||||||
// .executes(context -> execute_command_origin(
|
// .executes(context -> execute_command_origin(
|
||||||
// context.getSource(),
|
// context.getSource(),
|
||||||
// LongArgumentType.getLong(context, "Radius(半径)"),
|
// LongArgumentType.getLong(context, "Radius(半径)"),
|
||||||
// null,
|
// null,
|
||||||
// EntityArgumentType.getEntity(context,"Origin(随机中心)"))))));});
|
// EntityArgumentType.getEntity(context,"Origin(随机中心)")))))
|
||||||
|
|
||||||
// /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
|
// /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||||
CommandRegistrationCallback.EVENT
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.register((dispatcher, registryAccess, environment) -> {
|
.then(argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
||||||
dispatcher.register(literal(Name)
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
.executes(context -> ExecuteCommand(
|
||||||
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
|
||||||
.executes(context -> execute_command(
|
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
null,
|
null,
|
||||||
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)"))))));});
|
Vec2Argument.getVec2(context,CommandArgumentName_OriginPosition)))))
|
||||||
|
|
||||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginEntity(随机中心,实体)>
|
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginEntity(随机中心,实体)>
|
||||||
CommandRegistrationCallback.EVENT
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.register((dispatcher, registryAccess, environment) -> {
|
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||||
dispatcher.register(literal(Name)
|
.then(argument(CommandArgumentName_OriginEntity, EntityArgument.entity())
|
||||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
.executes(context -> ExecuteCommand(
|
||||||
.then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity())
|
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
|
||||||
.executes(context -> execute_command(
|
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
||||||
new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x,
|
new Vec2( (float) EntityArgument.getEntity( context,CommandArgumentName_OriginEntity).position().x,
|
||||||
(float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().z )))))));});
|
(float) EntityArgument.getEntity( context,CommandArgumentName_OriginEntity).position().z ))))))
|
||||||
|
|
||||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
|
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
|
||||||
CommandRegistrationCallback.EVENT
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.register((dispatcher, registryAccess, environment) -> {
|
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||||
dispatcher.register(literal(Name)
|
.then(argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
||||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
.executes(context -> ExecuteCommand(
|
||||||
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
|
||||||
.executes(context -> execute_command(
|
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
||||||
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});
|
Vec2Argument.getVec2(context,CommandArgumentName_OriginPosition))))))
|
||||||
|
|
||||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
||||||
CommandRegistrationCallback.EVENT
|
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||||
.register((dispatcher, registryAccess, environment) -> {
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
dispatcher.register(literal(Name)
|
.then(argument(CommandArgumentName_OriginEntity, EntityArgument.entity())
|
||||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
.executes(context -> ExecuteCommand(
|
||||||
.then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity())
|
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
|
||||||
.executes(context -> execute_command(
|
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
||||||
new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x,
|
new Vec2( (float) EntityArgument.getEntity( context,CommandArgumentName_OriginEntity).position().x,
|
||||||
(float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().z )))))));});
|
(float) EntityArgument.getEntity( context,CommandArgumentName_OriginEntity).position().z ))))))
|
||||||
|
|
||||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||||
CommandRegistrationCallback.EVENT
|
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||||
.register((dispatcher, registryAccess, environment) -> {
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
dispatcher.register(literal(Name)
|
.then(argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
||||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.then(argument("Radius(半径)", IntegerArgumentType.integer())
|
.executes(context -> ExecuteCommand(
|
||||||
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
|
||||||
.executes(context -> execute_command(
|
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, "Radius(半径)"),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
||||||
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});}
|
Vec2Argument.getVec2(context,CommandArgumentName_OriginPosition)))))) );});}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向游戏内注册命令
|
* 向游戏内注册命令
|
||||||
@@ -201,62 +199,67 @@ public class CommandRegister {
|
|||||||
*
|
*
|
||||||
* @param Source 命令执行者
|
* @param Source 命令执行者
|
||||||
* @param Radius 随机选择的目的坐标距离参数 {@code Origin} 的最大距离
|
* @param Radius 随机选择的目的坐标距离参数 {@code Origin} 的最大距离
|
||||||
* @param Player 被传送的玩家
|
* @param Entity 被传送的实体
|
||||||
* @param Origin 随机选择的目的坐标的中心
|
* @param Origin 随机选择的目的坐标的中心
|
||||||
* @return 命令运行是否成功
|
* @return 命令运行是否成功
|
||||||
*/
|
*/
|
||||||
static int execute_command(ServerCommandSource Source, @Nullable Integer Radius, @Nullable Entity Player, @Nullable Vec2f Origin){
|
static int ExecuteCommand(CommandSourceStack Source, @Nullable Integer Radius, @Nullable Entity Entity, @Nullable Vec2 Origin){
|
||||||
Entity entity = Player == null ? Source.getPlayer() : Player;
|
Entity TargetEntity = Entity == null ? Source.getPlayer() : Entity;
|
||||||
/*
|
/*
|
||||||
↑
|
↑
|
||||||
Entity entity = null;
|
Entity TargetEntity = null;
|
||||||
if (Player == null){
|
if (TargetEntity == null){
|
||||||
entity = Source.getPlayer();}
|
TargetEntity = Source.getPlayer();}
|
||||||
else{
|
else{
|
||||||
entity = Player;}
|
TargetEntity = Entity;}
|
||||||
*/
|
*/
|
||||||
if (entity == null) {
|
if (TargetEntity == null) {
|
||||||
Source.sendFeedback(()->{ return Text.translatableWithFallback("error.no_target","不存在被传送目标,由非玩家物体执行命令时请显式指定被传送玩家ID"); }, true);
|
Source.sendSuccess(()->{ return Component.translatableWithFallback("error.no_target","不存在被传送目标,由非玩家物体执行命令时请显式指定被传送玩家ID"); }, true);
|
||||||
return -1;}
|
return -1;}
|
||||||
if (Radius == null){Radius = (int) (WorldBorder - 1e4);}
|
if (Radius == null){Radius = (int) (WorldBorder - 1e4);}
|
||||||
// ↑ 远离世界边界
|
// ↑ 远离世界边界
|
||||||
Radius = Math.abs(Radius);
|
int Coordinate_X = 0;
|
||||||
int Coordinate_X;
|
int Coordinate_Z = 0;
|
||||||
int Coordinate_Z;
|
try {
|
||||||
if (Origin == null){
|
if (Origin == null){
|
||||||
Coordinate_X = new SplittableRandom().nextInt(-Radius, Radius);
|
Coordinate_X = SR.nextInt(-Radius, Radius + 1);
|
||||||
Coordinate_Z = new SplittableRandom().nextInt(-Radius, Radius);}
|
Coordinate_Z = SR.nextInt(-Radius, Radius + 1); }
|
||||||
else{
|
else{
|
||||||
Coordinate_X = new SplittableRandom().nextInt((int) Origin.x - Radius, (int) Origin.x + Radius);
|
Coordinate_X = SR.nextInt((int) Origin.x - Radius, (int) Origin.x + Radius + 1);
|
||||||
Coordinate_Z = new SplittableRandom().nextInt((int) Origin.y - Radius, (int) Origin.y + Radius);}
|
Coordinate_Z = SR.nextInt((int) Origin.y - Radius, (int) Origin.y + Radius + 1); } }
|
||||||
int Coordinate_Y = 320;
|
catch (IllegalArgumentException e) {
|
||||||
for (var CurrentBlock = Source.getWorld().getBlockState(new BlockPos(Coordinate_X, Coordinate_Y, Coordinate_Z)).getBlock();
|
// 半径为零
|
||||||
// 从世界顶层往下找,直到遇到一个非空气方块
|
if (Origin == null) {
|
||||||
Blocks.AIR == CurrentBlock ||
|
Source.sendSuccess(()->{ return Component.translatableWithFallback("warning.radius_equal_zero_no_target", "由于你设置的随机半径为0,并且未设置随机中心点坐标,因此什么都不会发生"); },true);
|
||||||
Blocks.VOID_AIR == CurrentBlock ||
|
return -1;}
|
||||||
Blocks.CAVE_AIR == CurrentBlock
|
else {
|
||||||
;CurrentBlock = Source.getWorld().getBlockState(new BlockPos(Coordinate_X, Coordinate_Y, Coordinate_Z)).getBlock()){
|
Coordinate_X = (int) Origin.x;
|
||||||
Coordinate_Y--;}
|
Coordinate_Z = (int) Origin.y;
|
||||||
|
int finalCoordinate_X1 = Coordinate_X;
|
||||||
|
int finalCoordinate_Z1 = Coordinate_Z;
|
||||||
|
// ↑ "lambda 表达式中使用的变量应为 final 或有效 final"
|
||||||
|
Source.sendSuccess(()->{ return Component.translatableWithFallback("warning.radius_equal_zero", "警告:由于你设置的随机半径为0,因此在选择出合适高度之后将直接把你传送至%d %d", finalCoordinate_X1, finalCoordinate_Z1); },true);}}
|
||||||
|
Level EntityWorld = TargetEntity.level();
|
||||||
|
EntityWorld.getChunk(Coordinate_X >> 4, Coordinate_Z >> 4, ChunkStatus.FULL, true);
|
||||||
|
// ↑ 加载目标区块,不然下面获取到的Coordinate_Y一定是-64
|
||||||
|
// 必须是 >> 4 ,不能是 / 16
|
||||||
|
int Coordinate_Y = EntityWorld.getHeight(MOTION_BLOCKING_NO_LEAVES, Coordinate_X, Coordinate_Z);
|
||||||
|
BlockPos.MutableBlockPos BlockPos = new BlockPos.MutableBlockPos();
|
||||||
for (int x = -1; x <= 1; x++) {
|
for (int x = -1; x <= 1; x++) {
|
||||||
for (int z = -1; z <= 1; z++) {
|
for (int z = -1; z <= 1; z++) {
|
||||||
// 如果传送到的位置周围一圈是空气、水或岩浆,将其替换为玻璃
|
// 如果传送到的位置周围一圈是ReplaceToTargetBlock的方块,将其替换为TargetBlock
|
||||||
var BlockPos = new BlockPos(Coordinate_X - x, Coordinate_Y, Coordinate_Z - z);
|
BlockPos.set(Coordinate_X - x, Coordinate_Y - 1, Coordinate_Z - z);
|
||||||
var CurrentBlock = Source.getWorld().getBlockState(BlockPos).getBlock();
|
var CurrentBlock = EntityWorld.getBlockState(BlockPos).getBlock();
|
||||||
if ( CurrentBlock == Blocks.AIR ||
|
if ( ReplaceToTargetBlock.contains(CurrentBlock) ) {
|
||||||
CurrentBlock == Blocks.VOID_AIR ||
|
// 只替换ReplaceToTargetBlock内的方块,其余保留
|
||||||
CurrentBlock == Blocks.CAVE_AIR ||
|
EntityWorld.setBlockAndUpdate(BlockPos, TargetBlock.defaultBlockState());}}}
|
||||||
CurrentBlock == Blocks.WATER ||
|
// if ( String.valueOf(TargetEntity.getWorld().getBiome(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getKey()).equals("minecraft:the_void") ) {
|
||||||
CurrentBlock == Blocks.LAVA ){
|
|
||||||
// 只替换空气、水和岩浆,其余保留
|
|
||||||
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") ) {
|
|
||||||
// Coordinate_Y++;}
|
// Coordinate_Y++;}
|
||||||
Coordinate_Y++;
|
TargetEntity.teleportTo((ServerLevel) EntityWorld,Coordinate_X + 0.5, Coordinate_Y, Coordinate_Z + 0.5, new HashSet<>(), TargetEntity.getYRot(), TargetEntity.getXRot(), false);
|
||||||
// ↑ 高一层,人别站在土里了
|
int finalCoordinate_X = Coordinate_X;
|
||||||
entity.teleport(Source.getWorld(),Coordinate_X + 0.5, Coordinate_Y, Coordinate_Z + 0.5, new HashSet<>(), entity.getYaw(), entity.getPitch(), false);
|
int finalCoordinate_Z = Coordinate_Z;
|
||||||
int finalCoordinate_Y = Coordinate_Y;
|
|
||||||
// ↑ "lambda 表达式中使用的变量应为 final 或有效 final"
|
// ↑ "lambda 表达式中使用的变量应为 final 或有效 final"
|
||||||
final var FeedbackFallbackString = String.format("已将玩家%s传送到%d %d %d", entity.getName().getString(), Coordinate_X, finalCoordinate_Y, Coordinate_Z);
|
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, entity.getName(), Coordinate_X, finalCoordinate_Y, Coordinate_Z); },true);
|
Source.sendSuccess(()->{ return Component.translatableWithFallback("info.success", FeedbackFallbackString, TargetEntity.getName(), finalCoordinate_X, Coordinate_Y, finalCoordinate_Z); },true);
|
||||||
return 16;}
|
return Command.SINGLE_SUCCESS;}
|
||||||
}
|
}
|
||||||
@@ -9,17 +9,17 @@ public class RandomTeleporter implements ModInitializer {
|
|||||||
// This logger is used to write text to the console and the log file.
|
// This logger is used to write text to the console and the log file.
|
||||||
// It is considered best practice to use your mod id as the logger's name.
|
// It is considered best practice to use your mod id as the logger's name.
|
||||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger("randomteleporter");
|
public static final String MOD_ID = "randomteleporter";
|
||||||
|
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||||
// However, some things (like resources) may still be uninitialized.
|
// However, some things (like resources) may still be uninitialized.
|
||||||
// Proceed with mild caution.
|
// Proceed with mild caution.
|
||||||
LOGGER.info("RandomTeleporter Loading!");
|
|
||||||
|
|
||||||
|
ResourceReloaderListener.Register();
|
||||||
CommandRegister.Register();
|
CommandRegister.Register();
|
||||||
|
LOGGER.info("RandomTeleporter已写入命令注册回调,目标命令将会在该注册的时候被注册");
|
||||||
LOGGER.info("RandomTeleporter Loaded!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package xyz.thewhitedog9487;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.resource.v1.ResourceLoader;
|
||||||
|
import net.fabricmc.fabric.api.resource.v1.reloader.SimpleResourceReloader;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
|
import static net.minecraft.server.packs.PackType.CLIENT_RESOURCES;
|
||||||
|
import static xyz.thewhitedog9487.RandomTeleporter.MOD_ID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在游戏资源重新加载之后刷新翻译文本
|
||||||
|
*/
|
||||||
|
public class ResourceReloaderListener {
|
||||||
|
public static String CommandArgumentName_Radius = "Radius(半径)";
|
||||||
|
public static String CommandArgumentName_Target = "被传送玩家名(PlayerID)";
|
||||||
|
public static String CommandArgumentName_OriginPosition = "OriginPos(随机中心,坐标)";
|
||||||
|
public static String CommandArgumentName_OriginEntity = "OriginEntity(随机中心,实体)";
|
||||||
|
|
||||||
|
public static void Register(){
|
||||||
|
ResourceLoader.get(CLIENT_RESOURCES).registerReloader(Identifier.fromNamespaceAndPath(MOD_ID, "translate_text_apply"), new SimpleResourceReloader<Void>() {
|
||||||
|
/**
|
||||||
|
* 用不到,不用管
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Void prepare(SharedState store) {
|
||||||
|
return null; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void apply(Void prepared, SharedState store) {
|
||||||
|
CommandArgumentName_Radius = Component.translatableWithFallback("command.argument.radius", "Radius(半径)").getString();
|
||||||
|
CommandArgumentName_Target = Component.translatableWithFallback("command.argument.target", "被传送玩家名(PlayerID)").getString();
|
||||||
|
CommandArgumentName_OriginPosition = Component.translatableWithFallback("command.argument.origin_pos", "OriginPos(随机中心,坐标)").getString();
|
||||||
|
CommandArgumentName_OriginEntity = Component.translatableWithFallback("command.argument.origin_entity", "OriginEntity(随机中心,实体)").getString(); } } ); } }
|
||||||
@@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
|
|
||||||
@Mixin(MinecraftServer.class)
|
@Mixin(MinecraftServer.class)
|
||||||
public class ExampleMixin {
|
public class ExampleMixin {
|
||||||
@Inject(at = @At("HEAD"), method = "loadWorld")
|
@Inject(at = @At("HEAD"), method = "loadLevel")
|
||||||
private void init(CallbackInfo info) {
|
private void init(CallbackInfo info) {
|
||||||
// This code is injected into the start of MinecraftServer.loadWorld()V
|
// This code is injected into the start of MinecraftServer.loadWorld()V
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,11 @@
|
|||||||
"modmenu.descriptionTranslation.randomteleporter": "Added two commands for random teleportation",
|
"modmenu.descriptionTranslation.randomteleporter": "Added two commands for random teleportation",
|
||||||
"info.success": "Teleported %s to %d %d %d",
|
"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",
|
"error.no_target": "There is no teleported target, and the teleported player ID is explicitly specified when executed by a non-player object",
|
||||||
"bilibili": "Bilibili"
|
"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",
|
||||||
|
"command.argument.radius": "radius",
|
||||||
|
"command.argument.target": "teleported entity",
|
||||||
|
"command.argument.origin_pos": "origin(pos)",
|
||||||
|
"command.argument.origin_entity": "origin(entity)"
|
||||||
}
|
}
|
||||||
@@ -3,5 +3,11 @@
|
|||||||
"modmenu.descriptionTranslation.randomteleporter": "增加了两个用于随机传送的命令",
|
"modmenu.descriptionTranslation.randomteleporter": "增加了两个用于随机传送的命令",
|
||||||
"info.success": "已将玩家%s传送到%d %d %d",
|
"info.success": "已将玩家%s传送到%d %d %d",
|
||||||
"error.no_target": "不存在被传送目标,由非玩家物体执行命令时请显式指定被传送玩家ID",
|
"error.no_target": "不存在被传送目标,由非玩家物体执行命令时请显式指定被传送玩家ID",
|
||||||
"bilibili": "TheWhiteDog9487的哔哩哔哩主页"
|
"warning.radius_equal_zero": "警告:由于你设置的随机半径为0,因此在选择出合适高度之后将直接把你传送至%d %d",
|
||||||
|
"warning.radius_equal_zero_no_target": "警告:由于你设置的随机半径为0,并且未设置随机中心点坐标,因此什么都不会发生",
|
||||||
|
"bilibili": "TheWhiteDog9487的哔哩哔哩主页",
|
||||||
|
"command.argument.radius": "半径",
|
||||||
|
"command.argument.target": "被传送实体",
|
||||||
|
"command.argument.origin_pos": "随机中心(坐标)",
|
||||||
|
"command.argument.origin_entity": "随机中心(实体)"
|
||||||
}
|
}
|
||||||
@@ -27,10 +27,10 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.16.10",
|
"fabricloader": ">=0.18.2",
|
||||||
"minecraft": "1.21.5",
|
"minecraft": "1.21.11",
|
||||||
"java": ">=21",
|
"java": ">=21",
|
||||||
"fabric-api": ">=0.119.5"
|
"fabric-api": ">=0.139.4"
|
||||||
},
|
},
|
||||||
"suggests": {
|
"suggests": {
|
||||||
"another-mod": "*"
|
"another-mod": "*"
|
||||||
|
|||||||
Reference in New Issue
Block a user