the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 141 lines 4.3 kB view raw
1#include "stdafx.h" 2#include "PaintingRenderer.h" 3#include "entityRenderDispatcher.h" 4#include "..\Minecraft.World\net.minecraft.world.entity.h" 5#include "..\Minecraft.World\net.minecraft.world.level.h" 6#include "..\Minecraft.World\Random.h" 7#include "..\Minecraft.World\Mth.h" 8 9ResourceLocation PaintingRenderer::PAINTING_LOCATION(TN_ART_KZ); 10 11PaintingRenderer::PaintingRenderer() 12{ 13 random = new Random(); 14} 15 16void PaintingRenderer::render(shared_ptr<Entity> _painting, double x, double y, double z, float rot, float a) 17{ 18 // 4J - dynamic cast required because we aren't using templates/generics in our version 19 shared_ptr<Painting> painting = dynamic_pointer_cast<Painting>(_painting); 20 21 random->setSeed(187); 22 23 glPushMatrix(); 24 glTranslatef((float)x, (float)y, (float)z); 25 glRotatef(rot, 0, 1, 0); 26 glEnable(GL_RESCALE_NORMAL); 27 bindTexture(painting); // 4J was L"/art/kz.png" 28 29 Painting::Motive *motive = painting->motive; 30 31 float s = 1 / 16.0f; 32 glScalef(s, s, s); 33 renderPainting(painting, motive->w, motive->h, motive->uo, motive->vo); 34 glDisable(GL_RESCALE_NORMAL); 35 glPopMatrix(); 36} 37 38void PaintingRenderer::renderPainting(shared_ptr<Painting> painting, int w, int h, int uo, int vo) 39{ 40 float xx0 = -w / 2.0f; 41 float yy0 = -h / 2.0f; 42 43 float edgeWidth = 0.5f; 44 45 // Back 46 float bu0 = (12 * 16) / 256.0f; 47 float bu1 = (12 * 16 + 16) / 256.0f; 48 float bv0 = (0) / 256.0f; 49 float bv1 = (0 + 16) / 256.0f; 50 51 // Border 52 float uu0 = (12 * 16) / 256.0f; 53 float uu1 = (12 * 16 + 16) / 256.0f; 54 float uv0 = (0.5f) / 256.0f; 55 float uv1 = (0.5f) / 256.0f; 56 57 // Border 58 float su0 = (12 * 16 + 0.5f) / 256.0f; 59 float su1 = (12 * 16 + 0.5f) / 256.0f; 60 float sv0 = (0) / 256.0f; 61 float sv1 = (0 + 16) / 256.0f; 62 63 for (int xs = 0; xs < w / 16; xs++) 64 { 65 for (int ys = 0; ys < h / 16; ys++) { 66 float x0 = xx0 + (xs + 1) * 16; 67 float x1 = xx0 + (xs) * 16; 68 float y0 = yy0 + (ys + 1) * 16; 69 float y1 = yy0 + (ys) * 16; 70 71 setBrightness(painting, (x0 + x1) / 2, (y0 + y1) / 2); 72 73 // Painting 74 float fu0 = (uo + w - (xs) * 16) / 256.0f; 75 float fu1 = (uo + w - (xs + 1) * 16) / 256.0f; 76 float fv0 = (vo + h - (ys) * 16) / 256.0f; 77 float fv1 = (vo + h - (ys + 1) * 16) / 256.0f; 78 79 Tesselator *t = Tesselator::getInstance(); 80 t->begin(); 81 t->normal(0, 0, -1); 82 t->vertexUV(x0, y1, -edgeWidth, fu1, fv0); 83 t->vertexUV(x1, y1, -edgeWidth, fu0, fv0); 84 t->vertexUV(x1, y0, -edgeWidth, fu0, fv1); 85 t->vertexUV(x0, y0, -edgeWidth, fu1, fv1); 86 87 t->normal(0, 0, 1); 88 t->vertexUV(x0, y0, edgeWidth, bu0, bv0); 89 t->vertexUV(x1, y0, edgeWidth, bu1, bv0); 90 t->vertexUV(x1, y1, edgeWidth, bu1, bv1); 91 t->vertexUV(x0, y1, edgeWidth, bu0, bv1); 92 93 t->normal(0, 1, 0); 94 t->vertexUV(x0, y0, -edgeWidth, uu0, uv0); 95 t->vertexUV(x1, y0, -edgeWidth, uu1, uv0); 96 t->vertexUV(x1, y0, edgeWidth, uu1, uv1); 97 t->vertexUV(x0, y0, edgeWidth, uu0, uv1); 98 99 t->normal(0, -1, 0); 100 t->vertexUV(x0, y1, edgeWidth, uu0, uv0); 101 t->vertexUV(x1, y1, edgeWidth, uu1, uv0); 102 t->vertexUV(x1, y1, -edgeWidth, uu1, uv1); 103 t->vertexUV(x0, y1, -edgeWidth, uu0, uv1); 104 105 t->normal(-1, 0, 0); 106 t->vertexUV(x0, y0, edgeWidth, su1, sv0); 107 t->vertexUV(x0, y1, edgeWidth, su1, sv1); 108 t->vertexUV(x0, y1, -edgeWidth, su0, sv1); 109 t->vertexUV(x0, y0, -edgeWidth, su0, sv0); 110 111 t->normal(1, 0, 0); 112 t->vertexUV(x1, y0, -edgeWidth, su1, sv0); 113 t->vertexUV(x1, y1, -edgeWidth, su1, sv1); 114 t->vertexUV(x1, y1, edgeWidth, su0, sv1); 115 t->vertexUV(x1, y0, edgeWidth, su0, sv0); 116 t->end(); 117 } 118 } 119} 120 121void PaintingRenderer::setBrightness(shared_ptr<Painting> painting, float ss, float ya) 122{ 123 int x = Mth::floor(painting->x); 124 int y = Mth::floor(painting->y + ya/16.0f); 125 int z = Mth::floor(painting->z); 126 if (painting->dir == 0) x = Mth::floor(painting->x + ss/16.0f); 127 if (painting->dir == 1) z = Mth::floor(painting->z - ss/16.0f); 128 if (painting->dir == 2) x = Mth::floor(painting->x - ss/16.0f); 129 if (painting->dir == 3) z = Mth::floor(painting->z + ss/16.0f); 130 131 int col = this->entityRenderDispatcher->level->getLightColor(x, y, z, 0); 132 int u = col % 65536; 133 int v = col / 65536; 134 glMultiTexCoord2f(0, u, v); 135 glColor3f(1, 1, 1); 136} 137 138ResourceLocation *PaintingRenderer::getTextureLocation(shared_ptr<Entity> mob) 139{ 140 return &PAINTING_LOCATION; 141}