Pony skulls, pony skulls, what 'chu gonna do when they come for you!

This commit is contained in:
Sollace 2018-06-10 18:16:37 +02:00
parent 224fe4b7ab
commit 4b6c49f6fa
15 changed files with 151 additions and 66 deletions

View file

@ -10,7 +10,7 @@ public interface IRenderPony {
/** /**
* Gets the wrapped pony model for this renderer. * Gets the wrapped pony model for this renderer.
*/ */
ModelWrapper getPlayerModel(); ModelWrapper getModelWrapper();
/** /**
* Gets the current shadow size for rendering. * Gets the current shadow size for rendering.

View file

@ -53,7 +53,7 @@ public class RenderPonyModel extends RenderPlayerModel<EntityPonyModel> {
renderingAsHuman = false; renderingAsHuman = false;
return pm.getModel(); return pm.getBody();
} }
@Override @Override

View file

@ -9,20 +9,20 @@ import com.minelittlepony.pony.data.IPonyData;
*/ */
public class ModelWrapper implements IModelWrapper { public class ModelWrapper implements IModelWrapper {
private final AbstractPonyModel model; private final AbstractPonyModel body;
private final PonyArmor armor; private final PonyArmor armor;
/** /**
* Created a new model wrapper to contain the given pony. * Created a new model wrapper to contain the given pony.
*/ */
public ModelWrapper(AbstractPonyModel model) { public ModelWrapper(AbstractPonyModel model) {
this.model = model; this.body = model;
armor = model.createArmour(); armor = model.createArmour();
armor.apply(model.metadata); armor.apply(model.metadata);
} }
public AbstractPonyModel getModel() { public AbstractPonyModel getBody() {
return model; return body;
} }
/** /**
@ -34,12 +34,12 @@ public class ModelWrapper implements IModelWrapper {
} }
public void apply(IPonyData meta) { public void apply(IPonyData meta) {
model.metadata = meta; body.metadata = meta;
armor.apply(meta); armor.apply(meta);
} }
public void init() { public void init() {
model.init(0, 0); body.init(0, 0);
armor.init(); armor.init();
} }
} }

View file

@ -3,10 +3,12 @@ package com.minelittlepony.model.components;
import com.minelittlepony.pony.data.PonyGender; import com.minelittlepony.pony.data.PonyGender;
import com.minelittlepony.render.plane.PlaneRenderer; import com.minelittlepony.render.plane.PlaneRenderer;
import net.minecraft.client.model.ModelBase;
import static com.minelittlepony.model.PonyModelConstants.*; import static com.minelittlepony.model.PonyModelConstants.*;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.capabilities.ICapitated;
public class PonySnout { public class PonySnout {
@ -15,12 +17,12 @@ public class PonySnout {
private PlaneRenderer mare; private PlaneRenderer mare;
private PlaneRenderer stallion; private PlaneRenderer stallion;
public PonySnout(AbstractPonyModel pony) { public <T extends ModelBase & ICapitated> PonySnout(T pony) {
mare = new PlaneRenderer(pony); mare = new PlaneRenderer(pony);
stallion = new PlaneRenderer(pony); stallion = new PlaneRenderer(pony);
pony.bipedHead.addChild(stallion); pony.getHead().addChild(stallion);
pony.bipedHead.addChild(mare); pony.getHead().addChild(mare);
} }
public void rotate(float x, float y, float z) { public void rotate(float x, float y, float z) {

View file

@ -1,9 +1,11 @@
package com.minelittlepony.model.components; package com.minelittlepony.model.components;
import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.capabilities.ICapitated;
import com.minelittlepony.render.HornGlowRenderer; import com.minelittlepony.render.HornGlowRenderer;
import com.minelittlepony.render.PonyRenderer; import com.minelittlepony.render.PonyRenderer;
import net.minecraft.client.model.ModelBase;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
import static net.minecraft.client.renderer.GlStateManager.*; import static net.minecraft.client.renderer.GlStateManager.*;
import static com.minelittlepony.model.PonyModelConstants.*; import static com.minelittlepony.model.PonyModelConstants.*;
@ -13,7 +15,7 @@ public class UnicornHorn {
private PonyRenderer horn; private PonyRenderer horn;
private HornGlowRenderer glow; private HornGlowRenderer glow;
public UnicornHorn(AbstractPonyModel pony, float yOffset, float stretch) { public <T extends ModelBase & ICapitated> UnicornHorn(T pony, float yOffset, float stretch) {
horn = new PonyRenderer(pony, 0, 3); horn = new PonyRenderer(pony, 0, 3);
glow = new HornGlowRenderer(pony, 0, 3); glow = new HornGlowRenderer(pony, 0, 3);

View file

@ -1,39 +1,45 @@
package com.minelittlepony.render; package com.minelittlepony.render;
import java.io.IOException; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyConfig; import com.minelittlepony.PonyConfig;
import com.minelittlepony.ducks.IRenderItem;
import com.minelittlepony.model.components.ModelPonyHead; import com.minelittlepony.model.components.ModelPonyHead;
import com.minelittlepony.pony.data.Pony; import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.render.ponies.RenderPonySkeleton;
import com.minelittlepony.render.ponies.RenderPonyZombie;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.GlStateManager.DestFactor;
import net.minecraft.client.renderer.GlStateManager.SourceFactor;
import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntitySkull; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@Mixin(TileEntitySkullRenderer.class) public class PonySkullRenderer extends TileEntitySkullRenderer implements IRenderItem {
public abstract class PonySkullRenderer extends TileEntitySpecialRenderer<TileEntitySkull> {
private final ModelPonyHead ponyHead = new ModelPonyHead(); private final ModelPonyHead ponyHead = new ModelPonyHead();
private boolean renderAsPony = false; private boolean renderAsPony = false;
@Inject(method = "renderSkull(FFFLnet/minecraft/util/EnumFacing;FILcom/mojang/authlib/GameProfile;IF)V", protected boolean transparency = false;
at = @At("HEAD"))
private void onRenderSkull(float x, float y, float z, EnumFacing facing, float rotationIn, int skullType, @Nullable GameProfile profile, int destroyStage, float animateTicks, CallbackInfo info) {
public void renderSkull(float x, float y, float z, EnumFacing facing, float rotationIn, int skullType, @Nullable GameProfile profile, int destroyStage, float animateTicks, CallbackInfo info) {
PonyConfig config = MineLittlePony.getConfig(); PonyConfig config = MineLittlePony.getConfig();
switch (skullType) switch (skullType)
@ -53,6 +59,97 @@ public abstract class PonySkullRenderer extends TileEntitySpecialRenderer<TileEn
case 5: // dragon case 5: // dragon
renderAsPony = false; renderAsPony = false;
} }
if (renderAsPony) {
renderPonySkull(x, y, z, facing, rotationIn, skullType, profile, destroyStage, animateTicks);
} else {
super.renderSkull(x, y, z, facing, rotationIn, skullType, profile, destroyStage, animateTicks);
}
}
protected ResourceLocation getSkinResource(GameProfile profile, int skullType) {
if (skullType == 1) {
return RenderPonySkeleton.WITHER;
}
if (skullType == 2) {
return RenderPonySkeleton.SKELETON;
}
if (skullType == 3) {
if (profile != null) {
Minecraft minecraft = Minecraft.getMinecraft();
Map<Type, MinecraftProfileTexture> map = minecraft.getSkinManager().loadSkinFromCache(profile);
if (map.containsKey(Type.SKIN)) {
return minecraft.getSkinManager().loadSkin(map.get(Type.SKIN), Type.SKIN);
} else {
return DefaultPlayerSkin.getDefaultSkin(EntityPlayer.getUUID(profile));
}
}
return DefaultPlayerSkin.getDefaultSkinLegacy();
}
return RenderPonyZombie.ZOMBIE;
}
public void renderPonySkull(float x, float y, float z, EnumFacing facing, float rotationIn, int skullType, @Nullable GameProfile profile, int destroyStage, float animateTicks) {
if (destroyStage >= 0) {
bindTexture(DESTROY_STAGES[destroyStage]);
GlStateManager.matrixMode(5890);
GlStateManager.pushMatrix();
GlStateManager.scale(4.0F, 2.0F, 1.0F);
GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
GlStateManager.matrixMode(5888);
} else {
bindTexture(getSkinResource(profile, skullType));
}
GlStateManager.pushMatrix();
GlStateManager.disableCull();
switch (facing) {
case UP:
GlStateManager.translate(x + 0.5F, y, z + 0.5F);
break;
case NORTH:
GlStateManager.translate(x + 0.5F, y + 0.25F, z + 0.74F);
break;
case SOUTH:
GlStateManager.translate(x + 0.5F, y + 0.25F, z + 0.26F);
rotationIn = 180.0F;
break;
case WEST:
GlStateManager.translate(x + 0.74F, y + 0.25F, z + 0.5F);
rotationIn = 270.0F;
break;
case EAST:
default:
GlStateManager.translate(x + 0.26F, y + 0.25F, z + 0.5F);
rotationIn = 90.0F;
}
GlStateManager.enableRescaleNormal();
GlStateManager.scale(-1, -1, 1);
GlStateManager.enableAlpha();
if (skullType == 3) {
if (transparency) {
GlStateManager.tryBlendFuncSeparate(SourceFactor.CONSTANT_COLOR, DestFactor.ONE, SourceFactor.ONE, DestFactor.ZERO);
} else {
GlStateManager.enableBlendProfile(GlStateManager.Profile.PLAYER_SKIN);
}
}
ponyHead.render((Entity)null, animateTicks, 0, 0, rotationIn, 0, 0.0625F);
GlStateManager.popMatrix();
if (destroyStage >= 0) {
GlStateManager.matrixMode(5890);
GlStateManager.popMatrix();
GlStateManager.matrixMode(5888);
}
} }
@Redirect(method = "renderSkull(FFFLnet/minecraft/util/EnumFacing;FILcom/mojang/authlib/GameProfile;IF)V", @Redirect(method = "renderSkull(FFFLnet/minecraft/util/EnumFacing;FILcom/mojang/authlib/GameProfile;IF)V",
@ -66,30 +163,14 @@ public abstract class PonySkullRenderer extends TileEntitySpecialRenderer<TileEn
self.render(entity, swing, swingAmount, age, headYaw, headPitch, scale); self.render(entity, swing, swingAmount, age, headYaw, headPitch, scale);
} }
@Inject(method = "bindTexture(Lnet/minecraft/util/ResourceLocation;)V", protected void bindTexture(ResourceLocation location, CallbackInfo info) {
at = @At("HEAD"), cancellable = true)
private void onBindTexture(ResourceLocation location, CallbackInfo info) {
location = resolvePonyResource(location);
Pony pony = MineLittlePony.getInstance().getManager().getPony(location, false); Pony pony = MineLittlePony.getInstance().getManager().getPony(location, false);
ponyHead.metadata = pony.getMetadata(); ponyHead.metadata = pony.getMetadata();
super.bindTexture(location); super.bindTexture(location);
} }
private ResourceLocation resolvePonyResource(ResourceLocation human) { @Override
String domain = human.getResourceDomain(); public void useTransparency(boolean use) {
String path = human.getResourcePath(); transparency = use;
if (domain.equals("minecraft")) {
domain = "minelittlepony";
}
ResourceLocation pony = new ResourceLocation(domain, path);
try {
Minecraft.getMinecraft().getResourceManager().getResource(pony);
return pony;
} catch (IOException e) {
return human;
}
} }
} }

View file

@ -30,9 +30,9 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
private Pony pony; private Pony pony;
public RenderPonyMob(RenderManager manager, ModelWrapper model) { public RenderPonyMob(RenderManager manager, ModelWrapper model) {
super(manager, model.getModel(), 0.5F); super(manager, model.getBody(), 0.5F);
playerModel = model; playerModel = model;
ponyModel = playerModel.getModel(); ponyModel = playerModel.getBody();
addLayers(); addLayers();
} }
@ -96,7 +96,7 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
} }
@Override @Override
public ModelWrapper getPlayerModel() { public ModelWrapper getModelWrapper() {
return playerModel; return playerModel;
} }

View file

@ -43,7 +43,7 @@ public abstract class AbstractPonyLayer<T extends EntityLivingBase> implements L
} }
public AbstractPonyModel getPlayerModel() { public AbstractPonyModel getPlayerModel() {
return ((IRenderPony) getRenderer()).getPlayerModel().getModel(); return ((IRenderPony) getRenderer()).getModelWrapper().getBody();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View file

@ -40,7 +40,7 @@ public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLaye
@Override @Override
public void doPonyRender(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) { public void doPonyRender(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) {
pony = ((IRenderPony) getRenderer()).getPlayerModel(); pony = ((IRenderPony) getRenderer()).getModelWrapper();
for (EntityEquipmentSlot i : EntityEquipmentSlot.values()) { for (EntityEquipmentSlot i : EntityEquipmentSlot.values()) {
if (i.getSlotType() == Type.ARMOR) { if (i.getSlotType() == Type.ARMOR) {
@ -57,9 +57,9 @@ public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLaye
ItemArmor itemarmor = (ItemArmor) itemstack.getItem(); ItemArmor itemarmor = (ItemArmor) itemstack.getItem();
ModelPonyArmor armour = getArmorModel(entity, itemstack, armorSlot, pony.getArmor().getArmorForSlot(armorSlot)); ModelPonyArmor armour = getArmorModel(entity, itemstack, armorSlot, pony.getArmor().getArmorForSlot(armorSlot));
armour.setModelAttributes(pony.getModel()); armour.setModelAttributes(pony.getBody());
armour.setRotationAngles(move, swing, ticks, headYaw, headPitch, scale, entity); armour.setRotationAngles(move, swing, ticks, headYaw, headPitch, scale, entity);
armour.synchroniseLegs(pony.getModel()); armour.synchroniseLegs(pony.getBody());
Tuple<ResourceLocation, Boolean> armors = getArmorTexture(entity, itemstack, armorSlot, null); Tuple<ResourceLocation, Boolean> armors = getArmorTexture(entity, itemstack, armorSlot, null);
prepareToRender(armour, armorSlot, armors.getSecond()); prepareToRender(armour, armorSlot, armors.getSecond());

View file

@ -24,16 +24,16 @@ public class LayerPonyCape extends AbstractPonyLayer<AbstractClientPlayer> {
@Override @Override
public void doPonyRender(@Nonnull AbstractClientPlayer player, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) { public void doPonyRender(@Nonnull AbstractClientPlayer player, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) {
ModelWrapper model = ((IRenderPony) getRenderer()).getPlayerModel(); ModelWrapper model = ((IRenderPony) getRenderer()).getModelWrapper();
if (player.hasPlayerInfo() && !player.isInvisible() if (player.hasPlayerInfo() && !player.isInvisible()
&& player.isWearing(EnumPlayerModelParts.CAPE) && player.getLocationCape() != null && player.isWearing(EnumPlayerModelParts.CAPE) && player.getLocationCape() != null
&& player.getItemStackFromSlot(EntityEquipmentSlot.CHEST).getItem() != Items.ELYTRA) { && player.getItemStackFromSlot(EntityEquipmentSlot.CHEST).getItem() != Items.ELYTRA) {
pushMatrix(); pushMatrix();
model.getModel().transform(BodyPart.BODY); model.getBody().transform(BodyPart.BODY);
translate(0, 0.24F, 0); translate(0, 0.24F, 0);
model.getModel().bipedBody.postRender(scale); model.getBody().bipedBody.postRender(scale);
double capeX = player.prevChasingPosX + (player.chasingPosX - player.prevChasingPosX) * scale - (player.prevPosX + (player.posX - player.prevPosX) * scale); double capeX = player.prevChasingPosX + (player.chasingPosX - player.prevChasingPosX) * scale - (player.prevPosX + (player.posX - player.prevPosX) * scale);
double capeY = player.prevChasingPosY + (player.chasingPosY - player.prevChasingPosY) * scale - (player.prevPosY + (player.posY - player.prevPosY) * scale); double capeY = player.prevChasingPosY + (player.chasingPosY - player.prevChasingPosY) * scale - (player.prevPosY + (player.posY - player.prevPosY) * scale);
@ -64,7 +64,7 @@ public class LayerPonyCape extends AbstractPonyLayer<AbstractClientPlayer> {
rotate(180, 0, 0, 1); rotate(180, 0, 0, 1);
rotate(90, 1, 0, 0); rotate(90, 1, 0, 0);
getRenderer().bindTexture(player.getLocationCape()); getRenderer().bindTexture(player.getLocationCape());
model.getModel().renderCape(0.0625F); model.getBody().renderCape(0.0625F);
popMatrix(); popMatrix();
} }
} }

View file

@ -103,7 +103,7 @@ public class LayerPonyCustomHead<T extends EntityLivingBase> implements LayerRen
} }
private ModelWrapper getModel() { private ModelWrapper getModel() {
return ((IRenderPony<?>) renderer).getModelWrapper(); return ((IRenderPony) renderer).getModelWrapper();
} }
@Override @Override

View file

@ -144,13 +144,13 @@ public abstract class RenderPonyBase extends RenderPlayer implements IRenderPony
} }
@Override @Override
public ModelWrapper getPlayerModel() { public ModelWrapper getModelWrapper() {
return playerModel; return playerModel;
} }
protected void setPlayerModel(ModelWrapper model) { protected void setPlayerModel(ModelWrapper model) {
playerModel = model; playerModel = model;
mainModel = ponyModel = playerModel.getModel(); mainModel = ponyModel = playerModel.getBody();
} }
protected void updateModel(AbstractClientPlayer player) { protected void updateModel(AbstractClientPlayer player) {

View file

@ -20,7 +20,7 @@ public class RenderPonyGuardian extends RenderGuardian {
public RenderPonyGuardian(RenderManager manager) { public RenderPonyGuardian(RenderManager manager) {
super(manager); super(manager);
mainModel = PMAPI.seapony.getModel(); mainModel = PMAPI.seapony.getBody();
ponyRenderer = new RenderPonyMob.Proxy<EntityGuardian>(manager, PMAPI.seapony) { ponyRenderer = new RenderPonyMob.Proxy<EntityGuardian>(manager, PMAPI.seapony) {
@Override @Override

View file

@ -14,9 +14,9 @@ import net.minecraft.util.ResourceLocation;
public class RenderPonySkeleton<Skeleton extends AbstractSkeleton> extends RenderPonyMob<Skeleton> { public class RenderPonySkeleton<Skeleton extends AbstractSkeleton> extends RenderPonyMob<Skeleton> {
private static final ResourceLocation SKELETON = new ResourceLocation("minelittlepony", "textures/entity/skeleton/skeleton_pony.png"); public static final ResourceLocation SKELETON = new ResourceLocation("minelittlepony", "textures/entity/skeleton/skeleton_pony.png");
private static final ResourceLocation WITHER = new ResourceLocation("minelittlepony", "textures/entity/skeleton/skeleton_wither_pony.png"); public static final ResourceLocation WITHER = new ResourceLocation("minelittlepony", "textures/entity/skeleton/skeleton_wither_pony.png");
private static final ResourceLocation STRAY = new ResourceLocation("minelittlepony", "textures/entity/skeleton/stray_pony.png"); public static final ResourceLocation STRAY = new ResourceLocation("minelittlepony", "textures/entity/skeleton/stray_pony.png");
public RenderPonySkeleton(RenderManager manager) { public RenderPonySkeleton(RenderManager manager) {
super(manager, PMAPI.skeleton); super(manager, PMAPI.skeleton);
@ -28,8 +28,8 @@ public class RenderPonySkeleton<Skeleton extends AbstractSkeleton> extends Rende
addLayer(new LayerBipedArmor(this) { addLayer(new LayerBipedArmor(this) {
@Override @Override
protected void initArmor() { protected void initArmor() {
modelLeggings = getPlayerModel().getArmor().leggings; modelLeggings = getModelWrapper().getArmor().leggings;
modelArmor = getPlayerModel().getArmor().chestplate; modelArmor = getModelWrapper().getArmor().chestplate;
} }
}); });
} }

View file

@ -12,8 +12,8 @@ import net.minecraft.util.ResourceLocation;
public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob<Zombie> { public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob<Zombie> {
private static final ResourceLocation ZOMBIE = new ResourceLocation("minelittlepony", "textures/entity/zombie/zombie_pony.png"); public static final ResourceLocation ZOMBIE = new ResourceLocation("minelittlepony", "textures/entity/zombie/zombie_pony.png");
private static final ResourceLocation HUSK = new ResourceLocation("minelittlepony", "textures/entity/zombie/husk_pony.png"); public static final ResourceLocation HUSK = new ResourceLocation("minelittlepony", "textures/entity/zombie/husk_pony.png");
public RenderPonyZombie(RenderManager manager) { public RenderPonyZombie(RenderManager manager) {
super(manager, PMAPI.zombie); super(manager, PMAPI.zombie);