feat: Skulls worn by mobs/players now display on the armor layer

This commit is contained in:
SevenToaster509 2026-04-17 20:50:32 +01:00
parent 4771bac148
commit 27d0a8ffc3
4 changed files with 71 additions and 10 deletions

View file

@ -1,6 +1,7 @@
#include "stdafx.h"
#include "PlayerRenderer.h"
#include "SkullTileRenderer.h"
#include "../Minecraft.World/SkullTileEntity.h"
#include "HumanoidMobRenderer.h"
#include "HumanoidModel.h"
#include "ModelPart.h"
@ -13,8 +14,15 @@
#include "../Minecraft.World/net.minecraft.world.level.tile.h"
#include "../Minecraft.World/net.minecraft.h"
#include "../Minecraft.World/StringHelpers.h"
#include "SkeletonHeadModel.h"
#include "Textures.h"
#include "Skins.h"
ResourceLocation PlayerRenderer::SKELETON_LOCATION = ResourceLocation(TN_MOB_SKELETON);
ResourceLocation PlayerRenderer::WITHER_SKELETON_LOCATION = ResourceLocation(TN_MOB_WITHER_SKELETON);
ResourceLocation PlayerRenderer::ZOMBIE_LOCATION = ResourceLocation(TN_MOB_ZOMBIE);
ResourceLocation PlayerRenderer::CREEPER_LOCATION = ResourceLocation(TN_MOB_CREEPER);
static unsigned int nametagColorForIndex(int index)
{
static const unsigned int s_firstColors[] = {
@ -65,6 +73,7 @@ PlayerRenderer::PlayerRenderer() : LivingEntityRenderer( new HumanoidModel(0), 0
armorParts1 = new HumanoidModel(1.0f);
armorParts2 = new HumanoidModel(0.5f);
armorParts3 = new HumanoidModel(0.5f);
}
unsigned int PlayerRenderer::getNametagColour(int index)
@ -93,8 +102,9 @@ int PlayerRenderer::prepareArmor(shared_ptr<LivingEntity> _player, int layer, fl
if (dynamic_cast<ArmorItem *>(item))
{
ArmorItem *armorItem = dynamic_cast<ArmorItem *>(item);
bindTexture(HumanoidMobRenderer::getArmorLocation(armorItem, layer));
bindTexture(HumanoidMobRenderer::getArmorLocation(armorItem, layer));
SkullItem* skullItem = dynamic_cast<SkullItem*>(item);
HumanoidModel *armor = layer == 2 ? armorParts2 : armorParts1;
armor->head->visible = layer == 0;
@ -131,6 +141,51 @@ int PlayerRenderer::prepareArmor(shared_ptr<LivingEntity> _player, int layer, fl
return 1;
}
else if (dynamic_cast<SkullItem*>(item)) {
SkullItem* skullItem = dynamic_cast<SkullItem*>(item);
HumanoidModel* armor = armorParts3;
auto t = new SkeletonHeadModel(0, 0, 64, 64, 1);
//armor->head->_init();
armor->head = t->head;
//armor->head->addHumanoidBox(-4, -8, -4, 8, 8, 8, 0.5); // Head
armor->head->visible = layer == 0;
armor->hair->visible = false;
armor->body->visible = false;
armor->arm0->visible = false;
armor->arm1->visible = false;
armor->leg0->visible = false;
armor->leg1->visible = false;
switch (itemInstance->getAuxValue())
{
case SkullTileEntity::TYPE_WITHER:
bindTexture(&WITHER_SKELETON_LOCATION);
break;
case SkullTileEntity::TYPE_ZOMBIE:
bindTexture(&ZOMBIE_LOCATION);
break;
case SkullTileEntity::TYPE_CREEPER:
bindTexture(&CREEPER_LOCATION);
break;
case SkullTileEntity::TYPE_CHAR:
{
bindTexture(&PlayerRenderer::DEFAULT_LOCATION);
break;
}
case SkullTileEntity::TYPE_SKELETON:
default:
bindTexture(&SKELETON_LOCATION);
break;
}
setArmor(armor);
if (armor != nullptr) armor->attackTime = model->attackTime;
if (armor != nullptr) armor->riding = model->riding;
if (armor != nullptr) armor->young = model->young;
return 1;
}
}
return -1;
@ -366,7 +421,7 @@ void PlayerRenderer::additionalRendering(shared_ptr<LivingEntity> _mob, float a)
entityRenderDispatcher->itemInHandRenderer->renderItem(mob, headGear, 0);
}
else if (headGear->getItem()->id == Item::skull_Id)
/*else if (headGear->getItem()->id == Item::skull_Id)
{
float s = 17 / 16.0f;
glScalef(s, -s, -s);
@ -377,8 +432,8 @@ void PlayerRenderer::additionalRendering(shared_ptr<LivingEntity> _mob, float a)
extra = headGear->getTag()->getString(L"SkullOwner");
}
SkullTileRenderer::instance->renderSkull(-0.5f, 0, -0.5f, Facing::UP, 180, headGear->getAuxValue(), extra);
}
}*/
//SkullTileRenderer::instance->renderSkull(-0.5f, 0, -0.5f, Facing::UP, 180, headGear->getAuxValue(), extra);
glPopMatrix();
}
}

View file

@ -20,8 +20,14 @@ private:
HumanoidModel *armorParts1;
HumanoidModel *armorParts2;
HumanoidModel *armorParts3;
bool defaultSlimHands;
static ResourceLocation SKELETON_LOCATION;
static ResourceLocation WITHER_SKELETON_LOCATION;
static ResourceLocation ZOMBIE_LOCATION;
static ResourceLocation CREEPER_LOCATION;
public:
PlayerRenderer();

View file

@ -2,7 +2,7 @@
#include "ModelPart.h"
#include "SkeletonHeadModel.h"
void SkeletonHeadModel::_init(int u, int v, int tw, int th)
void SkeletonHeadModel::_init(int u, int v, int tw, int th, int g)
{
texWidth = tw;
texHeight = th;
@ -10,7 +10,7 @@ void SkeletonHeadModel::_init(int u, int v, int tw, int th)
// 4J Stu - Set "g" param to 0.1 to fix z-fighting issues (hair has this set to 0.5, so need to be less that that)
// Fix for #101501 - TU12: Content: Art: Z-Fighting occurs on the bottom side of a character's head when a Mob Head is equipped.
head->addBox(-4, -8, -4, 8, 8, 8, 0.1); // Head
head->addBox(-4, -8, -4, 8, 8, 8, g); // Head
head->setPos(0, 0, 0);
// 4J added - compile now to avoid random performance hit first time cubes are rendered
@ -22,9 +22,9 @@ SkeletonHeadModel::SkeletonHeadModel()
_init(0, 35, 64, 64);
}
SkeletonHeadModel::SkeletonHeadModel(int u, int v, int tw, int th)
SkeletonHeadModel::SkeletonHeadModel(int u, int v, int tw, int th, int g)
{
_init(u,v,tw,th);
_init(u,v,tw,th,g);
}
void SkeletonHeadModel::render(shared_ptr<Entity> entity, float time, float r, float bob, float yRot, float xRot, float scale, bool usecompiled)

View file

@ -8,11 +8,11 @@ public:
ModelPart *head;
private:
void _init(int u, int v, int tw, int th);
void _init(int u, int v, int tw, int th, int g = 0.1);
public:
SkeletonHeadModel();
SkeletonHeadModel(int u, int v, int tw, int th);
SkeletonHeadModel(int u, int v, int tw, int th, int g = 0.1);
void render(shared_ptr<Entity> entity, float time, float r, float bob, float yRot, float xRot, float scale, bool usecompiled);
void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale, shared_ptr<Entity> entity, unsigned int uiBitmaskOverrideAnim=0);