pre修改:添加对事件的支持&API方法的修正

This commit is contained in:
叁玖领域 2025-10-22 11:03:17 +08:00
parent 6553f04b4e
commit 44bc1ad92a
16 changed files with 354 additions and 243 deletions

View File

@ -1,3 +1,5 @@
//noinspection GroovyAssignabilityCheck
//file:noinspection GroovyAssignabilityCheck
import proguard.gradle.ProGuardTask
buildscript {
@ -14,11 +16,11 @@ plugins {
id 'idea'
id 'java-library'
id 'maven-publish'
id 'org.jetbrains.dokka' version '1.9.10'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'net.neoforged.moddev.legacyforge' version '2.0.103'
}
// ===================== =====================
def enableProguard = project.hasProperty("enableProguard") && project.enableProguard.toBoolean()
tasks.named('wrapper', Wrapper).configure {
@ -38,68 +40,65 @@ base {
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
// ===================== =====================
repositories {
mavenCentral()
maven { url = "https://libraries.minecraft.net/" }
maven { url = "https://neoforged.forgecdn.net/releases" }
maven { url = "https://neoforged.forgecdn.net/mojang-meta" }
maven {
url "https://cursemaven.com"
content {
includeGroup "curse.maven"
}
content { includeGroup "curse.maven" }
}
maven {
// location of the maven that hosts JEI files before January 2023
name = "Progwml6's maven"
name = "Progwml6"
url = "https://dvs1.progwml6.com/files/maven/"
}
maven {
// location of the maven that hosts JEI files since January 2023
name = "Jared's maven"
name = "BlameJared"
url = "https://maven.blamejared.com/"
}
maven {
// location of a maven mirror for JEI files, as a fallback
name = "ModMaven"
url = "https://modmaven.dev"
}
maven {
name 'luck-repo'
url 'https://repo.lucko.me/'
content {
includeModule 'me.lucko', 'spark-api'
}
name = "Lucko"
url = "https://repo.lucko.me/"
content { includeModule 'me.lucko', 'spark-api' }
}
maven {
name "KosmX's maven"
url 'https://maven.kosmx.dev/'
name = "KosmX"
url = "https://maven.kosmx.dev/"
}
maven {
name = "Curios"
url = uri("https://maven.theillusivec4.top/")
url = "https://maven.theillusivec4.top/"
}
maven {
name = 'GeckoLib'
url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/'
name = "GeckoLib"
url = "https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/"
content {
includeGroupByRegex("software\\.bernie.*")
includeGroup("com.eliotlash.mclib")
}
}
mavenCentral()
flatDir {
dir "libs"
maven {
name = "LTD Maven"
url = "https://nexus.bot.leisuretimedock.top/repository/maven-public/"
}
flatDir { dir "libs" }
}
// ===================== Forge =====================
legacyForge {
version = "${minecraft_version}-${forge_version}"
accessTransformers = project.files "src/main/resources/META-INF/accesstransformer.cfg"
accessTransformers = files("src/main/templates/META-INF/accesstransformer.cfg")
parchment {
minecraftVersion = "${minecraft_version}"
mappingsVersion = "${mapping_lasting_version}"
minecraftVersion = minecraft_version
mappingsVersion = mapping_lasting_version
}
runs {
@ -108,57 +107,52 @@ legacyForge {
systemProperty 'forge.logging.markers', 'REGISTRIES'
logLevel = org.slf4j.event.Level.DEBUG
}
client {
client()
systemProperty 'forge.enabledGameTestNamespaces', mod_id
}
clientAuth {
devLogin = true
client()
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
// // RenderDoc library
// // 使
// systemProperty 'neoforged.rendernurse.renderdoc.library', file('RenderDoc_1.40_64/renderdoc.dll').absolutePath
//
// // JVM
// jvmArgument "-javaagent:${file('libs/RenderNurse-0.0.9.jar').absolutePath}"
// jvmArgument "--enable-preview"
// jvmArgument "--enable-native-access=ALL-UNNAMED"
}
client {
client()
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
}
gameTestServer {
type = "gameTestServer"
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
}
data {
systemProperty('gradle.task', 'runData')
data()
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
programArguments.addAll '--mod', project.mod_id, '--all',
'--output', file('src/generated/resources/').getAbsolutePath(),
'--existing', file('src/main/resources/').getAbsolutePath()
systemProperty 'forge.enabledGameTestNamespaces', mod_id
}
server {
server()
}
data {
data()
programArguments.addAll '--mod', mod_id, '--all',
'--output', file('src/generated/resources/').absolutePath,
'--existing', file('src/main/resources/').absolutePath
}
}
mods {
"${mod_id}" {
sourceSet(sourceSets.main)
sourceSet sourceSets.main
}
}
}
//
// ===================== =====================
sourceSets.main.resources {
srcDir 'src/generated/resources'
srcDir 'src/main/resources' // coremods
srcDir 'src/main/resources'
}
// ========== ==========
// ===================== =====================
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
// ===================== =====================
configurations {
runtimeClasspath.extendsFrom localRuntime
proguardLibs {
canBeResolved = true
canBeConsumed = false
extendsFrom modCompileOnly
}
}
dependencies {
@ -184,57 +178,107 @@ dependencies {
implementation 'org.ow2.asm:asm-tree:9.6'
implementation 'org.ow2.asm:asm-commons:9.6'
implementation 'org.ow2.asm:asm-util:9.6'
modCompileOnly("top.r3944realms.lib39:lib39:1.20.1-0.0.15:all@jar")
}
// ========== ==========
tasks.withType(JavaCompile).configureEach {
// ===================== Javadoc =====================
tasks.named('javadoc', Javadoc).configure {
group = 'documentation'
description = 'Generates full Javadoc for the mod.'
destinationDir = file("$buildDir/docs/javadoc")
//
source = sourceSets.main.allJava
classpath = sourceSets.main.compileClasspath
options.encoding = 'UTF-8'
options.charSet = 'UTF-8'
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")
}
dokkaJavadoc {
outputDirectory = file("$buildDir/javadoc")
// ===================== Javadoc =====================
tasks.register('javadocJar', Jar) {
archiveClassifier.set('javadoc')
from tasks.javadoc
dependsOn tasks.javadoc
}
// ========== API Jar ==========
tasks.register('apiJavadocJar', Jar) {
archiveClassifier.set('api-javadoc')
from tasks.javadoc
include "top/r3944realms/superleadrope/api/**/*"
dependsOn tasks.javadoc
}
// ===================== API Jarclass + java =====================
tasks.register('apiJar', Jar) {
archiveClassifier.set('api')
from sourceSets.main.output
include "top/r3944realms/superleadrope/api/**/*"
include "top/r3944realms/superleadrope/SuperLeadRopeAPI.class"
manifest {
attributes([
'Specification-Title' : "${mod_id}-api",
'Specification-Vendor' : mod_authors,
'Specification-Version' : '1',
'Implementation-Title' : "${project.name}-api",
'Implementation-Version' : archiveVersion,
'Implementation-Vendor' : mod_authors,
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
'FMLModType' : 'GAMELIBRARY'
])
attributes 'FMLModType': 'GAMELIBRARY'
}
// API
// class java
from(sourceSets.main.allSource) // java
from(sourceSets.main.output) { // class
exclude 'assets/**', 'data/**'
}
include "top/r3944realms/superleadrope/api/**/*"
include "top/r3944realms/superleadrope/SuperLeadRopeAPI.*"
dependsOn classes
}
// API Jar
tasks.register('sourcesApiJar', Jar) {
archiveClassifier.set('api-sources')
from sourceSets.main.allSource
include "top/r3944realms/superleadrope/api/**/*"
include "top/r3944realms/superleadrope/SuperLeadRopeAPI.java"
tasks.register('apiJavadoc', Javadoc) {
group = 'documentation'
description = 'Generates Javadoc for API package only.'
destinationDir = file("$buildDir/docs/api-javadoc")
source = sourceSets.main.allJava.matching {
include "top/r3944realms/superleadrope/api/**/*"
include "top/r3944realms/superleadrope/SuperLeadRopeAPI.java"
}
classpath = sourceSets.main.compileClasspath
options.encoding = 'UTF-8'
options.charSet = 'UTF-8'
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_name} API ${mod_version} Javadoc")
}
// API Javadoc Jar
tasks.register('javadocApiJar', Jar) {
archiveClassifier.set('api-javadoc')
from dokkaJavadoc
dependsOn dokkaJavadoc
from tasks.apiJavadoc
dependsOn tasks.apiJavadoc
}
// ===================== Jarclass + 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 {
manifest {
attributes([
@ -255,174 +299,162 @@ jar {
finalizedBy 'proguard'
}
//
processResources {
def props = [
minecraft_version : minecraft_version,
minecraft_version_range: minecraft_version_range,
forge_version : forge_version,
forge_version_range : forge_version_range,
loader_version_range : loader_version_range,
mod_id : mod_id,
mod_name : mod_name,
mod_license : mod_license,
mod_version : mod_version,
mod_authors : mod_authors,
mod_description : mod_description
]
inputs.properties props
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
expand props + [project: project]
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
// ShadowJar
shadowJar {
outputs.upToDateWhen { false }
}
// ProGuard
configurations {
proguardLibs {
canBeResolved = true
canBeConsumed = false
extendsFrom modCompileOnly
}
}
// ========== ProGuard ==========
tasks.register('proguard', ProGuardTask) {
onlyIf { enableProguard } // enableProguard=true
dependsOn(tasks.jar)
onlyIf { enableProguard }
dependsOn tasks.jar
configuration 'proguard.pro'
// JDK jmods
libraryjars "${System.getProperty('java.home')}/jmods"
// 使
configurations.proguardLibs.resolve().each { file ->
libraryjars file.absolutePath
}
//
def inputJar = tasks.jar.archiveFile.get().asFile
injars(inputJar)
outjars("${project.buildDir}/libs/[NOTUSE]${mod_id}-${minecraft_version}-${mod_version}-proguard.jar")
injars inputJar
outjars "${buildDir}/libs/[NOTUSE]${mod_id}-${minecraft_version}-${mod_version}-proguard.jar"
doFirst {
copy {
from inputJar
into "${project.buildDir}/libs"
into "${buildDir}/libs"
rename { "[NOTUSE]${mod_id}-${minecraft_version}-${mod_version}-origin.jar" }
}
}
inputs.files(tasks.jar.archiveFile)
inputs.files tasks.jar.archiveFile
finalizedBy 'reobfJar'
}
processResources {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {
var replaceProperties = [
minecraft_version : minecraft_version,
minecraft_version_range : minecraft_version_range,
forge_version : forge_version,
forge_version_range : forge_version_range,
loader_version_range : loader_version_range,
mod_id : mod_id,
mod_name : mod_name,
mod_license : mod_license,
mod_version : mod_version,
mod_authors : mod_authors,
mod_description : mod_description,
mod_credits : mod_credits
]
inputs.properties replaceProperties
expand replaceProperties
from "src/main/templates"
into "build/generated/sources/modMetadata"
}
sourceSets.main.resources.srcDir generateModMetadata
legacyForge.ideSyncTask generateModMetadata
// ========== Forge reobf ==========
afterEvaluate {
tasks.named('reobfJar') {
if (enableProguard) {
dependsOn('proguard')
dependsOn 'proguard'
input = file("${buildDir}/libs/[NOTUSE]${mod_id}-${minecraft_version}-${mod_version}-proguard.jar")
} else {
dependsOn('jar')
dependsOn 'jar'
input = tasks.jar.archiveFile.get().asFile
}
}
}
// ========== ==========
// ===================== =====================
publishing {
publications {
mavenJava(MavenPublication) {
artifact jar
// API
artifact apiJar
artifact sourcesApiJar
artifact javadocApiJar
artifactId = mod_id
artifact fullJar
artifact apiJar
//
artifact javadocJar
artifact apiJavadocJar
// POM 便
pom {
name = "${mod_name} API"
name = "${mod_id}"
description = "The API for ${mod_name}"
url = "https://github.com/3944Realms/SuperLeadMod"
licenses {
license {
name = mod_license
url = "https://opensource.org/licenses/MIT"
url = "https://www.gnu.org/licenses/gpl-3.0.en.html#license-text"
}
}
developers {
developer {
id = "r3944realms"
id = "${mod_id}"
name = mod_authors
}
}
}
}
}
repositories {
maven {
url "file://${project.projectDir}/mcmodsrepo"
}
maven {
name = 'LTDNexus'
url = 'https://nexus.bot.leisuretimedock.top/repository/maven-releases/'
credentials {
username = System.getenv('LTDNexusUsername') ?: ''
password = System.getenv('LTDNexusPassword') ?: ''
}
}
}
}
// ========== ==========
// API Jar
// ===================== =====================
tasks.named('build') {
dependsOn apiJar, sourcesApiJar, javadocApiJar
dependsOn apiJar, javadocApiJar
}
//
tasks.named('clean') {
delete fileTree(dir: "${project.projectDir}/mcmodsrepo")
}
// ===================== RenderDoc =====================
tasks.register("runWithRenderDoc", Exec) {
group = "minecraft"
description = "Run Minecraft with RenderDoc using runClientAuth configuration"
dependsOn("classes") //
def jdwpArgs = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
dependsOn "classes"
def renderDocCmd = file("RenderDoc_1.40_64/renderdoccmd.exe").absolutePath
def captureDir = file("$buildDir/renderdoc/capture").absolutePath
def runClientTask = tasks.named("runClientAuth", JavaExec).get()
def javaLauncher = runClientTask.getJavaLauncher().get()
def javaExecPath = new File(javaLauncher.metadata.installationPath.asFile, "bin/java.exe").absolutePath
def javaExecPath = new File(runClientTask.getJavaLauncher().get().metadata.installationPath.asFile, "bin/java.exe").absolutePath
def jdwpArgs = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
commandLine = [
renderDocCmd,
"capture",
"--opt-hook-children",
"--wait-for-exit",
commandLine renderDocCmd, "capture", "--opt-hook-children", "--wait-for-exit",
"--working-dir", "$projectDir/run",
"--capture-file", "${captureDir}/minecraft_capture",
javaExecPath,
jdwpArgs,
"@${buildDir}/moddev/clientRunVmArgs.txt", // JVM
"@${buildDir}/moddev/clientRunProgramArgs.txt" // Program
]
javaExecPath, jdwpArgs,
"@${buildDir}/moddev/clientRunVmArgs.txt",
"@${buildDir}/moddev/clientRunProgramArgs.txt"
environment "MOD_CLASSES", "superleadrope%%${buildDir}/classes/java/main;superleadrope%%${buildDir}/resources/main"
doFirst {
println "Using JVM: ${javaExecPath}"
println "RenderDoc capture dir: ${captureDir}"
println "Environment MOD_CLASSES: ${environment['MOD_CLASSES']}"
}
}
// IDEA
// ===================== IDEA =====================
idea {
module {
downloadSources = true
downloadJavadoc = true
}
}
}

View File

@ -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.5
mod_version=0.0.0.6-pre4
# 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
@ -68,3 +68,5 @@ mod_group_id=top.r3944realms.superleadrope
mod_authors=R3944Realms
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description= A Lead Rope which is better than Bugjump.
mod_credits=Leisure Time Dock

View File

@ -117,13 +117,15 @@ public class SuperLeadRopeApi {
/**
* Leashable in area list.
*
* @param <T> the type parameter
* @param holder the holder
* @param clazz the clazz
* @param box the box
* @param filter the filter
*
* @return the list
*/
public static @NotNull List<Entity> leashableInArea(Entity holder, Class<Entity> clazz, AABB box, Predicate<Entity> filter) {
public static <T extends Entity> @NotNull List<T> leashableInArea(Entity holder, Class<T> clazz, AABB box, Predicate<T> filter) {
return Services.WORK_SPACE.leashableInArea(holder.level(), clazz, i -> isLeashHolder(i, holder), box);
}

View File

@ -36,6 +36,27 @@ import java.util.UUID;
@SuppressWarnings("unused")
public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
private final Entity LeashedEntity;
/**
* The Has modified.
*/
protected boolean hasModified;
/**
* Is modified boolean.
*
* @return the boolean
*/
public boolean isModified() {
return hasModified;
}
/**
* Mark modified.
*/
public void markModified() {
this.hasModified = true;
}
/**
* Instantiates a new Super lead rope event.
@ -58,15 +79,15 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Add leash.
*/
// ADD LEASH
// ADD LEASH
@SuppressWarnings("unused")
@Cancelable
public static class AddLeash extends SuperLeadRopeEvent {
private final Entity holderEntity;
@Nullable
private final Double maxLeashDistance;
private Double maxLeashDistance;
@Nullable
private final Double elasticDistanceScale;
private Double elasticDistanceScale;
/**
* Instantiates a new Add leash.
@ -93,6 +114,26 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
this.elasticDistanceScale = elasticDistanceScale;
}
/**
* Sets elastic distance scale.
*
* @param elasticDistanceScale the elastic distance scale
*/
public void setElasticDistanceScale(@Nullable Double elasticDistanceScale) {
markModified();
this.elasticDistanceScale = elasticDistanceScale;
}
/**
* Sets max leash distance.
*
* @param maxLeashDistance the max leash distance
*/
public void setMaxLeashDistance(@Nullable Double maxLeashDistance) {
markModified();
this.maxLeashDistance = maxLeashDistance;
}
/**
* Gets holder entity.
*
@ -124,7 +165,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Remove leash.
*/
// REMOVE LEASH
// REMOVE LEASH
@SuppressWarnings("unused")
@Cancelable
public static class RemoveLeash extends SuperLeadRopeEvent {
@ -169,7 +210,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Transfer leash.
*/
// TRANSFORM LEASH
// TRANSFORM LEASH
@SuppressWarnings("unused")
@Cancelable
public static class TransferLeash extends SuperLeadRopeEvent {
@ -227,7 +268,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Modify value.
*/
// MODIFY LEASH MAX_LEASH_LENGTH / ELASTIC_DISTANCE_SCALE
// MODIFY LEASH MAX_LEASH_LENGTH / ELASTIC_DISTANCE_SCALE
@SuppressWarnings("unused")
@Cancelable
public static class ModifyValue extends SuperLeadRopeEvent {
@ -236,7 +277,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
@Nullable
private final Double oldValue;
@Nullable
private final Double newValue;
private Double newValue;
private final Type type;
private final Scope scope;
@ -366,12 +407,21 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
return scope;
}
/**
* Sets new value.
*
* @param newValue the new value
*/
public void setNewValue(@Nullable Double newValue) {
markModified();
this.newValue = newValue;
}
}
/**
* The type Has focus.
*/
// HAS FOCUS
// HAS FOCUS
@SuppressWarnings("unused")
@Cancelable
public static class hasFocus extends SuperLeadRopeEvent {
@ -421,6 +471,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
* @param combinedForce the combined force
*/
public void setCombinedForce(Vec3 combinedForce) {
markModified();
this.combinedForce = combinedForce;
}
@ -446,7 +497,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Keep not break tick.
*/
// KEEP NOT BREAK TICK
// KEEP NOT BREAK TICK
@SuppressWarnings("unused")
public static class keepNotBreakTick extends SuperLeadRopeEvent {
private final int remainedTicks;
@ -507,7 +558,7 @@ public abstract class SuperLeadRopeEvent extends Event implements IModBusEvent {
/**
* The type Teleport with holder.
*/
// TELEPORT
// TELEPORT
@Cancelable
@SuppressWarnings("unused")
public static class teleportWithHolder extends SuperLeadRopeEvent {

View File

@ -86,8 +86,9 @@ public interface ILeashHelper {
*
* @return {@link Set<Entity> 持有的实体集合}
*/
default Set<Entity> getLeashEntities (Class<Entity> clazz, AABB box, Predicate<Entity> filter) {
return getLeash(clazz, box, filter).stream().map(ILeashData::self).collect(Collectors.toSet());
@SuppressWarnings("unchecked")
default <T extends Entity> Set<T> getLeashEntities (Class<T> clazz, AABB box, Predicate<T> filter) {
return (Set<T>) getLeash(clazz, box, filter).stream().map(ILeashData::self).collect(Collectors.toSet());
}
/**
* 获取该实体持有的符合条件实体的拴绳数据能力
@ -98,7 +99,7 @@ public interface ILeashHelper {
*
* @return {@link Set<ILeashData> 持有的实体的拴绳数据能力集合}
*/
Set<ILeashData> getLeash(Class<Entity> clazz, AABB box, Predicate<Entity> filter);
<T extends Entity> Set<ILeashData> getLeash(Class<T> clazz, AABB box, Predicate<T> filter);
/**
* 获取该实体持有的符合条件实体实例
@ -109,8 +110,9 @@ public interface ILeashHelper {
*
* @return {@link Set<Entity> 持有的实体实例}
*/
default Set<Entity> getLeashEntities (Class<Entity> clazz, double fetchDistance, Predicate<Entity> filter) {
return getLeash(clazz, fetchDistance, filter).stream().map(ILeashData::self).collect(Collectors.toSet());
@SuppressWarnings("unchecked")
default <T extends Entity> Set<T> getLeashEntities (Class<T> clazz, double fetchDistance, Predicate<T> filter) {
return (Set<T>) getLeash(clazz, fetchDistance, filter).stream().map(ILeashData::self).collect(Collectors.toSet());
}
/**
@ -122,7 +124,7 @@ public interface ILeashHelper {
*
* @return {@link Set<ILeashData> 持有的实体的拴绳数据能力集合}
*/
default Set<ILeashData> getLeash(Class<Entity> clazz, double fetchDistance, Predicate<Entity> filter) {
default <T extends Entity> Set<ILeashData> getLeash(Class<T> clazz, double fetchDistance, Predicate<T> filter) {
return getLeash(clazz, AABB.ofSize(getHolderEntity().position(), fetchDistance, fetchDistance, fetchDistance), filter);
}
/**
@ -133,8 +135,9 @@ public interface ILeashHelper {
*
* @return {@link Set<Entity> 持有的实体实例}
*/
default Set<Entity> getLeashEntities (Class<Entity> clazz, Predicate<Entity> filter) {
return getLeash(clazz, filter).stream().map(ILeashData::self).collect(Collectors.toSet());
@SuppressWarnings("unchecked")
default <T extends Entity> Set<T> getLeashEntities (Class<T> clazz, Predicate<T> filter) {
return (Set<T>) getLeash(clazz, filter).stream().map(ILeashData::self).collect(Collectors.toSet());
}
/**
@ -145,7 +148,7 @@ public interface ILeashHelper {
*
* @return {@link Set<ILeashData> 持有的实体的拴绳数据能力集合}
*/
default Set<ILeashData> getLeash(Class<Entity> clazz, Predicate<Entity> filter) {
default <T extends Entity> Set<ILeashData> getLeash(Class<T> clazz, Predicate<T> filter) {
return getLeash(clazz, 1024D, filter);
}
/**
@ -155,8 +158,9 @@ public interface ILeashHelper {
*
* @return {@link Set<Entity> 持有的实体实例}
*/
default Set<Entity> getLeashEntities (Class<Entity> clazz) {
return getLeash(clazz).stream().map(ILeashData::self).collect(Collectors.toSet());
@SuppressWarnings("unchecked")
default <T extends Entity> Set<T> getLeashEntities (Class<T> clazz) {
return (Set<T>) getLeash(clazz).stream().map(ILeashData::self).collect(Collectors.toSet());
}
/**
@ -166,7 +170,7 @@ public interface ILeashHelper {
*
* @return {@link Set<ILeashData> 持有的实体的拴绳数据能力集合}
*/
default Set<ILeashData> getLeash(Class<Entity> clazz) {
default <T extends Entity> Set<ILeashData> getLeash(Class<T> clazz) {
return getLeash(clazz, 1024D, null);
}

View File

@ -51,9 +51,11 @@ public interface IWorkSpaceHelper {
* @param clazz the clazz
* @param filter the filter
* @param box the box
* @param <T> 实体类型
*
* @return the list
*/
@NotNull List<Entity> leashableInArea(@NotNull Level pLevel, Class<Entity> clazz,Predicate<Entity> filter, AABB box);
@NotNull <T extends Entity> List<T> leashableInArea(@NotNull Level pLevel, Class<T> clazz,Predicate<T> filter, AABB box);
/**

View File

@ -36,7 +36,7 @@ public class LeashCommonConfig {
/**
* The Enable slp mod command prefix.
*/
// Command
// Command
public final ForgeConfigSpec.BooleanValue enableSLPModCommandPrefix;
/**
* The Slp mod command prefix.
@ -46,13 +46,13 @@ public class LeashCommonConfig {
/**
* The Teleport whitelist.
*/
// Entity
// Entity
public final ForgeConfigSpec.ConfigValue<List<? extends String>> teleportWhitelist;
/**
* The Max leash length.
*/
// Leash settings
// Leash settings
public final ForgeConfigSpec.DoubleValue maxLeashLength;
/**
* The Elastic distance scale.
@ -78,7 +78,7 @@ public class LeashCommonConfig {
/**
* The Enable true damping.
*/
// True damping
// True damping
public final ForgeConfigSpec.BooleanValue enableTrueDamping;
/**
* The Damping factor.
@ -100,7 +100,7 @@ public class LeashCommonConfig {
/**
* The Default apply entity location offset.
*/
// Leash state offsets
// Leash state offsets
public final ForgeConfigSpec.ConfigValue<List<? extends String>> defaultApplyEntityLocationOffset;
/**
* The Default holder location offset.
@ -110,7 +110,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*"
);
@ -153,7 +153,7 @@ public class LeashCommonConfig {
builder.push("LeashSettings");
maxLeashLength = builder
.comment("Maximum leash distance (in blocks) for any entity")
.defineInRange("maxLeashLength", 6.0, 6.0, 256.0);
.defineInRange("maxLeashLength", 6.0, 1.0, 256.0);
elasticDistanceScale = builder
.comment("Default elastic distance for the Super Lead rope")

View File

@ -37,8 +37,8 @@ public class LeashConfigManager {
/**
* The constant MAX_DISTANCE_CHECK.
*/
// ========== 最值检测 ==========
public static final Predicate<Double> MAX_DISTANCE_CHECK = distance -> distance == null || (distance >= 6.0 && distance <= 256.0);
// ========== 最值检测 ==========
public static final Predicate<Double> MAX_DISTANCE_CHECK = distance -> distance == null || (distance >= 1.0 && distance <= 256.0);
/**
* The constant ELASTIC_DISTANCE_CHECK.
*/

View File

@ -293,7 +293,9 @@ public class LeashDataImpl implements ILeashData {
return false;
}
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(maxDistance) || !LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(elasticDistanceScale)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.AddLeash(holder, this.entity, maxDistance, elasticDistanceScale))) return false;
SuperLeadRopeEvent.AddLeash event = new SuperLeadRopeEvent.AddLeash(holder, this.entity, maxDistance, elasticDistanceScale);
//再次检查
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getMaxLeashDistance()) && LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getElasticDistanceScale()))) return false;
if (!canBeLeashed()) {
Optional<UUID> uuidOptional = occupyLeash();
if (uuidOptional.isEmpty()) {
@ -305,8 +307,8 @@ public class LeashDataImpl implements ILeashData {
LeashInfo info = LeashInfo.create(
holder,
reserved,
maxDistance,
elasticDistanceScale,
event.getMaxLeashDistance(),
event.getElasticDistanceScale(),
maxKeepLeashTicks,
maxKeepLeashTicks
);
@ -397,13 +399,14 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(UUID holderUUID, @Nullable Double newMaxDistance) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
newMaxDistance,
event.getNewValue(),
old.elasticDistanceScale(),
old.keepLeashTicks(),
old.maxKeepLeashTicks()
@ -419,13 +422,14 @@ public class LeashDataImpl implements ILeashData {
@SuppressWarnings("OptionalGetWithoutIsPresent")
public void setMaxDistanceInner(UUID holderUUID, @Nullable Double newMaxDistance) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE))) return;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return;
updateLeashInfoInner(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
newMaxDistance,
event.getNewValue(),
old.elasticDistanceScale(),
old.keepLeashTicks(),
old.maxKeepLeashTicks()
@ -436,13 +440,14 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(UUID holderUUID, @Nullable Double newMaxDistance, int newMaxKeepLeashTicks) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
newMaxDistance,
event.getNewValue(),
old.elasticDistanceScale(),
Math.min(old.keepLeashTicks(), newMaxKeepLeashTicks),
newMaxKeepLeashTicks
@ -453,13 +458,14 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(UUID holderUUID, @Nullable Double newMaxDistance, int maxKeepTicks, String reserved) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
old.holderIdOpt().get(),
old.marks(),
reserved,
newMaxDistance,
event.getNewValue(),
old.elasticDistanceScale(),
Math.min(old.keepLeashTicks(), maxKeepTicks),
maxKeepTicks
@ -470,13 +476,14 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(BlockPos knotPos, @Nullable Double newMaxDistance) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
newMaxDistance,
event.getNewValue(),
old.elasticDistanceScale(),
old.keepLeashTicks(),
old.maxKeepLeashTicks()
@ -492,13 +499,14 @@ public class LeashDataImpl implements ILeashData {
@SuppressWarnings("OptionalGetWithoutIsPresent")
public void setMaxDistanceInner(BlockPos knotPos, @Nullable Double newMaxDistance) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE))) return;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return;
updateLeashInfoInner(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
newMaxDistance,
event.getNewValue(),
old.elasticDistanceScale(),
old.keepLeashTicks(),
old.maxKeepLeashTicks()
@ -509,13 +517,14 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(BlockPos knotPos, @Nullable Double newMaxDistance, int newMaxKeepLeashTicks) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
newMaxDistance,
event.getNewValue(),
old.elasticDistanceScale(),
Math.min(old.keepLeashTicks(), newMaxKeepLeashTicks),
newMaxKeepLeashTicks
@ -526,13 +535,14 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setMaxDistance(BlockPos knotPos, @Nullable Double newMaxDistance, int maxKeepTicks, String reserved) {
if (!LeashConfigManager.MAX_DISTANCE_CHECK.test(newMaxDistance)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).maxDistance(), newMaxDistance, SuperLeadRopeEvent.ModifyValue.Type.MAX_DISTANCE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.MAX_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
old.holderIdOpt().get(),
old.marks(),
reserved,
newMaxDistance,
event.getNewValue(),
old.elasticDistanceScale(),
Math.min(old.keepLeashTicks(), maxKeepTicks),
maxKeepTicks
@ -551,14 +561,15 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(UUID holderUUID, @Nullable Double scale) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
old.maxDistance(),
scale,
event.getNewValue(),
old.keepLeashTicks(),
old.maxKeepLeashTicks()
));
@ -590,14 +601,15 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(BlockPos knotPos, @Nullable Double scale) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
old.maxDistance(),
scale,
event.getNewValue(),
old.keepLeashTicks(),
old.maxKeepLeashTicks()
));
@ -612,14 +624,15 @@ public class LeashDataImpl implements ILeashData {
@SuppressWarnings("OptionalGetWithoutIsPresent")
public void setElasticDistanceScaleInner(BlockPos knotPos, @Nullable Double scale) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE))) return;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return;
updateLeashInfoInner(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
old.maxDistance(),
scale,
event.getNewValue(),
old.keepLeashTicks(),
old.maxKeepLeashTicks()
));
@ -644,14 +657,15 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(UUID holderUUID, @Nullable Double scale, int newMaxKeepLeashTicks) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
old.maxDistance(),
scale,
event.getNewValue(),
Math.min(old.keepLeashTicks(), newMaxKeepLeashTicks),
newMaxKeepLeashTicks
));
@ -661,14 +675,15 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(UUID holderUUID, @Nullable Double scale, int maxKeepTicks, String reserved) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, holderUUID, leashHolders.get(holderUUID).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashHolders, holderUUID, old -> new LeashInfo(
old.holderUUIDOpt().get(),
old.holderIdOpt().get(),
old.marks(),
reserved,
old.maxDistance(),
scale,
event.getNewValue(),
Math.min(old.keepLeashTicks(), maxKeepTicks),
maxKeepTicks
));
@ -678,14 +693,15 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(BlockPos knotPos, @Nullable Double scale, int newMaxKeepLeashTicks) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
old.holderIdOpt().get(),
old.marks(),
old.reserved(),
old.maxDistance(),
scale,
event.getNewValue(),
old.keepLeashTicks(),
old.maxKeepLeashTicks()
));
@ -695,14 +711,15 @@ public class LeashDataImpl implements ILeashData {
@Override
public boolean setElasticDistanceScale(BlockPos knotPos, @Nullable Double scale, int newMaxKeepLeashTicks, String reserved) {
if (!LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(scale)) return false;
if (MinecraftForge.EVENT_BUS.post(new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE))) return false;
SuperLeadRopeEvent.ModifyValue event = new SuperLeadRopeEvent.ModifyValue(this.entity, knotPos, leashKnots.get(knotPos).elasticDistanceScale(), scale, SuperLeadRopeEvent.ModifyValue.Type.ELASTIC_DISTANCE_SCALE);
if (MinecraftForge.EVENT_BUS.post(event) || event.isModified() && !(LeashConfigManager.ELASTIC_DISTANCE_CHECK.test(event.getNewValue()))) return false;
return updateLeashInfo(leashKnots, knotPos, old -> new LeashInfo(
old.blockPosOpt().get(),
old.holderIdOpt().get(),
old.marks(),
reserved,
old.maxDistance(),
scale,
event.getNewValue(),
Math.min(old.keepLeashTicks(), newMaxKeepLeashTicks),
newMaxKeepLeashTicks
));
@ -1390,7 +1407,7 @@ public class LeashDataImpl implements ILeashData {
);
} else throw new IllegalArgumentException("Unknown LeashInfo");
}
private static Set<String> getMarks(CompoundTag infoTag) {
private static Set<String> getMarks(@NotNull CompoundTag infoTag) {
if (infoTag.contains("Marks")) {
CompoundTag marks = infoTag.getCompound("Marks");
int size = marks.getInt("MarkSize");

View File

@ -53,7 +53,7 @@ public class LeashHelper implements ILeashHelper {
}
@Override
public Set<ILeashData> getLeash(Class<Entity> clazz, AABB box, Predicate<Entity> filter) {
public <T extends Entity> Set<ILeashData> getLeash(Class<T> clazz, AABB box, Predicate<T> filter) {
return SuperLeadRopeApi.leashableInArea(getHolderEntity(), clazz, box, filter)
.stream()
.map(i -> i.getCapability(SLPCapability.LEASH_DATA_CAP).resolve())
@ -65,6 +65,7 @@ public class LeashHelper implements ILeashHelper {
@Override
public boolean leashEntity(UUID uuid) {
Entity entity = CommonEventHandler.Game.getServerLevel().getEntity(uuid);
if (entity != null && SuperLeadRopeApi.isLeashable(entity)) {
return LeashDataInnerAPI.getLeashData(entity).map(i-> i.addLeash(entity)).orElse(false);
}

View File

@ -47,7 +47,7 @@ public class WorkSpaceHelper implements IWorkSpaceHelper {
}
@Override
public @NotNull List<Entity> leashableInArea(@NotNull Level pLevel, Class<Entity> clazz, @Nullable Predicate<Entity> filter, AABB box) {
public <T extends Entity> @NotNull List<T> leashableInArea(@NotNull Level pLevel, Class<T> clazz, @Nullable Predicate<T> filter, AABB box) {
return pLevel.getEntitiesOfClass(clazz, box, e -> LeashDataImpl.isLeashable(e) && Objects.requireNonNullElse(filter, entity -> true).test(e));
}

View File

@ -25,9 +25,9 @@ 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="superleadrope_logo.png" #optional
logoFile= "../../resources/superleadrope_logo.png" #optional
# A text field displayed in the mod UI
credits="Leisuretimedock"
credits="${mod_credits}"
# A text field displayed in the mod UI
authors="${mod_authors}" #optional
# Display Test controls the display for your mod in the server connection screen