Fix crash when mods use null attributes

Fixes #658
This commit is contained in:
embeddedt 2026-05-05 20:23:06 -04:00
parent 44113d2536
commit 653a477060
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.common.mixin.perf.attribute_supplier_dedup;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
@ -22,11 +23,11 @@ public class AttributeSupplierMixin {
/**
* @author embeddedt
* @reason Java 9's Map.of() implementation is significantly more compact than ImmutableMap, and we do not
* @reason more compact than ImmutableMap due to less wrapper objects, and we do not
* care about insertion order in this context
*/
@Inject(method = "<init>", at = @At("RETURN"))
private void useCompactJavaMap(Map<Attribute, AttributeInstance> instances, CallbackInfo ci) {
this.instances = Map.copyOf(this.instances);
this.instances = new Object2ObjectOpenHashMap<>(this.instances);
}
}