Add pony features to skulls (WIP)

This commit is contained in:
Sollace 2018-05-26 22:50:30 +02:00
parent a637a213c4
commit 224fe4b7ab
6 changed files with 152 additions and 3 deletions

View file

@ -178,6 +178,11 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel {
copyModelAngles(bipedBody, bipedBodyWear); copyModelAngles(bipedBody, bipedBodyWear);
} }
@Override
public ModelRenderer getHead() {
return bipedHead;
}
/** /**
* Sets the head rotation point. * Sets the head rotation point.
*/ */

View file

@ -0,0 +1,7 @@
package com.minelittlepony.model.capabilities;
import net.minecraft.client.model.ModelRenderer;
public interface ICapitated {
ModelRenderer getHead();
}

View file

@ -5,7 +5,7 @@ import com.minelittlepony.model.armour.PonyArmor;
import com.minelittlepony.pony.data.IPonyData; import com.minelittlepony.pony.data.IPonyData;
import com.minelittlepony.pony.data.PonyWearable; import com.minelittlepony.pony.data.PonyWearable;
public interface IModel { public interface IModel extends ICapitated {
/** /**
* Sets up this model's initial values, like a constructor... * Sets up this model's initial values, like a constructor...

View file

@ -0,0 +1,42 @@
package com.minelittlepony.model.components;
import com.minelittlepony.model.capabilities.ICapitated;
import com.minelittlepony.pony.data.IPonyData;
import com.minelittlepony.pony.data.PonyData;
import net.minecraft.client.model.ModelHumanoidHead;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
public class ModelPonyHead extends ModelHumanoidHead implements ICapitated {
private final PonySnout snout;
private final UnicornHorn horn;
public IPonyData metadata = new PonyData();
public ModelPonyHead() {
super();
snout = new PonySnout(this);
horn = new UnicornHorn(this, 0, 0);
}
@Override
public ModelRenderer getHead() {
return skeletonHead;
}
@Override
public void render(Entity entity, float move, float swing, float ticks, float headYaw, float headPitch, float scale) {
snout.setGender(metadata.getGender());
super.render(entity, move, swing, ticks, headYaw, headPitch, scale);
if (metadata.hasMagic()) {
horn.render(scale);
}
}
}

View file

@ -0,0 +1,95 @@
package com.minelittlepony.render;
import java.io.IOException;
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.model.components.ModelPonyHead;
import com.minelittlepony.pony.data.Pony;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntitySkull;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
@Mixin(TileEntitySkullRenderer.class)
public abstract class PonySkullRenderer extends TileEntitySpecialRenderer<TileEntitySkull> {
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) {
PonyConfig config = MineLittlePony.getConfig();
switch (skullType)
{
default:
case 0: //skeleton
case 1: //wither skeleton
renderAsPony = config.skeletons;
break;
case 2: //zombie
renderAsPony = config.zombies;
break;
case 3: // player
renderAsPony = true;
break;
case 4: // creeper
case 5: // dragon
renderAsPony = false;
}
}
@Redirect(method = "renderSkull(FFFLnet/minecraft/util/EnumFacing;FILcom/mojang/authlib/GameProfile;IF)V",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/model/ModelBase;render(Let/minecraft/entity/Entity;FFFFFFF)V"))
private void redirectRender(ModelBase self, Entity entity, float ticks, float swing, float swingAmount, float age, float headYaw, float headPitch, float scale) {
if (renderAsPony) {
self = ponyHead;
}
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);
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;
}
}
}

View file

@ -37,7 +37,7 @@ public class LayerPonyCustomHead<T extends EntityLivingBase> implements LayerRen
public void doRenderLayer(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) { public void doRenderLayer(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) {
ItemStack itemstack = entity.getItemStackFromSlot(EntityEquipmentSlot.HEAD); ItemStack itemstack = entity.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
if (!itemstack.isEmpty()) { if (!itemstack.isEmpty()) {
AbstractPonyModel model = getModel().getModel(); AbstractPonyModel model = getModel().getBody();
Item item = itemstack.getItem(); Item item = itemstack.getItem();
pushMatrix(); pushMatrix();
@ -103,7 +103,7 @@ public class LayerPonyCustomHead<T extends EntityLivingBase> implements LayerRen
} }
private ModelWrapper getModel() { private ModelWrapper getModel() {
return ((IRenderPony) renderer).getPlayerModel(); return ((IRenderPony<?>) renderer).getModelWrapper();
} }
@Override @Override