diff --git a/leaf-server/src/main/java/org/dreeam/leaf/util/RegistryTypeManager.java b/leaf-server/src/main/java/org/dreeam/leaf/util/RegistryTypeManager.java new file mode 100644 index 00000000..be91b4ff --- /dev/null +++ b/leaf-server/src/main/java/org/dreeam/leaf/util/RegistryTypeManager.java @@ -0,0 +1,17 @@ +package org.dreeam.leaf.util; + +import net.minecraft.core.registries.BuiltInRegistries; + +public final class RegistryTypeManager { + + /** + * The total number of attributes in the Built-in Registry. + */ + public static final int ATTRIBUTE_ID_COUNTER; + + static { + ATTRIBUTE_ID_COUNTER = BuiltInRegistries.ATTRIBUTE.size(); + } + + private RegistryTypeManager() {} +} diff --git a/leaf-server/src/main/java/org/dreeam/leaf/util/map/AttributeInstanceArrayMap.java b/leaf-server/src/main/java/org/dreeam/leaf/util/map/AttributeInstanceArrayMap.java index 81e7e2bd..a99a1bb0 100644 --- a/leaf-server/src/main/java/org/dreeam/leaf/util/map/AttributeInstanceArrayMap.java +++ b/leaf-server/src/main/java/org/dreeam/leaf/util/map/AttributeInstanceArrayMap.java @@ -4,6 +4,7 @@ import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeInstance; +import org.dreeam.leaf.util.RegistryTypeManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -13,18 +14,14 @@ import java.util.AbstractMap.SimpleEntry; // fast array backend map with O(1) get & put & remove public final class AttributeInstanceArrayMap implements Map, AttributeInstance>, Cloneable { - private static final int VANILLA_ATTRIBUTE_SIZE = 35; // 1.21.6 (Check this on every Minecraft version) - private int size = 0; - private transient AttributeInstance[] a = new AttributeInstance[VANILLA_ATTRIBUTE_SIZE]; + private transient AttributeInstance[] a = new AttributeInstance[RegistryTypeManager.ATTRIBUTE_ID_COUNTER]; private transient KeySet keys; private transient Values values; private transient EntrySet entries; public AttributeInstanceArrayMap() { - if (BuiltInRegistries.ATTRIBUTE.size() != VANILLA_ATTRIBUTE_SIZE) { - throw new IllegalStateException("Unexpected registry minecraft:attribute size"); - } + // The check for a fixed vanilla size is no longer necessary } public AttributeInstanceArrayMap(final @NotNull Map, AttributeInstance> m) {