Make LayerEntityOnPonyShoulder include more entities

Includes a method for getting a possible forge layer later.
This commit is contained in:
Matthew Messinger 2017-06-16 01:41:36 -04:00
parent 8b99a03e28
commit 05483e1961
2 changed files with 51 additions and 71 deletions

View file

@ -2,13 +2,18 @@ package com.minelittlepony;
import com.mumfrey.liteloader.util.ModUtilities; import com.mumfrey.liteloader.util.ModUtilities;
import net.minecraft.client.model.ModelBiped; import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.layers.LayerRenderer;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.ForgeHooksClient;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Optional;
import java.util.function.Function;
public class ForgeProxy { public class ForgeProxy {
@ -26,4 +31,11 @@ public class ForgeProxy {
return def; return def;
} }
public static Optional<Function<RenderManager,LayerRenderer<EntityPlayer>>> createShoulderLayer() {
if (forgeLoaded) {
// TODO
}
return Optional.empty();
}
} }

View file

@ -1,124 +1,92 @@
package com.minelittlepony.renderer.layer; package com.minelittlepony.renderer.layer;
import com.minelittlepony.ForgeProxy;
import com.minelittlepony.model.BodyPart; import com.minelittlepony.model.BodyPart;
import com.minelittlepony.model.pony.ModelPlayerPony; import com.minelittlepony.model.pony.ModelPlayerPony;
import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelParrot;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderLiving; import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderLivingBase; import net.minecraft.client.renderer.entity.RenderLivingBase;
import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderParrot;
import net.minecraft.client.renderer.entity.layers.LayerEntityOnShoulder; import net.minecraft.client.renderer.entity.layers.LayerEntityOnShoulder;
import net.minecraft.client.renderer.entity.layers.LayerRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntityParrot;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.UUID;
public class LayerEntityOnPonyShoulder extends AbstractPonyLayer<EntityPlayer> { public class LayerEntityOnPonyShoulder extends AbstractPonyLayer<EntityPlayer> {
private final RenderManager rm; private final RenderManager rm;
private ShoulderEntity leftEntity; private EntityLivingBase leftEntity;
private ShoulderEntity rightEntity; private EntityLivingBase rightEntity;
public LayerEntityOnPonyShoulder(RenderManager rm, RenderLivingBase<AbstractClientPlayer> renderer) { public LayerEntityOnPonyShoulder(RenderManager rm, RenderLivingBase<AbstractClientPlayer> renderer) {
super(renderer, new LayerEntityOnShoulder(rm)); super(renderer, getForgeLayer(rm));
this.rm = rm; this.rm = rm;
} }
public void doPonyRender(EntityPlayer player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, public void doPonyRender(EntityPlayer player, float limbSwing, float limbSwingAmount, float partialTicks,
float headPitch, float scale) { float ageInTicks, float netHeadYaw, float headPitch, float scale) {
GlStateManager.enableRescaleNormal(); GlStateManager.enableRescaleNormal();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
NBTTagCompound leftTag = player.func_192023_dk(); NBTTagCompound leftTag = player.getLeftShoulderEntity();
if (!leftTag.hasNoTags()) { if (!leftTag.hasNoTags()) {
this.leftEntity = this.renderShoulderEntity(player, leftTag, this.leftEntity, this.leftEntity = this.renderShoulderEntity(player, this.leftEntity, leftTag,
limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale, true); limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale, true);
} }
NBTTagCompound rightTag = player.func_192025_dl(); NBTTagCompound rightTag = player.getRightShoulderEntity();
if (!rightTag.hasNoTags()) { if (!rightTag.hasNoTags()) {
this.rightEntity = this.rightEntity = this.renderShoulderEntity(player, this.rightEntity, rightTag,
this.renderShoulderEntity(player, rightTag, this.rightEntity, limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale, false);
limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale, false);
} }
GlStateManager.disableRescaleNormal(); GlStateManager.disableRescaleNormal();
} }
@SuppressWarnings("unchecked")
@Nullable @Nullable
private ShoulderEntity renderShoulderEntity(EntityPlayer player, NBTTagCompound tag, @Nullable ShoulderEntity shoulder, private EntityLivingBase renderShoulderEntity(EntityPlayer player, @Nullable EntityLivingBase entity, NBTTagCompound tag, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale, boolean left) {
float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale,
boolean left) {
if (shoulder == null || !shoulder.uuid.equals(tag.getUniqueId("UUID"))) { if (entity == null || !entity.getUniqueID().equals(tag.getUniqueId("UUID"))) {
UUID uuid = tag.getUniqueId("UUID"); entity = (EntityLivingBase) EntityList.createEntityFromNBT(tag, player.world);
Class<?> clazz = EntityList.func_192839_a(tag.getString("id")); // this isn't an entity.
if (entity == null) {
// this wan't an entity
if (uuid == null || clazz == null) {
return null;
}
if (clazz == EntityParrot.class) {
RenderLiving<?> renderer = new RenderParrot(this.rm);
ModelBase model = new ModelParrot();
ResourceLocation resource = RenderParrot.field_192862_a[tag.getInteger("Variant")];
shoulder = new ShoulderEntity(uuid, renderer, model, resource, clazz);
} else {
// not supported? TODO experiment with other mobs, probably will be changed by forge
return null; return null;
} }
} }
shoulder.renderer.bindTexture(shoulder.resource);
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
float f = -1.8F;
float f1 = left ? 0.2F : -0.2F;
ModelPlayerPony model = ((ModelPlayerPony)getRenderer().getMainModel());
model.transform(BodyPart.HEAD);
model.bipedHead.postRender(scale);
GlStateManager.translate(f1, f, -0.2F);
if (shoulder.clazz == EntityParrot.class) { ModelPlayerPony model = ((ModelPlayerPony) getRenderer().getMainModel());
ageInTicks = 0.0F; model.transform(BodyPart.BODY);
netHeadYaw = 0;
// render on the haunches
float f = .25F;
float f1 = left ? 0.25F : -0.25F;
GlStateManager.translate(f1, f, 0.35F);
GlStateManager.scale(1, -1, -1);
GlStateManager.rotate(5 * (left ? -1 : 1), 0, 0, 1);
Render<Entity> render = rm.getEntityRenderObject(entity);
if (render != null) {
render.doRender(entity, 0, 0, 0, 0, 0);
GlStateManager.popMatrix();
} }
return entity;
shoulder.model.setLivingAnimations(player, limbSwing, limbSwingAmount, partialTicks);
shoulder.model.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, player);
shoulder.model.render(player, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
GlStateManager.popMatrix();
return shoulder;
} }
private class ShoulderEntity { private static LayerRenderer<EntityPlayer> getForgeLayer(RenderManager rm) {
return ForgeProxy.createShoulderLayer()
public UUID uuid; .orElse(LayerEntityOnShoulder::new)
public RenderLivingBase<? extends EntityLivingBase> renderer; .apply(rm);
public ModelBase model;
public ResourceLocation resource;
public Class<?> clazz;
public ShoulderEntity(UUID uuid, RenderLivingBase<? extends EntityLivingBase> renderer,
ModelBase model, ResourceLocation res, Class<?> clazz) {
this.uuid = uuid;
this.renderer = renderer;
this.model = model;
this.resource = res;
this.clazz = clazz;
}
} }
} }