diff --git a/build.gradle b/build.gradle index 0aea5d0..1965159 100644 --- a/build.gradle +++ b/build.gradle @@ -197,33 +197,60 @@ tasks.named('javadoc', Javadoc).configure { options.links("https://docs.oracle.com/en/java/javase/17/docs/api/") options.memberLevel = JavadocMemberLevel.PUBLIC options.addBooleanOption('Xdoclint:none', true) - options.addStringOption('doctitle', "${mod_id} ${mod_version} Javadoc") + options.addStringOption('doctitle', "${mod_id} ${minecraft_version} ${mod_version} Javadoc") +} +// =====================(class/ java) ===================== +tasks.register('deobfJar', Jar) { + from(sourceSets.main.output) // class + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + manifest { + attributes([ + 'Specification-Title' : mod_id, + 'Specification-Vendor' : mod_authors, + 'Specification-Version' : '1', + 'Implementation-Title' : project.name, + 'Implementation-Version' : archiveVersion, + 'Implementation-Vendor' : mod_authors, + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + ]) + } + dependsOn classes +} +tasks.register('sourceJar', Jar) { + from(sourceSets.main.allSource) // java + archiveFileName = "${mod_id}-${minecraft_version}-${mod_version}-sources.jar" + archiveClassifier.set("sources") + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + manifest { + attributes([ + 'Specification-Title' : mod_id, + 'Specification-Vendor' : mod_authors, + 'Specification-Version' : '1', + 'Implementation-Title' : project.name, + 'Implementation-Version' : archiveVersion, + 'Implementation-Vendor' : mod_authors, + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + ]) + } + dependsOn classes } - // ===================== 普通 Javadoc ===================== tasks.register('javadocJar', Jar) { - archiveClassifier.set('javadoc') + archiveFileName = "${mod_id}-${minecraft_version}-${mod_version}-javadoc.jar" + archiveClassifier.set("javadoc") from tasks.javadoc dependsOn tasks.javadoc } -tasks.register('apiJavadocJar', Jar) { - archiveClassifier.set('api-javadoc') - from tasks.javadoc - include "top/r3944realms/superleadrope/api/**/*" - dependsOn tasks.javadoc -} - - -// ===================== API Jar(class + java 混杂) ===================== +// ===================== API Jar(class / java) ===================== tasks.register('apiJar', Jar) { - archiveClassifier.set('api') + archiveFileName = "${mod_id}-${minecraft_version}-${mod_version}-api.jar" + archiveClassifier.set("api") manifest { attributes 'FMLModType': 'GAMELIBRARY' } // 打包 class 和 java - from(sourceSets.main.allSource) // java from(sourceSets.main.output) { // class exclude 'assets/**', 'data/**' } @@ -233,6 +260,31 @@ tasks.register('apiJar', Jar) { dependsOn classes } +tasks.register('apiSourceJar', Jar) { + archiveFileName = "${mod_id}-${minecraft_version}-${mod_version}-api-sources.jar" + archiveClassifier.set("api-sources") + manifest { + attributes 'FMLModType': 'GAMELIBRARY' + } + + // 打包 class 和 java + from(sourceSets.main.allSource) { // java + exclude 'assets/**', 'data/**' + } + + include "top/r3944realms/superleadrope/api/**/*" + include "top/r3944realms/superleadrope/SuperLeadRopeAPI.*" + + dependsOn classes +} + +tasks.register('apiJavadocJar', Jar) { + archiveFileName = "${mod_id}-${minecraft_version}-${mod_version}-api-javadoc.jar" + archiveClassifier.set("api-javadoc") + from tasks.javadoc + include "top/r3944realms/superleadrope/api/**/*" + dependsOn tasks.javadoc +} tasks.register('apiJavadoc', Javadoc) { group = 'documentation' @@ -252,31 +304,8 @@ tasks.register('apiJavadoc', Javadoc) { options.addStringOption('doctitle', "${mod_name} API ${mod_version} Javadoc") } -tasks.register('javadocApiJar', Jar) { - archiveClassifier.set('api-javadoc') - from tasks.apiJavadoc - dependsOn tasks.apiJavadoc -} -// ===================== 主包完整 Jar(class + java) ===================== -tasks.register('fullJar', Jar) { - archiveClassifier.set('all') // Maven 上会是 -all.jar - from(sourceSets.main.allSource) // java - from(sourceSets.main.output) // class - // === 避免重复打包资源(即使混入其他 jar 时也不会重复) === - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - manifest { - attributes([ - 'Specification-Title' : mod_id, - 'Specification-Vendor' : mod_authors, - 'Specification-Version' : '1', - 'Implementation-Title' : project.name, - 'Implementation-Version' : archiveVersion, - 'Implementation-Vendor' : mod_authors, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - ]) - } - dependsOn classes -} + + // ===================== 主 Jar 与混淆 ===================== jar { @@ -291,10 +320,7 @@ jar { 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), ]) } - archiveFileName = "${mod_id}-${mod_version}-origin.jar" - - // 可选:排除 API 类(如果你不想在主 jar 中包含 API) - // exclude "top/r3944realms/superleadrope/api/**/*" + archiveFileName = "${mod_id}-${minecraft_version}-${mod_version}-origin.jar" finalizedBy 'proguard' } @@ -374,10 +400,11 @@ publishing { mavenJava(MavenPublication) { artifactId = mod_id - artifact fullJar - artifact apiJar - // 可选 + artifact deobfJar + artifact sourceJar artifact javadocJar + artifact apiJar + artifact apiSourceJar artifact apiJavadocJar pom { @@ -402,7 +429,8 @@ publishing { repositories { maven { - url "file://${project.projectDir}/mcmodsrepo" + name = "local" + url = layout.buildDirectory.dir("repo") } maven { name = 'LTDNexus' @@ -417,7 +445,7 @@ publishing { // ===================== 构建任务依赖 ===================== tasks.named('build') { - dependsOn apiJar, javadocApiJar + dependsOn apiJar, apiJavadocJar } tasks.named('clean') { @@ -458,3 +486,17 @@ idea { downloadJavadoc = true } } +afterEvaluate { + tasks.named('deobfJar') { + doLast { + def jar = file(layout.buildDirectory.dir("repo") + "${mod_id}-${minecraft_version}-${mod_version}.jar") + if (jar.exists()) ant.delete(jar) + } + } + 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) + } + } +} diff --git a/gradle.properties b/gradle.properties index 3d7e638..3506ee7 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-pre7 +mod_version=0.0.0.6-pre10 # 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/main/java/top/r3944realms/superleadrope/CommonEventHandler.java b/src/main/java/top/r3944realms/superleadrope/CommonEventHandler.java index 2d17584..8fbe570 100644 --- a/src/main/java/top/r3944realms/superleadrope/CommonEventHandler.java +++ b/src/main/java/top/r3944realms/superleadrope/CommonEventHandler.java @@ -62,6 +62,7 @@ import top.r3944realms.superleadrope.content.capability.CapabilityHandler; import top.r3944realms.superleadrope.content.capability.CapabilityRemainder; import top.r3944realms.superleadrope.content.capability.impi.LeashDataImpl; import top.r3944realms.superleadrope.content.capability.inter.IEternalPotato; +import top.r3944realms.superleadrope.content.command.LeashDataCommand; import top.r3944realms.superleadrope.content.command.MotionCommand; import top.r3944realms.superleadrope.content.entity.SuperLeashKnotEntity; import top.r3944realms.superleadrope.content.gamerule.server.TeleportWithLeashedEntities; @@ -477,6 +478,7 @@ public class CommonEventHandler { public static void onRegisterCommand (RegisterCommandsEvent event) { CommandDispatcher dispatcher = event.getDispatcher(); MotionCommand.register(dispatcher); + LeashDataCommand.register(dispatcher); } } diff --git a/src/main/java/top/r3944realms/superleadrope/api/SuperLeadRopeApi.java b/src/main/java/top/r3944realms/superleadrope/api/SuperLeadRopeApi.java index 1d0b266..b098c09 100644 --- a/src/main/java/top/r3944realms/superleadrope/api/SuperLeadRopeApi.java +++ b/src/main/java/top/r3944realms/superleadrope/api/SuperLeadRopeApi.java @@ -122,7 +122,6 @@ public class SuperLeadRopeApi { * @param clazz the clazz * @param box the box * @param filter the filter - * * @return the list */ public static @NotNull List leashableInArea(Entity holder, Class clazz, AABB box, Predicate filter) { diff --git a/src/main/java/top/r3944realms/superleadrope/api/type/capabilty/ILeashData.java b/src/main/java/top/r3944realms/superleadrope/api/type/capabilty/ILeashData.java index 889697c..85daace 100644 --- a/src/main/java/top/r3944realms/superleadrope/api/type/capabilty/ILeashData.java +++ b/src/main/java/top/r3944realms/superleadrope/api/type/capabilty/ILeashData.java @@ -621,6 +621,20 @@ public interface ILeashData extends INBTSerializable { */ Collection getAllLeashes(); + /** + * Gets all leashes. + * + * @return the all leashes + */ + Collection getAllHolderLeashes(); + + /** + * Gets all leashes. + * + * @return the all leashes + */ + Collection getAllKnotLeashes(); + /** * Is leashed by boolean. * diff --git a/src/main/java/top/r3944realms/superleadrope/api/type/util/ILeashHelper.java b/src/main/java/top/r3944realms/superleadrope/api/type/util/ILeashHelper.java index b8dd6d1..6947d1a 100644 --- a/src/main/java/top/r3944realms/superleadrope/api/type/util/ILeashHelper.java +++ b/src/main/java/top/r3944realms/superleadrope/api/type/util/ILeashHelper.java @@ -77,26 +77,28 @@ public interface ILeashHelper { default Set getAllLeashedEntities() { return getAllLeash().stream().map(ILeashData::self).collect(Collectors.toSet()); } + /** * 获取该实体持有的指定实体实例 * - * @param clazz 实体类型 - * @param box 搜索范围 + * @param the type parameter + * @param clazz 实体类型 + * @param box 搜索范围 * @param filter {@link Predicate 实体过滤器} - * * @return {@link Set 持有的实体集合} */ @SuppressWarnings("unchecked") default Set getLeashEntities (Class clazz, AABB box, Predicate filter) { return (Set) getLeash(clazz, box, filter).stream().map(ILeashData::self).collect(Collectors.toSet()); } + /** * 获取该实体持有的符合条件实体的拴绳数据能力 * - * @param clazz 实体类型 - * @param box 搜索范围 + * @param the type parameter + * @param clazz 实体类型 + * @param box 搜索范围 * @param filter {@link Predicate 实体过滤器} - * * @return {@link Set 持有的实体的拴绳数据能力集合} */ Set getLeash(Class clazz, AABB box, Predicate filter); @@ -104,10 +106,10 @@ public interface ILeashHelper { /** * 获取该实体持有的符合条件实体实例 * - * @param clazz 实体类型 + * @param the type parameter + * @param clazz 实体类型 * @param fetchDistance 搜索范围(以实体为中心的正方体{@link AABB#ofSize(Vec3, double, double, double) 包围盒}) - * @param filter {@link Predicate 实体过滤器} - * + * @param filter {@link Predicate 实体过滤器} * @return {@link Set 持有的实体实例} */ @SuppressWarnings("unchecked") @@ -118,21 +120,22 @@ public interface ILeashHelper { /** * 获取该实体持有的符合条件实体的拴绳数据能力 * - * @param clazz 实体类型 + * @param the type parameter + * @param clazz 实体类型 * @param fetchDistance 搜索范围(以实体为中心的正方体{@link AABB#ofSize(Vec3, double, double, double) 包围盒}) - * @param filter {@link Predicate 实体过滤器} - * + * @param filter {@link Predicate 实体过滤器} * @return {@link Set 持有的实体的拴绳数据能力集合} */ default Set getLeash(Class clazz, double fetchDistance, Predicate filter) { return getLeash(clazz, AABB.ofSize(getHolderEntity().position(), fetchDistance, fetchDistance, fetchDistance), filter); } + /** * 获取该实体持有的符合条件实体实例 * - * @param clazz 实体类型 + * @param the type parameter + * @param clazz 实体类型 * @param filter {@link Predicate 实体过滤器} - * * @return {@link Set 持有的实体实例} */ @SuppressWarnings("unchecked") @@ -143,19 +146,20 @@ public interface ILeashHelper { /** * 获取该实体持有的符合条件实体的拴绳数据能力 * - * @param clazz 实体类型 + * @param the type parameter + * @param clazz 实体类型 * @param filter {@link Predicate 实体过滤器} - * * @return {@link Set 持有的实体的拴绳数据能力集合} */ default Set getLeash(Class clazz, Predicate filter) { return getLeash(clazz, 1024D, filter); } + /** * 获取该实体持有的符合条件实体实例 * + * @param the type parameter * @param clazz 实体类型 - * * @return {@link Set 持有的实体实例} */ @SuppressWarnings("unchecked") @@ -166,8 +170,8 @@ public interface ILeashHelper { /** * 获取该实体持有的符合条件实体的拴绳数据能力 * + * @param the type parameter * @param clazz 实体类型 - * * @return {@link Set 持有的实体的拴绳数据能力集合} */ default Set getLeash(Class clazz) { @@ -186,6 +190,8 @@ public interface ILeashHelper { /** * 检查是否持有任何拴绳 + * + * @return the boolean */ default boolean hasLeashes() { return !getAllLeash().isEmpty(); diff --git a/src/main/java/top/r3944realms/superleadrope/api/workspace/IWorkSpaceHelper.java b/src/main/java/top/r3944realms/superleadrope/api/workspace/IWorkSpaceHelper.java index dd95512..5b51c8f 100644 --- a/src/main/java/top/r3944realms/superleadrope/api/workspace/IWorkSpaceHelper.java +++ b/src/main/java/top/r3944realms/superleadrope/api/workspace/IWorkSpaceHelper.java @@ -47,12 +47,11 @@ public interface IWorkSpaceHelper { /** * Leashable in area list. * + * @param 实体类型 * @param pLevel the p level * @param clazz the clazz * @param filter the filter * @param box the box - * @param 实体类型 - * * @return the list */ @NotNull List leashableInArea(@NotNull Level pLevel, Class clazz,Predicate filter, AABB box); diff --git a/src/main/java/top/r3944realms/superleadrope/config/LeashCommonConfig.java b/src/main/java/top/r3944realms/superleadrope/config/LeashCommonConfig.java index 0c8ef1e..bd50543 100644 --- a/src/main/java/top/r3944realms/superleadrope/config/LeashCommonConfig.java +++ b/src/main/java/top/r3944realms/superleadrope/config/LeashCommonConfig.java @@ -37,7 +37,7 @@ public class LeashCommonConfig { /** * The Enable slp mod command prefix. */ - // Command +// Command public final ForgeConfigSpec.BooleanValue enableSLPModCommandPrefix; /** * The Slp mod command prefix. @@ -47,13 +47,13 @@ public class LeashCommonConfig { /** * The Teleport whitelist. */ - // Entity +// Entity public final ForgeConfigSpec.ConfigValue> teleportWhitelist; /** * The Max leash length. */ - // Leash settings +// Leash settings public final ForgeConfigSpec.DoubleValue maxLeashLength; /** * The Elastic distance scale. @@ -79,7 +79,7 @@ public class LeashCommonConfig { /** * The Enable true damping. */ - // True damping +// True damping public final ForgeConfigSpec.BooleanValue enableTrueDamping; /** * The Damping factor. @@ -101,7 +101,7 @@ public class LeashCommonConfig { /** * The Default apply entity location offset. */ - // Leash state offsets +// Leash state offsets public final ForgeConfigSpec.ConfigValue> defaultApplyEntityLocationOffset; /** * The Default holder location offset. @@ -111,7 +111,7 @@ public class LeashCommonConfig { /** * The constant OFFSET_PATTERN. */ - // 正则表达式模式 +// 正则表达式模式 static final Pattern OFFSET_PATTERN = Pattern.compile( "(?i)(?:vec3|vec3d|vector3|offset)\\s*\\(\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*,\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*,\\s*([-+]?[0-9]*\\.?[0-9]+)\\s*\\)\\s*:\\s*\\[\\s*([^]]+?)\\s*]\\s*" ); 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 aea492a..e449369 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 @@ -1343,6 +1343,16 @@ public class LeashDataImpl implements ILeashData { ).collect(Collectors.toList()); } + @Override + public Collection getAllHolderLeashes() { + return Collections.unmodifiableCollection(leashHolders.values()); + } + + @Override + public Collection getAllKnotLeashes() { + return Collections.unmodifiableCollection(leashKnots.values()); + } + @Override public boolean isLeashedBy(Entity holder) { return holder instanceof SuperLeashKnotEntity superLeashKnotEntity ? 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 5b690f5..8530b19 100644 --- a/src/main/java/top/r3944realms/superleadrope/content/command/Command.java +++ b/src/main/java/top/r3944realms/superleadrope/content/command/Command.java @@ -48,9 +48,38 @@ public class Command { * The constant ABBREVIATION. */ public static final String ABBREVIATION = BASE_ + "abbreviation"; + /** + * The constant BLOCK_POS. + */ public static final String BLOCK_POS = BASE_ + ".block_pos"; + /** + * The constant SUC. + */ + public static final String SUC = "suc"; + /** + * The constant FAIL. + */ + public static final String FAIL = "fail"; + /** + * The constant SUC_FAIL. + */ + public static final String SUC_FAIL = "suc_fail"; + /** + * The constant COLON. + */ + public static final String COLON = BASE_ + ".colon"; + /** + * The constant MAX_SHOW_NUMBER. + */ public static final int MAX_SHOW_NUMBER = 4; + + /** + * Gets slp name. + * + * @param entity the entity + * @return the slp name + */ public static Component getSLPName(Entity entity) { if (entity instanceof SuperLeashKnotEntity superLeashKnot) { BlockPos pos = superLeashKnot.getPos(); @@ -58,6 +87,13 @@ public class Command { } return entity.getName(); } + + /** + * Gets slp name. + * + * @param pos the pos + * @return the slp name + */ public static Component getSLPName(BlockPos pos) { return Component.translatable(BLOCK_POS, pos.getX(), pos.getY(), pos.getZ()); } 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 54e5830..732bb45 100644 --- a/src/main/java/top/r3944realms/superleadrope/content/command/LeashDataCommand.java +++ b/src/main/java/top/r3944realms/superleadrope/content/command/LeashDataCommand.java @@ -23,6 +23,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; @@ -30,6 +31,7 @@ import net.minecraft.commands.arguments.coordinates.BlockPosArgument; import net.minecraft.commands.arguments.selector.EntitySelector; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.MutableComponent; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; @@ -46,6 +48,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; import static top.r3944realms.superleadrope.content.command.Command.*; @@ -57,43 +60,15 @@ public class LeashDataCommand { * The constant SLP_LEASH_MESSAGE_. */ public static final String SLP_LEASH_MESSAGE_ = Command.BASE_ + "leash.message."; + /** - * The constant LEASH_DATA_GET_. + * The constant ALL_KNOTS. */ - public static final String LEASH_DATA_GET_ = SLP_LEASH_MESSAGE_ + ".get.", + public static final String ALL_KNOTS = SLP_LEASH_MESSAGE_ + "all_knots"; /** - * The Title. + * The constant ALL_HOLDERS. */ - TITLE = LEASH_DATA_GET_ + "title", - /** - * The Total. - */ - TOTAL = LEASH_DATA_GET_ + "total", - /** - * The Block. - */ - BLOCK = LEASH_DATA_GET_ + "block", - /** - * The Uuid. - */ - UUID = LEASH_DATA_GET_ + "uuid", - /** - * The Max. - */ - MAX = LEASH_DATA_GET_ + "max", - /** - * The Elastic. - */ - ELASTIC = LEASH_DATA_GET_ + "elastic", - /** - * The Keep. - */ - KEEP = LEASH_DATA_GET_ + "keep", - /** - * The Reserved. - */ - RESERVED = LEASH_DATA_GET_ + "reserved" - ; + public static final String ALL_HOLDERS = SLP_LEASH_MESSAGE_ + "all_holders"; /** * Register. @@ -244,33 +219,56 @@ public class LeashDataCommand { .then(Commands.literal("fromBlock") .then(Commands.argument("fromPos", BlockPosArgument.blockPos()) .then(Commands.argument("to", EntityArgument.entity()) - .executes(LeashDataCommand::transferFromBlock) + .executes(context -> transferFromBlock( + context, + BlockPosArgument.getBlockPos(context, "fromPos"), + EntityArgument.getEntity(context, "to") + ) + ) .then(Commands.argument("reserved", StringArgumentType.string()) - .executes(context -> transferFromBlock(context, - StringArgumentType.getString(context, "reserved"))) + .executes(context -> transferFromBlock( + context, + BlockPosArgument.getBlockPos(context, "fromPos"), + EntityArgument.getEntity(context, "to"), + StringArgumentType.getString(context, "reserved") + ) + ) ) ) ) ) ); - RequiredArgumentBuilder $$$set$holder = Commands.argument("holder", EntityArgument.entity()) + + LiteralArgumentBuilder $$$set$holder = Commands.literal("entity") // 设置最大距离 .then(Commands.literal("maxDistance") .executes(LeashDataCommand::setMaxDistance) + .then(Commands.argument("holder", EntityArgument.entity()) + .executes( + context -> setMaxDistance( + context, + EntityArgument.getEntity(context, "holder") + ) + ) .then(Commands.argument("distance", DoubleArgumentType.doubleArg(LeashConfigManager.MAX_DISTANCE_MIN_VALUE, LeashConfigManager.MAX_DISTANCE_MAX_VALUE)) .executes(context -> setMaxDistance( context, + EntityArgument.getEntity(context, "holder"), DoubleArgumentType.getDouble(context,"distance") ) ) .then(Commands.argument("keepTicks", IntegerArgumentType.integer(0)) - .executes(context -> setMaxDistance(context, + .executes(context -> setMaxDistance( + context, + EntityArgument.getEntity(context, "holder"), DoubleArgumentType.getDouble(context,"distance"), IntegerArgumentType.getInteger(context, "keepTicks") ) ) .then(Commands.argument("reserved", StringArgumentType.string()) - .executes(context -> setMaxDistance(context, + .executes(context -> setMaxDistance( + context, + EntityArgument.getEntity(context, "holder"), DoubleArgumentType.getDouble(context,"distance"), IntegerArgumentType.getInteger(context, "keepTicks"), StringArgumentType.getString(context, "reserved") @@ -279,54 +277,77 @@ public class LeashDataCommand { ) ) ) - ) + ) + ) // 设置弹性距离比例 .then(Commands.literal("elasticDistanceScale") .executes(LeashDataCommand::setElasticDistanceScale) - .then(Commands.argument("scale", DoubleArgumentType.doubleArg(LeashConfigManager.ELASTIC_DISTANCE_MIN_VALUE, LeashConfigManager.ELASTIC_DISTANCE_MAX_VALUE)) - .executes(context -> setElasticDistanceScale( + .then(Commands.argument("holder", EntityArgument.entity()) + .executes( + context -> setElasticDistanceScale( context, - DoubleArgumentType.getDouble(context,"scale") - ) - ) - .then(Commands.argument("keepTicks", IntegerArgumentType.integer(0)) - .executes(context -> setElasticDistanceScale( - context, - DoubleArgumentType.getDouble(context,"scale"), - IntegerArgumentType.getInteger(context, "keepTicks") - ) - ) - .then(Commands.argument("reserved", StringArgumentType.string()) - .executes(context -> setElasticDistanceScale(context, - DoubleArgumentType.getDouble(context,"scale"), - IntegerArgumentType.getInteger(context, "keepTicks"), - StringArgumentType.getString(context, "reserved") - ) - ) + EntityArgument.getEntity(context, "holder") ) ) + .then(Commands.argument("scale", DoubleArgumentType.doubleArg(LeashConfigManager.ELASTIC_DISTANCE_MIN_VALUE, LeashConfigManager.ELASTIC_DISTANCE_MAX_VALUE)) + .executes( + context -> setElasticDistanceScale( + context, + EntityArgument.getEntity(context, "holder"), + DoubleArgumentType.getDouble(context,"scale") + ) + ) + .then(Commands.argument("keepTicks", IntegerArgumentType.integer(0)) + .executes( + context -> setElasticDistanceScale( + context, + EntityArgument.getEntity(context, "holder"), + DoubleArgumentType.getDouble(context,"scale"), + IntegerArgumentType.getInteger(context, "keepTicks") + ) + ) + .then(Commands.argument("reserved", StringArgumentType.string()) + .executes( + context -> setElasticDistanceScale(context, + EntityArgument.getEntity(context, "holder"), + DoubleArgumentType.getDouble(context,"scale"), + IntegerArgumentType.getInteger(context, "keepTicks"), + StringArgumentType.getString(context, "reserved") + ) + ) + ) + ) + ) ) ); LiteralArgumentBuilder $$$set$pos = Commands.literal("block") + .executes(LeashDataCommand::setBlockMaxDistance) .then(Commands.argument("pos", BlockPosArgument.blockPos()) // 设置最大距离 .then(Commands.literal("maxDistance") - .executes(LeashDataCommand::setBlockMaxDistance) + .executes(context -> setBlockMaxDistance( + context, + BlockPosArgument.getBlockPos(context, "pos") + ) + ) .then(Commands.argument("distance", DoubleArgumentType.doubleArg(LeashConfigManager.MAX_DISTANCE_MIN_VALUE, LeashConfigManager.MAX_DISTANCE_MAX_VALUE)) .executes(context -> setBlockMaxDistance( context, + BlockPosArgument.getBlockPos(context, "pos"), DoubleArgumentType.getDouble(context, "distance") ) ) .then(Commands.argument("keepTicks", IntegerArgumentType.integer(0)) .executes(context -> setBlockMaxDistance(context, + BlockPosArgument.getBlockPos(context, "pos"), DoubleArgumentType.getDouble(context, "distance"), IntegerArgumentType.getInteger(context, "keepTicks") ) ) .then(Commands.argument("reserved", StringArgumentType.string()) .executes(context -> setBlockMaxDistance(context, + BlockPosArgument.getBlockPos(context, "pos"), DoubleArgumentType.getDouble(context, "distance"), IntegerArgumentType.getInteger(context, "keepTicks"), StringArgumentType.getString(context, "reserved") @@ -340,28 +361,40 @@ public class LeashDataCommand { // 设置弹性距离比例 .then(Commands.literal("elasticDistanceScale") .executes(LeashDataCommand::setBlockElasticDistanceScale) - .then(Commands.argument("scale", DoubleArgumentType.doubleArg(LeashConfigManager.ELASTIC_DISTANCE_MIN_VALUE, LeashConfigManager.ELASTIC_DISTANCE_MAX_VALUE)) + .then(Commands.argument("pos", BlockPosArgument.blockPos()) .executes(context -> setBlockElasticDistanceScale( context, - DoubleArgumentType.getDouble(context, "scale") + BlockPosArgument.getBlockPos(context, "pos") ) ) - .then(Commands.argument("keepTicks", IntegerArgumentType.integer(0)) - .executes(context -> setBlockElasticDistanceScale(context, - DoubleArgumentType.getDouble(context, "scale"), - IntegerArgumentType.getInteger(context, "keepTicks") - ) - ) - .then(Commands.argument("reserved", StringArgumentType.string()) - .executes(context -> setBlockElasticDistanceScale(context, - DoubleArgumentType.getDouble(context, "scale"), - IntegerArgumentType.getInteger(context, "keepTicks"), - StringArgumentType.getString(context, "reserved") - ) - ) - ) - ) - ) + .then(Commands.argument("scale", DoubleArgumentType.doubleArg(LeashConfigManager.ELASTIC_DISTANCE_MIN_VALUE, LeashConfigManager.ELASTIC_DISTANCE_MAX_VALUE)) + .executes(context -> setBlockElasticDistanceScale( + context, + BlockPosArgument.getBlockPos(context, "pos"), + DoubleArgumentType.getDouble(context, "scale") + ) + ) + .then(Commands.argument("keepTicks", IntegerArgumentType.integer(0)) + .executes(context -> setBlockElasticDistanceScale( + context, + BlockPosArgument.getBlockPos(context, "pos"), + DoubleArgumentType.getDouble(context, "scale"), + IntegerArgumentType.getInteger(context, "keepTicks") + ) + ) + .then(Commands.argument("reserved", StringArgumentType.string()) + .executes(context -> setBlockElasticDistanceScale( + context, + BlockPosArgument.getBlockPos(context, "pos"), + DoubleArgumentType.getDouble(context, "scale"), + IntegerArgumentType.getInteger(context, "keepTicks"), + StringArgumentType.getString(context, "reserved") + ) + ) + ) + ) + ) + ) ) ); LiteralArgumentBuilder $$$set = Commands.literal("set") @@ -370,7 +403,7 @@ public class LeashDataCommand { .then($$$set$holder) // 方块拴绳设置 - .then($$$set$pos) + .then($$$set$pos).executes(LeashDataCommand::setBlockMaxDistance) ); LiteralArgumentBuilder $$$applayForces = Commands.literal("applyForces") .then(Commands.argument("targets", EntityArgument.entities()) @@ -412,203 +445,704 @@ public class LeashDataCommand { } } + + private static int setMaxDistance(CommandContext context) throws CommandSyntaxException { + return setMaxDistance(context, null); + } + private static int setMaxDistance(CommandContext context, @Nullable Entity holder) throws CommandSyntaxException { + return setMaxDistance(context, holder, -1); + } + private static int setMaxDistance(CommandContext context, @Nullable Entity holder, double maxDistance) throws CommandSyntaxException { + return setMaxDistance(context, holder, maxDistance, 0); + } + private static int setMaxDistance(CommandContext context, @Nullable Entity holder, double maxDistance, int keepTicks) throws CommandSyntaxException { + return setMaxDistance(context, holder, maxDistance, keepTicks, null); + } + /** * The constant SET_MAX_DISTANCE. */ public static final String SET_MAX_DISTANCE_ = SLP_LEASH_MESSAGE_ + "set.max_distance."; - - private static int setMaxDistance(CommandContext context) throws CommandSyntaxException { - return setMaxDistance(context, -1/* -1 -> null*/); - } - private static int setMaxDistance(CommandContext context, double maxDistance) throws CommandSyntaxException { - return setMaxDistance(context, maxDistance, 0); - } private static int setMaxDistance(CommandContext context, double maxDistance, int keepTicks) throws CommandSyntaxException { - return setMaxDistance(context, maxDistance, keepTicks, null); - } - - private static int setMaxDistance(CommandContext context, double maxDistance, int keepTicks,@Nullable String reserved) throws CommandSyntaxException { + /** + * The constant SET_MAX_DISTANCE_SUC. + */ + public static final String SET_MAX_DISTANCE_SUC = SET_MAX_DISTANCE_ + SUC; + /** + * The constant SET_MAX_DISTANCE_SUC_FAIL. + */ + public static final String SET_MAX_DISTANCE_SUC_FAIL = SET_MAX_DISTANCE_ + SUC_FAIL; + /** + * The constant SET_MAX_DISTANCE_FAIL. + */ + public static final String SET_MAX_DISTANCE_FAIL = SET_MAX_DISTANCE_ + FAIL; + private static int setMaxDistance(CommandContext context, @Nullable Entity holder, double maxDistance, int keepTicks, @Nullable String reserved) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); - Entity holder = EntityArgument.getEntity(context, "holder"); + CommandSourceStack source = context.getSource(); + AtomicInteger success = new AtomicInteger(-1); + AtomicInteger failure = new AtomicInteger(-1); + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER], failEntities = new Entity[MAX_SHOW_NUMBER]; for (Entity target : targets) { - boolean isSuccessful = LeashDataInnerAPI.PropertyOperations.setMaxDistance(holder, target, maxDistance== -1 ? null : maxDistance, keepTicks, reserved); + if (holder != null) { + boolean isSuccessful = LeashDataInnerAPI.PropertyOperations.setMaxDistance(target, holder, maxDistance == -1 ? null : maxDistance, keepTicks, reserved); + if (isSuccessful) { + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } else { + if (failure.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + failEntities[failure.get()] = target; + } + } + } else { + LeashDataInnerAPI.getLeashData(target) + .ifPresent( + leashData -> leashData.getAllHolderLeashes() + .forEach(info -> { + boolean isSuccessful = leashData.setMaxDistance(info.holderUUIDOpt().orElseThrow(), null); + if (isSuccessful) { + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } else { + if (failure.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + failEntities[failure.get()] = target; + } + } + } + ) + ); + } + } - // Successfully adjusted leash to the max distance from %s[if more than 4 items, display in abbreviated form] to %s[BlockPos] - // [if failed then add ", but failed to adjust from %s[if more than 4 items, display in abbreviated form] to %s", else "."] - return -1; + MutableComponent failureEntitiesComponent = Component.empty(), successEntitiesComponent = Component.empty(); + generateEntityComponent(sucEntities, success.get(), successEntitiesComponent); + generateEntityComponent(failEntities, failure.get(), failureEntitiesComponent); + MutableComponent send = Component.empty(); + if (success.get() >= 0) { + // Successfully adjusted the max distance of leash from %s[if more than 4 items, display in abbreviated form] to %s[BlockPos] + 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))); + } //. + else send.append("."); + } 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))); + } + source.sendSuccess(() -> send, true); + return 0; } /** * The constant REMOVE_ALL_BLOCK_LEASHES. */ - public static final String REMOVE_ALL_BLOCK_LEASHES = SLP_LEASH_MESSAGE_ + "remove_apply_entity.all_block_leashes"; + public static final String REMOVE_ALL_BLOCK_LEASHES = SLP_LEASH_MESSAGE_ + "remove.all_block_leashes"; private static int removeAllBlockLeashes(CommandContext context) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); + CommandSourceStack source = context.getSource(); + int success = -1; + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER]; for (Entity target : targets) { LeashDataInnerAPI.LeashOperations.detachAllKnots(target); + if (++success <= MAX_SHOW_NUMBER - 1) { + sucEntities[success] = target; + } } - // Successfully adjusted leash to the max distance from %s[if more than 4 items, display in abbreviated form] to %s[BlockPos] - // [if failed then add ", but failed to adjust from %s[if more than 4 items, display in abbreviated form] to %s", else "."] - return -1; + MutableComponent successEntitiesComponent = Component.empty(), send = Component.empty(); + generateEntityComponent(sucEntities, success, successEntitiesComponent); + // Successfully removed all holders' leash to [%s] + send.append(Component.translatable(REMOVE_ALL_BLOCK_LEASHES, successEntitiesComponent)); + source.sendSuccess(() -> send, true); + return 0; } /** * The constant REMOVE_ALL_HOLDER_LEASHES. */ - public static final String REMOVE_ALL_HOLDER_LEASHES = SLP_LEASH_MESSAGE_ + "remove_apply_entity.all_holder_leashes"; + public static final String REMOVE_ALL_HOLDER_LEASHES = SLP_LEASH_MESSAGE_ + "remove.all_holder_leashes"; private static int removeAllHolderLeashes(CommandContext context) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); + CommandSourceStack source = context.getSource(); + int success = -1; + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER]; for (Entity target : targets) { LeashDataInnerAPI.LeashOperations.detachAllHolders(target); + if (++success <= MAX_SHOW_NUMBER - 1) { + sucEntities[success] = target; + } } - return -1; + MutableComponent successEntitiesComponent = Component.empty(), send = Component.empty(); + generateEntityComponent(sucEntities, success, successEntitiesComponent); + // Successfully removed all holders' leash to [%s] + send.append(Component.translatable(REMOVE_ALL_HOLDER_LEASHES, successEntitiesComponent)); + source.sendSuccess(() -> send, true); + return 0; + } + + + private static int transferFromBlock(CommandContext context, BlockPos fromPos, Entity to) throws CommandSyntaxException { + return transferFromBlock(context, fromPos, to, null); } /** * The constant TRANSFER_FROM_BLOCK. */ - public static final String TRANSFER_FROM_BLOCK = SLP_LEASH_MESSAGE_ + "transfer.from_block"; - private static int transferFromBlock(CommandContext context) throws CommandSyntaxException { - return transferFromBlock(context, ""); - } - private static int transferFromBlock(CommandContext context, String reserved) throws CommandSyntaxException { + public static final String TRANSFER_FROM_BLOCK_ = SLP_LEASH_MESSAGE_ + "transfer.from_block."; + /** + * The constant TRANSFER_FROM_BLOCK_SUC. + */ + public static final String TRANSFER_FROM_BLOCK_SUC = TRANSFER_FROM_BLOCK_ + SUC; + /** + * The constant TRANSFER_FROM_BLOCK_SUC_FAIL. + */ + public static final String TRANSFER_FROM_BLOCK_SUC_FAIL = TRANSFER_FROM_BLOCK_ + SUC_FAIL; + /** + * 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"); - Entity from = EntityArgument.getEntity(context, "from"); - Entity to = EntityArgument.getEntity(context, "to"); + CommandSourceStack source = context.getSource(); + int success = -1, failure = -1; + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER], failEntities = new Entity[MAX_SHOW_NUMBER]; for (Entity target : targets) { - boolean isSuccessful = LeashDataInnerAPI.TransferOperations.transfer(target, from, to, reserved); + boolean isSuccessful = LeashDataInnerAPI.TransferOperations.transfer(target, fromPos, to, reserved); + if (isSuccessful) { + if (++success <= MAX_SHOW_NUMBER - 1) { + sucEntities[success] = target; + } + } else { + if (++failure <= MAX_SHOW_NUMBER - 1) { + failEntities[failure] = target; + } + } } - return -1; + MutableComponent failureEntitiesComponent = Component.empty(), successEntitiesComponent = Component.empty(); + generateEntityComponent(sucEntities, success, successEntitiesComponent); + generateEntityComponent(failEntities, failure, failureEntitiesComponent); + MutableComponent send = Component.empty(); + if (success >= 0) { + // Successfully transferred leash from %s[BlockPos] to %s[BlockPos/Entity] [Leashed: [if more than 4 items, display in abbreviated form]] + 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)); + } //. + else send.append("."); + } 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)); + } + source.sendSuccess(() -> send, true); + return 0; + } + + + + private static int setElasticDistanceScale(CommandContext context) throws CommandSyntaxException { + return setElasticDistanceScale(context, null); + } + private static int setElasticDistanceScale(CommandContext context, @Nullable Entity holder) throws CommandSyntaxException { + return setElasticDistanceScale(context, holder, -1); + } + private static int setElasticDistanceScale(CommandContext context, @Nullable Entity holder, double maxDistance) throws CommandSyntaxException { + return setElasticDistanceScale(context, holder, maxDistance ,0); + } + private static int setElasticDistanceScale(CommandContext context, @Nullable Entity holder, double maxDistance, int keepTicks) throws CommandSyntaxException { + return setElasticDistanceScale(context, holder, maxDistance, keepTicks, null); } /** * The constant SET_ELASTIC_DISTANCE_SCALE. */ - public static final String SET_ELASTIC_DISTANCE_SCALE = SLP_LEASH_MESSAGE_ + "set_apply_entity.elastic_distance_scale"; - private static int setElasticDistanceScale(CommandContext context) throws CommandSyntaxException { - return setElasticDistanceScale(context, -1); - } - private static int setElasticDistanceScale(CommandContext context, double maxDistance) throws CommandSyntaxException { - return setElasticDistanceScale(context, maxDistance ,0); - } - private static int setElasticDistanceScale(CommandContext context, double maxDistance, int keepTicks) throws CommandSyntaxException { - return setElasticDistanceScale(context, maxDistance, keepTicks,null); - } - private static int setElasticDistanceScale(CommandContext context, double maxDistance, int keepTicks, String reserved) throws CommandSyntaxException { + public static final String SET_ELASTIC_DISTANCE_SCALE_ = SLP_LEASH_MESSAGE_ + "set.elastic_distance_scale."; + /** + * The constant SET_ELASTIC_DISTANCE_SCALE_SUC. + */ + public static final String SET_ELASTIC_DISTANCE_SCALE_SUC = SET_ELASTIC_DISTANCE_SCALE_ + SUC; + /** + * The constant SET_ELASTIC_DISTANCE_SCALE_SUC_FAIL. + */ + public static final String SET_ELASTIC_DISTANCE_SCALE_SUC_FAIL = SET_ELASTIC_DISTANCE_SCALE_ + SUC_FAIL; + /** + * The constant SET_ELASTIC_DISTANCE_SCALE_FAIL. + */ + public static final String SET_ELASTIC_DISTANCE_SCALE_FAIL = SET_ELASTIC_DISTANCE_SCALE_ + FAIL; + private static int setElasticDistanceScale(CommandContext context, @Nullable Entity holder, double maxDistance, int keepTicks, String reserved) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); - Entity holder = EntityArgument.getEntity(context, "holder"); + CommandSourceStack source = context.getSource(); + AtomicInteger success = new AtomicInteger(-1); + AtomicInteger failure = new AtomicInteger(-1); + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER], failEntities = new Entity[MAX_SHOW_NUMBER]; for (Entity target : targets) { - boolean isSuccessful = LeashDataInnerAPI.PropertyOperations.setMaxDistance(holder, target, maxDistance == -1 ? null : maxDistance, keepTicks, reserved); + if (holder != null) { + boolean isSuccessful = LeashDataInnerAPI.PropertyOperations.setElasticDistanceScale(target, holder, maxDistance == -1 ? null : maxDistance, keepTicks, reserved); + if (isSuccessful) { + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } else { + if (failure.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + failEntities[failure.get()] = target; + } + } + } else { + LeashDataInnerAPI.getLeashData(target) + .ifPresent( + leashData -> leashData.getAllKnotLeashes() + .forEach(info -> { + boolean isSuccessful = leashData.setElasticDistanceScale(info.holderUUIDOpt().orElseThrow(), null); + if (isSuccessful) { + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } else { + if (failure.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + failEntities[failure.get()] = target; + } + } + } + ) + ); + } + } - // Successfully adjusted leash to the elastic distance scale from %s[if more than 4 items, display in abbreviated form] to %s[Entity] - // [if failed then add ", but failed to adjust from %s[if more than 4 items, display in abbreviated form] to %s", else "."] - return -1; + MutableComponent failureEntitiesComponent = Component.empty(), successEntitiesComponent = Component.empty(); + generateEntityComponent(sucEntities, success.get(), successEntitiesComponent); + generateEntityComponent(failEntities, failure.get(), failureEntitiesComponent); + MutableComponent send = Component.empty(); + if (success.get() >= 0) { + // Successfully adjusted the elastic distance scale of leash from %s[if more than 4 items, display in abbreviated form] to %s[BlockPos] + 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))); + } //. + else send.append("."); + } 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))); + } + source.sendSuccess(() -> send, true); + return 0; + } + + + private static int setBlockMaxDistance(CommandContext context) throws CommandSyntaxException { + return setBlockMaxDistance(context, null, -1); + } + private static int setBlockMaxDistance(CommandContext context, @Nullable BlockPos blockPos) throws CommandSyntaxException { + return setBlockMaxDistance(context, blockPos, -1); + } + private static int setBlockMaxDistance(CommandContext context, @Nullable BlockPos blockPos, double maxDistance) throws CommandSyntaxException { + return setBlockMaxDistance(context, blockPos, maxDistance, 0); + } + private static int setBlockMaxDistance(CommandContext context, @Nullable BlockPos blockPos, double maxDistance, int keepTicks) throws CommandSyntaxException { + return setBlockMaxDistance(context, blockPos, maxDistance, keepTicks, null); } /** * The constant SET_BLOCK_MAX_DISTANCE. */ - public static final String SET_BLOCK_MAX_DISTANCE = SLP_LEASH_MESSAGE_ + "set_apply_entity.block_max_distance"; - private static int setBlockMaxDistance(CommandContext context) throws CommandSyntaxException { - return setBlockMaxDistance(context, -1); - } - private static int setBlockMaxDistance(CommandContext context, double maxDistance) throws CommandSyntaxException { - return setBlockMaxDistance(context, maxDistance, 0); - } - private static int setBlockMaxDistance(CommandContext context, double maxDistance, int keepTicks) throws CommandSyntaxException { - return setBlockMaxDistance(context, maxDistance, keepTicks, null); - } - private static int setBlockMaxDistance(CommandContext context, double maxDistance, int keepTicks, String reserved) throws CommandSyntaxException { + public static final String SET_BLOCK_MAX_DISTANCE_ = SLP_LEASH_MESSAGE_ + "set.block_max_distance."; + /** + * The constant SET_BLOCK_MAX_DISTANCE_SUC. + */ + public static final String SET_BLOCK_MAX_DISTANCE_SUC = SET_BLOCK_MAX_DISTANCE_ + SUC; + /** + * The constant SET_BLOCK_MAX_DISTANCE_SUC_FAIL. + */ + public static final String SET_BLOCK_MAX_DISTANCE_SUC_FAIL = SET_BLOCK_MAX_DISTANCE_ + SUC_FAIL; + /** + * The constant SET_BLOCK_MAX_DISTANCE_FAIL. + */ + public static final String SET_BLOCK_MAX_DISTANCE_FAIL = SET_BLOCK_MAX_DISTANCE_ + FAIL; + private static int setBlockMaxDistance(CommandContext context, @Nullable BlockPos blockPos, double maxDistance, int keepTicks, String reserved) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); - Entity holder = EntityArgument.getEntity(context, "holder"); + CommandSourceStack source = context.getSource(); + AtomicInteger success = new AtomicInteger(-1); + AtomicInteger failure = new AtomicInteger(-1); + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER], failEntities = new Entity[MAX_SHOW_NUMBER]; for (Entity target : targets) { - boolean isSuccessful = LeashDataInnerAPI.PropertyOperations.setMaxDistance(holder, target, maxDistance == -1 ? null : maxDistance, keepTicks, reserved); + if (blockPos != null) { + boolean isSuccessful = LeashDataInnerAPI.PropertyOperations.setMaxDistance(target, blockPos, maxDistance == -1 ? null : maxDistance, keepTicks, reserved); + if (isSuccessful) { + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } else { + if (failure.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + failEntities[failure.get()] = target; + } + } + } else { + LeashDataInnerAPI.getLeashData(target) + .ifPresent( + leashData -> leashData.getAllKnotLeashes() + .forEach(info -> { + boolean isSuccessful = leashData.setMaxDistance(info.blockPosOpt().orElseThrow(), null); + if (isSuccessful) { + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } else { + if (failure.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + failEntities[failure.get()] = target; + } + } + } + ) + ); + } + } - // Successfully adjusted leash to the max distance from %s[if more than 4 items, display in abbreviated form] to %s[Entity] - // [if failed then add ", but failed to adjust from %s[if more than 4 items, display in abbreviated form] to %s", else "."] - return -1; + MutableComponent failureEntitiesComponent = Component.empty(), successEntitiesComponent = Component.empty(); + generateEntityComponent(sucEntities, success.get(), successEntitiesComponent); + generateEntityComponent(failEntities, failure.get(), failureEntitiesComponent); + MutableComponent send = Component.empty(); + if (success.get() >= 0) { + // Successfully adjusted the max distance of leash from %s[if more than 4 items, display in abbreviated form] to %s[BlockPos] + 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))); + } //. + else send.append("."); + } 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))); + } + source.sendSuccess(() -> send, true); + return 0; + } + + + private static int setBlockElasticDistanceScale(CommandContext context) throws CommandSyntaxException { + return setBlockElasticDistanceScale(context, null, -1); + } + private static int setBlockElasticDistanceScale(CommandContext context, @Nullable BlockPos blockPos) throws CommandSyntaxException { + return setBlockElasticDistanceScale(context, blockPos, -1); + } + private static int setBlockElasticDistanceScale(CommandContext context, @Nullable BlockPos blockPos, double scale) throws CommandSyntaxException { + return setBlockElasticDistanceScale(context, blockPos, scale ,0); + } + private static int setBlockElasticDistanceScale(CommandContext context, @Nullable BlockPos blockPos, double scale, int keepTicks) throws CommandSyntaxException { + return setBlockElasticDistanceScale(context, blockPos, scale ,keepTicks, null); } /** * The constant SET_BLOCK_ELASTIC_DISTANCE_SCALE. */ - public static final String SET_BLOCK_ELASTIC_DISTANCE_SCALE = SLP_LEASH_MESSAGE_ + "set_apply_entity.block_elastic_distance_scale"; - private static int setBlockElasticDistanceScale(CommandContext context) throws CommandSyntaxException { - return setBlockElasticDistanceScale(context, -1); - } - private static int setBlockElasticDistanceScale(CommandContext context, double scale) throws CommandSyntaxException { - return setBlockElasticDistanceScale(context, scale ,0); - } - private static int setBlockElasticDistanceScale(CommandContext context, double scale, int keepTicks) throws CommandSyntaxException { - return setBlockElasticDistanceScale(context, scale ,keepTicks, null); - } - private static int setBlockElasticDistanceScale(CommandContext context, double scale, int keepTicks,@Nullable String reserved) throws CommandSyntaxException { + public static final String SET_BLOCK_ELASTIC_DISTANCE_SCALE_ = SLP_LEASH_MESSAGE_ + "set.block_elastic_distance_scale."; + /** + * The constant SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC. + */ + public static final String SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC = SET_BLOCK_ELASTIC_DISTANCE_SCALE_ + SUC; + /** + * The constant SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC_FAIL. + */ + public static final String SET_BLOCK_ELASTIC_DISTANCE_SCALE_SUC_FAIL = SET_BLOCK_ELASTIC_DISTANCE_SCALE_ + SUC_FAIL; + /** + * The constant SET_BLOCK_ELASTIC_DISTANCE_SCALE_FAIL. + */ + public static final String SET_BLOCK_ELASTIC_DISTANCE_SCALE_FAIL = SET_BLOCK_ELASTIC_DISTANCE_SCALE_ + FAIL; + + private static int setBlockElasticDistanceScale(CommandContext context, @Nullable BlockPos blockPos, double scale, int keepTicks,@Nullable String reserved) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); - Entity holder = EntityArgument.getEntity(context, "holder"); + CommandSourceStack source = context.getSource(); + AtomicInteger success = new AtomicInteger(-1); + AtomicInteger failure = new AtomicInteger(-1); + Entity[] sucEntities = new Entity[MAX_SHOW_NUMBER], failEntities = new Entity[MAX_SHOW_NUMBER]; for (Entity target : targets) { + if (blockPos != null) { + boolean isSuccessful = LeashDataInnerAPI.PropertyOperations.setElasticDistanceScale(target, blockPos, scale == -1 ? null : scale, keepTicks, reserved); + if (isSuccessful) { + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } else { + if (failure.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + failEntities[failure.get()] = target; + } + } + } else { + LeashDataInnerAPI.getLeashData(target) + .ifPresent( + leashData -> leashData.getAllKnotLeashes() + .forEach(info -> { + boolean isSuccessful = leashData.setElasticDistanceScale(info.blockPosOpt().orElseThrow(), null); + if (isSuccessful) { + if (success.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + sucEntities[success.get()] = target; + } + } else { + if (failure.incrementAndGet() <= MAX_SHOW_NUMBER - 1) { + failEntities[failure.get()] = target; + } + } + } + ) + ); + } - boolean isSuccessful = LeashDataInnerAPI.PropertyOperations.setElasticDistanceScale(holder, target, scale == -1 ? null : scale, keepTicks, reserved); } - // Successfully adjusted leash to the elastic distance scale from %s[if more than 4 items, display in abbreviated form] to %s[BlockPos] - // [if failed then add ", but failed to adjust from %s[if more than 4 items, display in abbreviated form] to %s", else "."] - return -1; + MutableComponent failureEntitiesComponent = Component.empty(), successEntitiesComponent = Component.empty(); + generateEntityComponent(sucEntities, success.get(), successEntitiesComponent); + generateEntityComponent(failEntities, failure.get(), failureEntitiesComponent); + MutableComponent send = Component.empty(); + if (success.get() >= 0) { + // Successfully adjusted the elastic distance scale of leash from %s[if more than 4 items, display in abbreviated form] to %s[BlockPos] + 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))); + } //. + else send.append("."); + } 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))); + } + source.sendSuccess(() -> send, true); + return 0; } - // ==================== 命令执行方法 ==================== + /** + * The constant LEASH_DATA_HEAD. + */ +// LeashData: [Entity]{Holder:{[Entity]}, BlockPos{[BlockPos]}} ... + public static final String LEASH_DATA_HEAD = SLP_LEASH_MESSAGE_ + "leash_data.head"; + /** + * The constant LEASH_DATA_ITEM. + */ + public static final String LEASH_DATA_ITEM = SLP_LEASH_MESSAGE_ + "leash_data.item"; + /** + * The constant LEASH_DATA_GET_. + */ + public static final String LEASH_DATA_GET_ = SLP_LEASH_MESSAGE_ + ".get.", + /** + * The Block. + */ + BLOCK = LEASH_DATA_GET_ + "block", + /** + * The Uuid. + */ + UUID = LEASH_DATA_GET_ + "uuid", + /** + * The Max. + */ + MAX = LEASH_DATA_GET_ + "max", + /** + * The Elastic. + */ + ELASTIC = LEASH_DATA_GET_ + "elastic", + /** + * The Keep. + */ + KEEP = LEASH_DATA_GET_ + "keep", + /** + * The Reserved. + */ + RESERVED = LEASH_DATA_GET_ + "reserved", + /** + * The Entity. + */ + ENTITY = LEASH_DATA_GET_ + "entity", + /** + * The Knot. + */ + KNOT = LEASH_DATA_GET_ + "knot"; + /** + * The constant MAX_SHOW_ENTITY. + */ + public static final int MAX_SHOW_ENTITY = 25; private static int getLeashData(CommandContext context) throws CommandSyntaxException { Collection targets = EntityArgument.getEntities(context, "targets"); CommandSourceStack source = context.getSource(); - - for (Entity target : targets) { - Collection leashes = LeashDataInnerAPI.QueryOperations.getAllLeashes(target); - source.sendSuccess(() -> Component.literal("=== Leash Data for " + target.getName().getString() + " ==="), false); - source.sendSuccess(() -> Component.literal("Total leashes: " + leashes.size()), false); - // TODO:翻译支持 HoverTip实现部分信息简化显示 + // LeashData: \n + MutableComponent head = Component.translatable(LEASH_DATA_HEAD).append("\n"); + List list = targets.stream().toList(); + Component[] items = new Component[MAX_SHOW_ENTITY]; + for (int i = 0; i < list.size() ; i++) { + if (i > MAX_SHOW_ENTITY) break; + // [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(list.get(i)); + int entityCount = 0, knotCount = 0; + Component[] holders = new Component[4], knots = new Component[4]; for (LeashInfo leash : leashes) { - StringBuilder info = new StringBuilder(); - leash.blockPosOpt().ifPresent(pos -> info.append("Block: ").append(pos.toShortString()).append(" ")); - leash.holderUUIDOpt().ifPresent(uuid -> info.append("UUID: ").append(uuid).append(" ")); - info.append("Max: ").append(leash.maxDistance()).append(" "); - info.append("Elastic: ").append(leash.elasticDistanceScale()).append(" "); - info.append("Keep: ").append(leash.keepLeashTicks()).append("/").append(leash.maxKeepLeashTicks()); - if (!leash.reserved().isEmpty()) { - info.append(" Reserved: ").append(leash.reserved()); + MutableComponent info; + MutableComponent hover = Component.empty(); + if (leash.holderIdOpt().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; + 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++; // 在这里增加计数 + } + + } else { + if (knotCount >= MAX_SHOW_NUMBER && entityCount >= MAX_SHOW_NUMBER) { + break; + } else if (knotCount >= MAX_SHOW_NUMBER) { + continue; + } else { + info = Component.translatable(KNOT).withStyle(s -> s.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); + holders[knotCount] = 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++; // 在这里增加计数 + } + } + 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") + ); + 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") + ); + 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") + ); + if (!leash.reserved().isEmpty()) { + 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") + ); } - - source.sendSuccess(() -> Component.literal(info.toString()), false); } - // LeashData: [Entity]{Holder:{[Entity]}, BlockPos{[BlockPos]}} ... - } - return targets.size(); + MutableComponent item = Component.translatable(LEASH_DATA_ITEM, list.get(i).getName(), buildHolderComponent(holders, entityCount), buildHolderComponent(knots, knotCount)); + items[i] = item; + } + Component component = buildFinalComponent(items, list.size()); + source.sendSuccess(() -> head.append(component), true); + return 0; } + + /** + * The constant LEASH_INFO_HEAD. + */ +// LeashData: [Entity]{Holder:{[Entity]}, BlockPos{[BlockPos]}} ... + public static final String LEASH_INFO_HEAD = SLP_LEASH_MESSAGE_ + "leash_info.head"; + /** + * The constant LEASH_INFO_ITEM. + */ + public static final String LEASH_INFO_ITEM = SLP_LEASH_MESSAGE_ + "leash_info.item"; private static int getLeashInfo(CommandContext context) throws CommandSyntaxException { Entity target = EntityArgument.getEntity(context, "target"); CommandSourceStack source = context.getSource(); + // LeashData: \n + 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; + Component[] items = new Component[leashes.size()]; + for (LeashInfo leash : leashes) { + MutableComponent info; + MutableComponent hover = Component.empty(); + if (leash.holderIdOpt().isPresent()){ + info = Component.translatable(ENTITY).withStyle(s -> s.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); + items[entityCount] = 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++; // 在这里增加计数 + } else { + info = Component.translatable(KNOT).withStyle(s -> s.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); + items[knotCount] = 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++; // 在这里增加计数 - - Collection leashes = LeashDataInnerAPI.QueryOperations.getAllLeashes(target); - // +++ - - source.sendSuccess(() -> Component.literal("=== Leash Info from " + target.getName().getString() + " ==="), false); - source.sendSuccess(() -> Component.literal("Total leashes: " + leashes.size()), false); - // TODO:翻译支持 HoverTip实现部分信息简化显示 - for (LeashInfo leash : leashes) { - StringBuilder info = new StringBuilder(); - leash.blockPosOpt().ifPresent(pos -> info.append("Block: ").append(pos.toShortString()).append(" ")); - leash.holderUUIDOpt().ifPresent(uuid -> info.append("UUID: ").append(uuid).append(" ")); - info.append("Max: ").append(leash.maxDistance()).append(" "); - info.append("Elastic: ").append(leash.elasticDistanceScale()).append(" "); - info.append("Keep: ").append(leash.keepLeashTicks()).append("/").append(leash.maxKeepLeashTicks()); - if (!leash.reserved().isEmpty()) { - info.append(" Reserved: ").append(leash.reserved()); + } + 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") + ); + 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") + ); + 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") + ); + if (!leash.reserved().isEmpty()) { + 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") + ); + } } + // LeashInfo: [Entity]{LeashInfo: {B/U, M, E, K, R} ..,} + MutableComponent item = Component.translatable(LEASH_INFO_ITEM, target.getName(), buildHolderInfoComponent(items, entityCount + knotCount)); + source.sendSuccess(() -> head.append(item), true); + return 0; + } - source.sendSuccess(() -> Component.literal(info.toString()), false); + private static @NotNull Component buildFinalComponent(Component @NotNull [] items, int count) { + MutableComponent result = Component.empty(); + for (int i = 0; i < Math.min(items.length, count); i++) { + if (items[i] != null) { + result.append(items[i]); + if (i < Math.min(items.length, count) - 1) { + result.append(Component.literal("\n")); + } + } + } + if (count > MAX_SHOW_ENTITY - 1) { + result.append(Component.translatable(ABBREVIATION)); } - // LeashInfo: [Entity]{LeashInfo: {B/U, M, E, K, R} ..,} + return result; + } + // 辅助方法:构建holder组件 + private static @NotNull Component buildHolderComponent(Component @NotNull [] holders, int count) { + MutableComponent result = Component.empty(); + for (int i = 0; i < Math.min(holders.length, count); i++) { + if (holders[i] != null) { + result.append(holders[i]); + if (i < Math.min(holders.length, count) - 1) { + result.append(Component.literal(", ")); + } + } + } + if (count > MAX_SHOW_NUMBER - 1) { + result.append(Component.translatable(ABBREVIATION)); + } - return 0; + return result; + } + private static @NotNull Component buildHolderInfoComponent(Component @NotNull [] holders, int count) { + MutableComponent result = Component.empty(); + for (int i = 0; i < Math.min(holders.length, count); i++) { + if (holders[i] != null) { + result.append(holders[i]); + if (i < Math.min(holders.length, count) - 1) { + result.append(Component.literal(", ")); + } + } + } + return result; } private static int addLeash(CommandContext context, Entity holder) throws CommandSyntaxException { return addLeash(context, holder,-1); @@ -658,7 +1192,6 @@ public class LeashDataCommand { sucEntities[success] = target; } } else { - failure++; if (++failure <= MAX_SHOW_NUMBER - 1) { failEntities[failure] = target; } @@ -731,7 +1264,7 @@ public class LeashDataCommand { ServerLevel level = source.getLevel(); SuperLeashKnotEntity knotEntity = SuperLeashKnotEntity.get(level, pos) .or(() -> { - if (SLPGameruleRegistry.getGameruleBoolValue(level, CreateSuperLeashKnotEntityIfAbsent.NAME_KEY)) + if (SLPGameruleRegistry.getGameruleBoolValue(level, CreateSuperLeashKnotEntityIfAbsent.ID) && SuperLeashKnotEntity.isSupportBlock(level.getBlockState(pos))) return Optional.of(SuperLeashKnotEntity.createKnot(level, pos, true)); else return Optional.empty(); }).orElse(null); @@ -750,7 +1283,6 @@ public class LeashDataCommand { sucEntities[success] = target; } } else { - failure++; if (++failure <= MAX_SHOW_NUMBER - 1) { failEntities[failure] = target; } @@ -819,7 +1351,6 @@ public class LeashDataCommand { sucEntities[success] = target; } } else { - failure++; if (++failure <= MAX_SHOW_NUMBER - 1) { failEntities[failure] = target; } @@ -873,7 +1404,6 @@ public class LeashDataCommand { sucEntities[success] = target; } } else { - failure++; if (++failure <= MAX_SHOW_NUMBER - 1) { failEntities[failure] = target; } @@ -955,7 +1485,6 @@ public class LeashDataCommand { sucEntities[success] = target; } } else { - failure++; if (++failure <= MAX_SHOW_NUMBER - 1) { failEntities[failure] = target; } @@ -1005,6 +1534,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()); 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 1c14f2a..c0c900d 100644 --- a/src/main/java/top/r3944realms/superleadrope/content/command/LeashStateCommand.java +++ b/src/main/java/top/r3944realms/superleadrope/content/command/LeashStateCommand.java @@ -27,7 +27,7 @@ public class LeashStateCommand { * * @param dispatcher the dispatcher */ - // 获取State +// 获取State // 设置State // Holder> // 设置对应目标的 拴绳偏移 diff --git a/src/main/java/top/r3944realms/superleadrope/content/entity/SuperLeashKnotEntity.java b/src/main/java/top/r3944realms/superleadrope/content/entity/SuperLeashKnotEntity.java index 2895f23..fce3409 100644 --- a/src/main/java/top/r3944realms/superleadrope/content/entity/SuperLeashKnotEntity.java +++ b/src/main/java/top/r3944realms/superleadrope/content/entity/SuperLeashKnotEntity.java @@ -35,6 +35,8 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.AABB; import org.jetbrains.annotations.NotNull; import top.r3944realms.superleadrope.api.SuperLeadRopeApi; +import top.r3944realms.superleadrope.content.capability.impi.LeashDataImpl; +import top.r3944realms.superleadrope.content.item.SuperLeadRopeItem; import top.r3944realms.superleadrope.core.register.SLPEntityTypes; import top.r3944realms.superleadrope.util.capability.LeashDataInnerAPI; diff --git a/src/main/java/top/r3944realms/superleadrope/content/item/EternalPotatoItem.java b/src/main/java/top/r3944realms/superleadrope/content/item/EternalPotatoItem.java index 69c4322..fb37725 100644 --- a/src/main/java/top/r3944realms/superleadrope/content/item/EternalPotatoItem.java +++ b/src/main/java/top/r3944realms/superleadrope/content/item/EternalPotatoItem.java @@ -66,6 +66,7 @@ public class EternalPotatoItem extends Item { /** * 获取或生成 ItemStack 的唯一 UUID @param stack the stack * + * @param stack the stack * @return the or create item uuid */ public static UUID getOrCreateItemUUID(ItemStack stack) { diff --git a/src/main/java/top/r3944realms/superleadrope/core/punishment/PunishmentDefinition.java b/src/main/java/top/r3944realms/superleadrope/core/punishment/PunishmentDefinition.java index 5e40747..03b727a 100644 --- a/src/main/java/top/r3944realms/superleadrope/core/punishment/PunishmentDefinition.java +++ b/src/main/java/top/r3944realms/superleadrope/core/punishment/PunishmentDefinition.java @@ -58,6 +58,8 @@ public record PunishmentDefinition(PunishmentDefinition.Type type, float strengt /** * 序列化到网络 @param buf the buf + * + * @param buf the buf */ public void toNetwork(FriendlyByteBuf buf) { buf.writeEnum(this.type); @@ -68,6 +70,7 @@ public record PunishmentDefinition(PunishmentDefinition.Type type, float strengt /** * 从网络反序列化 @param buf the buf * + * @param buf the buf * @return the punishment definition */ public static PunishmentDefinition fromNetwork(FriendlyByteBuf buf) { 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 71ddd04..86f7d79 100644 --- a/src/main/java/top/r3944realms/superleadrope/datagen/data/SLPLangKeyValue.java +++ b/src/main/java/top/r3944realms/superleadrope/datagen/data/SLPLangKeyValue.java @@ -348,26 +348,6 @@ 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" ), - /** - * The Message leashdata get title. - */ - MESSAGE_LEASHDATA_GET_TITLE( - LeashDataCommand.TITLE, ModPartEnum.COMMAND, - "=== Leash Data for %s ===", - "=== %s 的拴绳数据 ===", - "=== %s 的拴繩數據 ===", - "=== %s 之繫繩數據 ===" - ), - /** - * The Message leashdata get total. - */ - MESSAGE_LEASHDATA_GET_TOTAL( - LeashDataCommand.TOTAL, ModPartEnum.COMMAND, - "Total leashes: %d", - "总拴绳数: %d", - "總拴繩數: %d", - "繫繩總數: %d" - ), /** * Message leashdata get block slp lang key value. */ 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 7b07bcb..9e381c6 100644 --- a/src/main/java/top/r3944realms/superleadrope/util/capability/LeashDataInnerAPI.java +++ b/src/main/java/top/r3944realms/superleadrope/util/capability/LeashDataInnerAPI.java @@ -91,11 +91,11 @@ public final class LeashDataInnerAPI { /** * Attach boolean. * - * @param entity the entity - * @param holder the holder - * @param maxDistance the max distance + * @param entity the entity + * @param holder the holder + * @param maxDistance the max distance * @param elasticdDistanceScale the elastic distance - * @param maxKeepTicks the max keep ticks + * @param maxKeepTicks the max keep ticks * @return the boolean */ public static boolean attach(Entity entity, Entity holder, @Nullable Double maxDistance, @Nullable Double elasticdDistanceScale, int maxKeepTicks) { @@ -118,12 +118,12 @@ public final class LeashDataInnerAPI { /** * Attach boolean. * - * @param entity the entity - * @param holder the holder - * @param maxDistance the max distance + * @param entity the entity + * @param holder the holder + * @param maxDistance the max distance * @param elasticDistanceScale the elastic distance - * @param maxKeepTicks the max keep ticks - * @param reserved the reserved + * @param maxKeepTicks the max keep ticks + * @param reserved the reserved * @return the boolean */ public static boolean attach(Entity entity, Entity holder, @Nullable Double maxDistance, @Nullable Double elasticDistanceScale, int maxKeepTicks, String reserved) { @@ -240,16 +240,18 @@ public final class LeashDataInnerAPI { * @param distance the distance * @return the max distance */ - // ---------------------- 设置最大距离 ---------------------- +// ---------------------- 设置最大距离 ---------------------- public static boolean setMaxDistance(Entity entity, Entity holder, @Nullable Double distance) { return getLeashData(entity).map(data -> data.setMaxDistance(holder, distance)).orElse(false); } + /** * Sets max distance. * * @param entity the entity * @param holder the holder * @param distance the distance + * @param reserved the reserved * @return the max distance */ public static boolean setMaxDistance(Entity entity, Entity holder, @Nullable Double distance, @Nullable String reserved) { @@ -385,9 +387,9 @@ public final class LeashDataInnerAPI { /** * Sets elastic scale. * - * @param entity the entity - * @param holder the holder - * @param scale the scale + * @param entity the entity + * @param holder the holder + * @param scale the scale * @return the elastic scale */ // ---------------------- 设置弹性距离 ---------------------- @@ -400,7 +402,7 @@ public final class LeashDataInnerAPI { * * @param entity the entity * @param holder the holder - * @param scale the scale + * @param scale the scale * @param maxKeepTicks the max keep ticks * @return the elastic scale */ @@ -413,7 +415,7 @@ public final class LeashDataInnerAPI { * * @param entity the entity * @param holder the holder - * @param scale the scale + * @param scale the scale * @param maxKeepTicks the max keep ticks * @param reserved the reserved * @return the elastic scale @@ -433,7 +435,7 @@ public final class LeashDataInnerAPI { * * @param entity the entity * @param holderUUID the holder uuid - * @param scale the scale + * @param scale the scale * @return the elastic scale */ public static boolean setElasticDistanceScale(Entity entity, UUID holderUUID, @Nullable Double scale) { @@ -445,7 +447,7 @@ public final class LeashDataInnerAPI { * * @param entity the entity * @param holderUUID the holder uuid - * @param scale the scale + * @param scale the scale * @param maxKeepTicks the max keep ticks * @return the elastic scale */ @@ -458,7 +460,7 @@ public final class LeashDataInnerAPI { * * @param entity the entity * @param holderUUID the holder uuid - * @param scale the scale + * @param scale the scale * @param maxKeepTicks the max keep ticks * @param reserved the reserved * @return the elastic scale @@ -476,9 +478,9 @@ public final class LeashDataInnerAPI { /** * Sets elastic scale. * - * @param entity the entity - * @param knotPos the knot pos - * @param scale the scale + * @param entity the entity + * @param knotPos the knot pos + * @param scale the scale * @return the elastic scale */ public static boolean setElasticDistanceScale(Entity entity, BlockPos knotPos, @Nullable Double scale) { @@ -490,7 +492,7 @@ public final class LeashDataInnerAPI { * * @param entity the entity * @param knotPos the knot pos - * @param scale the scale + * @param scale the scale * @param maxKeepTicks the max keep ticks * @return the elastic scale */ @@ -503,7 +505,7 @@ public final class LeashDataInnerAPI { * * @param entity the entity * @param knotPos the knot pos - * @param scale the scale + * @param scale the scale * @param maxKeepTicks the max keep ticks * @param reserved the reserved * @return the elastic scale