Jump to content

Recommended Posts

Posted

I've been trying to register my cart entity to `RenderingRegistry`but I have been receiving errors I am having a hard time understanding.

 

I register my entity renderer like this:

    public static void registerRenderers(final FMLClientSetupEvent event) {
        RenderingRegistry.registerEntityRenderingHandler(AllEntities.MINER_CART_ENTITY.get(), MinerModuleCartRenderer::new);
    }

and this is my MinerModuleCartRenderer:

@OnlyIn(Dist.CLIENT)
public class MinerModuleCartRenderer<T extends AbstractMinecartEntity> extends EntityRenderer<T> {

    private static final ResourceLocation MINER_TEXTURE = new ResourceLocation(MODID + ":textures/entity/miner_cart_module.png");
    private final EntityModel<T> modelCartModule = new MinerCartModuleModel<>();

    public MinerModuleCartRenderer(EntityRendererManager renderManager) {
        super(renderManager);
    }

    public void render(T entity, float entityYaw, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLight) {
  	// [...] long code copied from MinecartRenderer directly
    }

    public ResourceLocation getEntityTexture(T entity) {
        return MINER_TEXTURE;
    }

    protected void renderBlockState(T entity, float partialTicks, BlockState state, MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLight) {
        Minecraft.getInstance().getBlockRendererDispatcher().renderBlock(state, matrixStack, buffer, packedLight, OverlayTexture.NO_OVERLAY);
    }
}

but I get this error:

Bad return type in method reference: cannot convert com.than00ber.gameoflife.client.renderer.entity.MinerModuleCartRenderer<T> to net.minecraft.client.renderer.entity.EntityRenderer<? super ?>

(I get the same error when trying to register Minecraft's `MinercartRenderer` like this)

 

I've looked into Minecraft 's source code and noticed that it registers its entity renderers like this:

   public <T extends Entity> void register(EntityType<T> entityTypeIn, EntityRenderer<? super T> entityRendererIn) {
      this.renderers.put(entityTypeIn, entityRendererIn);
   }

but Forge with `IRenderFactory`:

    public static <T extends Entity> void registerEntityRenderingHandler(EntityType<T> entityClass, IRenderFactory<? super T> renderFactory)
    {
        INSTANCE.entityRenderers.put(entityClass, renderFactory);
    }

so I implemented `IRenderFactorty` in `MinerModuleCartRenderer` to see if it makes a difference but to no avail; the error stays the same.

 

Any idea why that is and how can I solve this?

 

Now I know this is more of Java error but I figured I'll get a better shot here since people have prior knowledge. 

Posted (edited)

I was able to solve the issue by rewriting all classes (must have gotten a class extending the wrong thing I think) but why shouldn't I use @OnlyIn on the renderers? Isn't it just client-side?

Edit: Should I remove all @OnlyIn?

Edited by than00ber1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.