diff --git a/src/main/java/net/neoforged/neoforge/registries/DeferredRegister.java b/src/main/java/net/neoforged/neoforge/registries/DeferredRegister.java index 62f9501512..1c770e7e77 100644 --- a/src/main/java/net/neoforged/neoforge/registries/DeferredRegister.java +++ b/src/main/java/net/neoforged/neoforge/registries/DeferredRegister.java @@ -13,6 +13,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Set; +import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; @@ -806,11 +807,27 @@ public class DeferredRegister { * @param category The category of the entity, typically {@link MobCategory#MISC} for non-living entities, or one of the others for living entities. * @return A {@link DeferredHolder} which reflects the data that will be registered. * @param the type of the entity + * @see #registerEntityType(String, EntityType.EntityFactory, MobCategory, BiFunction) + * @see #registerEntityType(String, EntityType.EntityFactory, MobCategory, UnaryOperator) */ public DeferredHolder, EntityType> registerEntityType(String name, EntityType.EntityFactory factory, MobCategory category) { return this.registerEntityType(name, factory, category, UnaryOperator.identity()); } + /// Convenience method that constructs a builder for use in the operator. Use this to avoid inference issues. + /// + /// @param name The name for this entity type. It will automatically have the [namespace][#getNamespace()] prefixed. + /// @param factory The factory used to typically construct the entity when using an existing helper from the type. + /// @param category The category of the entity, typically [MobCategory#MISC] for non-living entities, or one of the others for living entities. + /// @param builder The bifunction that is passed `factory` and `category` and returns an [EntityType.Builder] which is built upon registration. + /// @return A [DeferredHolder] which reflects the data that will be registered. + /// @param the type of the entity + /// @see #registerEntityType(String, EntityType.EntityFactory, MobCategory) + /// @see #registerEntityType(String, EntityType.EntityFactory, MobCategory, UnaryOperator) + public DeferredHolder, EntityType> registerEntityType(String name, EntityType.EntityFactory factory, MobCategory category, BiFunction, MobCategory, EntityType.Builder> builder) { + return this.register(name, key -> builder.apply(factory, category).build(ResourceKey.create(Registries.ENTITY_TYPE, key))); + } + /** * Convenience method that constructs a builder for use in the operator. Use this to avoid inference issues. * @@ -820,9 +837,11 @@ public class DeferredRegister { * @param builder The unary operator, which is passed a new builder for user operators, then builds it upon registration. * @return A {@link DeferredHolder} which reflects the data that will be registered. * @param the type of the entity + * @see #registerEntityType(String, EntityType.EntityFactory, MobCategory) + * @see #registerEntityType(String, EntityType.EntityFactory, MobCategory, BiFunction) */ public DeferredHolder, EntityType> registerEntityType(String name, EntityType.EntityFactory factory, MobCategory category, UnaryOperator> builder) { - return this.register(name, key -> builder.apply(EntityType.Builder.of(factory, category)).build(ResourceKey.create(Registries.ENTITY_TYPE, key))); + return this.registerEntityType(name, factory, category, (fact, cat) -> builder.apply(EntityType.Builder.of(fact, cat))); } } diff --git a/testframework/src/main/java/net/neoforged/testframework/registration/DeferredEntityTypes.java b/testframework/src/main/java/net/neoforged/testframework/registration/DeferredEntityTypes.java index 7148c74ce0..4c484d09c6 100644 --- a/testframework/src/main/java/net/neoforged/testframework/registration/DeferredEntityTypes.java +++ b/testframework/src/main/java/net/neoforged/testframework/registration/DeferredEntityTypes.java @@ -5,6 +5,7 @@ package net.neoforged.testframework.registration; +import java.util.function.BiFunction; import java.util.function.UnaryOperator; import net.minecraft.core.Registry; import net.minecraft.resources.Identifier; @@ -27,6 +28,11 @@ public class DeferredEntityTypes extends DeferredRegister.Entities { return new DeferredEntityTypeBuilder(ResourceKey.create(registryKey, key), helper); } + @Override + public DeferredEntityTypeBuilder> registerEntityType(String name, EntityType.EntityFactory factory, MobCategory category, BiFunction, MobCategory, EntityType.Builder> builder) { + return (DeferredEntityTypeBuilder>) super.registerEntityType(name, factory, category, builder); + } + @Override public DeferredEntityTypeBuilder> registerEntityType(String name, EntityType.EntityFactory factory, MobCategory category, UnaryOperator> builder) { return (DeferredEntityTypeBuilder>) super.registerEntityType(name, factory, category, builder);