mirror of
https://github.com/TheWhiteDog9487/RandomTeleporter.git
synced 2026-06-17 20:24:47 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2ecf4fdda | ||
|
|
39027e398e |
@@ -1,9 +1,10 @@
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("net.fabricmc.fabric-loom")
|
id("net.fabricmc.fabric-loom")
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("org.jetbrains.kotlin.jvm") version "2.3.21"
|
id("org.jetbrains.kotlin.jvm") version "2.4.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
version = providers.gradleProperty("mod_version").get()
|
version = providers.gradleProperty("mod_version").get()
|
||||||
@@ -20,6 +21,27 @@ repositories {
|
|||||||
url = uri("https://maven.terraformersmc.com/") }
|
url = uri("https://maven.terraformersmc.com/") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
val MixinJarPath = configurations.loaderLibraries.get().resolvedConfiguration
|
||||||
|
.resolvedArtifacts
|
||||||
|
.find { it.moduleVersion.id.group == "net.fabricmc" && it.moduleVersion.id.name == "sponge-mixin" }!!
|
||||||
|
.file
|
||||||
|
val IsSupportDceVM = Paths.get(System.getProperty("java.home"))
|
||||||
|
.resolve("bin")
|
||||||
|
.resolve("java")
|
||||||
|
.toFile()
|
||||||
|
.let {
|
||||||
|
val ReturnCode = ProcessBuilder(it.absolutePath, "-XX:+AllowEnhancedClassRedefinition", "-version")
|
||||||
|
.start()
|
||||||
|
.waitFor()
|
||||||
|
return@let ReturnCode == 0 }
|
||||||
|
loom.runs.named("client") {
|
||||||
|
jvmArguments.add("-javaagent:${MixinJarPath.absolutePath}")
|
||||||
|
if (IsSupportDceVM == true) jvmArguments.add("-XX:+AllowEnhancedClassRedefinition") }
|
||||||
|
loom.runs.named("server") {
|
||||||
|
jvmArguments.add("-javaagent:${MixinJarPath.absolutePath}")
|
||||||
|
if (IsSupportDceVM == true) jvmArguments.add("-XX:+AllowEnhancedClassRedefinition") } }
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
splitEnvironmentSourceSets()
|
splitEnvironmentSourceSets()
|
||||||
|
|
||||||
@@ -46,7 +68,7 @@ dependencies {
|
|||||||
// "modImplementation"("net.fabricmc.fabric-api:fabric-api-deprecated:${project.extra["fabric_version"]}")
|
// "modImplementation"("net.fabricmc.fabric-api:fabric-api-deprecated:${project.extra["fabric_version"]}")
|
||||||
|
|
||||||
// ↓ 开发测试用
|
// ↓ 开发测试用
|
||||||
// runtimeOnly("com.terraformersmc:modmenu:${project.extra["modmenu_version"]}")
|
runtimeOnly("com.terraformersmc:modmenu:${providers.gradleProperty("modmenu_version").get()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,18 +4,22 @@ org.gradle.parallel=true
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/develop
|
# check these on https://fabricmc.net/develop
|
||||||
minecraft_version=26.1.2
|
minecraft_version=26.2
|
||||||
loader_version=0.18.6
|
loader_version=0.19.3
|
||||||
loom_version=1.16-SNAPSHOT
|
loom_version=1.17-SNAPSHOT
|
||||||
fabric_kotlin_version=1.13.11+kotlin.2.3.21
|
|
||||||
|
# Fabric API
|
||||||
|
fabric_api_version=0.152.1+26.2
|
||||||
|
|
||||||
|
# https://modrinth.com/mod/fabric-language-kotlin/versions
|
||||||
|
fabric_kotlin_version=1.13.12+kotlin.2.4.0
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=0.5.3
|
mod_version=0.5.4
|
||||||
maven_group=xyz.thewhitedog9487
|
maven_group=xyz.thewhitedog9487
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_api_version=0.145.4+26.1.2
|
|
||||||
|
|
||||||
# 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=18.0.0-alpha.8
|
modmenu_version=20.0.0-beta.2
|
||||||
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-9.5.0-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-all.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package xyz.thewhitedog9487
|
package xyz.thewhitedog9487
|
||||||
|
|
||||||
import com.mojang.brigadier.Command
|
import com.mojang.brigadier.Command
|
||||||
|
import com.mojang.brigadier.CommandDispatcher
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType
|
import com.mojang.brigadier.arguments.IntegerArgumentType
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode
|
||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
|
||||||
import net.minecraft.commands.CommandSourceStack
|
import net.minecraft.commands.CommandSourceStack
|
||||||
import net.minecraft.commands.Commands
|
import net.minecraft.commands.Commands
|
||||||
@@ -12,7 +14,6 @@ import net.minecraft.network.chat.Component
|
|||||||
import net.minecraft.server.commands.TeleportCommand
|
import net.minecraft.server.commands.TeleportCommand
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.world.entity.Entity
|
import net.minecraft.world.entity.Entity
|
||||||
import net.minecraft.world.level.block.Block
|
|
||||||
import net.minecraft.world.level.block.Blocks
|
import net.minecraft.world.level.block.Blocks
|
||||||
import net.minecraft.world.level.chunk.status.ChunkStatus
|
import net.minecraft.world.level.chunk.status.ChunkStatus
|
||||||
import net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING_NO_LEAVES
|
import net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING_NO_LEAVES
|
||||||
@@ -81,18 +82,40 @@ const val CommandExecuteFailure = 0
|
|||||||
val CommandRootNodeName = setOf(
|
val CommandRootNodeName = setOf(
|
||||||
"随机传送",
|
"随机传送",
|
||||||
"rtp" )
|
"rtp" )
|
||||||
|
|
||||||
|
val CommandNodes: MutableSet<LiteralCommandNode<CommandSourceStack>> = mutableSetOf()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否注册过Fabric API的命令注册回调监听器
|
||||||
|
*/
|
||||||
|
var CommandRegistrationCallbackEventHasBeenRegistered = false
|
||||||
|
|
||||||
|
val CommandArgumentName_Radius = Component.translatableWithFallback("command.argument.radius", "Radius(半径)")
|
||||||
|
val CommandArgumentName_Target = Component.translatableWithFallback("command.argument.target", "PlayerID(被传送玩家名)")
|
||||||
|
val CommandArgumentName_OriginPosition = Component.translatableWithFallback("command.argument.origin_pos", "OriginPos(随机中心,坐标)")
|
||||||
|
val CommandArgumentName_OriginEntity = Component.translatableWithFallback("command.argument.origin_entity", "OriginEntity(随机中心,实体)")
|
||||||
|
val CommandArgumentName_RegionFromPosition = Component.translatableWithFallback(
|
||||||
|
"command.argument.region_from_pos",
|
||||||
|
"RegionFrom(随机范围起始位置,坐标)")
|
||||||
|
val CommandArgumentName_RegionToPosition = Component.translatableWithFallback(
|
||||||
|
"command.argument.region_to_pos",
|
||||||
|
"RegionTo(随机范围结束位置,坐标)")
|
||||||
|
val CommandArgumentName_RegionFromEntity = Component.translatableWithFallback(
|
||||||
|
"command.argument.region_from_entity",
|
||||||
|
"RegionFrom(随机范围起始位置,实体)")
|
||||||
|
val CommandArgumentName_RegionToEntity = Component.translatableWithFallback(
|
||||||
|
"command.argument.region_to_entity",
|
||||||
|
"RegionTo(随机范围结束位置,实体)")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用Fabric API向游戏内注册命令
|
* 使用Fabric API向游戏内注册命令
|
||||||
* <br>
|
* <br>
|
||||||
* @see <a href="https://docs.fabricmc.net/zh_cn/develop/commands/basics">Fabric Docs (中文)</a>
|
* @see <a href="https://docs.fabricmc.net/zh_cn/develop/commands/basics">Fabric Docs (中文)</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 Docs (English)</a>
|
* @see <a href="https://docs.fabricmc.net/develop/commands/basics">Fabric Docs (English)</a>
|
||||||
* @see <a href="https://wiki.fabricmc.net/tutorial:commands">Fabric Wiki (English)</a>
|
|
||||||
*/
|
*/
|
||||||
fun CommandRegister() {
|
fun CommandRegister(InGameCommandDispatcherInstance: CommandDispatcher<CommandSourceStack>? = null) {
|
||||||
for (RootNodeName in CommandRootNodeName) {
|
val Register: (CommandDispatcherInstance: CommandDispatcher<CommandSourceStack>, NodeName: String) -> Unit = { CommandDispatcherInstance, NodeName ->
|
||||||
CommandRegistrationCallback.EVENT.register { dispatcher, context, selection ->
|
val Node = CommandDispatcherInstance.register(Commands.literal(NodeName)
|
||||||
dispatcher.register(Commands.literal(RootNodeName)
|
|
||||||
// /rtp
|
// /rtp
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes{ commandContext -> ExecuteCommand(commandContext.source) }
|
.executes{ commandContext -> ExecuteCommand(commandContext.source) }
|
||||||
@@ -104,152 +127,160 @@ fun CommandRegister() {
|
|||||||
|
|
||||||
// /rtp back <PlayerID(被传送玩家名)>
|
// /rtp back <PlayerID(被传送玩家名)>
|
||||||
.then(Commands.literal("back")
|
.then(Commands.literal("back")
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> TeleportBack(commandContext.source,
|
.executes { commandContext -> TeleportBack(commandContext.source,
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_Target)) } ) )
|
EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string)) } ) )
|
||||||
|
|
||||||
// /rtp <PlayerID(被传送玩家名)> back
|
// /rtp <PlayerID(被传送玩家名)> back
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.then(Commands.literal("back")
|
.then(Commands.literal("back")
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> TeleportBack(commandContext.source,
|
.executes { commandContext -> TeleportBack(commandContext.source,
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_Target)) } ) )
|
EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string)) } ) )
|
||||||
|
|
||||||
// /rtp <Radius(半径)>
|
// /rtp <Radius(半径)>
|
||||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius)) } )
|
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string)) } )
|
||||||
|
|
||||||
// /rtp <PlayerID(被传送玩家名)>
|
// /rtp <PlayerID(被传送玩家名)>
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target)) } )
|
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string)) } )
|
||||||
|
|
||||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)>
|
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)>
|
||||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target)) } ) )
|
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string)) } ) )
|
||||||
|
|
||||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)>
|
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)>
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target)) } ) )
|
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string)) } ) )
|
||||||
|
|
||||||
// /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
|
// /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||||
.then(Commands.argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
.then(Commands.argument(CommandArgumentName_OriginPosition.string, Vec2Argument.vec2())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||||
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition)) } ) )
|
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition.string)) } ) )
|
||||||
|
|
||||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)> <OriginEntity(随机中心,实体)>
|
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)> <OriginEntity(随机中心,实体)>
|
||||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.then(Commands.argument(CommandArgumentName_OriginEntity, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_OriginEntity.string, EntityArgument.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||||
Origin = Vec2(
|
Origin = Vec2(
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity).position().x.toFloat(),
|
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity.string).position().x.toFloat(),
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity).position().z.toFloat() ) ) } ) ) )
|
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity.string).position().z.toFloat() ) ) } ) ) )
|
||||||
|
|
||||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)> <OriginPos(随机中心,坐标)>
|
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)> <OriginPos(随机中心,坐标)>
|
||||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.then(Commands.argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
.then(Commands.argument(CommandArgumentName_OriginPosition.string, Vec2Argument.vec2())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||||
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition) ) } ) ) )
|
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition.string) ) } ) ) )
|
||||||
|
|
||||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||||
.then(Commands.argument(CommandArgumentName_OriginEntity, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_OriginEntity.string, EntityArgument.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||||
Origin = Vec2(
|
Origin = Vec2(
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity).position().x.toFloat(),
|
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity.string).position().x.toFloat(),
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity).position().z.toFloat() ) ) } ) ) )
|
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity.string).position().z.toFloat() ) ) } ) ) )
|
||||||
|
|
||||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||||
.then(Commands.argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
.then(Commands.argument(CommandArgumentName_OriginPosition.string, Vec2Argument.vec2())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||||
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition) ) } ) ) )
|
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition.string) ) } ) ) )
|
||||||
|
|
||||||
// /rtp <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)>
|
// /rtp <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)>
|
||||||
.then(Commands.argument(CommandArgumentName_RegionFromPosition, Vec2Argument.vec2())
|
.then(Commands.argument(CommandArgumentName_RegionFromPosition.string, Vec2Argument.vec2())
|
||||||
.then(Commands.argument(CommandArgumentName_RegionToPosition, Vec2Argument.vec2())
|
.then(Commands.argument(CommandArgumentName_RegionToPosition.string, Vec2Argument.vec2())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition),
|
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition.string),
|
||||||
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition) ) } ) )
|
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition.string) ) } ) )
|
||||||
|
|
||||||
// /rtp <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)> <PlayerID(被传送玩家名)>
|
// /rtp <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)> <PlayerID(被传送玩家名)>
|
||||||
.then(Commands.argument(CommandArgumentName_RegionFromPosition, Vec2Argument.vec2())
|
.then(Commands.argument(CommandArgumentName_RegionFromPosition.string, Vec2Argument.vec2())
|
||||||
.then(Commands.argument(CommandArgumentName_RegionToPosition, Vec2Argument.vec2())
|
.then(Commands.argument(CommandArgumentName_RegionToPosition.string, Vec2Argument.vec2())
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||||
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition),
|
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition.string),
|
||||||
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition) ) } ) ) )
|
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition.string) ) } ) ) )
|
||||||
|
|
||||||
// /rtp <PlayerID(被传送玩家名)> <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)>
|
// /rtp <PlayerID(被传送玩家名)> <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)>
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.then(Commands.argument(CommandArgumentName_RegionFromPosition, Vec2Argument.vec2())
|
.then(Commands.argument(CommandArgumentName_RegionFromPosition.string, Vec2Argument.vec2())
|
||||||
.then(Commands.argument(CommandArgumentName_RegionToPosition, Vec2Argument.vec2())
|
.then(Commands.argument(CommandArgumentName_RegionToPosition.string, Vec2Argument.vec2())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||||
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition),
|
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition.string),
|
||||||
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition) ) } ) ) )
|
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition.string) ) } ) ) )
|
||||||
|
|
||||||
// /rtp <RegionFrom(随机区域起点,实体)> <RegionTo(随机区域终点,实体)>
|
// /rtp <RegionFrom(随机区域起点,实体)> <RegionTo(随机区域终点,实体)>
|
||||||
.then(Commands.argument(CommandArgumentName_RegionFromEntity, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_RegionFromEntity.string, EntityArgument.entity())
|
||||||
.then(Commands.argument(CommandArgumentName_RegionToEntity, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_RegionToEntity.string, EntityArgument.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
RegionFrom = Vec2(
|
RegionFrom = Vec2(
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity).position().x.toFloat(),
|
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity.string).position().x.toFloat(),
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity).position().z.toFloat() ),
|
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity.string).position().z.toFloat() ),
|
||||||
RegionTo = Vec2(
|
RegionTo = Vec2(
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity).position().x.toFloat(),
|
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity.string).position().x.toFloat(),
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity).position().z.toFloat() ) ) } ) )
|
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity.string).position().z.toFloat() ) ) } ) )
|
||||||
|
|
||||||
// /rtp <RegionFrom(随机区域起点,实体)> <RegionTo(随机区域终点,实体)> <PlayerID(被传送玩家名)>
|
// /rtp <RegionFrom(随机区域起点,实体)> <RegionTo(随机区域终点,实体)> <PlayerID(被传送玩家名)>
|
||||||
.then(Commands.argument(CommandArgumentName_RegionFromEntity, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_RegionFromEntity.string, EntityArgument.entity())
|
||||||
.then(Commands.argument(CommandArgumentName_RegionToEntity, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_RegionToEntity.string, EntityArgument.entity())
|
||||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(Commands.hasPermission(PermissionLevel))
|
||||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||||
RegionFrom = Vec2(
|
RegionFrom = Vec2(
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity).position().x.toFloat(),
|
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity.string).position().x.toFloat(),
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity).position().z.toFloat() ),
|
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity.string).position().z.toFloat() ),
|
||||||
RegionTo = Vec2(
|
RegionTo = Vec2(
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity).position().x.toFloat(),
|
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity.string).position().x.toFloat(),
|
||||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity).position().z.toFloat() ) ) } ) ) )
|
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity.string).position().z.toFloat() ) ) } ) ) ) )
|
||||||
) } } }
|
CommandNodes.add(Node) }
|
||||||
|
for (RootNodeName in CommandRootNodeName) {
|
||||||
|
InGameCommandDispatcherInstance?.let {
|
||||||
|
Register(it, RootNodeName) } }
|
||||||
|
if (CommandRegistrationCallbackEventHasBeenRegistered) return
|
||||||
|
for (RootNodeName in CommandRootNodeName) {
|
||||||
|
CommandRegistrationCallback.EVENT.register { dispatcher, context, selection ->
|
||||||
|
Register(dispatcher, RootNodeName) } }
|
||||||
|
CommandRegistrationCallbackEventHasBeenRegistered = true }
|
||||||
|
|
||||||
fun ExecuteCommand(
|
fun ExecuteCommand(
|
||||||
Source: CommandSourceStack,
|
Source: CommandSourceStack,
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package xyz.thewhitedog9487.Event
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.resource.v1.ResourceLoader
|
||||||
|
import net.fabricmc.fabric.api.resource.v1.reloader.SimpleReloadListener
|
||||||
|
import net.minecraft.resources.Identifier
|
||||||
|
import net.minecraft.server.packs.PackType
|
||||||
|
import net.minecraft.server.packs.resources.PreparableReloadListener
|
||||||
|
import xyz.thewhitedog9487.CommandNodes
|
||||||
|
import xyz.thewhitedog9487.CommandRegister
|
||||||
|
import xyz.thewhitedog9487.ModID
|
||||||
|
|
||||||
|
fun ResourceReloaderListenerRegister() {
|
||||||
|
ResourceLoader.get(PackType.CLIENT_RESOURCES).registerReloadListener(
|
||||||
|
Identifier.fromNamespaceAndPath(
|
||||||
|
ModID,
|
||||||
|
"translate_text_apply"),
|
||||||
|
object: SimpleReloadListener<Unit>() {
|
||||||
|
override fun prepare(p0: PreparableReloadListener.SharedState) {}
|
||||||
|
|
||||||
|
override fun apply(p0: Unit, p1: PreparableReloadListener.SharedState) {
|
||||||
|
val TempSet = CommandNodes.toSet()
|
||||||
|
CommandNodes.clear()
|
||||||
|
for (Node in TempSet) {
|
||||||
|
MinecraftServerInstanceBackendField
|
||||||
|
?.commands
|
||||||
|
?.dispatcher
|
||||||
|
?.root
|
||||||
|
?.children
|
||||||
|
?.remove(Node) }
|
||||||
|
CommandRegister(MinecraftServerInstanceBackendField?.commands?.dispatcher)
|
||||||
|
MinecraftServerInstanceBackendField
|
||||||
|
?.playerList
|
||||||
|
?.players
|
||||||
|
?.forEach { SPE ->
|
||||||
|
MinecraftServerInstance.commands.sendCommands(SPE) } } } ) }
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package xyz.thewhitedog9487.Event
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
import xyz.thewhitedog9487.ModLogger
|
||||||
|
import xyz.thewhitedog9487.OldPositions
|
||||||
|
|
||||||
|
var MinecraftServerInstanceBackendField: MinecraftServer? = null
|
||||||
|
val MinecraftServerInstance get() =
|
||||||
|
MinecraftServerInstanceBackendField ?: throw NullPointerException("当前服务器实例不可用")
|
||||||
|
|
||||||
|
fun ServerLifecycleListenerRegister() {
|
||||||
|
ServerLifecycleEvents.SERVER_STARTED.register { MinecraftServerInstance ->
|
||||||
|
MinecraftServerInstanceBackendField = MinecraftServerInstance
|
||||||
|
OldPositions.clear()
|
||||||
|
ModLogger.info("已清空传送历史记录") }
|
||||||
|
ServerLifecycleEvents.SERVER_STOPPED.register { MinecraftServerInstance ->
|
||||||
|
MinecraftServerInstanceBackendField = null } }
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
package xyz.thewhitedog9487
|
package xyz.thewhitedog9487
|
||||||
|
|
||||||
|
import net.fabricmc.api.EnvType
|
||||||
|
import net.fabricmc.api.Environment
|
||||||
import net.fabricmc.api.ModInitializer
|
import net.fabricmc.api.ModInitializer
|
||||||
|
import net.fabricmc.loader.api.FabricLoader
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import xyz.thewhitedog9487.Event.ResourceReloaderListenerRegister
|
||||||
|
import xyz.thewhitedog9487.Event.ServerLifecycleListenerRegister
|
||||||
|
|
||||||
const val ModID = "randomteleporter"
|
const val ModID = "randomteleporter"
|
||||||
const val FriendlyModID = "RandomTeleporter"
|
const val FriendlyModID = "RandomTeleporter"
|
||||||
@@ -21,6 +26,7 @@ object RandomTeleporter : ModInitializer {
|
|||||||
|
|
||||||
ServerLifecycleListenerRegister()
|
ServerLifecycleListenerRegister()
|
||||||
ResourceReloaderListenerRegister()
|
ResourceReloaderListenerRegister()
|
||||||
CommandRegister()
|
// ↑ 命令注册在这个里面,在资源加载完成之后注册事件监听器
|
||||||
ModLogger.info("RandomTeleporter已写入命令注册回调,目标命令将会在该注册的时候被注册") }
|
if (FabricLoader.getInstance().environmentType == EnvType.SERVER){
|
||||||
}
|
// 独立服务器根本不可能重载资源,需要手动注册
|
||||||
|
CommandRegister() } } }
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package xyz.thewhitedog9487
|
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.resource.v1.ResourceLoader
|
|
||||||
import net.fabricmc.fabric.api.resource.v1.reloader.SimpleReloadListener
|
|
||||||
import net.minecraft.network.chat.Component
|
|
||||||
import net.minecraft.resources.Identifier
|
|
||||||
import net.minecraft.server.packs.PackType
|
|
||||||
import net.minecraft.server.packs.resources.PreparableReloadListener
|
|
||||||
|
|
||||||
var CommandArgumentName_Radius = "Radius(半径)"
|
|
||||||
var CommandArgumentName_Target = "PlayerID(被传送玩家名)"
|
|
||||||
var CommandArgumentName_OriginPosition = "OriginPos(随机中心,坐标)"
|
|
||||||
var CommandArgumentName_OriginEntity = "OriginEntity(随机中心,实体)"
|
|
||||||
var CommandArgumentName_RegionFromPosition = "RegionFrom(随机范围起始位置,坐标)"
|
|
||||||
var CommandArgumentName_RegionToPosition = "RegionTo(随机范围结束位置,坐标)"
|
|
||||||
var CommandArgumentName_RegionFromEntity = "RegionFrom(随机范围起始位置,实体)"
|
|
||||||
var CommandArgumentName_RegionToEntity = "RegionTo(随机范围结束位置,实体)"
|
|
||||||
|
|
||||||
fun ResourceReloaderListenerRegister() {
|
|
||||||
ResourceLoader.get(PackType.CLIENT_RESOURCES).registerReloadListener(
|
|
||||||
Identifier.fromNamespaceAndPath(ModID,
|
|
||||||
"translate_text_apply"), object: SimpleReloadListener<Unit>() {
|
|
||||||
override fun prepare(p0: PreparableReloadListener.SharedState) {}
|
|
||||||
|
|
||||||
override fun apply(p0: Unit, p1: PreparableReloadListener.SharedState) {
|
|
||||||
CommandArgumentName_Radius =
|
|
||||||
Component.translatableWithFallback("command.argument.radius", "Radius(半径)").string
|
|
||||||
CommandArgumentName_Target =
|
|
||||||
Component.translatableWithFallback("command.argument.target", "PlayerID(被传送玩家名)").string
|
|
||||||
CommandArgumentName_OriginPosition =
|
|
||||||
Component.translatableWithFallback("command.argument.origin_pos", "OriginPos(随机中心,坐标)").string
|
|
||||||
CommandArgumentName_OriginEntity =
|
|
||||||
Component.translatableWithFallback("command.argument.origin_entity", "OriginEntity(随机中心,实体)").string
|
|
||||||
CommandArgumentName_RegionFromPosition = Component.translatableWithFallback(
|
|
||||||
"command.argument.region_from_pos",
|
|
||||||
"RegionFrom(随机范围起始位置,坐标)").string
|
|
||||||
CommandArgumentName_RegionToPosition = Component.translatableWithFallback(
|
|
||||||
"command.argument.region_to_pos",
|
|
||||||
"RegionTo(随机范围结束位置,坐标)").string
|
|
||||||
CommandArgumentName_RegionFromEntity = Component.translatableWithFallback(
|
|
||||||
"command.argument.region_from_entity",
|
|
||||||
"RegionFrom(随机范围起始位置,实体)").string
|
|
||||||
CommandArgumentName_RegionToEntity = Component.translatableWithFallback(
|
|
||||||
"command.argument.region_to_entity",
|
|
||||||
"RegionTo(随机范围结束位置,实体)").string } } ) }
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package xyz.thewhitedog9487
|
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents
|
|
||||||
|
|
||||||
fun ServerLifecycleListenerRegister() {
|
|
||||||
ServerLifecycleEvents.SERVER_STARTED.register { server ->
|
|
||||||
OldPositions.clear()
|
|
||||||
ModLogger.info("已清空传送历史记录") } }
|
|
||||||
@@ -31,10 +31,10 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.18.6",
|
"fabricloader": ">=0.9.3",
|
||||||
"minecraft": "26.1.2",
|
"minecraft": "26.2",
|
||||||
"java": ">=25",
|
"java": ">=25",
|
||||||
"fabric-api": ">=0.145.4",
|
"fabric-api": ">=0.152.1",
|
||||||
"fabric-language-kotlin": "*"
|
"fabric-language-kotlin": "*"
|
||||||
},
|
},
|
||||||
"suggests": {
|
"suggests": {
|
||||||
|
|||||||
Reference in New Issue
Block a user