diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2021-10-13 22:51:23 -0700 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2021-10-13 22:51:23 -0700 |
commit | 407a3cfabed3869b38527153e8b3322a824f1263 (patch) | |
tree | 06909dc024d048e999354a0c7102a57bccf32ef8 /src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java | |
parent | 0eb0e8504684ad9e7bdae99a54de618809cee8d4 (diff) | |
download | Iceberg-407a3cfabed3869b38527153e8b3322a824f1263.tar.gz Iceberg-407a3cfabed3869b38527153e8b3322a824f1263.tar.bz2 Iceberg-407a3cfabed3869b38527153e8b3322a824f1263.zip |
Initial commit for 1.17.1 version.
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java b/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java index e77fd1f..1b0a053 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java +++ b/src/main/java/com/anthonyhilyard/iceberg/registry/RendererRegistrar.java @@ -1,21 +1,36 @@ package com.anthonyhilyard.iceberg.registry; -import net.minecraft.entity.Entity; -import net.minecraftforge.fml.client.registry.IRenderFactory; -import net.minecraftforge.fml.client.registry.RenderingRegistry; +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraftforge.client.event.EntityRenderersEvent; public abstract class RendererRegistrar { - protected static <T extends Entity> void registerRenderer(String name, IRenderFactory<? super T> renderFactory) + private static Map<EntityType<? extends Entity>, EntityRendererProvider<?>> entityRenderers = new HashMap<>(); + + protected static <T extends Entity> void registerRenderer(String name, EntityRendererProvider<T> rendererProvider) { if (AutoRegistry.isEntityTypeRegistered(name)) { - // Register the rendering handler. - RenderingRegistry.registerEntityRenderingHandler(AutoRegistry.<T>getEntityType(name), renderFactory); + // Store this renderer provider. + entityRenderers.put(AutoRegistry.getEntityType(name), rendererProvider); } else { throw new RuntimeException("Tried to register a renderer for an unregistered entity type! Make sure you register renderers after entities."); } } + + @SuppressWarnings({"unchecked", "unused"}) + private <T extends Entity> void onEntityCreation(EntityRenderersEvent.RegisterRenderers event) + { + for (EntityType<? extends Entity> entityType : entityRenderers.keySet()) + { + event.registerEntityRenderer((EntityType<T>)entityType, (EntityRendererProvider<T>)entityRenderers.get(entityType)); + } + } } |