diff options
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/registry/AutoRegistry.java | 19 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java | 21 |
2 files changed, 36 insertions, 4 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/registry/AutoRegistry.java b/src/main/java/com/anthonyhilyard/iceberg/registry/AutoRegistry.java index dd7da65..c42a8d0 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/registry/AutoRegistry.java +++ b/src/main/java/com/anthonyhilyard/iceberg/registry/AutoRegistry.java @@ -14,7 +14,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.client.registry.IRenderFactory; -import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.IForgeRegistry; @@ -32,6 +31,8 @@ public abstract class AutoRegistry private static Map<EntityType<?>, Supplier<AttributeModifierMap.MutableAttribute>> entityAttributes = new HashMap<>(); + private static Map<String, EntityType<? extends Entity>> registeredEntityTypes = new HashMap<>(); + public static void init(String ModID) { MODID = ModID; @@ -60,6 +61,17 @@ public abstract class AutoRegistry } } + public static boolean isEntityTypeRegistered(String name) + { + return registeredEntityTypes.containsKey(name); + } + + @SuppressWarnings("unchecked") + public static <T extends Entity> EntityType<T> getEntityType(String name) + { + return (EntityType<T>) registeredEntityTypes.getOrDefault(name, null); + } + @SuppressWarnings("unchecked") private final <T extends IForgeRegistryEntry<T>> void registerAllOfType(Class<IForgeRegistryEntry<?>> type, RegistryEvent.Register<T> event) { @@ -111,8 +123,8 @@ public abstract class AutoRegistry ResourceLocation resourceLocation = new ResourceLocation(MODID, name); EntityType<T> entityType = (EntityType<T>) builder.build(name).setRegistryName(resourceLocation); - // Register the rendering handler. - RenderingRegistry.registerEntityRenderingHandler(entityType, renderFactory); + // Add this entity type to the registered hashmap. + registeredEntityTypes.put(name, entityType); // Store mob attributes if provided. These will be added in the attribute creation event below. if (attributes != null) @@ -120,7 +132,6 @@ public abstract class AutoRegistry entityAttributes.put(entityType, attributes); } - return entityType; } diff --git a/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java b/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java new file mode 100644 index 0000000..e77fd1f --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java @@ -0,0 +1,21 @@ +package com.anthonyhilyard.iceberg.registry; + +import net.minecraft.entity.Entity; +import net.minecraftforge.fml.client.registry.IRenderFactory; +import net.minecraftforge.fml.client.registry.RenderingRegistry; + +public abstract class RendererRegistrar +{ + protected static <T extends Entity> void registerRenderer(String name, IRenderFactory<? super T> renderFactory) + { + if (AutoRegistry.isEntityTypeRegistered(name)) + { + // Register the rendering handler. + RenderingRegistry.registerEntityRenderingHandler(AutoRegistry.<T>getEntityType(name), renderFactory); + } + else + { + throw new RuntimeException("Tried to register a renderer for an unregistered entity type! Make sure you register renderers after entities."); + } + } +} |