我不明白如何將泛型型別格式化為此代碼:
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;
}
}
uj5u.com熱心網友回復:
您的子類是泛型型別,但必須是型別SpiderEntity
public class SpiderRenderer<T extends SpiderEntity>
您的子類是沒有界限的泛型型別:
public class VariantSpiderRenderer<T> extends SpiderRenderer<T>
這意味著你正試圖使,所以你可以創建一個VariantSpiderRenderer某種型別的-喜歡VariantSpiderRenderer<String>-這是不是與基類,這是需要有兼容的SpiderRenderer某種型別的T是至少一個SpiderEntity。
要解決此問題,派生類也必須遵守并指定這些邊界:
public class VariantSpiderRenderer<T extends SpiderEntity> extends SpiderRenderer<T>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/386765.html
下一篇:JTextfield自定義問題
