I don't understand how to format generic types into this code:
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.SpiderRenderer;
import net.minecraft.entity.monster.SpiderEntity;
import net.minecraft.util.ResourceLocation;
import vazkii.quark.content.client.module.VariantAnimalTexturesModule;
import vazkii.quark.content.client.module.VariantAnimalTexturesModule.VariantTextureType;
public class VariantSpiderRenderer<T> extends SpiderRenderer<T> {
public VariantSpiderRenderer(EntityRendererManager renderManagerIn) {
super(renderManagerIn);
}
@Override
public ResourceLocation getEntityTexture(SpiderEntity entity) {
return VariantAnimalTexturesModule.getTextureOrShiny(entity, VariantTextureType.SPIDER, VariantAnimalTexturesModule.enableSpider);
}
}
This is the error I get:
public class VariantSpiderRenderer extends SpiderRenderer {
^
missing type arguments for generic class SpiderRenderer<T>
where T is a type-variable:
T extends SpiderEntity declared in class SpiderRenderer
error: warnings found and -Werror specified
warnings found and -Werror specified
I've been googling trying to figure out how to fix it but I don't understand.
Is this the code you asked for in the comment?
package net.minecraft.client.renderer.entity;
import net.minecraft.client.renderer.entity.layers.SpiderEyesLayer;
import net.minecraft.client.renderer.entity.model.SpiderModel;
import net.minecraft.entity.monster.SpiderEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class SpiderRenderer<T extends SpiderEntity> extends MobRenderer<T, SpiderModel<T>> {
private static final ResourceLocation SPIDER_TEXTURES = new ResourceLocation("textures/entity/spider/spider.png");
public SpiderRenderer(EntityRendererManager renderManagerIn) {
super(renderManagerIn, new SpiderModel<>(), 0.8F);
this.addLayer(new SpiderEyesLayer<>(this));
}
protected float getDeathMaxRotation(T entityLivingBaseIn) {
return 180.0F;
}
/**
* Returns the location of an entity's texture.
*/
public ResourceLocation getEntityTexture(T entity) {
return SPIDER_TEXTURES;
}
}
CodePudding user response:
Your subclass is a generic type but bound to be of type SpiderEntity
public class SpiderRenderer<T extends SpiderEntity>
Your subclass is a generic type with no bounds:
public class VariantSpiderRenderer<T> extends SpiderRenderer<T>
Which means that you are trying to make it so you can create a VariantSpiderRenderer
of some type - like VariantSpiderRenderer<String>
- that is not compatible with the base class, which is required to be a SpiderRenderer
of some type T
that is at least a SpiderEntity
.
To fix this, the derived class must respect and specify those bounds as well:
public class VariantSpiderRenderer<T extends SpiderEntity> extends SpiderRenderer<T>