Skip to content

Commit

Permalink
Replace failing entity attributes during loading
Browse files Browse the repository at this point in the history
Fixes #1298
  • Loading branch information
Su5eD committed Aug 8, 2024
1 parent 48e0ff0 commit 60bc4e2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
with:
distribution: 'microsoft'
java-version: '21'
- uses: gradle/wrapper-validation-action@v1
- uses: gradle/actions/wrapper-validation@v3
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
with:
distribution: 'microsoft'
java-version: '21'
- uses: gradle/wrapper-validation-action@v1
- uses: gradle/actions/wrapper-validation@v3
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
Expand Down
23 changes: 10 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ logger.lifecycle("Project version: $version")
val mod: SourceSet by sourceSets.creating
val test: SourceSet by sourceSets

val shade: Configuration by configurations.creating {
isTransitive = false
}
val legacyClasspath: Configuration by configurations.creating { isTransitive = false }
val shade: Configuration by configurations.creating
val adapterData: Configuration by configurations.creating

java {
Expand All @@ -72,7 +69,7 @@ configurations {
}

additionalRuntimeClasspath {
extendsFrom(legacyClasspath)
extendsFrom(shade)
}
}

Expand Down Expand Up @@ -134,10 +131,9 @@ repositories {

dependencies {
shade(group = "org.sinytra", name = "forgified-fabric-loader", version = versionForgifiedFabricLoader)
legacyClasspath(group = "org.sinytra", name = "forgified-fabric-loader", version = versionForgifiedFabricLoader, classifier = "full")
legacyClasspath(shade(group = "net.fabricmc", name = "access-widener", version = versionAccessWidener))
legacyClasspath(shade(group = "org.sinytra", name = "ForgeAutoRenamingTool", version = versionForgeAutoRenamingTool))
legacyClasspath(shade(group = "org.sinytra.adapter", name = "definition", version = versionAdapterDefinition) { isTransitive = false })
shade(group = "net.fabricmc", name = "access-widener", version = versionAccessWidener) { isTransitive = false }
shade(group = "org.sinytra", name = "ForgeAutoRenamingTool", version = versionForgeAutoRenamingTool) { isTransitive = false }
shade(group = "org.sinytra.adapter", name = "definition", version = versionAdapterDefinition) { isTransitive = false }
adapterData(group = "org.sinytra.adapter", name = "adapter", version = versionAdapter)

jarJar(implementation(group = "org.sinytra.adapter", name = "runtime", version = versionAdapterRuntime))
Expand All @@ -160,10 +156,11 @@ localJarJar("modJarConfig", "org.sinytra:connector-mod", project.version.toStrin
val depsJar: ShadowJar by tasks.creating(ShadowJar::class) {
configurations = listOf(shade)

exclude("assets/fabricloader/**")
exclude("META-INF/*.SF")
exclude("META-INF/*.RSA")
exclude("META-INF/maven/**")
exclude(
"assets/fabricloader/**",
"META-INF/*.SF", "META-INF/*.RSA",
"META-INF/maven/**", "META-INF/jars/**", "META-INF/jarjar/**"
)
exclude("META-INF/services/net.neoforged.neoforgespi.language.IModLanguageLoader")
exclude("ui/**")
exclude("*.json", "*.html", "*.version")
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.caching=true
#org.gradle.configuration-cache=true

# Versions
versionConnector=2.0.0-beta.1
versionConnector=2.0.0-beta.2
versionAdapter=1.13.1+1.21-20240719.094540
versionAdapterDefinition=1.13.16+1.21
versionAdapterRuntime=1.0.0+1.21
Expand All @@ -16,7 +16,7 @@ versionMc=1.21
versionNeoForge=21.0.160
versionParchment=2024.06.23
versionForgeAutoRenamingTool=1.0.12
versionForgifiedFabricLoader=2.5.29+0.16.0+1.21
versionForgifiedFabricLoader=2.5.30+0.16.0+1.21
versionAccessWidener=2.1.0
versionForgifiedFabricApi=0.100.7+2.0.8+1.21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class LazyEntityAttributes {

public static void inject() {
for (Holder<Attribute> holder : ATTRIBUTES) {
Holder<Attribute> lazyAttribute = PLACEHOLDERS.computeIfAbsent(holder, s -> Holder.direct(new PlaceholderAttribute()));
Holder<Attribute> lazyAttribute = replaceAttribute(holder);
try {
DEFERRED_HOLDER_SET_VALUE.invoke(holder, lazyAttribute);
} catch (Throwable e) {
Expand All @@ -48,6 +48,10 @@ public static void release() {
}
}

public static Holder<Attribute> replaceAttribute(Holder<Attribute> original) {
return PLACEHOLDERS.computeIfAbsent(original, s -> Holder.direct(new PlaceholderAttribute()));
}

public static void initializeLazyAttributes(EntityAttributeModificationEvent event) {
updateAttributeSuppliers(ObfuscationReflectionHelper.getPrivateValue(DefaultAttributes.class, null, "SUPPLIERS"));
updateAttributeSuppliers(CommonHooks.getAttributesView());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.sinytra.connector.mod.mixin;

import net.minecraft.core.Holder;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import org.sinytra.connector.mod.ConnectorLoader;
import org.sinytra.connector.mod.compat.LazyEntityAttributes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(AttributeSupplier.Builder.class)
public abstract class AttributeSupplierBuilderMixin {

// Mitigates https://github.com/Sinytra/Connector/issues/1298
@ModifyVariable(method = "create", at = @At("HEAD"), argsOnly = true)
private Holder<Attribute> onCreate(Holder<Attribute> original) {
if (ConnectorLoader.isLoading()) {
try {
original.value();
} catch (NullPointerException n) {
// Likely a deferred holder that has not been initialized yet
return LazyEntityAttributes.replaceAttribute(original);
}
}
return original;
}
}
1 change: 1 addition & 0 deletions src/mod/resources/connector.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compatibilityLevel": "JAVA_17",
"plugin": "org.sinytra.connector.mod.ConnectorBootstrap",
"mixins": [
"AttributeSupplierBuilderMixin",
"CommonHooksMixin",
"PlayerListMixin",
"ChunkGeneratorMixin",
Expand Down

0 comments on commit 60bc4e2

Please sign in to comment.