From c3fe7fbe6ad9915115f3200c949b0557dfde77dd Mon Sep 17 00:00:00 2001 From: 3944Realms Date: Sat, 25 Oct 2025 00:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9ELeashData=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=20=E6=8F=90=E4=BE=9B=E4=BA=86=E5=AE=8C=E5=96=84=E7=9A=84API?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=B8=8E=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.MD | 55 ++ build.gradle | 29 +- gradle.properties | 2 +- .../1de3d2ee724999f84a11b20b51c37030049be277 | 4 +- .../2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac | 4 +- .../82018c5420b46ddbb7071e62df09fdecd98133e6 | 4 +- .../c622617f6fabf890a00b9275cd5f643584a8a2c8 | 4 +- .../assets/superleadrope/lang/en_us.json | 73 ++- .../assets/superleadrope/lang/lzh.json | 73 ++- .../assets/superleadrope/lang/zh_cn.json | 73 ++- .../assets/superleadrope/lang/zh_tw.json | 73 ++- .../capability/impi/LeashDataImpl.java | 1 + .../content/command/Command.java | 7 +- .../content/command/LeashDataCommand.java | 363 ++++++++++---- .../content/command/LeashStateCommand.java | 469 +++++++++++++++++- .../core/leash/LeashInteractHandler.java | 5 +- .../datagen/data/SLPLangKeyValue.java | 455 ++++++++++++++--- .../util/capability/LeashDataInnerAPI.java | 19 +- src/main/templates/META-INF/mods.toml | 2 +- 19 files changed, 1483 insertions(+), 232 deletions(-) diff --git a/README.MD b/README.MD index 503e482..6f8a7ed 100644 --- a/README.MD +++ b/README.MD @@ -64,6 +64,61 @@ Compared to the original, it is not only more powerful but also supports cross-d --- +## 💻 开发 / Develop + +### Maven 仓库配置 + +在您的 `build.gradle` 中添加以下仓库配置: + +```gradle +repositories { + maven { + name = "LTD Maven" + url = "https://nexus.bot.leisuretimedock.top/repository/maven-public/" + } +} +``` + +### 依赖导入 + +在 `dependencies` 区块中添加 Super Lead Rope 依赖: + +```gradle +dependencies { + compileOnly 'top.r3944realms.superleadrope:superleadrope:版本号:api@jar' + runtimeOnly 'top.r3944realms.superleadrope:superleadrope:版本号' +} +``` + +#### 版本号示例: +```groovy +compileOnly 'top.r3944realms.superleadrope:superleadrope:1.20.1-0.0.0.7:api@jar' +runtimeOnly 'top.r3944realms.superleadrope:superleadrope:1.20.1-0.0.0.7' +``` + +### 使用说明 + +1. **构建项目**:配置完成后即可从仓库中下载并使用本 Mod +2. **源代码文档**:在右侧窗口中点击"下载源代码"即可查看完整的 Javadoc 注解 +3. **API 参考**:详见源代码中的注解文档 + +### 快速开始 + +```groovy +repositories { + maven { + name = "LTD Maven" + url = "https://nexus.bot.leisuretimedock.top/repository/maven-public/" + } +} + +dependencies { + compileOnly 'top.r3944realms.superleadrope:superleadrope:1.20.1-0.0.0.7:api@jar' + runtimeOnly 'top.r3944realms.superleadrope:superleadrope:1.20.1-0.0.0.7' +} +``` + +--- # 📜 License / 许可证 This project is licensed under the **GNU GPL v3** open source license. diff --git a/build.gradle b/build.gradle index 1965159..ae82f2a 100644 --- a/build.gradle +++ b/build.gradle @@ -487,16 +487,29 @@ idea { } } afterEvaluate { - tasks.named('deobfJar') { + // 创建清理任务 + tasks.register('cleanGeneratedJars') { doLast { - def jar = file(layout.buildDirectory.dir("repo") + "${mod_id}-${minecraft_version}-${mod_version}.jar") - if (jar.exists()) ant.delete(jar) + def jars = [ + file("build/libs/${mod_id}-${minecraft_version}-${mod_version}.jar"), + file("build/libs/${mod_id}-${minecraft_version}-${mod_version}-api.jar") + ] + jars.each { jar -> + if (jar.exists()) { + println "Deleting: ${jar.name}" + jar.delete() + } + } } } - tasks.named('apiJar') { - doLast { - def jar = file(layout.buildDirectory.dir("repo") + "${mod_id}-${minecraft_version}-${mod_version}-api.jar") - if (jar.exists()) ant.delete(jar) - } + + // 在 public 任务后执行清理 + tasks.named('publish') { + finalizedBy cleanGeneratedJars + } + + // 或者如果还有其他发布任务 + tasks.named('publishToMavenLocal') { + finalizedBy cleanGeneratedJars } } diff --git a/gradle.properties b/gradle.properties index 3506ee7..0b966bf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -59,7 +59,7 @@ mod_name=Super Lead Rope # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=0.0.0.6-pre10 +mod_version=0.0.0.7 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/generated/resources/.cache/1de3d2ee724999f84a11b20b51c37030049be277 b/src/generated/resources/.cache/1de3d2ee724999f84a11b20b51c37030049be277 index 49a747e..74df684 100644 --- a/src/generated/resources/.cache/1de3d2ee724999f84a11b20b51c37030049be277 +++ b/src/generated/resources/.cache/1de3d2ee724999f84a11b20b51c37030049be277 @@ -1,2 +1,2 @@ -// 1.20.1 2025-09-20T18:20:23.4290773 Languages: zh_tw -0237411659cf392d87e4f866cec642396bc91382 assets/superleadrope/lang/zh_tw.json +// 1.20.1 2025-10-24T23:36:36.156494 Languages: zh_tw +b63c143870a5792603f9967a8044196d59389588 assets/superleadrope/lang/zh_tw.json diff --git a/src/generated/resources/.cache/2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac b/src/generated/resources/.cache/2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac index ab1c085..934ee1e 100644 --- a/src/generated/resources/.cache/2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac +++ b/src/generated/resources/.cache/2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac @@ -1,2 +1,2 @@ -// 1.20.1 2025-09-20T18:20:23.4270438 Languages: zh_cn -c09eff43c9dc28c3fe516d4637ec6302af4c6656 assets/superleadrope/lang/zh_cn.json +// 1.20.1 2025-10-24T23:36:36.1535157 Languages: zh_cn +25e849cfb08702cdfeb426a3ef90b88d7f621d36 assets/superleadrope/lang/zh_cn.json diff --git a/src/generated/resources/.cache/82018c5420b46ddbb7071e62df09fdecd98133e6 b/src/generated/resources/.cache/82018c5420b46ddbb7071e62df09fdecd98133e6 index 5a5434f..a4b0db6 100644 --- a/src/generated/resources/.cache/82018c5420b46ddbb7071e62df09fdecd98133e6 +++ b/src/generated/resources/.cache/82018c5420b46ddbb7071e62df09fdecd98133e6 @@ -1,2 +1,2 @@ -// 1.20.1 2025-09-20T18:15:03.8019547 Languages: lzh -f2ebd8aedd40b511793d238ff726c86f95693613 assets/superleadrope/lang/lzh.json +// 1.20.1 2025-10-24T23:36:36.1554931 Languages: lzh +3c9a7976df8a08b199eb5f9016aff4cbd7632c64 assets/superleadrope/lang/lzh.json diff --git a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 index 051a9e6..2ef4352 100644 --- a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 +++ b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 @@ -1,2 +1,2 @@ -// 1.20.1 2025-09-20T18:20:23.4290773 Languages: en_us -0b7f741121c31dd391168341de47844cd4a5a03c assets/superleadrope/lang/en_us.json +// 1.20.1 2025-10-24T23:36:36.1554931 Languages: en_us +cb4fd115c1067f38c218bdc1ddf3cc06b9f2d8d8 assets/superleadrope/lang/en_us.json diff --git a/src/generated/resources/assets/superleadrope/lang/en_us.json b/src/generated/resources/assets/superleadrope/lang/en_us.json index 30183f6..638cb96 100644 --- a/src/generated/resources/assets/superleadrope/lang/en_us.json +++ b/src/generated/resources/assets/superleadrope/lang/en_us.json @@ -1,8 +1,4 @@ { - "command.leashdata.addApplyEntity.success": "§bAdded leash successfully. §a%s §7→ §e%s", - "command.leashdata.removeApplyEntity.success": "§bRemoved leash successfully. §a%s §7- §e%s", - "command.leashdata.setApplyEntity.success": "§bSet leash property successfully. §a%s §7: §e%s §7= §6%.1f", - "command.leashdata.transfer.success": "§bTransferred leash successfully. §a%s §7→ §e%s §7→ §6%s", "death.attack.eternal_potato_not_complete": "§c%1$s was not the rightful owner, struck by lightning!", "death.attack.eternal_potato_not_owner": "§c%1$s was not the rightful owner, struck by lightning!", "entity.superleadrope.super_lead_knot": "Super Lead Knot", @@ -31,15 +27,66 @@ "sound.superleadrope.subtitle.lead_break": "Lead Break", "sound.superleadrope.subtitle.lead_tied": "Lead Tied", "sound.superleadrope.subtitle.lead_untied": "Lead Untie", - "superleadrope.command.leash.message..get.block": "§7Block: §e%s", - "superleadrope.command.leash.message..get.elastic": "§7Elastic: §6%.1f", - "superleadrope.command.leash.message..get.keep": "§7Keep: §c%d§7/§c%d", - "superleadrope.command.leash.message..get.max": "§7Max: §a%.1f", - "superleadrope.command.leash.message..get.reserved": "§7Reserved: §d%s", - "superleadrope.command.leash.message..get.title": "=== Leash Data for %s ===", - "superleadrope.command.leash.message..get.total": "Total leashes: %d", - "superleadrope.command.leash.message..get.uuid": "§7UUID: §b%s", + "superleadrope.command..block_pos": "§7[§fX: %d, Y: %d, Z: %d§7]", + "superleadrope.command.abbreviation": "...", + "superleadrope.command.colon": ":", + "superleadrope.command.end": ".", + "superleadrope.command.leash.message.add_block.fail": "Failed to attached %s leash from %s to %s.", + "superleadrope.command.leash.message.add_block.fail.no_knot_found": "Unable to tie the towing rope to %s as there is no knot in the position.", + "superleadrope.command.leash.message.add_block.suc": "Successfully attached %s leash from %s to %s", + "superleadrope.command.leash.message.add_block.suc_fail": ", but failed to attached %s leash from %s to %s.", + "superleadrope.command.leash.message.add_holder.fail": "Failed to attached %s leash from %s to %s.", + "superleadrope.command.leash.message.add_holder.suc": "Successfully attached %s leash from %s to %s", + "superleadrope.command.leash.message.add_holder.suc_fail": ", but failed to attached %s leash from %s to %s.", + "superleadrope.command.leash.message.all_holders": "All Holders", + "superleadrope.command.leash.message.all_knots": "All Knots", + "superleadrope.command.leash.message.apply_forces": "Successfully applied force on %s", + "superleadrope.command.leash.message.default": "Default", + "superleadrope.command.leash.message.get.block": "Block", + "superleadrope.command.leash.message.get.elastic": "Elastic Scale", + "superleadrope.command.leash.message.get.entity": "§7[ §l§fEntity §r§7]", + "superleadrope.command.leash.message.get.keep": "Keep Ticks", + "superleadrope.command.leash.message.get.knot": "Knot", + "superleadrope.command.leash.message.get.max": "Max Distance", + "superleadrope.command.leash.message.get.reserved": "Reserved", + "superleadrope.command.leash.message.get.uuid": "UUID", + "superleadrope.command.leash.message.leash_data.head": "LeashData:", + "superleadrope.command.leash.message.leash_data.item": "%s { Holder:%s, BlockPos:%s }", + "superleadrope.command.leash.message.leash_info.head": "LeashInfo:", + "superleadrope.command.leash.message.leash_info.item": "%s { Info: %s }", + "superleadrope.command.leash.message.remove.all_block_leashes": "Successfully removed all holders' leash to %s", + "superleadrope.command.leash.message.remove.all_holder_leashes": "Successfully removed all holders' leash to %s", + "superleadrope.command.leash.message.remove_all_leashes": "Successfully detached all leash from %s", + "superleadrope.command.leash.message.remove_holder.fail": "Failed to detach leash from %s to %s.", + "superleadrope.command.leash.message.remove_holder.suc": "Successfully detached leash from %s to %s", + "superleadrope.command.leash.message.remove_holder.suc_fail": ", but failed to detach leash from %s to %s", + "superleadrope.command.leash.message.remove_knot.fail": "Failed to detach leash from %s to %s.", + "superleadrope.command.leash.message.remove_knot.suc": "Successfully detached leash from %s to %s", + "superleadrope.command.leash.message.remove_knot.suc_fail": ", but failed to detach leash from %s to %s", + "superleadrope.command.leash.message.reset.static.elastic_distance_scale.suc": "Successfully reset the static elastic distance scale of leash from %s", + "superleadrope.command.leash.message.reset.static.max_distance.suc": "Successfully reset the static max distance of leash from %s", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.fail": "Failed to adjust the elastic distance scale of leash from %s to %s", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.suc": "Successfully adjusted the elastic distance scale of leash from %s to %s", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.suc_fail": ", but failed to adjust it from %s to %s", + "superleadrope.command.leash.message.set.block_max_distance.fail": "Failed to adjust the max distance of leash from %s to %s", + "superleadrope.command.leash.message.set.block_max_distance.suc": "Successfully adjusted the max distance of leash from %s to %s", + "superleadrope.command.leash.message.set.block_max_distance.suc_fail": ", but failed to adjust it from %s to %s", + "superleadrope.command.leash.message.set.elastic_distance_scale.fail": "Failed to adjust the elastic distance scale of leash from %s to %s", + "superleadrope.command.leash.message.set.elastic_distance_scale.suc": "Successfully adjusted the elastic distance scale of leash from %s to %s", + "superleadrope.command.leash.message.set.elastic_distance_scale.suc_fail": ", but failed to adjust it from %s to %s", + "superleadrope.command.leash.message.set.max_distance.fail": "Failed to adjust the max distance of leash from %s to %s", + "superleadrope.command.leash.message.set.max_distance.suc": "Successfully adjusted the max distance of leash from %s to %s", + "superleadrope.command.leash.message.set.max_distance.suc_fail": ", but failed to adjust it from %s to %s", + "superleadrope.command.leash.message.set.static.elastic_distance_scale.suc": "Successfully set the static elastic distance scale of leash to %.2f from %s", + "superleadrope.command.leash.message.set.static.max_distance.suc": "Successfully set the static max distance of leash to %.2f from %s", + "superleadrope.command.leash.message.transfer.from_block.fail": "Failed to transfer leash from %s to %s.", + "superleadrope.command.leash.message.transfer.from_block.suc": "Successfully transferred leash from %s to %s", + "superleadrope.command.leash.message.transfer.from_block.suc_fail": ", but failed to transfer leash from %s to %s.", + "superleadrope.command.leash.message.transfer_leash.fail": "Failed to transfer leash from %s to %s.", + "superleadrope.command.leash.message.transfer_leash.suc": "Successfully transferred leash from %s to %s", + "superleadrope.command.leash.message.transfer_leash.suc_fail": ", but failed to transfer leash from %s to %s.", "superleadrope.command.motion.message.adder.successful": "§bAdd Successfully.§a%s§7:§f[§eVec§7:§a(§f%.2f§7,§f%.2f§7,§f%.2f§7)§f]§r", "superleadrope.command.motion.message.multiply.successful": "§bMultiply Successfully.§a%s§7:§f[§eVec§7:§a(§f%.2f§7,§f%.2f§7,§f%.2f§7)§f]§r", - "superleadrope.command.motion.message.setter.successful": "§bSet Successfully.§a%s§7:§f[§eVec§7:§a(§f%.2f§7,§f%.2f§7,§f%.2f§7)§f]§r" + "superleadrope.command.motion.message.setter.successful": "§bSet Successfully.§a%s§7:§f[§eVec§7:§a(§f%.2f§7,§f%.2f§7,§f%.2f§7)§f]§r", + "superleadrope.command.none": "" } \ No newline at end of file diff --git a/src/generated/resources/assets/superleadrope/lang/lzh.json b/src/generated/resources/assets/superleadrope/lang/lzh.json index cdcdfac..9172581 100644 --- a/src/generated/resources/assets/superleadrope/lang/lzh.json +++ b/src/generated/resources/assets/superleadrope/lang/lzh.json @@ -1,8 +1,4 @@ { - "command.leashdata.addApplyEntity.success": "§b繫繩既添. §a%s §7→ §e%s", - "command.leashdata.removeApplyEntity.success": "§b繫繩既除. §a%s §7- §e%s", - "command.leashdata.setApplyEntity.success": "§b繫繩性既定. §a%s §7: §e%s §7= §6%.1f", - "command.leashdata.transfer.success": "§b繫繩既移. §a%s §7→ §e%s §7→ §6%s", "death.attack.eternal_potato_not_complete": "§c%1$s 非汝所主,雷霆降身!", "death.attack.eternal_potato_not_owner": "§c%1$s 非汝所主,雷霆降身!", "entity.superleadrope.super_lead_knot": "神駒羈縻索結", @@ -31,15 +27,66 @@ "sound.superleadrope.subtitle.lead_break": "索絕", "sound.superleadrope.subtitle.lead_tied": "繫索", "sound.superleadrope.subtitle.lead_untied": "解索", - "superleadrope.command.leash.message..get.block": "§7磚石: §e%s", - "superleadrope.command.leash.message..get.elastic": "§7彈距: §6%.1f", - "superleadrope.command.leash.message..get.keep": "§7持時: §c%d§7/§c%d", - "superleadrope.command.leash.message..get.max": "§7極距: §a%.1f", - "superleadrope.command.leash.message..get.reserved": "§7備註: §d%s", - "superleadrope.command.leash.message..get.title": "=== %s 之繫繩數據 ===", - "superleadrope.command.leash.message..get.total": "繫繩總數: %d", - "superleadrope.command.leash.message..get.uuid": "§7UUID: §b%s", + "superleadrope.command..block_pos": "§7[§fX: %d, Y: %d, Z: %d§7]", + "superleadrope.command.abbreviation": "...", + "superleadrope.command.colon": ":", + "superleadrope.command.end": "。", + "superleadrope.command.leash.message.add_block.fail": "%s繩自%s繫於%s之舉未遂", + "superleadrope.command.leash.message.add_block.fail.no_knot_found": "%s處無結,拴繩難繫", + "superleadrope.command.leash.message.add_block.suc": "%s繩自%s繫於%s,其事已成", + "superleadrope.command.leash.message.add_block.suc_fail": ",然%s繩自%s繫於%s未竟", + "superleadrope.command.leash.message.add_holder.fail": "%s繩自%s繫於%s之舉未遂", + "superleadrope.command.leash.message.add_holder.suc": "%s繩自%s繫於%s,其事已成", + "superleadrope.command.leash.message.add_holder.suc_fail": ",然%s繩自%s繫於%s未竟", + "superleadrope.command.leash.message.all_holders": "諸持者", + "superleadrope.command.leash.message.all_knots": "諸結", + "superleadrope.command.leash.message.apply_forces": "%s之力,今已發", + "superleadrope.command.leash.message.default": "原值", + "superleadrope.command.leash.message.get.block": "磚石", + "superleadrope.command.leash.message.get.elastic": "彈距度", + "superleadrope.command.leash.message.get.entity": "§7[ §l§f實者 §r§7]", + "superleadrope.command.leash.message.get.keep": "持時", + "superleadrope.command.leash.message.get.knot": "§7[ §l§f結 §r§7]", + "superleadrope.command.leash.message.get.max": "極距", + "superleadrope.command.leash.message.get.reserved": "備註", + "superleadrope.command.leash.message.get.uuid": "UUID", + "superleadrope.command.leash.message.leash_data.head": "繫繩錄:", + "superleadrope.command.leash.message.leash_data.item": "%s { 持者: %s, 位: %s }", + "superleadrope.command.leash.message.leash_info.head": "繫繩訊:", + "superleadrope.command.leash.message.leash_info.item": "%s { 訊: %s }", + "superleadrope.command.leash.message.remove.all_block_leashes": "%s之所有羈絆,今已盡釋", + "superleadrope.command.leash.message.remove.all_holder_leashes": "%s之所有繫繩,今已盡除", + "superleadrope.command.leash.message.remove_all_leashes": "%s之諸拴繩,今盡解", + "superleadrope.command.leash.message.remove_holder.fail": "%s至%s之拴繩,今已解", + "superleadrope.command.leash.message.remove_holder.suc": "%s至%s之拴繩,今已解", + "superleadrope.command.leash.message.remove_holder.suc_fail": "%s至%s之拴繩未除", + "superleadrope.command.leash.message.remove_knot.fail": "%s之諸拴繩,今盡解", + "superleadrope.command.leash.message.remove_knot.suc": ",然%s至%s之拴繩未解", + "superleadrope.command.leash.message.remove_knot.suc_fail": "%s至%s之拴繩未除", + "superleadrope.command.leash.message.reset.static.elastic_distance_scale.suc": "%s之全域伸縮比例,今已復初", + "superleadrope.command.leash.message.reset.static.max_distance.suc": "%s之全域極距,今已復初", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.fail": "繩距伸縮比例自%s易為%s之舉未遂", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.suc": "%s至%s之拴繩伸縮比例,今已定", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.suc_fail": ",然%s至%s之拴繩伸縮比例未定", + "superleadrope.command.leash.message.set.block_max_distance.fail": "%s至%s之拴繩極距未成", + "superleadrope.command.leash.message.set.block_max_distance.suc": "%s至%s之拴繩極距,今已定", + "superleadrope.command.leash.message.set.block_max_distance.suc_fail": ",然%s至%s之拴繩極距未定", + "superleadrope.command.leash.message.set.elastic_distance_scale.fail": "%s至%s之拴繩伸縮比例未成", + "superleadrope.command.leash.message.set.elastic_distance_scale.suc": "%s至%s之拴繩伸縮比例,今已定", + "superleadrope.command.leash.message.set.elastic_distance_scale.suc_fail": ",然%s至%s之拴繩伸縮比例未定", + "superleadrope.command.leash.message.set.max_distance.fail": "%s至%s之拴繩極距未成", + "superleadrope.command.leash.message.set.max_distance.suc": "%s至%s之拴繩極距,今已定", + "superleadrope.command.leash.message.set.max_distance.suc_fail": ",然%s至%s之拴繩極距未定", + "superleadrope.command.leash.message.set.static.elastic_distance_scale.suc": "繩距彈性比例定為%.2f,已立%s之全域伸縮度", + "superleadrope.command.leash.message.set.static.max_distance.suc": "繩距定為%.2f,已立%s之全域極距", + "superleadrope.command.leash.message.transfer.from_block.fail": "繫繩自%s遷於%s之舉未遂", + "superleadrope.command.leash.message.transfer.from_block.suc": "繫繩自%s移至%s,其事已成", + "superleadrope.command.leash.message.transfer.from_block.suc_fail": ",然自%s至%s之遷移未竟", + "superleadrope.command.leash.message.transfer_leash.fail": "拴繩自%s遷於%s之舉未遂", + "superleadrope.command.leash.message.transfer_leash.suc": "拴繩自%s移至%s,其事已成", + "superleadrope.command.leash.message.transfer_leash.suc_fail": ",然自%s至%s之遷移未竟", "superleadrope.command.motion.message.adder.successful": "§b增益既成.§a%s§7:§f[§e速勢§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r", "superleadrope.command.motion.message.multiply.successful": "§b倍乘既成.§a%s§7:§f[§e速勢§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r", - "superleadrope.command.motion.message.setter.successful": "§b定值既成.§a%s§7:§f[§e速勢§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r" + "superleadrope.command.motion.message.setter.successful": "§b定值既成.§a%s§7:§f[§e速勢§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r", + "superleadrope.command.none": "無" } \ No newline at end of file diff --git a/src/generated/resources/assets/superleadrope/lang/zh_cn.json b/src/generated/resources/assets/superleadrope/lang/zh_cn.json index ecaa453..6c70782 100644 --- a/src/generated/resources/assets/superleadrope/lang/zh_cn.json +++ b/src/generated/resources/assets/superleadrope/lang/zh_cn.json @@ -1,8 +1,4 @@ { - "command.leashdata.addApplyEntity.success": "§b添加拴绳成功. §a%s §7→ §e%s", - "command.leashdata.removeApplyEntity.success": "§b移除拴绳成功. §a%s §7- §e%s", - "command.leashdata.setApplyEntity.success": "§b设置拴绳属性成功. §a%s §7: §e%s §7= §6%.1f", - "command.leashdata.transfer.success": "§b转移拴绳成功. §a%s §7→ §e%s §7→ §6%s", "death.attack.eternal_potato_not_complete": "§c%1$s 因使用非自己绑定物品,受到闪电惩罚!", "death.attack.eternal_potato_not_owner": "§c%1$s 因使用非自己绑定物品,受到闪电惩罚!", "entity.superleadrope.super_lead_knot": "超级拴绳结", @@ -31,15 +27,66 @@ "sound.superleadrope.subtitle.lead_break": "拴绳断裂", "sound.superleadrope.subtitle.lead_tied": "拴绳系上", "sound.superleadrope.subtitle.lead_untied": "拴绳解开", - "superleadrope.command.leash.message..get.block": "§7方块: §e%s", - "superleadrope.command.leash.message..get.elastic": "§7弹性距离: §6%.1f", - "superleadrope.command.leash.message..get.keep": "§7保持: §c%d§7/§c%d", - "superleadrope.command.leash.message..get.max": "§7最大距离: §a%.1f", - "superleadrope.command.leash.message..get.reserved": "§7保留字段: §d%s", - "superleadrope.command.leash.message..get.title": "=== %s 的拴绳数据 ===", - "superleadrope.command.leash.message..get.total": "总拴绳数: %d", - "superleadrope.command.leash.message..get.uuid": "§7UUID: §b%s", + "superleadrope.command..block_pos": "§7[§fX: %d, Y: %d, Z: %d§7]", + "superleadrope.command.abbreviation": "...", + "superleadrope.command.colon": ":", + "superleadrope.command.end": "。", + "superleadrope.command.leash.message.add_block.fail": "未能将%s拴绳从%s连接到%s", + "superleadrope.command.leash.message.add_block.fail.no_knot_found": "无法将拴绳系到%s,因为该位置没有绳结", + "superleadrope.command.leash.message.add_block.suc": "成功将%s拴绳从%s连接到%s", + "superleadrope.command.leash.message.add_block.suc_fail": ",但未能将%s拴绳从%s连接到%s", + "superleadrope.command.leash.message.add_holder.fail": "未能将%s拴绳从%s连接到%s", + "superleadrope.command.leash.message.add_holder.suc": "成功将%s拴绳从%s连接到%s", + "superleadrope.command.leash.message.add_holder.suc_fail": ",但未能将%s拴绳从%s连接到%s", + "superleadrope.command.leash.message.all_holders": "所有持有者", + "superleadrope.command.leash.message.all_knots": "所有绳结", + "superleadrope.command.leash.message.apply_forces": "成功触发%s的力", + "superleadrope.command.leash.message.default": "默认值", + "superleadrope.command.leash.message.get.block": "方块", + "superleadrope.command.leash.message.get.elastic": "弹性尺度", + "superleadrope.command.leash.message.get.entity": "§7[ §l§f实体 §r§7]", + "superleadrope.command.leash.message.get.keep": "保持刻", + "superleadrope.command.leash.message.get.knot": "§7[ §l§f绳结 §r§7]", + "superleadrope.command.leash.message.get.max": "最大距离", + "superleadrope.command.leash.message.get.reserved": "保留字段", + "superleadrope.command.leash.message.get.uuid": "UUID", + "superleadrope.command.leash.message.leash_data.head": "拴绳数据:", + "superleadrope.command.leash.message.leash_data.item": "%s { 持有者: %s, 坐标: %s }", + "superleadrope.command.leash.message.leash_info.head": "拴绳信息:", + "superleadrope.command.leash.message.leash_info.item": "%s { 信息: %s }", + "superleadrope.command.leash.message.remove.all_block_leashes": "已成功移除所有持有者对%s的牵引", + "superleadrope.command.leash.message.remove.all_holder_leashes": "已成功移除所有持有者对%s的牵引", + "superleadrope.command.leash.message.remove_all_leashes": "成功解除%s的所有拴绳连接", + "superleadrope.command.leash.message.remove_holder.fail": "成功解除%s到%s的拴绳连接", + "superleadrope.command.leash.message.remove_holder.suc": "成功解除%s到%s的拴绳连接", + "superleadrope.command.leash.message.remove_holder.suc_fail": "未能解除%s到%s的拴绳连接", + "superleadrope.command.leash.message.remove_knot.fail": "成功解除%s的所有拴绳连接", + "superleadrope.command.leash.message.remove_knot.suc": ",但未能解除%s到%s的拴绳连接", + "superleadrope.command.leash.message.remove_knot.suc_fail": "未能解除%s到%s的拴绳连接", + "superleadrope.command.leash.message.reset.static.elastic_distance_scale.suc": "成功重置%s的全局弹性距离比例", + "superleadrope.command.leash.message.reset.static.max_distance.suc": "已成功重置%s的全局最大距离", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.fail": "未能调整%s到%s的拴绳弹性距离比例", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.suc": "成功调整%s到%s的拴绳弹性距离比例", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.suc_fail": ",但未能调整%s到%s的拴绳弹性距离比例", + "superleadrope.command.leash.message.set.block_max_distance.fail": "未能调整%s到%s的拴绳最大距离", + "superleadrope.command.leash.message.set.block_max_distance.suc": "成功调整%s到%s的拴绳最大距离", + "superleadrope.command.leash.message.set.block_max_distance.suc_fail": ",但未能调整%s到%s的拴绳最大距离", + "superleadrope.command.leash.message.set.elastic_distance_scale.fail": "未能调整%s到%s的拴绳弹性距离比例", + "superleadrope.command.leash.message.set.elastic_distance_scale.suc": "成功调整%s到%s的拴绳弹性距离比例", + "superleadrope.command.leash.message.set.elastic_distance_scale.suc_fail": ",但未能调整%s到%s的拴绳弹性距离比例", + "superleadrope.command.leash.message.set.max_distance.fail": "未能调整%s到%s的拴绳最大距离", + "superleadrope.command.leash.message.set.max_distance.suc": "成功调整%s到%s的拴绳最大距离", + "superleadrope.command.leash.message.set.max_distance.suc_fail": ",但未能调整%s到%s的拴绳最大距离", + "superleadrope.command.leash.message.set.static.elastic_distance_scale.suc": "已成功设置%.2f为%s的全局弹性距离比例", + "superleadrope.command.leash.message.set.static.max_distance.suc": "已成功设置%.2f为%s的全局最大距离", + "superleadrope.command.leash.message.transfer.from_block.fail": "未能将牵引从%s转移至%s", + "superleadrope.command.leash.message.transfer.from_block.suc": "已成功将牵引从%s转移至%s", + "superleadrope.command.leash.message.transfer.from_block.suc_fail": ",但未能将牵引从%s转移至%s", + "superleadrope.command.leash.message.transfer_leash.fail": "未能将拴绳从%s转移至%s", + "superleadrope.command.leash.message.transfer_leash.suc": "成功将拴绳从%s转移至%s", + "superleadrope.command.leash.message.transfer_leash.suc_fail": ",但未能将拴绳从%s转移至%s", "superleadrope.command.motion.message.adder.successful": "§b添加成功.§a%s§7:§f[§e加速§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r", "superleadrope.command.motion.message.multiply.successful": "§b倍乘成功.§a%s§7:§f[§e加速§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r", - "superleadrope.command.motion.message.setter.successful": "§b设置成功.§a%s§7:§f[§e加速§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r" + "superleadrope.command.motion.message.setter.successful": "§b设置成功.§a%s§7:§f[§e加速§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r", + "superleadrope.command.none": "无" } \ No newline at end of file diff --git a/src/generated/resources/assets/superleadrope/lang/zh_tw.json b/src/generated/resources/assets/superleadrope/lang/zh_tw.json index f2863c0..c3fe847 100644 --- a/src/generated/resources/assets/superleadrope/lang/zh_tw.json +++ b/src/generated/resources/assets/superleadrope/lang/zh_tw.json @@ -1,8 +1,4 @@ { - "command.leashdata.addApplyEntity.success": "§b添加拴繩成功. §a%s §7→ §e%s", - "command.leashdata.removeApplyEntity.success": "§b移除拴繩成功. §a%s §7- §e%s", - "command.leashdata.setApplyEntity.success": "§b設置拴繩屬性成功. §a%s §7: §e%s §7= §6%.1f", - "command.leashdata.transfer.success": "§b轉移拴繩成功. §a%s §7→ §e%s §7→ §6%s", "death.attack.eternal_potato_not_complete": "§c%1$s 因使用非自己綁定物品,受到閃電懲罰!", "death.attack.eternal_potato_not_owner": "§c%1$s 因使用非自己綁定物品,受到閃電懲罰!", "entity.superleadrope.super_lead_knot": "超級拴繩結", @@ -31,15 +27,66 @@ "sound.superleadrope.subtitle.lead_break": "拴繩斷裂", "sound.superleadrope.subtitle.lead_tied": "拴繩係上", "sound.superleadrope.subtitle.lead_untied": "拴繩解開", - "superleadrope.command.leash.message..get.block": "§7方塊: §e%s", - "superleadrope.command.leash.message..get.elastic": "§7彈性距離: §6%.1f", - "superleadrope.command.leash.message..get.keep": "§7保持: §c%d§7/§c%d", - "superleadrope.command.leash.message..get.max": "§7最大距離: §a%.1f", - "superleadrope.command.leash.message..get.reserved": "§7保留字段: §d%s", - "superleadrope.command.leash.message..get.title": "=== %s 的拴繩數據 ===", - "superleadrope.command.leash.message..get.total": "總拴繩數: %d", - "superleadrope.command.leash.message..get.uuid": "§7UUID: §b%s", + "superleadrope.command..block_pos": "§7[§fX: %d, Y: %d, Z: %d§7]", + "superleadrope.command.abbreviation": "...", + "superleadrope.command.colon": ":", + "superleadrope.command.end": "。", + "superleadrope.command.leash.message.add_block.fail": "未能將%s拴繩從%s連接到%s", + "superleadrope.command.leash.message.add_block.fail.no_knot_found": "無法將拴繩繫到%s,因為該位置沒有繩結", + "superleadrope.command.leash.message.add_block.suc": "成功將%s拴繩從%s連接到%s", + "superleadrope.command.leash.message.add_block.suc_fail": ",但未能將%s拴繩從%s連接到%s", + "superleadrope.command.leash.message.add_holder.fail": "未能將%s拴繩從%s連接到%s", + "superleadrope.command.leash.message.add_holder.suc": "成功將%s拴繩從%s連接到%s", + "superleadrope.command.leash.message.add_holder.suc_fail": ",但未能將%s拴繩從%s連接到%s", + "superleadrope.command.leash.message.all_holders": "所有持有者", + "superleadrope.command.leash.message.all_knots": "所有繩結", + "superleadrope.command.leash.message.apply_forces": "成功觸發%s的力", + "superleadrope.command.leash.message.default": "默認值", + "superleadrope.command.leash.message.get.block": "方塊", + "superleadrope.command.leash.message.get.elastic": "彈性尺度", + "superleadrope.command.leash.message.get.entity": "§7[ §l§f實體 §r§7]", + "superleadrope.command.leash.message.get.keep": "保持刻", + "superleadrope.command.leash.message.get.knot": "§7[ §l§f繩結 §r§7]", + "superleadrope.command.leash.message.get.max": "最大距離", + "superleadrope.command.leash.message.get.reserved": "保留字段", + "superleadrope.command.leash.message.get.uuid": "UUID", + "superleadrope.command.leash.message.leash_data.head": "拴繩數據:", + "superleadrope.command.leash.message.leash_data.item": "%s { 持有者: %s, 座標: %s }", + "superleadrope.command.leash.message.leash_info.head": "拴繩資訊:", + "superleadrope.command.leash.message.leash_info.item": "%s { 資訊: %s }", + "superleadrope.command.leash.message.remove.all_block_leashes": "已成功移除所有持有者對%s的牽引", + "superleadrope.command.leash.message.remove.all_holder_leashes": "已成功移除所有持有者對%s的牽引", + "superleadrope.command.leash.message.remove_all_leashes": "成功解除%s的所有拴繩連接", + "superleadrope.command.leash.message.remove_holder.fail": "成功解除%s到%s的拴繩連接", + "superleadrope.command.leash.message.remove_holder.suc": "成功解除%s到%s的拴繩連接", + "superleadrope.command.leash.message.remove_holder.suc_fail": "未能解除%s到%s的拴繩連接", + "superleadrope.command.leash.message.remove_knot.fail": "成功解除%s的所有拴繩連接", + "superleadrope.command.leash.message.remove_knot.suc": ",但未能解除%s到%s的拴繩連接", + "superleadrope.command.leash.message.remove_knot.suc_fail": "未能解除%s到%s的拴繩連接", + "superleadrope.command.leash.message.reset.static.elastic_distance_scale.suc": "成功重置%s的全域彈性距離比例", + "superleadrope.command.leash.message.reset.static.max_distance.suc": "已成功重置%s的全域最大距離", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.fail": "未能%s調整為拴繩彈性距離比例從%s", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.suc": "成功調整%s到%s的拴繩彈性距離比例", + "superleadrope.command.leash.message.set.block_elastic_distance_scale.suc_fail": ",但未能調整%s到%s的拴繩彈性距離比例", + "superleadrope.command.leash.message.set.block_max_distance.fail": "未能調整%s到%s的拴繩最大距離", + "superleadrope.command.leash.message.set.block_max_distance.suc": "成功調整%s到%s的拴繩最大距離", + "superleadrope.command.leash.message.set.block_max_distance.suc_fail": ",但未能調整%s到%s的拴繩最大距離", + "superleadrope.command.leash.message.set.elastic_distance_scale.fail": "未能調整%s到%s的拴繩彈性距離比例", + "superleadrope.command.leash.message.set.elastic_distance_scale.suc": "成功調整%s到%s的拴繩彈性距離比例", + "superleadrope.command.leash.message.set.elastic_distance_scale.suc_fail": ",但未能調整%s到%s的拴繩彈性距離比例", + "superleadrope.command.leash.message.set.max_distance.fail": "未能調整%s到%s的拴繩最大距離", + "superleadrope.command.leash.message.set.max_distance.suc": "成功調整%s到%s的拴繩最大距離", + "superleadrope.command.leash.message.set.max_distance.suc_fail": ",但未能調整%s到%s的拴繩最大距離", + "superleadrope.command.leash.message.set.static.elastic_distance_scale.suc": "已成功設定%.2f為%s的全域彈性距離比例", + "superleadrope.command.leash.message.set.static.max_distance.suc": "已成功設定%.2f為%s的全域最大距離", + "superleadrope.command.leash.message.transfer.from_block.fail": "未能將牽引從%s轉移至%s", + "superleadrope.command.leash.message.transfer.from_block.suc": "已成功將牽引從%s轉移至%s", + "superleadrope.command.leash.message.transfer.from_block.suc_fail": ",但未能將牽引從%s轉移至%s", + "superleadrope.command.leash.message.transfer_leash.fail": "未能將拴繩從%s轉移至%s", + "superleadrope.command.leash.message.transfer_leash.suc": "成功將拴繩從%s轉移至%s", + "superleadrope.command.leash.message.transfer_leash.suc_fail": ",但未能將拴繩從%s轉移至%s", "superleadrope.command.motion.message.adder.successful": "§b添加成功.§a%s§7:§f[§e加速§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r", "superleadrope.command.motion.message.multiply.successful": "§b倍乘成功.§a%s§7:§f[§e加速§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r", - "superleadrope.command.motion.message.setter.successful": "§b設置成功.§a%s§7:§f[§e加速§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r" + "superleadrope.command.motion.message.setter.successful": "§b設置成功.§a%s§7:§f[§e加速§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r", + "superleadrope.command.none": "無" } \ No newline at end of file diff --git a/src/main/java/top/r3944realms/superleadrope/content/capability/impi/LeashDataImpl.java b/src/main/java/top/r3944realms/superleadrope/content/capability/impi/LeashDataImpl.java index e449369..1e16da3 100644 --- a/src/main/java/top/r3944realms/superleadrope/content/capability/impi/LeashDataImpl.java +++ b/src/main/java/top/r3944realms/superleadrope/content/capability/impi/LeashDataImpl.java @@ -289,6 +289,7 @@ public class LeashDataImpl implements ILeashData { @Override public boolean addLeash(Entity holder, Double maxDistance, Double elasticDistanceScale, int maxKeepLeashTicks, String reserved) { + if(holder == entity) return false; boolean isSuperKnot = holder instanceof SuperLeashKnotEntity; if ((!isSuperKnot && leashHolders.containsKey(holder.getUUID())) || (isSuperKnot && leashKnots.containsKey(((SuperLeashKnotEntity) holder).getPos()))) { diff --git a/src/main/java/top/r3944realms/superleadrope/content/command/Command.java b/src/main/java/top/r3944realms/superleadrope/content/command/Command.java index 8530b19..81c1a91 100644 --- a/src/main/java/top/r3944realms/superleadrope/content/command/Command.java +++ b/src/main/java/top/r3944realms/superleadrope/content/command/Command.java @@ -67,13 +67,14 @@ public class Command { /** * The constant COLON. */ - public static final String COLON = BASE_ + ".colon"; + public static final String COLON = BASE_ + "colon"; /** * The constant MAX_SHOW_NUMBER. */ public static final int MAX_SHOW_NUMBER = 4; - + public static final String END = BASE_ + "end"; + public static final String NONE = BASE_ + "none"; /** * Gets slp name. * @@ -85,7 +86,7 @@ public class Command { BlockPos pos = superLeashKnot.getPos(); return Component.translatable(BLOCK_POS, pos.getX(), pos.getY(), pos.getZ()); } - return entity.getName(); + return entity.getDisplayName(); } /** diff --git a/src/main/java/top/r3944realms/superleadrope/content/command/LeashDataCommand.java b/src/main/java/top/r3944realms/superleadrope/content/command/LeashDataCommand.java index 732bb45..45797fe 100644 --- a/src/main/java/top/r3944realms/superleadrope/content/command/LeashDataCommand.java +++ b/src/main/java/top/r3944realms/superleadrope/content/command/LeashDataCommand.java @@ -30,6 +30,7 @@ import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; import net.minecraft.commands.arguments.selector.EntitySelector; import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.MutableComponent; @@ -44,10 +45,7 @@ import top.r3944realms.superleadrope.content.gamerule.server.CreateSuperLeashKno import top.r3944realms.superleadrope.core.register.SLPGameruleRegistry; import top.r3944realms.superleadrope.util.capability.LeashDataInnerAPI; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import static top.r3944realms.superleadrope.content.command.Command.*; @@ -189,7 +187,7 @@ public class LeashDataCommand { .then(Commands.literal("holders") .executes(LeashDataCommand::removeAllHolderLeashes) ) - .then(Commands.literal("blocks") + .then(Commands.literal("knots") .executes(LeashDataCommand::removeAllBlockLeashes) ) ); @@ -235,10 +233,57 @@ public class LeashDataCommand { ) ) ) + .then(Commands.literal("toBlock") + .then(Commands.argument("toPos", BlockPosArgument.blockPos()) + .executes(context -> transferFromBlock( + context, + BlockPosArgument.getBlockPos(context, "fromPos"), + BlockPosArgument.getBlockPos(context, "toPos") + ) + ) + .then(Commands.argument("reserved", StringArgumentType.string()) + .executes(context -> transferFromBlock( + context, + BlockPosArgument.getBlockPos(context, "fromPos"), + BlockPosArgument.getBlockPos(context, "toPos"), + StringArgumentType.getString(context, "reserved") + ) + ) + ) + ) + ) + ) + ) + ); + LiteralArgumentBuilder $$$set$staic = Commands.literal("static") + .then(Commands.literal("maxDistance") + .then(Commands.literal("reset").executes( + LeashDataCommand::resetStaticMaxDistance + )) + .then(Commands.argument("value", DoubleArgumentType.doubleArg(LeashConfigManager.MAX_DISTANCE_MIN_VALUE, LeashConfigManager.MAX_DISTANCE_MAX_VALUE)) + .executes( + context -> setStaticMaxDistance( + context, + DoubleArgumentType.getDouble(context, "value") + ) + ) + ) + ) + .then(Commands.literal("elasticDistanceScale") + .then(Commands.literal("reset") + .then(Commands.literal("reset").executes( + LeashDataCommand::resetStaticElasticDistanceScale + )) + ) + .then(Commands.argument("value", DoubleArgumentType.doubleArg(LeashConfigManager.ELASTIC_DISTANCE_MIN_VALUE, LeashConfigManager.ELASTIC_DISTANCE_MAX_VALUE)) + .executes( + context -> setStaticElasticDistanceScale( + context, + DoubleArgumentType.getDouble(context, "value") + ) ) ) ); - LiteralArgumentBuilder $$$set$holder = Commands.literal("entity") // 设置最大距离 .then(Commands.literal("maxDistance") @@ -403,7 +448,8 @@ public class LeashDataCommand { .then($$$set$holder) // 方块拴绳设置 - .then($$$set$pos).executes(LeashDataCommand::setBlockMaxDistance) + .then($$$set$pos) + .then($$$set$staic) ); LiteralArgumentBuilder $$$applayForces = Commands.literal("applyForces") .then(Commands.argument("targets", EntityArgument.entities()) @@ -445,6 +491,98 @@ public class LeashDataCommand { } } + public static final String RESET_STATIC_MAX_DISTANCE_ = SLP_LEASH_MESSAGE_ + "reset.static.max_distance."; + public static final String RESET_STATIC_MAX_DISTANCE_SUC = RESET_STATIC_MAX_DISTANCE_ + SUC; + private static int resetStaticMaxDistance(CommandContext context) throws CommandSyntaxException { + Collection targets = EntityArgument.getEntities(context, "targets"); + CommandSourceStack source = context.getSource(); + AtomicInteger success = new AtomicInteger(-1); + + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER]; + for (Entity target : targets) { + LeashDataInnerAPI.PropertyOperations.setStaticMaxDistance(target, null); + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } + MutableComponent successEntitiesComponent = Component.empty(); + generateEntityComponent(sucEntities, success.get(), successEntitiesComponent); + MutableComponent send = Component.empty(); + // Successfully reset the static max distance of leash from %s[if more than 4 items, display in abbreviated form] + send.append(Component.translatable(RESET_STATIC_MAX_DISTANCE_SUC, successEntitiesComponent)); + source.sendSuccess(() -> send, true); + return 0; + } + + public static final String SET_STATIC_MAX_DISTANCE_ = SLP_LEASH_MESSAGE_ + "set.static.max_distance."; + public static final String SET_STATIC_MAX_DISTANCE_SUC = SET_STATIC_MAX_DISTANCE_ + SUC; + private static int setStaticMaxDistance(CommandContext context, double value) throws CommandSyntaxException { + Collection targets = EntityArgument.getEntities(context, "targets"); + CommandSourceStack source = context.getSource(); + AtomicInteger success = new AtomicInteger(-1); + + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER]; + for (Entity target : targets) { + LeashDataInnerAPI.PropertyOperations.setStaticMaxDistance(target, value); + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } + MutableComponent successEntitiesComponent = Component.empty(); + generateEntityComponent(sucEntities, success.get(), successEntitiesComponent); + MutableComponent send = Component.empty(); + // Successfully set the max distance scale of leash to %.2f from %s[if more than 4 items, display in abbreviated form] + send.append(Component.translatable(SET_STATIC_MAX_DISTANCE_SUC, value, successEntitiesComponent)); + source.sendSuccess(() -> send, true); + return 0; + } + + public static final String SET_STATIC_ELASTIC_DISTANCE_SCALE_ = SLP_LEASH_MESSAGE_ + "set.static.elastic_distance_scale."; + public static final String SET_STATIC_ELASTIC_DISTANCE_SCALE_SUC = SET_STATIC_ELASTIC_DISTANCE_SCALE_ + SUC; + private static int setStaticElasticDistanceScale(CommandContext context, double value) throws CommandSyntaxException { + Collection targets = EntityArgument.getEntities(context, "targets"); + CommandSourceStack source = context.getSource(); + AtomicInteger success = new AtomicInteger(-1); + + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER]; + for (Entity target : targets) { + LeashDataInnerAPI.PropertyOperations.setStaticMaxDistance(target, value); + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } + MutableComponent successEntitiesComponent = Component.empty(); + generateEntityComponent(sucEntities, success.get(), successEntitiesComponent); + MutableComponent send = Component.empty(); + // Successfully set the static elastic distance scale of leash to %.2f from %s[if more than 4 items, display in abbreviated form] + send.append(Component.translatable(SET_STATIC_ELASTIC_DISTANCE_SCALE_SUC, value, successEntitiesComponent)); + source.sendSuccess(() -> send, true); + return 0; + } + + public static final String RESET_STATIC_ELASTIC_DISTANCE_SCALE_ = SLP_LEASH_MESSAGE_ + "reset.static.elastic_distance_scale."; + public static final String RESET_STATIC_ELASTIC_DISTANCE_SCALE_SUC = RESET_STATIC_ELASTIC_DISTANCE_SCALE_ + SUC; + private static int resetStaticElasticDistanceScale(CommandContext context) throws CommandSyntaxException { + Collection targets = EntityArgument.getEntities(context, "targets"); + CommandSourceStack source = context.getSource(); + AtomicInteger success = new AtomicInteger(-1); + + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER]; + for (Entity target : targets) { + LeashDataInnerAPI.PropertyOperations.setStaticMaxDistance(target, null); + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } + MutableComponent successEntitiesComponent = Component.empty(); + generateEntityComponent(sucEntities, success.get(), successEntitiesComponent); + MutableComponent send = Component.empty(); + // Successfully reset the static elastic distance scale of leash from %s[if more than 4 items, display in abbreviated form] + send.append(Component.translatable(RESET_STATIC_ELASTIC_DISTANCE_SCALE_SUC, successEntitiesComponent)); + source.sendSuccess(() -> send, true); + return 0; + } + private static int setMaxDistance(CommandContext context) throws CommandSyntaxException { return setMaxDistance(context, null); @@ -523,9 +661,9 @@ public class LeashDataCommand { send.append(Component.translatable(SET_MAX_DISTANCE_SUC, successEntitiesComponent, holder == null ? Component.translatable(ALL_HOLDERS) : Command.getSLPName(holder))); if (failure.get() >= 0) { // , but failed to adjust it from %s[if more than 4 items, display in abbreviated form] to %s - send.append(Component.translatable(SET_MAX_DISTANCE_SUC_FAIL, failureEntitiesComponent, holder == null ? Component.translatable(ALL_HOLDERS) : Command.getSLPName(holder))); + send.append("\n").append(Component.translatable(SET_MAX_DISTANCE_SUC_FAIL, failureEntitiesComponent, holder == null ? Component.translatable(ALL_HOLDERS) : Command.getSLPName(holder))); } //. - else send.append("."); + else send.append(Component.translatable(END)); } else { // Failed to adjust the max distance of leash from %s[if more than 4 items, display in abbreviated form] to %s send.append(Component.translatable(SET_MAX_DISTANCE_FAIL, failureEntitiesComponent, holder == null ? Component.translatable(ALL_KNOTS) : Command.getSLPName(holder))); @@ -585,6 +723,14 @@ public class LeashDataCommand { return transferFromBlock(context, fromPos, to, null); } + private static int transferFromBlock(CommandContext context, BlockPos fromPos, BlockPos toPos) throws CommandSyntaxException { + return transferFromBlock(context, fromPos, new SuperLeashKnotEntity(context.getSource().getLevel(), toPos), null); + } + + private static int transferFromBlock(CommandContext context, BlockPos fromPos, BlockPos toPos, @Nullable String reserved) throws CommandSyntaxException { + return transferFromBlock(context, fromPos, new SuperLeashKnotEntity(context.getSource().getLevel(), toPos), reserved); + } + /** * The constant TRANSFER_FROM_BLOCK. */ @@ -601,6 +747,7 @@ public class LeashDataCommand { * The constant TRANSFER_FROM_BLOCK_FAIL. */ public static final String TRANSFER_FROM_BLOCK_FAIL = TRANSFER_FROM_BLOCK_ + FAIL; + private static int transferFromBlock(CommandContext context, BlockPos fromPos, Entity to, @Nullable String reserved) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); CommandSourceStack source = context.getSource(); @@ -627,9 +774,9 @@ public class LeashDataCommand { send.append(Component.translatable(TRANSFER_FROM_BLOCK_SUC, Command.getSLPName(fromPos), Command.getSLPName(to), successEntitiesComponent)); if (failure >= 0) { // , but failed to transfer leash from %s to %s [Leashed: [if more than 4 items, display in abbreviated form]]. - send.append(Component.translatable(TRANSFER_FROM_BLOCK_SUC_FAIL, Command.getSLPName(fromPos), Command.getSLPName(to), failureEntitiesComponent)); + send.append("\n").append(Component.translatable(TRANSFER_FROM_BLOCK_SUC_FAIL, Command.getSLPName(fromPos), Command.getSLPName(to), failureEntitiesComponent)); } //. - else send.append("."); + else send.append(Component.translatable(END)); } else { // Failed to transfer leash from %s to %s [Leashed: [if more than 4 items, display in abbreviated form]]. send.append(Component.translatable(TRANSFER_FROM_BLOCK_FAIL, Command.getSLPName(fromPos), Command.getSLPName(to), failureEntitiesComponent)); @@ -717,9 +864,9 @@ public class LeashDataCommand { send.append(Component.translatable(SET_ELASTIC_DISTANCE_SCALE_SUC, successEntitiesComponent, holder == null ? Component.translatable(ALL_HOLDERS) : Command.getSLPName(holder))); if (failure.get() >= 0) { // , but failed to adjust it from %s[if more than 4 items, display in abbreviated form] to %s - send.append(Component.translatable(SET_ELASTIC_DISTANCE_SCALE_SUC_FAIL, failureEntitiesComponent, holder == null ? Component.translatable(ALL_HOLDERS) : Command.getSLPName(holder))); + send.append("\n").append(Component.translatable(SET_ELASTIC_DISTANCE_SCALE_SUC_FAIL, failureEntitiesComponent, holder == null ? Component.translatable(ALL_HOLDERS) : Command.getSLPName(holder))); } //. - else send.append("."); + else send.append(Component.translatable(END)); } else { // Failed to adjust the elastic distance scale of leash from %s[if more than 4 items, display in abbreviated form] to %s send.append(Component.translatable(SET_ELASTIC_DISTANCE_SCALE_FAIL, failureEntitiesComponent, holder == null ? Component.translatable(ALL_HOLDERS) : Command.getSLPName(holder))); @@ -806,9 +953,9 @@ public class LeashDataCommand { send.append(Component.translatable(SET_BLOCK_MAX_DISTANCE_SUC, successEntitiesComponent, blockPos == null ? Component.translatable(ALL_KNOTS) : Command.getSLPName(blockPos))); if (failure.get() >= 0) { // , but failed to adjust it from %s[if more than 4 items, display in abbreviated form] to %s - send.append(Component.translatable(SET_BLOCK_MAX_DISTANCE_SUC_FAIL, failureEntitiesComponent, blockPos == null ? Component.translatable(ALL_KNOTS) : Command.getSLPName(blockPos))); + send.append("\n").append(Component.translatable(SET_BLOCK_MAX_DISTANCE_SUC_FAIL, failureEntitiesComponent, blockPos == null ? Component.translatable(ALL_KNOTS) : Command.getSLPName(blockPos))); } //. - else send.append("."); + else send.append(Component.translatable(END)); } else { // Failed to adjust the max distance of leash from %s[if more than 4 items, display in abbreviated form] to %s send.append(Component.translatable(SET_BLOCK_MAX_DISTANCE_FAIL, failureEntitiesComponent, blockPos == null ? Component.translatable(ALL_KNOTS) : Command.getSLPName(blockPos))); @@ -896,9 +1043,9 @@ public class LeashDataCommand { send.append(Component.translatable(SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC, successEntitiesComponent, blockPos == null ? Component.translatable(ALL_KNOTS) : Command.getSLPName(blockPos))); if (failure.get() >= 0) { // , but failed to adjust it from %s[if more than 4 items, display in abbreviated form] to %s - send.append(Component.translatable(SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC_FAIL, failureEntitiesComponent, blockPos == null ? Component.translatable(ALL_KNOTS) : Command.getSLPName(blockPos))); + send.append("\n").append(Component.translatable(SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC_FAIL, failureEntitiesComponent, blockPos == null ? Component.translatable(ALL_KNOTS) : Command.getSLPName(blockPos))); } //. - else send.append("."); + else send.append(Component.translatable(END)); } else { // Failed to adjust the elastic distance scale of leash from %s[if more than 4 items, display in abbreviated form] to %s send.append(Component.translatable(SET_BLOCK_ELASTIC_DISTANCE_SCALE_FAIL, failureEntitiesComponent, blockPos == null ? Component.translatable(ALL_KNOTS) : Command.getSLPName(blockPos))); @@ -919,7 +1066,7 @@ public class LeashDataCommand { /** * The constant LEASH_DATA_GET_. */ - public static final String LEASH_DATA_GET_ = SLP_LEASH_MESSAGE_ + ".get.", + public static final String LEASH_DATA_GET_ = SLP_LEASH_MESSAGE_ + "get.", /** * The Block. */ @@ -971,16 +1118,16 @@ public class LeashDataCommand { Component[] holders = new Component[4], knots = new Component[4]; for (LeashInfo leash : leashes) { MutableComponent info; + ClickEvent clickEvent; MutableComponent hover = Component.empty(); - if (leash.holderIdOpt().isPresent()){ - + if (leash.holderUUIDOpt().isPresent()){ if (entityCount >= MAX_SHOW_NUMBER && knotCount >= MAX_SHOW_NUMBER) { break; } else if (entityCount >= MAX_SHOW_NUMBER) { continue; } else { info = Component.translatable(ENTITY).withStyle(s -> s.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); - knots[entityCount] = info; + holders[entityCount] = info; leash.holderUUIDOpt().ifPresent(uuid -> hover .append(Component.translatable(UUID).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) @@ -988,7 +1135,7 @@ public class LeashDataCommand { ); entityCount++; // 在这里增加计数 } - + clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, leash.holderUUIDOpt().map(java.util.UUID::toString).orElse("Unknown UUID")); } else { if (knotCount >= MAX_SHOW_NUMBER && entityCount >= MAX_SHOW_NUMBER) { break; @@ -996,7 +1143,7 @@ public class LeashDataCommand { continue; } else { info = Component.translatable(KNOT).withStyle(s -> s.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); - holders[knotCount] = info; + knots[knotCount] = info; leash.blockPosOpt().ifPresent(pos -> hover .append(Component.translatable(BLOCK).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) @@ -1004,28 +1151,32 @@ public class LeashDataCommand { ); knotCount++; // 在这里增加计数 } + clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, leash.blockPosOpt() + .map(p -> String.format("%d %d %d", p.getX(), p.getY(), p.getZ())) + .orElse("Unknown Pos")); } hover.append(Component.translatable(MAX).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) - .append(Component.literal(String.format("%.2f", leash.maxDistance())).append("\n") - ); + .append(leash.maxDistance() == null ? Component.translatable(DEFAULT) : Component.literal(String.format("%.2f", leash.maxDistance())) + ).append("\n"); hover.append(Component.translatable(ELASTIC).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) - .append(Component.literal(String.format("%.2f", leash.elasticDistanceScale())).append("\n") - ); + .append(leash.elasticDistanceScale() == null ? Component.translatable(DEFAULT) :Component.literal(String.format("%.2f", leash.elasticDistanceScale())) + ).append("\n"); hover.append(Component.translatable(KEEP).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) - .append(Component.literal(String.valueOf(leash.maxKeepLeashTicks())).append("\n") + .append(Component.literal(String.valueOf(leash.maxKeepLeashTicks())) ); if (!leash.reserved().isEmpty()) { - hover.append(Component.translatable(KEEP).withStyle(ChatFormatting.DARK_AQUA)) + hover.append("\n").append(Component.translatable(RESERVED).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) - .append(Component.literal(String.valueOf(leash.maxKeepLeashTicks())).append("\n") + .append(Component.literal(String.valueOf(leash.maxKeepLeashTicks())) ); } + info.withStyle(s -> s.withClickEvent(clickEvent)); } - MutableComponent item = Component.translatable(LEASH_DATA_ITEM, list.get(i).getName(), buildHolderComponent(holders, entityCount), buildHolderComponent(knots, knotCount)); + MutableComponent item = Component.translatable(LEASH_DATA_ITEM, list.get(i).getDisplayName(), buildHolderComponent(holders, entityCount), buildHolderComponent(knots, knotCount)); items[i] = item; } Component component = buildFinalComponent(items, list.size()); @@ -1036,7 +1187,7 @@ public class LeashDataCommand { /** * The constant LEASH_INFO_HEAD. */ -// LeashData: [Entity]{Holder:{[Entity]}, BlockPos{[BlockPos]}} ... +// LeashInfo: [Entity]{Holder:{[Entity]}, BlockPos{[BlockPos]}} ... public static final String LEASH_INFO_HEAD = SLP_LEASH_MESSAGE_ + "leash_info.head"; /** * The constant LEASH_INFO_ITEM. @@ -1049,58 +1200,66 @@ public class LeashDataCommand { MutableComponent head = Component.translatable(LEASH_INFO_HEAD).append("\n"); // [Entity]%s { Holder: { %s[Entity]{UUID,Max,Elastic,Keep,Reserved} ... 4 }, BlockPos{ %s [BlockPos]{Max,Elastic,Keep,Reserved} ... 4 } } [\n] ... 25 break; Collection leashes = LeashDataInnerAPI.QueryOperations.getAllLeashes(target); - int entityCount = 0, knotCount = 0; + int count = 0; Component[] items = new Component[leashes.size()]; for (LeashInfo leash : leashes) { + ClickEvent clickEvent; MutableComponent info; MutableComponent hover = Component.empty(); - if (leash.holderIdOpt().isPresent()){ + if (leash.holderUUIDOpt().isPresent()){ + info = Component.translatable(ENTITY).withStyle(s -> s.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); - items[entityCount] = info; + items[count] = info; leash.holderUUIDOpt().ifPresent(uuid -> hover .append(Component.translatable(UUID).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) .append(Component.literal(uuid.toString())).append("\n") ); - entityCount++; // 在这里增加计数 + clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, leash.holderUUIDOpt().map(java.util.UUID::toString).orElse("Unknown UUID")); } else { info = Component.translatable(KNOT).withStyle(s -> s.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); - items[knotCount] = info; + items[count] = info; leash.blockPosOpt().ifPresent(pos -> hover .append(Component.translatable(BLOCK).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) .append(Command.getSLPName(pos)).append("\n") ); - knotCount++; // 在这里增加计数 - + clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, leash.blockPosOpt() + .map(p -> String.format("%d %d %d", p.getX(), p.getY(), p.getZ())) + .orElse("Unknown Pos")); } + count++; // 在这里增加计数 hover.append(Component.translatable(MAX).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) - .append(Component.literal(String.format("%.2f", leash.maxDistance())).append("\n") - ); + .append(leash.maxDistance() == null ? Component.translatable(DEFAULT) : Component.literal(String.format("%.2f", leash.maxDistance())) + ).append("\n"); hover.append(Component.translatable(ELASTIC).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) - .append(Component.literal(String.format("%.2f", leash.elasticDistanceScale())).append("\n") - ); + .append(leash.elasticDistanceScale() == null ? Component.translatable(DEFAULT) : Component.literal(String.format("%.2f", leash.elasticDistanceScale())) + ).append("\n"); hover.append(Component.translatable(KEEP).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) - .append(Component.literal(String.valueOf(leash.maxKeepLeashTicks())).append("\n") + .append(Component.literal(String.valueOf(leash.maxKeepLeashTicks())) ); if (!leash.reserved().isEmpty()) { - hover.append(Component.translatable(KEEP).withStyle(ChatFormatting.DARK_AQUA)) + hover.append("\n").append(Component.translatable(RESERVED).withStyle(ChatFormatting.DARK_AQUA)) .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) - .append(Component.literal(String.valueOf(leash.maxKeepLeashTicks())).append("\n") + .append(Component.literal(String.valueOf(leash.maxKeepLeashTicks())) ); } + info.withStyle(s -> s.withClickEvent(clickEvent)); } // LeashInfo: [Entity]{LeashInfo: {B/U, M, E, K, R} ..,} - MutableComponent item = Component.translatable(LEASH_INFO_ITEM, target.getName(), buildHolderInfoComponent(items, entityCount + knotCount)); + MutableComponent item = Component.translatable(LEASH_INFO_ITEM, target.getDisplayName(), buildHolderInfoComponent(items, count)); source.sendSuccess(() -> head.append(item), true); return 0; } private static @NotNull Component buildFinalComponent(Component @NotNull [] items, int count) { MutableComponent result = Component.empty(); + if(count == 0) { + return Component.translatable(NONE); + } for (int i = 0; i < Math.min(items.length, count); i++) { if (items[i] != null) { result.append(items[i]); @@ -1118,6 +1277,9 @@ public class LeashDataCommand { // 辅助方法:构建holder组件 private static @NotNull Component buildHolderComponent(Component @NotNull [] holders, int count) { MutableComponent result = Component.empty(); + if(count == 0) { + return Component.translatable(NONE); + } for (int i = 0; i < Math.min(holders.length, count); i++) { if (holders[i] != null) { result.append(holders[i]); @@ -1134,6 +1296,9 @@ public class LeashDataCommand { } private static @NotNull Component buildHolderInfoComponent(Component @NotNull [] holders, int count) { MutableComponent result = Component.empty(); + if(count == 0) { + return Component.translatable(NONE); + } for (int i = 0; i < Math.min(holders.length, count); i++) { if (holders[i] != null) { result.append(holders[i]); @@ -1168,15 +1333,15 @@ public class LeashDataCommand { /** * The constant ADD_HOLDER_LEASHES_SUC. */ - public static final String ADD_HOLDER_LEASHES_SUC = ADD_HOLDER_LEASHES_ + "suc"; + public static final String ADD_HOLDER_LEASHES_SUC = ADD_HOLDER_LEASHES_ + SUC; /** * The constant ADD_HOLDER_LEASHES_SUC_FAIL. */ - public static final String ADD_HOLDER_LEASHES_SUC_FAIL = ADD_HOLDER_LEASHES_ + "suc_fail"; + public static final String ADD_HOLDER_LEASHES_SUC_FAIL = ADD_HOLDER_LEASHES_ + SUC_FAIL; /** * The constant ADD_HOLDER_LEASHES_FAIL. */ - public static final String ADD_HOLDER_LEASHES_FAIL = ADD_HOLDER_LEASHES_ + "fail"; + public static final String ADD_HOLDER_LEASHES_FAIL = ADD_HOLDER_LEASHES_ + FAIL; private static int addLeash(CommandContext context, Entity holder, double maxDistance, double elasticDistanceScale, int keepTicks, String reserved) throws CommandSyntaxException { @@ -1206,18 +1371,15 @@ public class LeashDataCommand { send.append(Component.translatable(ADD_HOLDER_LEASHES_SUC, showLeashInfo(maxDistance == -1 ? null : maxDistance, elasticDistanceScale == -1 ? null : elasticDistanceScale, keepTicks, reserved), successEntitiesComponent, Command.getSLPName(holder))); if (failure >= 0) { // , but failed to attached >leash<[Basic Info] from %s to %s [Leashed: [if more than 4 items, display in abbreviated form]]. - send.append(Component.translatable(ADD_HOLDER_LEASHES_SUC_FAIL, showLeashInfo(maxDistance == -1 ? null : maxDistance, elasticDistanceScale == -1 ? null : elasticDistanceScale, keepTicks, reserved), failureEntitiesComponent, Command.getSLPName(holder))); + send.append("\n").append(Component.translatable(ADD_HOLDER_LEASHES_SUC_FAIL, showLeashInfo(maxDistance == -1 ? null : maxDistance, elasticDistanceScale == -1 ? null : elasticDistanceScale, keepTicks, reserved), failureEntitiesComponent, Command.getSLPName(holder))); } //. - else send.append("."); + else send.append(Component.translatable(END)); } else { // Failed to attached >leash<[Basic Info] from %s to %s [Leashed: [if more than 4 items, display in abbreviated form]]. send.append(Component.translatable(ADD_HOLDER_LEASHES_FAIL, showLeashInfo(maxDistance == -1 ? null : maxDistance, elasticDistanceScale == -1 ? null : elasticDistanceScale, keepTicks, reserved), failureEntitiesComponent, Command.getSLPName(holder))); } source.sendSuccess(() -> send, true); return 0; - // - // [if failed then add ", but failed to attached leash from %s[if more than 4 items, display in abbreviated form] to %s", else "."] -// todo: source.sendSuccess(() -> Component.translatable(/*成功{},失败{}*/), true); } private static int addBlockLeash(CommandContext context) throws CommandSyntaxException { return addBlockLeash(context, -1); @@ -1242,15 +1404,15 @@ public class LeashDataCommand { /** * The constant ADD_BLOCK_LEASHES_SUC. */ - public static final String ADD_BLOCK_LEASHES_SUC = ADD_BLOCK_LEASHES_ + "suc"; + public static final String ADD_BLOCK_LEASHES_SUC = ADD_BLOCK_LEASHES_ + SUC; /** * The constant ADD_BLOCK_LEASHES_SUC_FAIL. */ - public static final String ADD_BLOCK_LEASHES_SUC_FAIL = ADD_BLOCK_LEASHES_ + "suc_fail"; + public static final String ADD_BLOCK_LEASHES_SUC_FAIL = ADD_BLOCK_LEASHES_ + SUC_FAIL; /** * The constant ADD_BLOCK_LEASHES_FAIL. */ - public static final String ADD_BLOCK_LEASHES_FAIL = ADD_BLOCK_LEASHES_ + "fail"; + public static final String ADD_BLOCK_LEASHES_FAIL = ADD_BLOCK_LEASHES_ + FAIL; /** * The constant ADD_BLOCK_LEASHES_FAIL_NO_KNOT_FOUND. */ @@ -1269,9 +1431,8 @@ public class LeashDataCommand { else return Optional.empty(); }).orElse(null); if (knotEntity == null) { - // Failed to attach leash to %s because there is not existed knot in pos."] + // Failed to attach leash to %s because there is not existed knot in pos. source.sendFailure(Component.translatable(ADD_BLOCK_LEASHES_FAIL_NO_KNOT_FOUND, Command.getSLPName(pos))); -// todo: source.sendFailure(Component.translatable(/*失败,目标上无拴绳结*/)); return -1; } int success = -1, failure = -1; @@ -1297,30 +1458,49 @@ public class LeashDataCommand { send.append(Component.translatable(ADD_BLOCK_LEASHES_SUC, showLeashInfo(maxDistance == -1 ? null : maxDistance, elasticDistanceScale == -1 ? null : elasticDistanceScale, keepTicks, reserved), successEntitiesComponent, Command.getSLPName(pos))); if (failure >= 0) { // , but failed to attached >leash<[Basic Info] from %s to %s [Leashed: [if more than 4 items, display in abbreviated form]]. - send.append(Component.translatable(ADD_BLOCK_LEASHES_SUC_FAIL, showLeashInfo(maxDistance == -1 ? null : maxDistance, elasticDistanceScale == -1 ? null : elasticDistanceScale, keepTicks, reserved), failureEntitiesComponent, Command.getSLPName(pos))); + send.append("\n").append(Component.translatable(ADD_BLOCK_LEASHES_SUC_FAIL, showLeashInfo(maxDistance == -1 ? null : maxDistance, elasticDistanceScale == -1 ? null : elasticDistanceScale, keepTicks, reserved), failureEntitiesComponent, Command.getSLPName(pos))); } //. - else send.append("."); + else send.append(Component.translatable(END)); } else { // Failed to attached >leash<[Basic Info] from %s to %s [Leashed: [if more than 4 items, display in abbreviated form]]. send.append(Component.translatable(ADD_BLOCK_LEASHES_FAIL, showLeashInfo(maxDistance == -1 ? null : maxDistance, elasticDistanceScale == -1 ? null : elasticDistanceScale, keepTicks, reserved), failureEntitiesComponent, Command.getSLPName(pos))); } source.sendSuccess(() -> send, true); return 0; - // - // [if failed then add ", but failed to attach leash from %s[if more than 4 items, display in abbreviated form] to %s", else "."] -// todo: source.sendSuccess(() -> Component.translatable(/*成功{},失败{}*/), true); } - /** - * The constant LEASH_INFO. - */ - public static final String LEASH_INFO = SLP_LEASH_MESSAGE_ + "leash.info"; /** * The constant DEFAULT. */ public static final String DEFAULT = SLP_LEASH_MESSAGE_ + "default"; - private static Component showLeashInfo(@Nullable Double maxDistance, @Nullable Double elasticDistanceScale, int keepTicks, String reserved) { - return Component.translatable(LEASH_INFO, maxDistance == null ? DEFAULT : maxDistance , elasticDistanceScale == null ? DEFAULT : elasticDistanceScale, keepTicks, reserved); + private static Component showLeashInfo(@Nullable Double maxDistance, @Nullable Double elasticDistanceScale, int keepTicks,@Nullable String reserved) { + MutableComponent item = Component.literal("[*]"); + MutableComponent hover = Component.empty(); + hover.append(Component.translatable(MAX).withStyle(ChatFormatting.DARK_AQUA)) + .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) + .append(maxDistance == null ? Component.translatable(DEFAULT) : Component.literal(String.format("%.2f", maxDistance)) + ).append("\n"); + hover.append(Component.translatable(ELASTIC).withStyle(ChatFormatting.DARK_AQUA)) + .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) + .append(elasticDistanceScale == null ? Component.translatable(DEFAULT) : Component.literal(String.format("%.2f", elasticDistanceScale)) + ).append("\n"); + hover.append(Component.translatable(KEEP).withStyle(ChatFormatting.DARK_AQUA)) + .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) + .append(String.valueOf(keepTicks)); + if (reserved != null && !reserved.isEmpty()) { + hover.append("\n").append(Component.translatable(RESERVED).withStyle(ChatFormatting.DARK_AQUA)) + .append(Component.translatable(COLON).withStyle(ChatFormatting.GRAY)) + .append(Component.literal(reserved)); + } + return + item.withStyle( + s -> s.withHoverEvent( + new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + hover + ) + ) + ); } /** @@ -1330,15 +1510,15 @@ public class LeashDataCommand { /** * The constant REMOVE_HOLDER_LEASHES_SUC. */ - public static final String REMOVE_HOLDER_LEASHES_SUC = REMOVE_HOLDER_LEASHES_ + "suc"; + public static final String REMOVE_HOLDER_LEASHES_SUC = REMOVE_HOLDER_LEASHES_ + SUC; /** * The constant REMOVE_HOLDER_LEASHES_SUC_FAIL. */ - public static final String REMOVE_HOLDER_LEASHES_SUC_FAIL = REMOVE_HOLDER_LEASHES_ + "suc_fail"; + public static final String REMOVE_HOLDER_LEASHES_SUC_FAIL = REMOVE_HOLDER_LEASHES_ + SUC_FAIL; /** * The constant REMOVE_HOLDER_LEASHES_FAIL. */ - public static final String REMOVE_HOLDER_LEASHES_FAIL = REMOVE_HOLDER_LEASHES_ + "fail"; + public static final String REMOVE_HOLDER_LEASHES_FAIL = REMOVE_HOLDER_LEASHES_ + FAIL; private static int removeLeash(CommandContext context, Entity holder) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); CommandSourceStack source = context.getSource(); @@ -1365,9 +1545,9 @@ public class LeashDataCommand { send.append(Component.translatable(REMOVE_HOLDER_LEASHES_SUC, successEntitiesComponent, Command.getSLPName(holder))); if (failure >= 0) { // , but failed to detach leash from %s[if more than 4 items, display in abbreviated form] to %s - send.append(Component.translatable(REMOVE_HOLDER_LEASHES_SUC_FAIL, failureEntitiesComponent, Command.getSLPName(holder))); + send.append("\n").append(Component.translatable(REMOVE_HOLDER_LEASHES_SUC_FAIL, failureEntitiesComponent, Command.getSLPName(holder))); } // . - else send.append("."); + else send.append(Component.translatable(END)); } else { // Failed to detach leash from %s to %s [Leashed: [if more than 4 items, display in abbreviated form]]. send.append(Component.translatable(REMOVE_HOLDER_LEASHES_FAIL, failureEntitiesComponent, Command.getSLPName(holder))); @@ -1383,15 +1563,15 @@ public class LeashDataCommand { /** * The constant REMOVE_BLOCK_LEASHES_SUC. */ - public static final String REMOVE_BLOCK_LEASHES_SUC = REMOVE_BLOCK_LEASHES_ + "suc"; + public static final String REMOVE_BLOCK_LEASHES_SUC = REMOVE_BLOCK_LEASHES_ + SUC; /** * The constant REMOVE_BLOCK_LEASHES_SUC_FAIL. */ - public static final String REMOVE_BLOCK_LEASHES_SUC_FAIL = REMOVE_BLOCK_LEASHES_ + "suc_fail"; + public static final String REMOVE_BLOCK_LEASHES_SUC_FAIL = REMOVE_BLOCK_LEASHES_ + SUC_FAIL; /** * The constant REMOVE_BLOCK_LEASHES_FAIL. */ - public static final String REMOVE_BLOCK_LEASHES_FAIL = REMOVE_BLOCK_LEASHES_ + "fail"; + public static final String REMOVE_BLOCK_LEASHES_FAIL = REMOVE_BLOCK_LEASHES_ + FAIL; private static int removeBlockLeash(CommandContext context, BlockPos pos) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); CommandSourceStack source = context.getSource(); @@ -1418,9 +1598,9 @@ public class LeashDataCommand { send.append(Component.translatable(REMOVE_BLOCK_LEASHES_SUC, successEntitiesComponent, Command.getSLPName(pos))); if (failure >= 0) { // , but failed to detach leash from %s[if more than 4 items, display in abbreviated form] to %s - send.append(Component.translatable(REMOVE_BLOCK_LEASHES_SUC_FAIL, failureEntitiesComponent, Command.getSLPName(pos))); + send.append("\n").append(Component.translatable(REMOVE_BLOCK_LEASHES_SUC_FAIL, failureEntitiesComponent, Command.getSLPName(pos))); } //. - else send.append("."); + else send.append(Component.translatable(END)); } else { // Failed to detach leash from %s to %s [Leashed: [if more than 4 items, display in abbreviated form]]. send.append(Component.translatable(REMOVE_BLOCK_LEASHES_FAIL, failureEntitiesComponent, Command.getSLPName(pos))); @@ -1460,18 +1640,18 @@ public class LeashDataCommand { * The constant TRANSFER_LEASH_. */ public static final String TRANSFER_LEASH_ = SLP_LEASH_MESSAGE_ + "transfer_leash."; - /** - * The constant TRANSFER_LEASH_FAIL. - */ - public static final String TRANSFER_LEASH_FAIL = TRANSFER_LEASH_ + "fail"; /** * The constant TRANSFER_LEASH_SUC. */ - public static final String TRANSFER_LEASH_SUC = TRANSFER_LEASH_ + "suc"; + public static final String TRANSFER_LEASH_SUC = TRANSFER_LEASH_ + SUC; + /** + * The constant TRANSFER_LEASH_FAIL. + */ + public static final String TRANSFER_LEASH_FAIL = TRANSFER_LEASH_ + FAIL; /** * The constant TRANSFER_LEASH_SUC_FAIL. */ - public static final String TRANSFER_LEASH_SUC_FAIL = TRANSFER_LEASH_ + "suc_fail"; + public static final String TRANSFER_LEASH_SUC_FAIL = TRANSFER_LEASH_ + SUC_FAIL; private static int transferLeash(CommandContext context, Entity from, Entity to, @Nullable String reserved) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); @@ -1479,6 +1659,7 @@ public class LeashDataCommand { int success = -1, failure = -1; Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER], failEntities = new Entity[MAX_SHOW_NUMBER]; for (Entity target : targets) { + if(target == from) continue; boolean isSuccessful = LeashDataInnerAPI.TransferOperations.transfer(target, from, to, reserved); if (isSuccessful) { if (++success <= MAX_SHOW_NUMBER - 1) { @@ -1495,13 +1676,13 @@ public class LeashDataCommand { generateEntityComponent(failEntities, failure, failureEntitiesComponent); MutableComponent send = Component.empty(); if (success >= 0) { - // Successfully transferred leash from %s[BlockPos/Entity] to %s[BlockPos/Entity] [Leashed ((>1)Entities/Entity): [if more than 4 items, display in abbreviated form]] + // Successfully transferred leash from %s[BlockPos/Entity] to %s[BlockPos/Entity] [Leashed: [if more than 4 items, display in abbreviated form]] send.append(Component.translatable(TRANSFER_LEASH_SUC, Command.getSLPName(from), Command.getSLPName(to), successEntitiesComponent)); if (failure >= 0) { // , but failed to transfer leash from %s to %s [Leashed ((>1)Entities/Entity): [if more than 4 items, display in abbreviated form]]. - send.append(Component.translatable(TRANSFER_LEASH_SUC_FAIL, Command.getSLPName(from), Command.getSLPName(to), failureEntitiesComponent)); + send.append("\n").append(Component.translatable(TRANSFER_LEASH_SUC_FAIL, Command.getSLPName(from), Command.getSLPName(to), failureEntitiesComponent)); } //. - else send.append("."); + else send.append(Component.translatable(END)); } else { // Failed to transfer leash from %s to %s [Leashed ((>1)Entities/Entity): [if more than 4 items, display in abbreviated form]]. send.append(Component.translatable(TRANSFER_LEASH_FAIL, Command.getSLPName(from), Command.getSLPName(to), failureEntitiesComponent)); @@ -1535,7 +1716,7 @@ public class LeashDataCommand { private static void generateEntityComponent(Entity @NotNull [] entities, int successful, MutableComponent entitiesComponent) { for (int i = 0; i < entities.length; i++) { if (entities[i] == null) break; - entitiesComponent.append(entities[i].getName()); + entitiesComponent.append(entities[i].getDisplayName()); if (i < entities.length - 1) { entitiesComponent.append(", "); } diff --git a/src/main/java/top/r3944realms/superleadrope/content/command/LeashStateCommand.java b/src/main/java/top/r3944realms/superleadrope/content/command/LeashStateCommand.java index c0c900d..a243b27 100644 --- a/src/main/java/top/r3944realms/superleadrope/content/command/LeashStateCommand.java +++ b/src/main/java/top/r3944realms/superleadrope/content/command/LeashStateCommand.java @@ -16,22 +16,481 @@ package top.r3944realms.superleadrope.content.command; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.commands.arguments.coordinates.BlockPosArgument; +import net.minecraft.commands.arguments.coordinates.Vec3Argument; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.Vec3; +import top.r3944realms.superleadrope.util.capability.LeashStateInnerAPI; + +import static top.r3944realms.superleadrope.content.command.Command.*; /** * The type Leash state command. */ +//TODO: 未来扩展,启用 public class LeashStateCommand { + + /** + * The constant SLP_LEASH_STATE_MESSAGE_. + */ + public static final String SLP_LEASH_STATE_MESSAGE_ = Command.BASE_ + "leash_state.message."; + + // ==================== 重置操作消息键 ==================== + public static final String RESET_ALL_HOLDER_ = SLP_LEASH_STATE_MESSAGE_ + "reset_all_holder."; + public static final String RESET_ALL_HOLDER_SUC = RESET_ALL_HOLDER_ + SUC; + + public static final String RESET_HOLDER_FOR_ = SLP_LEASH_STATE_MESSAGE_ + "reset_holder_for."; + public static final String RESET_HOLDER_FOR_SUC = RESET_HOLDER_FOR_ + SUC; + + public static final String RESET_HOLDER_FOR_BLOCK_POS_ = SLP_LEASH_STATE_MESSAGE_ + "reset_holder_for_block_pos."; + public static final String RESET_HOLDER_FOR_BLOCK_POS_SUC = RESET_HOLDER_FOR_BLOCK_POS_ + SUC; + + public static final String RESET_APPLY_ENTITY_ALL_ = SLP_LEASH_STATE_MESSAGE_ + "reset_apply_entity_all."; + public static final String RESET_APPLY_ENTITY_ALL_SUC = RESET_APPLY_ENTITY_ALL_ + SUC; + + // ==================== 设置操作消息键 ==================== + public static final String SET_HOLDER_FOR_ = SLP_LEASH_STATE_MESSAGE_ + "set_holder_for."; + public static final String SET_HOLDER_FOR_SUC = SET_HOLDER_FOR_ + SUC; + public static final String SET_HOLDER_FOR_SUC_FAIL = SET_HOLDER_FOR_ + SUC_FAIL; + public static final String SET_HOLDER_FOR_FAIL = SET_HOLDER_FOR_ + FAIL; + + public static final String SET_HOLDER_FOR_BLOCK_POS_ = SLP_LEASH_STATE_MESSAGE_ + "set_holder_for_block_pos."; + public static final String SET_HOLDER_FOR_BLOCK_POS_SUC = SET_HOLDER_FOR_BLOCK_POS_ + SUC; + public static final String SET_HOLDER_FOR_BLOCK_POS_SUC_FAIL = SET_HOLDER_FOR_BLOCK_POS_ + SUC_FAIL; + public static final String SET_HOLDER_FOR_BLOCK_POS_FAIL = SET_HOLDER_FOR_BLOCK_POS_ + FAIL; + + public static final String SET_APPLY_ENTITY_ = SLP_LEASH_STATE_MESSAGE_ + "set_apply_entity."; + public static final String SET_APPLY_ENTITY_SUC = SET_APPLY_ENTITY_ + SUC; + public static final String SET_APPLY_ENTITY_SUC_FAIL = SET_APPLY_ENTITY_ + SUC_FAIL; + public static final String SET_APPLY_ENTITY_FAIL = SET_APPLY_ENTITY_ + FAIL; + + // ==================== 添加操作消息键 ==================== + public static final String ADD_HOLDER_TO_ = SLP_LEASH_STATE_MESSAGE_ + "add_holder_to."; + public static final String ADD_HOLDER_TO_SUC = ADD_HOLDER_TO_ + SUC; + public static final String ADD_HOLDER_TO_SUC_FAIL = ADD_HOLDER_TO_ + SUC_FAIL; + public static final String ADD_HOLDER_TO_FAIL = ADD_HOLDER_TO_ + FAIL; + + public static final String ADD_HOLDER_TO_BLOCK_POS_ = SLP_LEASH_STATE_MESSAGE_ + "add_holder_to_block_pos."; + public static final String ADD_HOLDER_TO_BLOCK_POS_SUC = ADD_HOLDER_TO_BLOCK_POS_ + SUC; + public static final String ADD_HOLDER_TO_BLOCK_POS_SUC_FAIL = ADD_HOLDER_TO_BLOCK_POS_ + SUC_FAIL; + public static final String ADD_HOLDER_TO_BLOCK_POS_FAIL = ADD_HOLDER_TO_BLOCK_POS_ + FAIL; + + public static final String ADD_APPLY_ENTITY_ = SLP_LEASH_STATE_MESSAGE_ + "add_apply_entity."; + public static final String ADD_APPLY_ENTITY_SUC = ADD_APPLY_ENTITY_ + SUC; + public static final String ADD_APPLY_ENTITY_SUC_FAIL = ADD_APPLY_ENTITY_ + SUC_FAIL; + public static final String ADD_APPLY_ENTITY_FAIL = ADD_APPLY_ENTITY_ + FAIL; + + // ==================== 移除操作消息键 ==================== + public static final String REMOVE_HOLDER_FOR_ = SLP_LEASH_STATE_MESSAGE_ + "remove_holder_for."; + public static final String REMOVE_HOLDER_FOR_SUC = REMOVE_HOLDER_FOR_ + SUC; + public static final String REMOVE_HOLDER_FOR_SUC_FAIL = REMOVE_HOLDER_FOR_ + SUC_FAIL; + public static final String REMOVE_HOLDER_FOR_FAIL = REMOVE_HOLDER_FOR_ + FAIL; + + public static final String REMOVE_HOLDER_FOR_BLOCK_POS_ = SLP_LEASH_STATE_MESSAGE_ + "remove_holder_for_block_pos."; + public static final String REMOVE_HOLDER_FOR_BLOCK_POS_SUC = REMOVE_HOLDER_FOR_BLOCK_POS_ + SUC; + public static final String REMOVE_HOLDER_FOR_BLOCK_POS_SUC_FAIL = REMOVE_HOLDER_FOR_BLOCK_POS_ + SUC_FAIL; + public static final String REMOVE_HOLDER_FOR_BLOCK_POS_FAIL = REMOVE_HOLDER_FOR_BLOCK_POS_ + FAIL; + + public static final String REMOVE_HOLDER_ALL_ = SLP_LEASH_STATE_MESSAGE_ + "remove_holder_all."; + public static final String REMOVE_HOLDER_ALL_SUC = REMOVE_HOLDER_ALL_ + SUC; + + public static final String REMOVE_ALL_HOLDER_UUIDS_ = SLP_LEASH_STATE_MESSAGE_ + "remove_all_holder_uuids."; + public static final String REMOVE_ALL_HOLDER_UUIDS_SUC = REMOVE_ALL_HOLDER_UUIDS_ + SUC; + + public static final String REMOVE_ALL_HOLDER_BLOCK_POSES_ = SLP_LEASH_STATE_MESSAGE_ + "remove_all_holder_block_poses."; + public static final String REMOVE_ALL_HOLDER_BLOCK_POSES_SUC = REMOVE_ALL_HOLDER_BLOCK_POSES_ + SUC; + + public static final String REMOVE_APPLY_ENTITY_ = SLP_LEASH_STATE_MESSAGE_ + "remove_apply_entity."; + public static final String REMOVE_APPLY_ENTITY_SUC = REMOVE_APPLY_ENTITY_ + SUC; + + // ==================== 查询操作消息键 ==================== + public static final String QUERY_HAS_STATE_ = SLP_LEASH_STATE_MESSAGE_ + "query.has_state."; + public static final String QUERY_HAS_STATE_SUC = QUERY_HAS_STATE_ + SUC; + + public static final String GET_ALL_UUID_STATES_ = SLP_LEASH_STATE_MESSAGE_ + "get_all_uuid_states."; + public static final String GET_ALL_UUID_STATES_SUC = GET_ALL_UUID_STATES_ + SUC; + + public static final String GET_ALL_BLOCK_POS_STATES_ = SLP_LEASH_STATE_MESSAGE_ + "get_all_block_pos_states."; + public static final String GET_ALL_BLOCK_POS_STATES_SUC = GET_ALL_BLOCK_POS_STATES_ + SUC; + + public static final String GET_APPLY_ENTITY_OFFSET_ = SLP_LEASH_STATE_MESSAGE_ + "get_apply_entity_offset."; + public static final String GET_APPLY_ENTITY_OFFSET_SUC = GET_APPLY_ENTITY_OFFSET_ + SUC; + public static final String GET_APPLY_ENTITY_OFFSET_NONE = GET_APPLY_ENTITY_OFFSET_ + "none"; + + public static final String GET_DEFAULT_APPLY_ENTITY_OFFSET_ = SLP_LEASH_STATE_MESSAGE_ + "get_default_apply_entity_offset."; + public static final String GET_DEFAULT_APPLY_ENTITY_OFFSET_SUC = GET_DEFAULT_APPLY_ENTITY_OFFSET_ + SUC; + /** * Register. * * @param dispatcher the dispatcher */ -// 获取State - // 设置State - // Holder> - // 设置对应目标的 拴绳偏移 public static void register(CommandDispatcher dispatcher) { + dispatcher.register(Commands.literal("leashstate") + .requires(source -> source.hasPermission(2)) // 需要权限等级2 + // ==================== 重置操作 ==================== + .then(Commands.literal("resetAllHolder") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> resetAllHolder(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + .then(Commands.literal("resetHolderFor") + .then(Commands.argument("entity", EntityArgument.entity()) + .then(Commands.argument("holder", EntityArgument.entity()) + .executes(context -> resetHolderFor(context, + EntityArgument.getEntity(context, "entity"), + EntityArgument.getEntity(context, "holder"))) + ) + ) + ) + .then(Commands.literal("resetHolderForBlockPos") + .then(Commands.argument("entity", EntityArgument.entity()) + .then(Commands.argument("pos", BlockPosArgument.blockPos()) + .executes(context -> resetHolderForBlockPos(context, + EntityArgument.getEntity(context, "entity"), + BlockPosArgument.getLoadedBlockPos(context, "pos"))) + ) + ) + ) + .then(Commands.literal("resetApplyEntityAll") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> resetApplyEntityAll(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + + // ==================== 设置操作 ==================== + .then(Commands.literal("setHolderFor") + .then(Commands.argument("entity", EntityArgument.entity()) + .then(Commands.argument("holder", EntityArgument.entity()) + .executes(context -> setHolderFor(context, + EntityArgument.getEntity(context, "entity"), + EntityArgument.getEntity(context, "holder"))) + .then(Commands.argument("offset", Vec3Argument.vec3()) + .executes(context -> setHolderForWithOffset(context, + EntityArgument.getEntity(context, "entity"), + EntityArgument.getEntity(context, "holder"), + Vec3Argument.getVec3(context, "offset"))) + ) + ) + ) + ) + .then(Commands.literal("setHolderForBlockPos") + .then(Commands.argument("entity", EntityArgument.entity()) + .then(Commands.argument("pos", BlockPosArgument.blockPos()) + .executes(context -> setHolderForBlockPos(context, + EntityArgument.getEntity(context, "entity"), + BlockPosArgument.getLoadedBlockPos(context, "pos"))) + .then(Commands.argument("offset", Vec3Argument.vec3()) + .executes(context -> setHolderForBlockPosWithOffset(context, + EntityArgument.getEntity(context, "entity"), + BlockPosArgument.getLoadedBlockPos(context, "pos"), + Vec3Argument.getVec3(context, "offset"))) + ) + ) + ) + ) + .then(Commands.literal("setApplyEntity") + .then(Commands.argument("entity", EntityArgument.entity()) + .then(Commands.argument("offset", Vec3Argument.vec3()) + .executes(context -> setApplyEntity(context, + EntityArgument.getEntity(context, "entity"), + Vec3Argument.getVec3(context, "offset"))) + ) + ) + ) + + // ==================== 添加操作 ==================== + .then(Commands.literal("addHolderTo") + .then(Commands.argument("entity", EntityArgument.entity()) + .then(Commands.argument("holder", EntityArgument.entity()) + .then(Commands.argument("offset", Vec3Argument.vec3()) + .executes(context -> addHolderTo(context, + EntityArgument.getEntity(context, "entity"), + EntityArgument.getEntity(context, "holder"), + Vec3Argument.getVec3(context, "offset"))) + ) + ) + ) + ) + .then(Commands.literal("addHolderToBlockPos") + .then(Commands.argument("entity", EntityArgument.entity()) + .then(Commands.argument("pos", BlockPosArgument.blockPos()) + .then(Commands.argument("offset", Vec3Argument.vec3()) + .executes(context -> addHolderToBlockPos(context, + EntityArgument.getEntity(context, "entity"), + BlockPosArgument.getLoadedBlockPos(context, "pos"), + Vec3Argument.getVec3(context, "offset"))) + ) + ) + ) + ) + .then(Commands.literal("addApplyEntity") + .then(Commands.argument("entity", EntityArgument.entity()) + .then(Commands.argument("offset", Vec3Argument.vec3()) + .executes(context -> addApplyEntity(context, + EntityArgument.getEntity(context, "entity"), + Vec3Argument.getVec3(context, "offset"))) + ) + ) + ) + + // ==================== 移除操作 ==================== + .then(Commands.literal("removeHolderFor") + .then(Commands.argument("entity", EntityArgument.entity()) + .then(Commands.argument("holder", EntityArgument.entity()) + .executes(context -> removeHolderFor(context, + EntityArgument.getEntity(context, "entity"), + EntityArgument.getEntity(context, "holder"))) + ) + ) + ) + .then(Commands.literal("removeHolderForBlockPos") + .then(Commands.argument("entity", EntityArgument.entity()) + .then(Commands.argument("pos", BlockPosArgument.blockPos()) + .executes(context -> removeHolderForBlockPos(context, + EntityArgument.getEntity(context, "entity"), + BlockPosArgument.getLoadedBlockPos(context, "pos"))) + ) + ) + ) + .then(Commands.literal("removeHolderAll") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> removeHolderAll(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + .then(Commands.literal("removeAllHolderUUIDs") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> removeAllHolderUUIDs(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + .then(Commands.literal("removeAllHolderBlockPoses") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> removeAllHolderBlockPoses(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + .then(Commands.literal("removeApplyEntity") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> removeApplyEntity(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + + // ==================== 查询操作 ==================== + .then(Commands.literal("query") + .then(Commands.literal("hasState") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> queryHasState(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + .then(Commands.literal("getAllUUIDStates") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> getAllUUIDStates(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + .then(Commands.literal("getAllBlockPosStates") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> getAllBlockPosStates(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + .then(Commands.literal("getApplyEntityOffset") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> getApplyEntityOffset(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + .then(Commands.literal("getDefaultApplyEntityOffset") + .then(Commands.argument("entity", EntityArgument.entity()) + .executes(context -> getDefaultApplyEntityOffset(context, EntityArgument.getEntity(context, "entity"))) + ) + ) + ) + ); } -} + + // ==================== 重置操作实现 ==================== + + private static int resetAllHolder(CommandContext context, Entity entity) { + LeashStateInnerAPI.Offset.resetAllHolder(entity); + context.getSource().sendSuccess(() -> + Component.translatable(RESET_ALL_HOLDER_SUC, getSLPName(entity)), false); + return 1; + } + + private static int resetHolderFor(CommandContext context, Entity entity, Entity holder) { + LeashStateInnerAPI.Offset.resetHolderFor(entity, holder); + context.getSource().sendSuccess(() -> + Component.translatable(RESET_HOLDER_FOR_SUC, getSLPName(entity), getSLPName(holder)), false); + return 1; + } + + private static int resetHolderForBlockPos(CommandContext context, Entity entity, BlockPos pos) { + LeashStateInnerAPI.Offset.resetHolderFor(entity, pos); + context.getSource().sendSuccess(() -> + Component.translatable(RESET_HOLDER_FOR_BLOCK_POS_SUC, getSLPName(entity), getSLPName(pos)), false); + return 1; + } + + private static int resetApplyEntityAll(CommandContext context, Entity entity) { + LeashStateInnerAPI.Offset.resetApplyEntityAll(entity); + context.getSource().sendSuccess(() -> + Component.translatable(RESET_APPLY_ENTITY_ALL_SUC, getSLPName(entity)), false); + return 1; + } + + // ==================== 设置操作实现 ==================== + + private static int setHolderFor(CommandContext context, Entity entity, Entity holder) { + LeashStateInnerAPI.Offset.setHolderFor(entity, holder); + context.getSource().sendSuccess(() -> + Component.translatable(SET_HOLDER_FOR_SUC, getSLPName(entity), getSLPName(holder)), false); + return 1; + } + + private static int setHolderForWithOffset(CommandContext context, Entity entity, Entity holder, Vec3 offset) { + LeashStateInnerAPI.Offset.setHolderFor(entity, holder, offset); + context.getSource().sendSuccess(() -> + Component.translatable(SET_HOLDER_FOR_SUC, getSLPName(entity), getSLPName(holder), offset), false); + return 1; + } + + private static int setHolderForBlockPos(CommandContext context, Entity entity, BlockPos pos) { + LeashStateInnerAPI.Offset.setHolderFor(entity, pos); + context.getSource().sendSuccess(() -> + Component.translatable(SET_HOLDER_FOR_BLOCK_POS_SUC, getSLPName(entity), getSLPName(pos)), false); + return 1; + } + + private static int setHolderForBlockPosWithOffset(CommandContext context, Entity entity, BlockPos pos, Vec3 offset) { + LeashStateInnerAPI.Offset.setHolderFor(entity, pos, offset); + context.getSource().sendSuccess(() -> + Component.translatable(SET_HOLDER_FOR_BLOCK_POS_SUC, getSLPName(entity), getSLPName(pos), offset), false); + return 1; + } + + private static int setApplyEntity(CommandContext context, Entity entity, Vec3 offset) { + LeashStateInnerAPI.Offset.setApplyEntity(entity, offset); + context.getSource().sendSuccess(() -> + Component.translatable(SET_APPLY_ENTITY_SUC, getSLPName(entity), offset), false); + return 1; + } + + // ==================== 添加操作实现 ==================== + + private static int addHolderTo(CommandContext context, Entity entity, Entity holder, Vec3 offset) { + LeashStateInnerAPI.Offset.addHolderTo(entity, holder, offset); + context.getSource().sendSuccess(() -> + Component.translatable(ADD_HOLDER_TO_SUC, getSLPName(entity), getSLPName(holder), offset), false); + return 1; + } + + private static int addHolderToBlockPos(CommandContext context, Entity entity, BlockPos pos, Vec3 offset) { + LeashStateInnerAPI.Offset.addHolderTo(entity, pos, offset); + context.getSource().sendSuccess(() -> + Component.translatable(ADD_HOLDER_TO_BLOCK_POS_SUC, getSLPName(entity), getSLPName(pos), offset), false); + return 1; + } + + private static int addApplyEntity(CommandContext context, Entity entity, Vec3 offset) { + LeashStateInnerAPI.Offset.addApplyEntity(entity, offset); + context.getSource().sendSuccess(() -> + Component.translatable(ADD_APPLY_ENTITY_SUC, getSLPName(entity), offset), false); + return 1; + } + + // ==================== 移除操作实现 ==================== + + private static int removeHolderFor(CommandContext context, Entity entity, Entity holder) { + LeashStateInnerAPI.Offset.removeHolderFor(entity, holder); + context.getSource().sendSuccess(() -> + Component.translatable(REMOVE_HOLDER_FOR_SUC, getSLPName(entity), getSLPName(holder)), false); + return 1; + } + + private static int removeHolderForBlockPos(CommandContext context, Entity entity, BlockPos pos) { + LeashStateInnerAPI.Offset.removeHolderFor(entity, pos); + context.getSource().sendSuccess(() -> + Component.translatable(REMOVE_HOLDER_FOR_BLOCK_POS_SUC, getSLPName(entity), getSLPName(pos)), false); + return 1; + } + + private static int removeHolderAll(CommandContext context, Entity entity) { + LeashStateInnerAPI.Offset.removeHolderAll(entity); + context.getSource().sendSuccess(() -> + Component.translatable(REMOVE_HOLDER_ALL_SUC, getSLPName(entity)), false); + return 1; + } + + private static int removeAllHolderUUIDs(CommandContext context, Entity entity) { + LeashStateInnerAPI.Offset.removeAllHolderUUIDs(entity); + context.getSource().sendSuccess(() -> + Component.translatable(REMOVE_ALL_HOLDER_UUIDS_SUC, getSLPName(entity)), false); + return 1; + } + + private static int removeAllHolderBlockPoses(CommandContext context, Entity entity) { + LeashStateInnerAPI.Offset.removeAllHolderBlockPoses(entity); + context.getSource().sendSuccess(() -> + Component.translatable(REMOVE_ALL_HOLDER_BLOCK_POSES_SUC, getSLPName(entity)), false); + return 1; + } + + private static int removeApplyEntity(CommandContext context, Entity entity) { + LeashStateInnerAPI.Offset.removeApplyEntity(entity); + context.getSource().sendSuccess(() -> + Component.translatable(REMOVE_APPLY_ENTITY_SUC, getSLPName(entity)), false); + return 1; + } + + // ==================== 查询操作实现 ==================== + + private static int queryHasState(CommandContext context, Entity entity) { + boolean hasState = LeashStateInnerAPI.Query.hasState(entity); + context.getSource().sendSuccess(() -> + Component.translatable(QUERY_HAS_STATE_SUC, getSLPName(entity), hasState), false); + return 1; + } + + private static int getAllUUIDStates(CommandContext context, Entity entity) { + var states = LeashStateInnerAPI.Query.getAllUUIDStates(entity); + context.getSource().sendSuccess(() -> + Component.translatable(GET_ALL_UUID_STATES_SUC, getSLPName(entity), states.size()), false); + states.forEach((uuid, state) -> { + context.getSource().sendSuccess(() -> + Component.literal(" UUID: " + uuid + ", 状态: " + state), false); + }); + return 1; + } + + private static int getAllBlockPosStates(CommandContext context, Entity entity) { + var states = LeashStateInnerAPI.Query.getAllBlockPosStates(entity); + context.getSource().sendSuccess(() -> + Component.translatable(GET_ALL_BLOCK_POS_STATES_SUC, getSLPName(entity), states.size()), false); + states.forEach((pos, state) -> { + context.getSource().sendSuccess(() -> + Component.literal(" 位置: " + pos + ", 状态: " + state), false); + }); + return 1; + } + + private static int getApplyEntityOffset(CommandContext context, Entity entity) { + LeashStateInnerAPI.Offset.getApplyEntityOffset(entity).ifPresentOrElse( + offset -> context.getSource().sendSuccess(() -> + Component.translatable(GET_APPLY_ENTITY_OFFSET_SUC, getSLPName(entity), offset), false), + () -> context.getSource().sendSuccess(() -> + Component.translatable(GET_APPLY_ENTITY_OFFSET_NONE, getSLPName(entity)), false) + ); + return 1; + } + + private static int getDefaultApplyEntityOffset(CommandContext context, Entity entity) { + Vec3 offset = LeashStateInnerAPI.Offset.getDefaultApplyEntityOffset(entity); + context.getSource().sendSuccess(() -> + Component.translatable(GET_DEFAULT_APPLY_ENTITY_OFFSET_SUC, getSLPName(entity), offset), false); + return 1; + } +} \ No newline at end of file diff --git a/src/main/java/top/r3944realms/superleadrope/core/leash/LeashInteractHandler.java b/src/main/java/top/r3944realms/superleadrope/core/leash/LeashInteractHandler.java index 89e1bda..48d0ef3 100644 --- a/src/main/java/top/r3944realms/superleadrope/core/leash/LeashInteractHandler.java +++ b/src/main/java/top/r3944realms/superleadrope/core/leash/LeashInteractHandler.java @@ -63,7 +63,10 @@ public class LeashInteractHandler { event.setCanceled(true); event.setCancellationResult(InteractionResult.SUCCESS); } - + if (SuperLeadRopeApi.isLeashHolder(target, player)) { + event.setCanceled(true); + event.setCancellationResult(InteractionResult.SUCCESS); + } return; } if (hand == InteractionHand.OFF_HAND) { diff --git a/src/main/java/top/r3944realms/superleadrope/datagen/data/SLPLangKeyValue.java b/src/main/java/top/r3944realms/superleadrope/datagen/data/SLPLangKeyValue.java index 86f7d79..721932a 100644 --- a/src/main/java/top/r3944realms/superleadrope/datagen/data/SLPLangKeyValue.java +++ b/src/main/java/top/r3944realms/superleadrope/datagen/data/SLPLangKeyValue.java @@ -18,6 +18,7 @@ package top.r3944realms.superleadrope.datagen.data; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import org.jetbrains.annotations.NotNull; +import top.r3944realms.superleadrope.content.command.Command; import top.r3944realms.superleadrope.content.command.LeashDataCommand; import top.r3944realms.superleadrope.content.command.MotionCommand; import top.r3944realms.superleadrope.content.gamerule.server.CreateSuperLeashKnotEntityIfAbsent; @@ -348,106 +349,438 @@ public enum SLPLangKeyValue { "§b倍乘成功.§a%s§7:§f[§e加速§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r", "§b倍乘既成.§a%s§7:§f[§e速勢§7:(§a%.2f§7,§a%.2f§7,§a%.2f§7)§f]§r" ), + MESSAGE_ABBREVIATION( + Command.ABBREVIATION, ModPartEnum.COMMAND, + "...", + "...", + "...", + "..." + ), + MESSAGE_END( + Command.END, ModPartEnum.COMMAND, + ".", + "。", + "。", + "。" + ), + MESSAGE_COLON( + Command.COLON, ModPartEnum.COMMAND, + ":", + ":", + ":", + ":" + ), + MESSAGE_BLOCK_POS( + Command.BLOCK_POS, ModPartEnum.COMMAND, + "§7[§fX: %d, Y: %d, Z: %d§7]", + "§7[§fX: %d, Y: %d, Z: %d§7]", + "§7[§fX: %d, Y: %d, Z: %d§7]", + "§7[§fX: %d, Y: %d, Z: %d§7]" + ), + MESSAGE_NONE( + Command.NONE, ModPartEnum.COMMAND, + "", + "无", + "無", + "無" + ), + MESSAGE_LEASHDATA_ALL_KNOTS( + LeashDataCommand.ALL_KNOTS, ModPartEnum.COMMAND, + "All Knots", + "所有绳结", + "所有繩結", + "諸結" + ), + MESSAGE_LEASHDATA_ALL_HOLDERS( + LeashDataCommand.ALL_HOLDERS, ModPartEnum.COMMAND, + "All Holders", + "所有持有者", + "所有持有者", + "諸持者" + ), + MESSAGE_LEASHDATA_SET_STATIC_MAX_DISTANCE( + LeashDataCommand.SET_STATIC_MAX_DISTANCE_SUC, ModPartEnum.COMMAND, + "Successfully set the static max distance of leash to %.2f from %s", + "已成功设置%.2f为%s的全局最大距离", + "已成功設定%.2f為%s的全域最大距離", + "繩距定為%.2f,已立%s之全域極距" + ), + MESSAGE_LEASHDATA_RESET_STATIC_MAX_DISTANCE( + LeashDataCommand.RESET_STATIC_MAX_DISTANCE_SUC, ModPartEnum.COMMAND, + "Successfully reset the static max distance of leash from %s", + "已成功重置%s的全局最大距离", + "已成功重置%s的全域最大距離", + "%s之全域極距,今已復初" + ), + MESSAGE_LEASHDATA_SET_STATIC_ELASTIC_DISTANCE_SCALE( + LeashDataCommand.SET_STATIC_ELASTIC_DISTANCE_SCALE_SUC, ModPartEnum.COMMAND, + "Successfully set the static elastic distance scale of leash to %.2f from %s", + "已成功设置%.2f为%s的全局弹性距离比例", + "已成功設定%.2f為%s的全域彈性距離比例", + "繩距彈性比例定為%.2f,已立%s之全域伸縮度" + ), + MESSAGE_LEASHDATA_RESET_STATIC_ELASTIC_DISTANCE_SCALE( + LeashDataCommand.RESET_STATIC_ELASTIC_DISTANCE_SCALE_SUC, ModPartEnum.COMMAND, + "Successfully reset the static elastic distance scale of leash from %s", + "成功重置%s的全局弹性距离比例", + "成功重置%s的全域彈性距離比例", + "%s之全域伸縮比例,今已復初" + ), + MESSAGE_LEASHDATA_SET_MAX_DISTANCE_SUC( + LeashDataCommand.SET_MAX_DISTANCE_SUC, ModPartEnum.COMMAND, + "Successfully adjusted the max distance of leash from %s to %s", + "成功调整%s到%s的拴绳最大距离", + "成功調整%s到%s的拴繩最大距離", + "%s至%s之拴繩極距,今已定" + ), + MESSAGE_LEASHDATA_SET_MAX_DISTANCE_SUC_FAIL( + LeashDataCommand.SET_MAX_DISTANCE_SUC_FAIL, ModPartEnum.COMMAND, + ", but failed to adjust it from %s to %s", + ",但未能调整%s到%s的拴绳最大距离", + ",但未能調整%s到%s的拴繩最大距離", + ",然%s至%s之拴繩極距未定" + ), + MESSAGE_LEASHDATA_SET_MAX_DISTANCE_FAIL( + LeashDataCommand.SET_MAX_DISTANCE_FAIL, ModPartEnum.COMMAND, + "Failed to adjust the max distance of leash from %s to %s", + "未能调整%s到%s的拴绳最大距离", + "未能調整%s到%s的拴繩最大距離", + "%s至%s之拴繩極距未成" + ), + MESSAGE_LEASHDATA_REMOVE_ALL_BLOCK_LEASHES( + LeashDataCommand.REMOVE_ALL_BLOCK_LEASHES, ModPartEnum.COMMAND, + "Successfully removed all holders' leash to %s", + "已成功移除所有持有者对%s的牵引", + "已成功移除所有持有者對%s的牽引", + "%s之所有羈絆,今已盡釋" + ), + MESSAGE_LEASHDATA_REMOVE_REMOVE_ALL_HOLDER_LEASHES( + LeashDataCommand.REMOVE_ALL_HOLDER_LEASHES, ModPartEnum.COMMAND, + "Successfully removed all holders' leash to %s", + "已成功移除所有持有者对%s的牵引", + "已成功移除所有持有者對%s的牽引", + "%s之所有繫繩,今已盡除" + ), + MESSAGE_LEASHDATA_TRANSFER_FROM_BLOCK_SUC( + LeashDataCommand.TRANSFER_FROM_BLOCK_SUC, ModPartEnum.COMMAND, + "Successfully transferred leash from %s to %s", + "已成功将牵引从%s转移至%s", + "已成功將牽引從%s轉移至%s", + "繫繩自%s移至%s,其事已成" + ), + MESSAGE_LEASHDATA_TRANSFER_FROM_BLOCK_SUC_FAIL( + LeashDataCommand.TRANSFER_FROM_BLOCK_SUC_FAIL, ModPartEnum.COMMAND, + ", but failed to transfer leash from %s to %s.", + ",但未能将牵引从%s转移至%s", + ",但未能將牽引從%s轉移至%s", + ",然自%s至%s之遷移未竟" + ), + MESSAGE_LEASHDATA_TRANSFER_FROM_BLOCK_FAIL( + LeashDataCommand.TRANSFER_FROM_BLOCK_FAIL, ModPartEnum.COMMAND, + "Failed to transfer leash from %s to %s.", + "未能将牵引从%s转移至%s", + "未能將牽引從%s轉移至%s", + "繫繩自%s遷於%s之舉未遂" + ), + MESSAGE_LEASHDATA_SET_ELASTIC_DISTANCE_SCALE_SUC( + LeashDataCommand.SET_ELASTIC_DISTANCE_SCALE_SUC, ModPartEnum.COMMAND, + "Successfully adjusted the elastic distance scale of leash from %s to %s", + "成功调整%s到%s的拴绳弹性距离比例", + "成功調整%s到%s的拴繩彈性距離比例", + "%s至%s之拴繩伸縮比例,今已定" + ), + MESSAGE_LEASHDATA_SET_ELASTIC_DISTANCE_SCALE_SUC_FAIL( + LeashDataCommand.SET_ELASTIC_DISTANCE_SCALE_SUC_FAIL, ModPartEnum.COMMAND, + ", but failed to adjust it from %s to %s", + ",但未能调整%s到%s的拴绳弹性距离比例", + ",但未能調整%s到%s的拴繩彈性距離比例", + ",然%s至%s之拴繩伸縮比例未定" + ), + MESSAGE_LEASHDATA_SET_ELASTIC_DISTANCE_SCALE_FAIL( + LeashDataCommand.SET_ELASTIC_DISTANCE_SCALE_FAIL, ModPartEnum.COMMAND, + "Failed to adjust the elastic distance scale of leash from %s to %s", + "未能调整%s到%s的拴绳弹性距离比例", + "未能調整%s到%s的拴繩彈性距離比例", + "%s至%s之拴繩伸縮比例未成" + ), + MESSAGE_LEASHDATA_SET_BLOCK_MAX_DISTANCE_SUC( + LeashDataCommand.SET_BLOCK_MAX_DISTANCE_SUC, ModPartEnum.COMMAND, + "Successfully adjusted the max distance of leash from %s to %s", + "成功调整%s到%s的拴绳最大距离", + "成功調整%s到%s的拴繩最大距離", + "%s至%s之拴繩極距,今已定" + ), + MESSAGE_LEASHDATA_SET_BLOCK_MAX_DISTANCE_SUC_FAIL( + LeashDataCommand.SET_BLOCK_MAX_DISTANCE_SUC_FAIL, ModPartEnum.COMMAND, + ", but failed to adjust it from %s to %s", + ",但未能调整%s到%s的拴绳最大距离", + ",但未能調整%s到%s的拴繩最大距離", + ",然%s至%s之拴繩極距未定" + ), + MESSAGE_LEASHDATA_SET_BLOCK_MAX_DISTANCE_FAIL( + LeashDataCommand.SET_BLOCK_MAX_DISTANCE_FAIL, ModPartEnum.COMMAND, + "Failed to adjust the max distance of leash from %s to %s", + "未能调整%s到%s的拴绳最大距离", + "未能調整%s到%s的拴繩最大距離", + "%s至%s之拴繩極距未成" + ), + MESSAGE_LEASHDATA_SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC( + LeashDataCommand.SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC, ModPartEnum.COMMAND, + "Successfully adjusted the elastic distance scale of leash from %s to %s", + "成功调整%s到%s的拴绳弹性距离比例", + "成功調整%s到%s的拴繩彈性距離比例", + "%s至%s之拴繩伸縮比例,今已定" + ), + MESSAGE_LEASHDATA_SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC_FAIL( + LeashDataCommand.SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC_FAIL, ModPartEnum.COMMAND, + ", but failed to adjust it from %s to %s", + ",但未能调整%s到%s的拴绳弹性距离比例", + ",但未能調整%s到%s的拴繩彈性距離比例", + ",然%s至%s之拴繩伸縮比例未定" + ), + MESSAGE_LEASHDATA_SET_BLOCK_ELASTIC_DISTANCE_SCALE_FAIL( + LeashDataCommand.SET_BLOCK_ELASTIC_DISTANCE_SCALE_FAIL, ModPartEnum.COMMAND, + "Failed to adjust the elastic distance scale of leash from %s to %s", + "未能调整%s到%s的拴绳弹性距离比例", + "未能%s調整為拴繩彈性距離比例從%s", + "繩距伸縮比例自%s易為%s之舉未遂" + ), + MESSAGE_LEASHDATA_LEASH_DATA_HEAD( + LeashDataCommand.LEASH_DATA_HEAD, ModPartEnum.COMMAND, + "LeashData:", + "拴绳数据:", + "拴繩數據:", + "繫繩錄:" + ), + MESSAGE_LEASHDATA_LEASH_DATA_ITEM( + LeashDataCommand.LEASH_DATA_ITEM, ModPartEnum.COMMAND, + "%s { Holder:%s, BlockPos:%s }", + "%s { 持有者: %s, 坐标: %s }", + "%s { 持有者: %s, 座標: %s }", + "%s { 持者: %s, 位: %s }" + ), /** * Message leashdata get block slp lang key value. */ MESSAGE_LEASHDATA_GET_BLOCK( LeashDataCommand.BLOCK, ModPartEnum.COMMAND, - "§7Block: §e%s", - "§7方块: §e%s", - "§7方塊: §e%s", - "§7磚石: §e%s" + "Block", + "方块", + "方塊", + "磚石" ), /** * Message leashdata get uuid slp lang key value. */ MESSAGE_LEASHDATA_GET_UUID( LeashDataCommand.UUID, ModPartEnum.COMMAND, - "§7UUID: §b%s", - "§7UUID: §b%s", - "§7UUID: §b%s", - "§7UUID: §b%s" + "UUID", + "UUID", + "UUID", + "UUID" ), /** * Message leashdata get max slp lang key value. */ MESSAGE_LEASHDATA_GET_MAX( LeashDataCommand.MAX, ModPartEnum.COMMAND, - "§7Max: §a%.1f", - "§7最大距离: §a%.1f", - "§7最大距離: §a%.1f", - "§7極距: §a%.1f" + "Max Distance", + "最大距离", + "最大距離", + "極距" ), /** * Message leashdata get elastic slp lang key value. */ MESSAGE_LEASHDATA_GET_ELASTIC( LeashDataCommand.ELASTIC, ModPartEnum.COMMAND, - "§7Elastic: §6%.1f", - "§7弹性距离: §6%.1f", - "§7彈性距離: §6%.1f", - "§7彈距: §6%.1f" + "Elastic Scale", + "弹性尺度", + "彈性尺度", + "彈距度" ), /** * Message leashdata get keep slp lang key value. */ MESSAGE_LEASHDATA_GET_KEEP( LeashDataCommand.KEEP, ModPartEnum.COMMAND, - "§7Keep: §c%d§7/§c%d", - "§7保持: §c%d§7/§c%d", - "§7保持: §c%d§7/§c%d", - "§7持時: §c%d§7/§c%d" + "Keep Ticks", + "保持刻", + "保持刻", + "持時" ), /** * Message leashdata get reserved slp lang key value. */ MESSAGE_LEASHDATA_GET_RESERVED( LeashDataCommand.RESERVED, ModPartEnum.COMMAND, - "§7Reserved: §d%s", - "§7保留字段: §d%s", - "§7保留字段: §d%s", - "§7備註: §d%s" + "Reserved", + "保留字段", + "保留字段", + "備註" ), - /** - * The Message leashdata add success. - */ - MESSAGE_LEASHDATA_ADD_SUCCESS( - "command.leashdata.add_apply_entity.success", ModPartEnum.COMMAND, - "§bAdded leash successfully. §a%s §7→ §e%s", - "§b添加拴绳成功. §a%s §7→ §e%s", - "§b添加拴繩成功. §a%s §7→ §e%s", - "§b繫繩既添. §a%s §7→ §e%s" + MESSAGE_LEASHDATA_ENTITY( + LeashDataCommand.ENTITY, ModPartEnum.COMMAND, + "§7[ §l§fEntity §r§7]", + "§7[ §l§f实体 §r§7]", + "§7[ §l§f實體 §r§7]", + "§7[ §l§f實者 §r§7]" ), - /** - * The Message leashdata remove success. - */ - MESSAGE_LEASHDATA_REMOVE_SUCCESS( - "command.leashdata.removeApplyEntity.success", ModPartEnum.COMMAND, - "§bRemoved leash successfully. §a%s §7- §e%s", - "§b移除拴绳成功. §a%s §7- §e%s", - "§b移除拴繩成功. §a%s §7- §e%s", - "§b繫繩既除. §a%s §7- §e%s" + + MESSAGE_LEASHDATA_KNOT( + LeashDataCommand.KNOT, ModPartEnum.COMMAND, + "Knot", + "§7[ §l§f绳结 §r§7]", + "§7[ §l§f繩結 §r§7]", + "§7[ §l§f結 §r§7]" ), - /** - * The Message leashdata transfer success. - */ - MESSAGE_LEASHDATA_TRANSFER_SUCCESS( - "command.leashdata.transfer.success", ModPartEnum.COMMAND, - "§bTransferred leash successfully. §a%s §7→ §e%s §7→ §6%s", - "§b转移拴绳成功. §a%s §7→ §e%s §7→ §6%s", - "§b轉移拴繩成功. §a%s §7→ §e%s §7→ §6%s", - "§b繫繩既移. §a%s §7→ §e%s §7→ §6%s" + MESSAGE_LEASHDATA_LEASH_INFO_HEAD( + LeashDataCommand.LEASH_INFO_HEAD, ModPartEnum.COMMAND, + "LeashInfo:", + "拴绳信息:", + "拴繩資訊:", + "繫繩訊:" + ), + MESSAGE_LEASHDATA_LEASH_INFO_ITEM( + LeashDataCommand.LEASH_INFO_ITEM, ModPartEnum.COMMAND, + "%s { Info: %s }", + "%s { 信息: %s }", + "%s { 資訊: %s }", + "%s { 訊: %s }" + ), + MESSAGE_LEASHDATA_ADD_HOLDER_LEASHES_SUC( + LeashDataCommand.ADD_HOLDER_LEASHES_SUC, ModPartEnum.COMMAND, + "Successfully attached %s leash from %s to %s", + "成功将%s拴绳从%s连接到%s", + "成功將%s拴繩從%s連接到%s", + "%s繩自%s繫於%s,其事已成" + ), + MESSAGE_LEASHDATA_ADD_HOLDER_LEASHES_SUC_FAIL( + LeashDataCommand.ADD_HOLDER_LEASHES_SUC_FAIL, ModPartEnum.COMMAND, + ", but failed to attached %s leash from %s to %s.", + ",但未能将%s拴绳从%s连接到%s", + ",但未能將%s拴繩從%s連接到%s", + ",然%s繩自%s繫於%s未竟" + ), + MESSAGE_LEASHDATA_ADD_HOLDER_LEASHES_FAIL( + LeashDataCommand.ADD_HOLDER_LEASHES_FAIL, ModPartEnum.COMMAND, + "Failed to attached %s leash from %s to %s.", + "未能将%s拴绳从%s连接到%s", + "未能將%s拴繩從%s連接到%s", + "%s繩自%s繫於%s之舉未遂" + ), + MESSAGE_LEASHDATA_ADD_BLOCK_LEASHES_SUC( + LeashDataCommand.ADD_BLOCK_LEASHES_SUC, ModPartEnum.COMMAND, + "Successfully attached %s leash from %s to %s", + "成功将%s拴绳从%s连接到%s", + "成功將%s拴繩從%s連接到%s", + "%s繩自%s繫於%s,其事已成" + ), + MESSAGE_LEASHDATA_ADD_BLOCK_LEASHES_SUC_FAIL( + LeashDataCommand.ADD_BLOCK_LEASHES_SUC_FAIL, ModPartEnum.COMMAND, + ", but failed to attached %s leash from %s to %s.", + ",但未能将%s拴绳从%s连接到%s", + ",但未能將%s拴繩從%s連接到%s", + ",然%s繩自%s繫於%s未竟" + ), + MESSAGE_LEASHDATA_ADD_BLOCK_LEASHES_FAIL( + LeashDataCommand.ADD_BLOCK_LEASHES_FAIL, ModPartEnum.COMMAND, + "Failed to attached %s leash from %s to %s.", + "未能将%s拴绳从%s连接到%s", + "未能將%s拴繩從%s連接到%s", + "%s繩自%s繫於%s之舉未遂" + ), + MESSAGE_LEASHDATA_ADD_BLOCK_LEASHES_FAIL_NO_KNOT_FOUND( + LeashDataCommand.ADD_BLOCK_LEASHES_FAIL_NO_KNOT_FOUND, ModPartEnum.COMMAND, + "Unable to tie the towing rope to %s as there is no knot in the position.", + "无法将拴绳系到%s,因为该位置没有绳结", + "無法將拴繩繫到%s,因為該位置沒有繩結", + "%s處無結,拴繩難繫" + ), + MESSAGE_LEASHDATA_DEFAULT( + LeashDataCommand.DEFAULT, ModPartEnum.COMMAND, + "Default", + "默认值", + "默認值", + "原值" + ), + MESSAGE_LEASHDATA_REMOVE_HOLDER_LEASHES_SUC( + LeashDataCommand.REMOVE_HOLDER_LEASHES_SUC, ModPartEnum.COMMAND, + "Successfully detached leash from %s to %s", + "成功解除%s到%s的拴绳连接", + "成功解除%s到%s的拴繩連接", + "%s至%s之拴繩,今已解" + ), + MESSAGE_LEASHDATA_REMOVE_HOLDER_LEASHES_SUC_FAIL( + LeashDataCommand.REMOVE_HOLDER_LEASHES_SUC_FAIL, ModPartEnum.COMMAND, + ", but failed to detach leash from %s to %s", + "未能解除%s到%s的拴绳连接", + "未能解除%s到%s的拴繩連接", + "%s至%s之拴繩未除" + ), + MESSAGE_LEASHDATA_REMOVE_HOLDER_LEASHES_FAIL( + LeashDataCommand.REMOVE_HOLDER_LEASHES_FAIL, ModPartEnum.COMMAND, + "Failed to detach leash from %s to %s.", + "成功解除%s到%s的拴绳连接", + "成功解除%s到%s的拴繩連接", + "%s至%s之拴繩,今已解" + ), + MESSAGE_LEASHDATA_REMOVE_BLOCK_LEASHES_SUC( + LeashDataCommand.REMOVE_BLOCK_LEASHES_SUC, ModPartEnum.COMMAND, + "Successfully detached leash from %s to %s", + ",但未能解除%s到%s的拴绳连接", + ",但未能解除%s到%s的拴繩連接", + ",然%s至%s之拴繩未解" + ), + MESSAGE_LEASHDATA_REMOVE_BLOCK_LEASHES_SUC_FAIL( + LeashDataCommand.REMOVE_BLOCK_LEASHES_SUC_FAIL, ModPartEnum.COMMAND, + ", but failed to detach leash from %s to %s", + "未能解除%s到%s的拴绳连接", + "未能解除%s到%s的拴繩連接", + "%s至%s之拴繩未除" + ), + MESSAGE_LEASHDATA_REMOVE_BLOCK_LEASHES_FAIL( + LeashDataCommand.REMOVE_BLOCK_LEASHES_FAIL, ModPartEnum.COMMAND, + "Failed to detach leash from %s to %s.", + "成功解除%s的所有拴绳连接", + "成功解除%s的所有拴繩連接", + "%s之諸拴繩,今盡解" + ), + MESSAGE_LEASHDATA_REMOVE_ALL_LEASHES( + LeashDataCommand.REMOVE_ALL_LEASHES, ModPartEnum.COMMAND, + "Successfully detached all leash from %s", + "成功解除%s的所有拴绳连接", + "成功解除%s的所有拴繩連接", + "%s之諸拴繩,今盡解" + ), + MESSAGE_LEASHDATA_TRANSFER_LEASH_SUC( + LeashDataCommand.TRANSFER_LEASH_SUC, ModPartEnum.COMMAND, + "Successfully transferred leash from %s to %s", + "成功将拴绳从%s转移至%s", + "成功將拴繩從%s轉移至%s", + "拴繩自%s移至%s,其事已成" + ), + MESSAGE_LEASHDATA_TRANSFER_LEASH_SUC_FAIL( + LeashDataCommand.TRANSFER_LEASH_SUC_FAIL, ModPartEnum.COMMAND, + ", but failed to transfer leash from %s to %s.", + ",但未能将拴绳从%s转移至%s", + ",但未能將拴繩從%s轉移至%s", + ",然自%s至%s之遷移未竟" + ), + MESSAGE_LEASHDATA_TRANSFER_LEASH_FAIL( + LeashDataCommand.TRANSFER_LEASH_FAIL, ModPartEnum.COMMAND, + "Failed to transfer leash from %s to %s.", + "未能将拴绳从%s转移至%s", + "未能將拴繩從%s轉移至%s", + "拴繩自%s遷於%s之舉未遂" + ), + MESSAGE_LEASHDATA_APPLY_FORCE( + LeashDataCommand.APPLY_FORCE, ModPartEnum.COMMAND, + "Successfully applied force on %s", + "成功触发%s的力", + "成功觸發%s的力", + "%s之力,今已發" ), - /** - * The Message leashdata set success. - */ - MESSAGE_LEASHDATA_SET_SUCCESS( - "command.leashdata.setApplyEntity.success", ModPartEnum.COMMAND, - "§bSet leash property successfully. §a%s §7: §e%s §7= §6%.1f", - "§b设置拴绳属性成功. §a%s §7: §e%s §7= §6%.1f", - "§b設置拴繩屬性成功. §a%s §7: §e%s §7= §6%.1f", - "§b繫繩性既定. §a%s §7: §e%s §7= §6%.1f" - ); ; private final Supplier supplier; diff --git a/src/main/java/top/r3944realms/superleadrope/util/capability/LeashDataInnerAPI.java b/src/main/java/top/r3944realms/superleadrope/util/capability/LeashDataInnerAPI.java index 9e381c6..9537bbd 100644 --- a/src/main/java/top/r3944realms/superleadrope/util/capability/LeashDataInnerAPI.java +++ b/src/main/java/top/r3944realms/superleadrope/util/capability/LeashDataInnerAPI.java @@ -231,7 +231,24 @@ public final class LeashDataInnerAPI { */ public static final class PropertyOperations { private PropertyOperations() {} - + /** + * Set static max distance. + * + * @param entity the entity + * @param distance the distance + */ + public static void setStaticMaxDistance(Entity entity, @Nullable Double distance) { + getLeashData(entity).ifPresent(data -> data.setStaticMaxDistance(distance)); + } + /** + * Set static elastic distance scale. + * + * @param entity the entity + * @param distance the distance + */ + public static void setElasticDistanceScale(Entity entity, @Nullable Double distance) { + getLeashData(entity).ifPresent(data -> data.setStaticElasticDistanceScale(distance)); + } /** * Sets max distance. * diff --git a/src/main/templates/META-INF/mods.toml b/src/main/templates/META-INF/mods.toml index aa58fdd..fae2f89 100644 --- a/src/main/templates/META-INF/mods.toml +++ b/src/main/templates/META-INF/mods.toml @@ -25,7 +25,7 @@ displayName="${mod_name}" #mandatory # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional # A file name (in the root of the mod JAR) containing a logo for display -logoFile= "../../resources/superleadrope_logo.png" #optional +logoFile= "superleadrope_logo.png" #optional # A text field displayed in the mod UI credits="${mod_credits}" # A text field displayed in the mod UI