【发布时间】:2022-01-21 16:52:53
【问题描述】:
我不明白如何将泛型类型格式化为这段代码:
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);
}
}
这是我得到的错误:
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
我一直在谷歌搜索,试图弄清楚如何解决它,但我不明白。
这是您在评论中要求的代码吗?
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;
}
}
【问题讨论】:
-
我们需要查看产生此错误的代码,但我愿意猜测您没有为
T填写任何内容,或者您填写的内容拼写错误。 -
@markspace 已更新。
-
您用采用
SpiderEntity的方法覆盖了采用T的方法getEntityTexture。