mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 12:37:59 +01:00
Make LayerEntityOnPonyShoulder include more entities
Includes a method for getting a possible forge layer later.
This commit is contained in:
parent
8b99a03e28
commit
05483e1961
2 changed files with 51 additions and 71 deletions
|
@ -2,13 +2,18 @@ package com.minelittlepony;
|
|||
|
||||
import com.mumfrey.liteloader.util.ModUtilities;
|
||||
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.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ForgeProxy {
|
||||
|
||||
|
@ -26,4 +31,11 @@ public class ForgeProxy {
|
|||
return def;
|
||||
}
|
||||
|
||||
public static Optional<Function<RenderManager,LayerRenderer<EntityPlayer>>> createShoulderLayer() {
|
||||
if (forgeLoaded) {
|
||||
// TODO
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,124 +1,92 @@
|
|||
package com.minelittlepony.renderer.layer;
|
||||
|
||||
import com.minelittlepony.ForgeProxy;
|
||||
import com.minelittlepony.model.BodyPart;
|
||||
import com.minelittlepony.model.pony.ModelPlayerPony;
|
||||
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.entity.RenderLiving;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderLivingBase;
|
||||
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.LayerRenderer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.passive.EntityParrot;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LayerEntityOnPonyShoulder extends AbstractPonyLayer<EntityPlayer> {
|
||||
|
||||
private final RenderManager rm;
|
||||
private ShoulderEntity leftEntity;
|
||||
private ShoulderEntity rightEntity;
|
||||
private EntityLivingBase leftEntity;
|
||||
private EntityLivingBase rightEntity;
|
||||
|
||||
public LayerEntityOnPonyShoulder(RenderManager rm, RenderLivingBase<AbstractClientPlayer> renderer) {
|
||||
super(renderer, new LayerEntityOnShoulder(rm));
|
||||
super(renderer, getForgeLayer(rm));
|
||||
this.rm = rm;
|
||||
}
|
||||
|
||||
public void doPonyRender(EntityPlayer player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw,
|
||||
float headPitch, float scale) {
|
||||
public void doPonyRender(EntityPlayer player, float limbSwing, float limbSwingAmount, float partialTicks,
|
||||
float ageInTicks, float netHeadYaw, float headPitch, float scale) {
|
||||
|
||||
GlStateManager.enableRescaleNormal();
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
NBTTagCompound leftTag = player.func_192023_dk();
|
||||
NBTTagCompound leftTag = player.getLeftShoulderEntity();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
NBTTagCompound rightTag = player.func_192025_dl();
|
||||
NBTTagCompound rightTag = player.getRightShoulderEntity();
|
||||
|
||||
if (!rightTag.hasNoTags()) {
|
||||
this.rightEntity =
|
||||
this.renderShoulderEntity(player, rightTag, this.rightEntity,
|
||||
limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale, false);
|
||||
this.rightEntity = this.renderShoulderEntity(player, this.rightEntity, rightTag,
|
||||
limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale, false);
|
||||
}
|
||||
|
||||
GlStateManager.disableRescaleNormal();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
private ShoulderEntity renderShoulderEntity(EntityPlayer player, NBTTagCompound tag, @Nullable ShoulderEntity shoulder,
|
||||
float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale,
|
||||
boolean left) {
|
||||
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) {
|
||||
|
||||
if (shoulder == null || !shoulder.uuid.equals(tag.getUniqueId("UUID"))) {
|
||||
UUID uuid = tag.getUniqueId("UUID");
|
||||
Class<?> clazz = EntityList.func_192839_a(tag.getString("id"));
|
||||
|
||||
// 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
|
||||
if (entity == null || !entity.getUniqueID().equals(tag.getUniqueId("UUID"))) {
|
||||
entity = (EntityLivingBase) EntityList.createEntityFromNBT(tag, player.world);
|
||||
// this isn't an entity.
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
shoulder.renderer.bindTexture(shoulder.resource);
|
||||
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) {
|
||||
ageInTicks = 0.0F;
|
||||
netHeadYaw = 0;
|
||||
ModelPlayerPony model = ((ModelPlayerPony) getRenderer().getMainModel());
|
||||
model.transform(BodyPart.BODY);
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
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;
|
||||
return entity;
|
||||
}
|
||||
|
||||
private class ShoulderEntity {
|
||||
|
||||
public UUID uuid;
|
||||
public RenderLivingBase<? extends EntityLivingBase> renderer;
|
||||
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;
|
||||
}
|
||||
private static LayerRenderer<EntityPlayer> getForgeLayer(RenderManager rm) {
|
||||
return ForgeProxy.createShoulderLayer()
|
||||
.orElse(LayerEntityOnShoulder::new)
|
||||
.apply(rm);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue