-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace failing entity attributes during loading
Fixes #1298
- Loading branch information
Showing
6 changed files
with
48 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/mod/java/org/sinytra/connector/mod/mixin/AttributeSupplierBuilderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters