4jcraft/minecraft/Minecraft.Client/net/minecraft/client/renderer/tileentity/EnchantTableRenderer.cpp
MatthewBeshay 8f0c2a3f26 refactor: replace Mth with GameMath, switch to stdlib math and std::numbers::pi
Inlined trivial wrappers, moved ranged random methods to Random, replaced M_PI with std::numbers::pi, unified DEGRAD/RAD_TO_GRAD as DEG_TO_RAD, fixed getInt/getDouble default fallback bug, and switched non-worldgen sin/cos to sinf/cosf.
2026-03-31 13:12:34 +11:00

52 lines
2 KiB
C++

#include "Minecraft.World/Header Files/stdafx.h"
#include "../../model/BookModel.h"
#include "Minecraft.World/net/minecraft/world/level/tile/entity/net.minecraft.world.level.tile.entity.h"
#include "Minecraft.World/net/minecraft/util/GameMath.h"
#include "EnchantTableRenderer.h"
ResourceLocation EnchantTableRenderer::BOOK_LOCATION =
ResourceLocation(TN_ITEM_BOOK);
EnchantTableRenderer::EnchantTableRenderer() { bookModel = new BookModel(); }
EnchantTableRenderer::~EnchantTableRenderer() { delete bookModel; }
void EnchantTableRenderer::render(std::shared_ptr<TileEntity> _table, double x,
double y, double z, float a, bool setColor,
float alpha, bool useCompiled) {
// 4J Convert as we aren't using a templated class
std::shared_ptr<EnchantmentTableEntity> table =
std::dynamic_pointer_cast<EnchantmentTableEntity>(_table);
glPushMatrix();
glTranslatef((float)x + 0.5f, (float)y + 12 / 16.0f, (float)z + 0.5f);
float tt = table->time + a;
glTranslatef(0, 0.1f + sin(tt * 0.1f) * 0.01f, 0);
float orot = (table->rot - table->oRot);
while (orot >= std::numbers::pi) orot -= std::numbers::pi * 2;
while (orot < -std::numbers::pi ) orot += std::numbers::pi * 2;
float yRot = table->oRot + orot * a;
glRotatef(-yRot * 180 / std::numbers::pi, 0, 1, 0);
glRotatef(80, 0, 0, 1);
bindTexture(&BOOK_LOCATION); // 4J was "/item/book.png"
float ff1 = table->oFlip + (table->flip - table->oFlip) * a + 0.25f;
float ff2 = table->oFlip + (table->flip - table->oFlip) * a + 0.75f;
ff1 = (ff1 - GameMath::fastFloor(ff1)) * 1.6f - 0.3f;
ff2 = (ff2 - GameMath::fastFloor(ff2)) * 1.6f - 0.3f;
if (ff1 < 0) ff1 = 0;
if (ff2 < 0) ff2 = 0;
if (ff1 > 1) ff1 = 1;
if (ff2 > 1) ff2 = 1;
float o = table->oOpen + (table->open - table->oOpen) * a;
glEnable(GL_CULL_FACE);
bookModel->render(nullptr, tt, ff1, ff2, o, 0, 1 / 16.0f, true);
glPopMatrix();
}