Use generics

This commit is contained in:
Sollace 2018-04-27 17:50:13 +02:00
parent 0e0ee17f46
commit 13ba3379c9
13 changed files with 54 additions and 61 deletions

View file

@ -44,15 +44,11 @@ public class RenderPonyModel extends RenderPlayerModel<EntityPonyModel> {
@Override
protected LayerRenderer<EntityLivingBase> getElytraLayer() {
final LayerRenderer<EntityLivingBase> elytra = super.getElytraLayer();
final PonyElytra modelElytra = new PonyElytra();
return new AbstractPonyLayer<EntityLivingBase>(this, elytra) {
return new AbstractPonyLayer<EntityPonyModel>(this, super.getElytraLayer()) {
final PonyElytra modelElytra = new PonyElytra();
@Override
public void doPonyRender(EntityLivingBase entityBase, float swing, float swingAmount, float ticks, float age, float yaw, float head, float scale) {
EntityPonyModel entity = (EntityPonyModel) entityBase;
public void doPonyRender(EntityPonyModel entity, float swing, float swingAmount, float ticks, float age, float yaw, float head, float scale) {
ItemStack itemstack = entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
if (itemstack.getItem() == Items.ELYTRA) {

View file

@ -28,11 +28,11 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
}
protected void addLayers() {
addLayer(new LayerPonyArmor(this));
addLayer(new LayerHeldPonyItem(this));
addLayer(new LayerPonyArmor<>(this));
addLayer(new LayerHeldPonyItem<>(this));
// addLayer(new LayerArrow(this));
addLayer(new LayerPonyCustomHead(this));
addLayer(new LayerPonyElytra(this));
addLayer(new LayerPonyCustomHead<>(this));
addLayer(new LayerPonyElytra<>(this));
}
@Override

View file

@ -7,31 +7,32 @@ import net.minecraft.client.renderer.entity.RenderLivingBase;
import net.minecraft.client.renderer.entity.layers.LayerRenderer;
import net.minecraft.entity.EntityLivingBase;
public abstract class AbstractPonyLayer<T extends EntityLivingBase> implements LayerRenderer<T> {
public abstract class AbstractPonyLayer<T extends EntityLivingBase> implements LayerRenderer<EntityLivingBase> {
private final RenderLivingBase<? extends T> renderer;
private LayerRenderer<T> layer;
private final RenderLivingBase<T> renderer;
private LayerRenderer<? super T> layer;
public AbstractPonyLayer(RenderLivingBase<? extends T> renderer, LayerRenderer<T> humanLayer) {
public AbstractPonyLayer(RenderLivingBase<T> renderer, LayerRenderer<? super T> humanLayer) {
this.renderer = renderer;
this.layer = humanLayer;
}
@SuppressWarnings("unchecked")
@Override
public final void doRenderLayer(T entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
public final void doRenderLayer(EntityLivingBase entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
ModelBase model = renderer.getMainModel();
if (model instanceof ModelHumanPlayer) {
// render the human layer
layer.doRenderLayer(entity, move, swing, ticks, age, headYaw, headPitch, scale);
layer.doRenderLayer((T)entity, move, swing, ticks, age, headYaw, headPitch, scale);
} else {
// render the pony layer
doPonyRender(entity, move, swing, ticks, age, headYaw, headPitch, scale);
doPonyRender((T)entity, move, swing, ticks, age, headYaw, headPitch, scale);
}
}
protected abstract void doPonyRender(T entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale);
protected RenderLivingBase<? extends T> getRenderer() {
protected RenderLivingBase<T> getRenderer() {
return renderer;
}

View file

@ -19,7 +19,7 @@ import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nullable;
public class LayerEntityOnPonyShoulder extends AbstractPonyLayer<EntityPlayer> {
public class LayerEntityOnPonyShoulder extends AbstractPonyLayer<AbstractClientPlayer> {
private final RenderManager renderManager;
@ -32,7 +32,7 @@ public class LayerEntityOnPonyShoulder extends AbstractPonyLayer<EntityPlayer> {
}
@Override
public void doPonyRender(EntityPlayer player, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
public void doPonyRender(AbstractClientPlayer player, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
GlStateManager.enableRescaleNormal();
GlStateManager.color(1, 1, 1, 1);
@ -56,7 +56,7 @@ public class LayerEntityOnPonyShoulder extends AbstractPonyLayer<EntityPlayer> {
@SuppressWarnings("unchecked")
@Nullable
private EntityLivingBase renderShoulderEntity(EntityPlayer player, @Nullable EntityLivingBase entity, NBTTagCompound tag,
private EntityLivingBase renderShoulderEntity(AbstractClientPlayer player, @Nullable EntityLivingBase entity, NBTTagCompound tag,
float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale, boolean left) {
if (entity == null || !entity.getUniqueID().equals(tag.getUniqueId("UUID"))) {

View file

@ -26,14 +26,14 @@ import javax.annotation.Nullable;
import static net.minecraft.client.renderer.GlStateManager.*;
public class LayerHeldPonyItem extends AbstractPonyLayer<EntityLivingBase> {
public class LayerHeldPonyItem<T extends EntityLivingBase> extends AbstractPonyLayer<T> {
public LayerHeldPonyItem(RenderLivingBase<? extends EntityLivingBase> livingPony) {
public LayerHeldPonyItem(RenderLivingBase<T> livingPony) {
super(livingPony, new LayerHeldItem(livingPony));
}
@Override
public void doPonyRender(EntityLivingBase entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
public void doPonyRender(T entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
ModelBase model = getRenderer().getMainModel();
boolean mainRight = entity.getPrimaryHand() == EnumHandSide.RIGHT;
@ -62,7 +62,7 @@ public class LayerHeldPonyItem extends AbstractPonyLayer<EntityLivingBase> {
}
}
private void renderHeldItem(EntityLivingBase entity, ItemStack drop, TransformType transform, EnumHandSide hand) {
private void renderHeldItem(T entity, ItemStack drop, TransformType transform, EnumHandSide hand) {
if (!drop.isEmpty()) {
GlStateManager.pushMatrix();
translateToHand(hand);
@ -108,7 +108,7 @@ public class LayerHeldPonyItem extends AbstractPonyLayer<EntityLivingBase> {
}
}
public void renderItemGlow(EntityLivingBase entity, ItemStack drop, TransformType transform, EnumHandSide hand, int glowColor) {
public void renderItemGlow(T entity, ItemStack drop, TransformType transform, EnumHandSide hand, int glowColor) {
// enchantments mess up the rendering
ItemStack drop2 = drop.copy();

View file

@ -29,7 +29,7 @@ import org.lwjgl.opengl.GL11;
import java.io.IOException;
import java.util.Map;
public class LayerPonyArmor extends AbstractPonyLayer<EntityLivingBase> {
public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLayer<T> {
private static final ResourceLocation ENCHANTED_ITEM_GLINT_RES = new ResourceLocation("textures/misc/enchanted_item_glint.png");
@ -38,12 +38,12 @@ public class LayerPonyArmor extends AbstractPonyLayer<EntityLivingBase> {
private ModelWrapper pony;
public LayerPonyArmor(RenderLivingBase<? extends EntityLivingBase> renderer) {
public LayerPonyArmor(RenderLivingBase<T> renderer) {
super(renderer, new LayerBipedArmor(renderer));
}
@Override
public void doPonyRender(EntityLivingBase entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
public void doPonyRender(T entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
pony = ((IRenderPony) getRenderer()).getPlayerModel();
for (EntityEquipmentSlot i : EntityEquipmentSlot.values()) {
@ -53,7 +53,7 @@ public class LayerPonyArmor extends AbstractPonyLayer<EntityLivingBase> {
}
}
private void renderArmor(EntityLivingBase entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale, EntityEquipmentSlot armorSlot) {
private void renderArmor(T entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale, EntityEquipmentSlot armorSlot) {
ItemStack itemstack = entity.getItemStackFromSlot(armorSlot);
if (!itemstack.isEmpty() && itemstack.getItem() instanceof ItemArmor) {
@ -93,7 +93,7 @@ public class LayerPonyArmor extends AbstractPonyLayer<EntityLivingBase> {
}
}
private Tuple<ResourceLocation, Boolean> getArmorTexture(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, @Nullable String type) {
private Tuple<ResourceLocation, Boolean> getArmorTexture(T entity, ItemStack itemstack, EntityEquipmentSlot slot, @Nullable String type) {
ItemArmor item = (ItemArmor) itemstack.getItem();
String texture = item.getArmorMaterial().getName();
String domain = "minecraft";
@ -166,7 +166,7 @@ public class LayerPonyArmor extends AbstractPonyLayer<EntityLivingBase> {
}
}
private void renderEnchantment(EntityLivingBase entity, ModelBase model, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
private void renderEnchantment(T entity, ModelBase model, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
getRenderer().bindTexture(ENCHANTED_ITEM_GLINT_RES);

View file

@ -20,7 +20,7 @@ import static com.minelittlepony.model.PonyModelConstants.PI;
public class LayerPonyCape extends AbstractPonyLayer<AbstractClientPlayer> {
public LayerPonyCape(RenderLivingBase<? extends AbstractClientPlayer> entity) {
public LayerPonyCape(RenderLivingBase<AbstractClientPlayer> entity) {
super(entity, new LayerCape((RenderPlayer) entity));
}

View file

@ -26,16 +26,16 @@ import net.minecraft.util.EnumFacing;
import static net.minecraft.client.renderer.GlStateManager.*;
public class LayerPonyCustomHead implements LayerRenderer<EntityLivingBase> {
public class LayerPonyCustomHead<T extends EntityLivingBase> implements LayerRenderer<T> {
private RenderLivingBase<? extends EntityLivingBase> renderer;
private RenderLivingBase<T> renderer;
public LayerPonyCustomHead(RenderLivingBase<? extends EntityLivingBase> renderPony) {
public LayerPonyCustomHead(RenderLivingBase<T> renderPony) {
renderer = renderPony;
}
@Override
public void doRenderLayer(EntityLivingBase entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
public void doRenderLayer(T entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
ItemStack itemstack = entity.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
if (!itemstack.isEmpty()) {
AbstractPonyModel model = getModel().getModel();
@ -67,7 +67,7 @@ public class LayerPonyCustomHead implements LayerRenderer<EntityLivingBase> {
}
private void renderBlock(EntityLivingBase entity, ItemStack itemstack) {
private void renderBlock(T entity, ItemStack itemstack) {
rotate(180, 0, 1, 0);
scale(0.625, -0.625F, -0.625F);
translate(0, 0.4F, -0.21F);

View file

@ -19,17 +19,17 @@ import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
public class LayerPonyElytra extends AbstractPonyLayer<EntityLivingBase> {
public class LayerPonyElytra<T extends EntityLivingBase> extends AbstractPonyLayer<T> {
private static final ResourceLocation TEXTURE_ELYTRA = new ResourceLocation("textures/entity/elytra.png");
private PonyElytra modelElytra = new PonyElytra();
public LayerPonyElytra(RenderLivingBase<?> rp) {
public LayerPonyElytra(RenderLivingBase<T> rp) {
super(rp, new LayerElytra(rp));
}
@Override
public void doPonyRender(@Nonnull EntityLivingBase entity, float move, float swing, float ticks, float age, float yaw, float head, float scale) {
public void doPonyRender(@Nonnull T entity, float move, float swing, float ticks, float age, float yaw, float head, float scale) {
AbstractPonyModel model = ((IRenderPony) getRenderer()).getPlayerModel().getModel();

View file

@ -44,12 +44,12 @@ public abstract class RenderPonyBase extends RenderPlayer implements IRenderPony
}
protected void addExtraLayers() {
addLayer(new LayerPonyArmor(this));
addLayer(new LayerHeldPonyItem(this));
addLayer(new LayerPonyArmor<>(this));
addLayer(new LayerHeldPonyItem<>(this));
addLayer(new LayerArrow(this));
addLayer(new LayerPonyCape(this));
addLayer(new LayerPonyCustomHead(this));
addLayer(new LayerPonyElytra(this));
addLayer(new LayerPonyCustomHead<>(this));
addLayer(new LayerPonyElytra<>(this));
addLayer(new LayerEntityOnPonyShoulder(renderManager, this));
}

View file

@ -7,9 +7,7 @@ import com.minelittlepony.render.layer.LayerHeldPonyItem;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityEvoker;
import net.minecraft.entity.monster.EntitySpellcasterIllager;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ResourceLocation;
@ -23,11 +21,11 @@ public class RenderPonyEvoker extends RenderPonyMob<EntityEvoker> {
@Override
protected void addLayers() {
addLayer(new LayerHeldPonyItem(this) {
addLayer(new LayerHeldPonyItem<EntityEvoker>(this) {
@Override
public void doPonyRender(EntityLivingBase entity, float limbSwing, float limbSwingAmount, float ticks, float age, float headYaw, float headPitch, float scale) {
if (((EntitySpellcasterIllager) entity).isSpellcasting()) {
super.doPonyRender(entity, limbSwing, limbSwingAmount, ticks, age, headYaw, headPitch, scale);
public void doPonyRender(EntityEvoker entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
if (entity.isSpellcasting()) {
super.doPonyRender(entity, move, swing, ticks, age, headYaw, headPitch, scale);
}
}

View file

@ -7,7 +7,6 @@ import com.minelittlepony.render.layer.LayerHeldPonyItem;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityIllusionIllager;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ResourceLocation;
@ -25,11 +24,11 @@ public class RenderPonyIllusionIllager extends RenderPonyMob<EntityIllusionIllag
@Override
protected void addLayers() {
addLayer(new LayerHeldPonyItem(this) {
addLayer(new LayerHeldPonyItem<EntityIllusionIllager>(this) {
@Override
public void doPonyRender(EntityLivingBase entity, float limbSwing, float limbSwingAmount, float ticks, float age, float headYaw, float headPitch, float scale) {
if (((EntityIllusionIllager) entity).isSpellcasting() || ((EntityIllusionIllager) entity).isAggressive()) {
super.doPonyRender(entity, limbSwing, limbSwingAmount, ticks, age, headYaw, headPitch, scale);
public void doPonyRender(EntityIllusionIllager entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
if (entity.isSpellcasting() || entity.isAggressive()) {
super.doPonyRender(entity, move, swing, ticks, age, headYaw, headPitch, scale);
}
}

View file

@ -7,7 +7,6 @@ import com.minelittlepony.render.layer.LayerHeldPonyItem;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityVindicator;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ResourceLocation;
@ -23,10 +22,10 @@ public class RenderPonyVindicator extends RenderPonyMob<EntityVindicator> {
@Override
protected void addLayers() {
this.addLayer(new LayerHeldPonyItem(this) {
this.addLayer(new LayerHeldPonyItem<EntityVindicator>(this) {
@Override
public void doPonyRender(EntityLivingBase entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
if (((EntityVindicator) entity).isAggressive()) {
public void doPonyRender(EntityVindicator entity, float move, float swing, float ticks, float age, float headYaw, float headPitch, float scale) {
if (entity.isAggressive()) {
super.doPonyRender(entity, move, swing, ticks, age, headYaw, headPitch, scale);
}
}