Deprecate @ObjectHolder, add a couple of fast-paths (#10230)

Cherry-pick a few optimizations from HEAD

Co-authored-by: Paint_Ninja <PaintNinja@users.noreply.github.com>
This commit is contained in:
JonathingandPaint_Ninja authored and GitHub committed 2024-12-23 15:15:05 -08:00
1 parent 1fe85f5396
commit 69037051ab
3 files changed
+44 -9

No files matched your search

@@ -16,7 +16,19 @@ import java.lang.annotation.Target;
/**
* ObjectHolder can be used to automatically populate public static final fields with entries
* from the registry. These values can then be referred within mod code directly.
* @deprecated Use {@link DeferredRegister} or {@link RegistryObject} instead. Refer to the MDK for more detailed examples.
* <br>
* Example usage of alternatives:
* <pre>{@code
* // To register something
* public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
* public static final RegistryObject<Item> EXAMPLE_ITEM = ITEMS.register("example_item", () -> new Item(new Item.Properties()));
*
* // To get a RegistryObject that you didn't register yourself:
* public static final RegistryObject<Block> DIRT = RegistryObject.create(ResourceLocation.withDefaultNamespace("dirt"), ForgeRegistries.BLOCKS);
* }</pre>
*/
@Deprecated(since = "1.21.4", forRemoval = true)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ObjectHolder
@@ -89,6 +89,9 @@ public class ObjectHolderRegistry
.filter(a -> OBJECT_HOLDER.equals(a.annotationType()) || MOD.equals(a.annotationType()))
.toList();
if (annotations.stream().noneMatch(a -> OBJECT_HOLDER.equals(a.annotationType())))
return; // No object holders found, skip the rest of the processing
Map<Type, String> classModIds = Maps.newHashMap();
Map<Type, Class<?>> classCache = Maps.newHashMap();