mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-07-18 03:50:49 +00:00
feat: armorstand from decomp
This commit is contained in:
@@ -1,61 +1,99 @@
|
||||
#include "stdafx.h"
|
||||
#include "ArmorStandRenderer.h"
|
||||
#include "Textures.h"
|
||||
#include "HumanoidModel.h"
|
||||
#include "ArmorStandModel.h"
|
||||
#include "..\Minecraft.World\ArmorStand.h"
|
||||
|
||||
|
||||
|
||||
class ArmorStandArmorModel : public HumanoidModel {
|
||||
public:
|
||||
ArmorStandArmorModel(float scale) : HumanoidModel(scale) {}
|
||||
|
||||
|
||||
virtual void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale, shared_ptr<Entity> entity, unsigned int uiBitmaskOverrideAnim = 0) override {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
#include "ArmorStandArmorModel.h"
|
||||
#include "HumanoidModel.h"
|
||||
#include "ItemInHandLayer.h"
|
||||
#include "CustomHeadLayer.h"
|
||||
#include "Textures.h"
|
||||
#include "HumanoidMobRenderer.h"
|
||||
#include "../Minecraft.World/ArmorStand.h"
|
||||
#include "../Minecraft.World/ArmorItem.h"
|
||||
|
||||
static const float DEG_TO_RAD = 3.14159265f / 180.0f;
|
||||
|
||||
ResourceLocation ArmorStandRenderer::LOC_ARMOR_STAND = ResourceLocation(TN_MOB_ARMORSTAND);
|
||||
ResourceLocation ArmorStandRenderer::LOC_ARMOR_STAND =
|
||||
ResourceLocation(TN_MOB_ARMORSTAND);
|
||||
|
||||
ArmorStandRenderer::ArmorStandRenderer()
|
||||
: HumanoidMobRenderer(new ArmorStandModel(), 0.0f, 1.0f)
|
||||
|
||||
|
||||
ArmorStandRenderer::ArmorStandArmorLayer::ArmorStandArmorLayer(
|
||||
LivingEntityRenderer* renderer)
|
||||
: HumanoidArmorLayer(renderer)
|
||||
{
|
||||
createArmorParts();
|
||||
|
||||
delete armorModel1;
|
||||
delete armorModel2;
|
||||
armorModel1 = new ArmorStandArmorModel(0.5f);
|
||||
armorModel2 = new ArmorStandArmorModel(1.0f);
|
||||
}
|
||||
|
||||
void ArmorStandRenderer::ArmorStandArmorLayer::createArmorModels()
|
||||
{
|
||||
delete armorModel1;
|
||||
delete armorModel2;
|
||||
armorModel1 = new ArmorStandArmorModel(0.5f);
|
||||
armorModel2 = new ArmorStandArmorModel(1.0f);
|
||||
}
|
||||
|
||||
|
||||
ResourceLocation *ArmorStandRenderer::getTextureLocation(shared_ptr<Entity> entity)
|
||||
|
||||
ArmorStandRenderer::ArmorStandRenderer()
|
||||
: LivingEntityRenderer(new ArmorStandModel(0.0f), 0.0f)
|
||||
{
|
||||
|
||||
addLayer(new ArmorStandArmorLayer(this));
|
||||
|
||||
|
||||
addLayer(new ItemInHandLayer(this));
|
||||
|
||||
|
||||
ArmorStandModel* m = static_cast<ArmorStandModel*>(getModel());
|
||||
addLayer(new CustomHeadLayer(m->head));
|
||||
}
|
||||
|
||||
ArmorStandRenderer::~ArmorStandRenderer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ResourceLocation* ArmorStandRenderer::getTextureLocation(shared_ptr<Entity> entity)
|
||||
{
|
||||
return &LOC_ARMOR_STAND;
|
||||
}
|
||||
|
||||
void ArmorStandRenderer::createArmorParts()
|
||||
bool ArmorStandRenderer::shouldShowName(shared_ptr<LivingEntity> entity)
|
||||
{
|
||||
|
||||
armorParts1 = new ArmorStandArmorModel(1.0f);
|
||||
armorParts2 = new ArmorStandArmorModel(0.5f);
|
||||
if (!entity) return false;
|
||||
return entity->isCustomNameVisible();
|
||||
}
|
||||
|
||||
void ArmorStandRenderer::render(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a)
|
||||
{
|
||||
HumanoidMobRenderer::render(entity, x, y, z, rot, a);
|
||||
}
|
||||
|
||||
void ArmorStandRenderer::renderModel(shared_ptr<LivingEntity> mob, float wp, float ws, float bob,
|
||||
float headRotMinusBodyRot, float headRotx, float scale)
|
||||
void ArmorStandRenderer::setupRotations(shared_ptr<LivingEntity> mob,
|
||||
float bob, float bodyRot, float a)
|
||||
{
|
||||
|
||||
glRotatef(180.0f - bodyRot, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
void ArmorStandRenderer::render(shared_ptr<Entity> entity,
|
||||
double x, double y, double z,
|
||||
float rot, float a)
|
||||
{
|
||||
LivingEntityRenderer::render(entity, x, y, z, rot, a);
|
||||
}
|
||||
|
||||
void ArmorStandRenderer::renderModel(shared_ptr<LivingEntity> mob,
|
||||
float wp, float ws, float bob,
|
||||
float headRotMinusBodyRot,
|
||||
float headRotx, float scale)
|
||||
{
|
||||
shared_ptr<ArmorStand> stand = dynamic_pointer_cast<ArmorStand>(mob);
|
||||
if (!stand) return;
|
||||
|
||||
ArmorStandModel *m = static_cast<ArmorStandModel *>(model);
|
||||
ArmorStandModel* m = static_cast<ArmorStandModel*>(getModel());
|
||||
if (!m) return;
|
||||
|
||||
|
||||
|
||||
Rotations h = stand->getHeadPose();
|
||||
Rotations b = stand->getBodyPose();
|
||||
@@ -66,46 +104,118 @@ void ArmorStandRenderer::renderModel(shared_ptr<LivingEntity> mob, float wp, flo
|
||||
|
||||
|
||||
m->setupPose(
|
||||
h.x * DEG_TO_RAD, h.y * DEG_TO_RAD, h.z * DEG_TO_RAD,
|
||||
b.x * DEG_TO_RAD, b.y * DEG_TO_RAD, b.z * DEG_TO_RAD,
|
||||
la.x * DEG_TO_RAD, la.y * DEG_TO_RAD, la.z * DEG_TO_RAD,
|
||||
ra.x * DEG_TO_RAD, ra.y * DEG_TO_RAD, ra.z * DEG_TO_RAD,
|
||||
ll.x * DEG_TO_RAD, ll.y * DEG_TO_RAD, ll.z * DEG_TO_RAD,
|
||||
rl.x * DEG_TO_RAD, rl.y * DEG_TO_RAD, rl.z * DEG_TO_RAD
|
||||
h.getX() * DEG_TO_RAD, h.getY() * DEG_TO_RAD, h.getZ() * DEG_TO_RAD,
|
||||
b.getX() * DEG_TO_RAD, b.getY() * DEG_TO_RAD, b.getZ() * DEG_TO_RAD,
|
||||
la.getX() * DEG_TO_RAD, la.getY() * DEG_TO_RAD, la.getZ() * DEG_TO_RAD,
|
||||
ra.getX() * DEG_TO_RAD, ra.getY() * DEG_TO_RAD, ra.getZ() * DEG_TO_RAD,
|
||||
ll.getX() * DEG_TO_RAD, ll.getY() * DEG_TO_RAD, ll.getZ() * DEG_TO_RAD,
|
||||
rl.getX() * DEG_TO_RAD, rl.getY() * DEG_TO_RAD, rl.getZ() * DEG_TO_RAD
|
||||
);
|
||||
|
||||
|
||||
|
||||
HumanoidModel *a1 = static_cast<HumanoidModel*>(armorParts1);
|
||||
if (a1) {
|
||||
a1->head->xRot = h.x * DEG_TO_RAD; a1->head->yRot = h.y * DEG_TO_RAD; a1->head->zRot = h.z * DEG_TO_RAD;
|
||||
if (a1->hair) { a1->hair->xRot = h.x * DEG_TO_RAD; a1->hair->yRot = h.y * DEG_TO_RAD; a1->hair->zRot = h.z * DEG_TO_RAD; }
|
||||
|
||||
a1->body->xRot = b.x * DEG_TO_RAD; a1->body->yRot = b.y * DEG_TO_RAD; a1->body->zRot = b.z * DEG_TO_RAD;
|
||||
|
||||
a1->arm0->xRot = ra.x * DEG_TO_RAD; a1->arm0->yRot = ra.y * DEG_TO_RAD; a1->arm0->zRot = ra.z * DEG_TO_RAD; // right
|
||||
a1->arm1->xRot = la.x * DEG_TO_RAD; a1->arm1->yRot = la.y * DEG_TO_RAD; a1->arm1->zRot = la.z * DEG_TO_RAD; // left
|
||||
|
||||
a1->leg0->xRot = rl.x * DEG_TO_RAD; a1->leg0->yRot = rl.y * DEG_TO_RAD; a1->leg0->zRot = rl.z * DEG_TO_RAD; // right
|
||||
a1->leg1->xRot = ll.x * DEG_TO_RAD; a1->leg1->yRot = ll.y * DEG_TO_RAD; a1->leg1->zRot = ll.z * DEG_TO_RAD; // left
|
||||
}
|
||||
|
||||
HumanoidModel *a2 = static_cast<HumanoidModel*>(armorParts2);
|
||||
if (a2) {
|
||||
a2->head->xRot = h.x * DEG_TO_RAD; a2->head->yRot = h.y * DEG_TO_RAD; a2->head->zRot = h.z * DEG_TO_RAD;
|
||||
if (a2->hair) { a2->hair->xRot = h.x * DEG_TO_RAD; a2->hair->yRot = h.y * DEG_TO_RAD; a2->hair->zRot = h.z * DEG_TO_RAD; }
|
||||
|
||||
a2->body->xRot = b.x * DEG_TO_RAD; a2->body->yRot = b.y * DEG_TO_RAD; a2->body->zRot = b.z * DEG_TO_RAD;
|
||||
|
||||
a2->arm0->xRot = ra.x * DEG_TO_RAD; a2->arm0->yRot = ra.y * DEG_TO_RAD; a2->arm0->zRot = ra.z * DEG_TO_RAD;
|
||||
a2->arm1->xRot = la.x * DEG_TO_RAD; a2->arm1->yRot = la.y * DEG_TO_RAD; a2->arm1->zRot = la.z * DEG_TO_RAD;
|
||||
|
||||
a2->leg0->xRot = rl.x * DEG_TO_RAD; a2->leg0->yRot = rl.y * DEG_TO_RAD; a2->leg0->zRot = rl.z * DEG_TO_RAD;
|
||||
a2->leg1->xRot = ll.x * DEG_TO_RAD; a2->leg1->yRot = ll.y * DEG_TO_RAD; a2->leg1->zRot = ll.z * DEG_TO_RAD;
|
||||
}
|
||||
|
||||
|
||||
HumanoidMobRenderer::renderModel(mob, wp, ws, bob, headRotMinusBodyRot, headRotx, scale);
|
||||
ArmorStandArmorLayer* al = getArmorLayer();
|
||||
|
||||
if (al)
|
||||
{
|
||||
auto applyPose = [&](HumanoidModel* am)
|
||||
{
|
||||
if (!am) return;
|
||||
|
||||
|
||||
am->head->xRot = h.getX() * DEG_TO_RAD;
|
||||
am->head->yRot = h.getY() * DEG_TO_RAD;
|
||||
am->head->zRot = h.getZ() * DEG_TO_RAD;
|
||||
if (am->hair) {
|
||||
am->hair->xRot = h.getX() * DEG_TO_RAD;
|
||||
am->hair->yRot = h.getY() * DEG_TO_RAD;
|
||||
am->hair->zRot = h.getZ() * DEG_TO_RAD;
|
||||
}
|
||||
|
||||
|
||||
am->body->xRot = b.getX() * DEG_TO_RAD;
|
||||
am->body->yRot = b.getY() * DEG_TO_RAD;
|
||||
am->body->zRot = b.getZ() * DEG_TO_RAD;
|
||||
|
||||
|
||||
am->arm1->xRot = la.getX() * DEG_TO_RAD;
|
||||
am->arm1->yRot = la.getY() * DEG_TO_RAD;
|
||||
am->arm1->zRot = la.getZ() * DEG_TO_RAD;
|
||||
|
||||
|
||||
am->arm0->xRot = ra.getX() * DEG_TO_RAD;
|
||||
am->arm0->yRot = ra.getY() * DEG_TO_RAD;
|
||||
am->arm0->zRot = ra.getZ() * DEG_TO_RAD;
|
||||
|
||||
|
||||
am->leg0->xRot = rl.getX() * DEG_TO_RAD;
|
||||
am->leg0->yRot = rl.getY() * DEG_TO_RAD;
|
||||
am->leg0->zRot = rl.getZ() * DEG_TO_RAD;
|
||||
|
||||
|
||||
am->leg1->xRot = ll.getX() * DEG_TO_RAD;
|
||||
am->leg1->yRot = ll.getY() * DEG_TO_RAD;
|
||||
am->leg1->zRot = ll.getZ() * DEG_TO_RAD;
|
||||
};
|
||||
|
||||
applyPose(static_cast<HumanoidModel*>(al->armorModel1));
|
||||
applyPose(static_cast<HumanoidModel*>(al->armorModel2));
|
||||
}
|
||||
|
||||
LivingEntityRenderer::renderModel(mob, wp, ws, bob,
|
||||
headRotMinusBodyRot, headRotx, scale);
|
||||
|
||||
for (size_t i = 0; i < renderLayers.size(); ++i) {
|
||||
if (renderLayers[i]) {
|
||||
renderLayers[i]->render(mob, wp, ws, bob, headRotMinusBodyRot, headRotx, scale, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ArmorStandRenderer::prepareArmor(shared_ptr<LivingEntity> mob, int layer, float a)
|
||||
{
|
||||
if (!armorLayer) return -1;
|
||||
|
||||
shared_ptr<ItemInstance> itemInstance = mob->getArmor(3 - layer);
|
||||
if (itemInstance != nullptr)
|
||||
{
|
||||
Item *item = itemInstance->getItem();
|
||||
ArmorItem *armorItem = dynamic_cast<ArmorItem *>(item);
|
||||
if (armorItem != nullptr)
|
||||
{
|
||||
bindTexture(HumanoidMobRenderer::getArmorLocation(armorItem, layer));
|
||||
|
||||
HumanoidModel *am = armorLayer->getArmorModel(layer);
|
||||
|
||||
am->head->visible = (layer == 0);
|
||||
if (am->hair) am->hair->visible = (layer == 0);
|
||||
am->body->visible = (layer == 1 || layer == 2);
|
||||
am->arm0->visible = (layer == 1);
|
||||
am->arm1->visible = (layer == 1);
|
||||
am->leg0->visible = (layer == 2 || layer == 3);
|
||||
am->leg1->visible = (layer == 2 || layer == 3);
|
||||
|
||||
setArmor(am);
|
||||
am->attackTime = model->attackTime;
|
||||
am->riding = model->riding;
|
||||
am->young = mob->isBaby();
|
||||
|
||||
if (armorItem->getMaterial() == ArmorItem::ArmorMaterial::CLOTH)
|
||||
{
|
||||
int color = armorItem->getColor(itemInstance);
|
||||
float red = static_cast<float>((color >> 16) & 0xFF) / 255.0f;
|
||||
float green = static_cast<float>((color >> 8) & 0xFF) / 255.0f;
|
||||
float blue = static_cast<float>(color & 0xFF) / 255.0f;
|
||||
glColor3f(red, green, blue);
|
||||
|
||||
if (itemInstance->isEnchanted()) return 0x1f;
|
||||
return 0x10;
|
||||
}
|
||||
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
if (itemInstance->isEnchanted()) return 15;
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
Reference in New Issue
Block a user