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.
*/
ModelWrapper getPlayerModel();
ModelWrapper getModelWrapper();
/**
* Gets the current shadow size for rendering.

View file

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

View file

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

View file

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

View file

@ -1,9 +1,11 @@
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.PonyRenderer;
import net.minecraft.client.model.ModelBase;
import static org.lwjgl.opengl.GL11.*;
import static net.minecraft.client.renderer.GlStateManager.*;
import static com.minelittlepony.model.PonyModelConstants.*;
@ -13,7 +15,7 @@ public class UnicornHorn {
private PonyRenderer horn;
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);
glow = new HornGlowRenderer(pony, 0, 3);

View file

@ -1,39 +1,45 @@
package com.minelittlepony.render;
import java.io.IOException;
import java.util.Map;
import javax.annotation.Nullable;
import org.spongepowered.asm.mixin.Mixin;
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.callback.CallbackInfo;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyConfig;
import com.minelittlepony.ducks.IRenderItem;
import com.minelittlepony.model.components.ModelPonyHead;
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.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import net.minecraft.client.Minecraft;
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.TileEntitySpecialRenderer;
import net.minecraft.client.resources.DefaultPlayerSkin;
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.ResourceLocation;
@Mixin(TileEntitySkullRenderer.class)
public abstract class PonySkullRenderer extends TileEntitySpecialRenderer<TileEntitySkull> {
public class PonySkullRenderer extends TileEntitySkullRenderer implements IRenderItem {
private final ModelPonyHead ponyHead = new ModelPonyHead();
private boolean renderAsPony = false;
@Inject(method = "renderSkull(FFFLnet/minecraft/util/EnumFacing;FILcom/mojang/authlib/GameProfile;IF)V",
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) {
protected boolean transparency = false;
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();
switch (skullType)
@ -53,6 +59,97 @@ public abstract class PonySkullRenderer extends TileEntitySpecialRenderer<TileEn
case 5: // dragon
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",
@ -66,30 +163,14 @@ public abstract class PonySkullRenderer extends TileEntitySpecialRenderer<TileEn
self.render(entity, swing, swingAmount, age, headYaw, headPitch, scale);
}
@Inject(method = "bindTexture(Lnet/minecraft/util/ResourceLocation;)V",
at = @At("HEAD"), cancellable = true)
private void onBindTexture(ResourceLocation location, CallbackInfo info) {
location = resolvePonyResource(location);
protected void bindTexture(ResourceLocation location, CallbackInfo info) {
Pony pony = MineLittlePony.getInstance().getManager().getPony(location, false);
ponyHead.metadata = pony.getMetadata();
super.bindTexture(location);
}
private ResourceLocation resolvePonyResource(ResourceLocation human) {
String domain = human.getResourceDomain();
String path = human.getResourcePath();
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;
}
@Override
public void useTransparency(boolean use) {
transparency = use;
}
}

View file

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

View file

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

View file

@ -40,7 +40,7 @@ public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLaye
@Override
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()) {
if (i.getSlotType() == Type.ARMOR) {
@ -57,9 +57,9 @@ public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLaye
ItemArmor itemarmor = (ItemArmor) itemstack.getItem();
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.synchroniseLegs(pony.getModel());
armour.synchroniseLegs(pony.getBody());
Tuple<ResourceLocation, Boolean> armors = getArmorTexture(entity, itemstack, armorSlot, null);
prepareToRender(armour, armorSlot, armors.getSecond());

View file

@ -24,16 +24,16 @@ public class LayerPonyCape extends AbstractPonyLayer<AbstractClientPlayer> {
@Override
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()
&& player.isWearing(EnumPlayerModelParts.CAPE) && player.getLocationCape() != null
&& player.getItemStackFromSlot(EntityEquipmentSlot.CHEST).getItem() != Items.ELYTRA) {
pushMatrix();
model.getModel().transform(BodyPart.BODY);
model.getBody().transform(BodyPart.BODY);
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 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(90, 1, 0, 0);
getRenderer().bindTexture(player.getLocationCape());
model.getModel().renderCape(0.0625F);
model.getBody().renderCape(0.0625F);
popMatrix();
}
}

View file

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

View file

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

View file

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

View file

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

View file

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