the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "..\Minecraft.World\Random.h"
3#include "..\Minecraft.World\net.minecraft.world.level.tile.entity.h"
4#include "Tesselator.h"
5#include "TileEntityRenderDispatcher.h"
6#include "Camera.h"
7#include "..\Minecraft.World\FloatBuffer.h"
8#include "TheEndPortalRenderer.h"
9
10ResourceLocation TheEndPortalRenderer::END_SKY_LOCATION = ResourceLocation(TN_MISC_TUNNEL);
11ResourceLocation TheEndPortalRenderer::END_PORTAL_LOCATION = ResourceLocation(TN_MISC_PARTICLEFIELD);
12int TheEndPortalRenderer::RANDOM_SEED = 31100;
13Random TheEndPortalRenderer::RANDOM = Random(RANDOM_SEED);
14
15void TheEndPortalRenderer::render(shared_ptr<TileEntity> _table, double x, double y, double z, float a, bool setColor, float alpha, bool useCompiled)
16{
17 // 4J Convert as we aren't using a templated class
18 shared_ptr<TheEndPortalTileEntity> table = dynamic_pointer_cast<TheEndPortalTileEntity>(_table);
19 float xx = (float) tileEntityRenderDispatcher->xPlayer;
20 float yy = (float) tileEntityRenderDispatcher->yPlayer;
21 float zz = (float) tileEntityRenderDispatcher->zPlayer;
22
23 glDisable(GL_LIGHTING);
24
25 RANDOM.setSeed(RANDOM_SEED);
26
27 float hoff = 12 / 16.0f;
28 for (int i = 0; i < 16; i++)
29 {
30 glPushMatrix();
31
32 float dist = (16 - (i));
33 float sscale = 1 / 16.0f;
34
35 float br = 1.0f / (dist + 1);
36 if (i == 0)
37 {
38 this->bindTexture(&END_SKY_LOCATION);
39 br = 0.1f;
40 dist = 65;
41 sscale = 1 / 8.0f;
42 glEnable(GL_BLEND);
43 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
44 }
45 if (i == 1)
46 {
47 this->bindTexture(&END_PORTAL_LOCATION);
48 glEnable(GL_BLEND);
49 glBlendFunc(GL_ONE, GL_ONE);
50 sscale = 1 / 2.0f;
51 }
52
53 float dd = (float) -(y + hoff);
54 {
55 float ss1 = (float) (dd + Camera::yPlayerOffs);
56 float ss2 = (float) (dd + dist + Camera::yPlayerOffs);
57 float s = ss1 / ss2;
58 s = (float) (y + hoff) + s;
59
60 glTranslatef(xx, s, zz);
61 }
62 // 4J - note that the glTexGeni/glEnable calls don't actually do anything in our opengl wrapper version, everything is currently just inferred from the glTexGen calls.
63
64 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
65 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
66 glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
67 glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
68
69 glTexGen(GL_S, GL_OBJECT_PLANE, getBuffer(1, 0, 0, 0));
70 glTexGen(GL_T, GL_OBJECT_PLANE, getBuffer(0, 0, 1, 0));
71 glTexGen(GL_R, GL_OBJECT_PLANE, getBuffer(0, 0, 0, 1));
72 glTexGen(GL_Q, GL_EYE_PLANE, getBuffer(0, 1, 0, 0));
73
74 glEnable(GL_TEXTURE_GEN_S);
75 glEnable(GL_TEXTURE_GEN_T);
76 glEnable(GL_TEXTURE_GEN_R);
77 glEnable(GL_TEXTURE_GEN_Q);
78
79
80 glPopMatrix();
81 glMatrixMode(GL_TEXTURE);
82
83 glPushMatrix();
84 glLoadIdentity();
85
86 glTranslatef(0, System::currentTimeMillis() % 700000 / 700000.0f, 0);
87 glScalef(sscale, sscale, sscale);
88 glTranslatef(0.5f, 0.5f, 0);
89 glRotatef((i * i * 4321 + i * 9) * 2.0f, 0, 0, 1);
90 glTranslatef(-0.5f, -0.5f, 0);
91 glTranslatef(-xx, -zz, -yy);
92 float ss1 = (float) (dd + Camera::yPlayerOffs);
93 glTranslatef(Camera::xPlayerOffs * dist / ss1, Camera::zPlayerOffs * dist / ss1, -yy);
94
95 Tesselator *t = Tesselator::getInstance();
96 t->useProjectedTexture(true); // 4J added - turns on both the generation of texture coordinates in the vertex shader & perspective divide of the texture coord in the pixel shader
97 t->begin();
98
99 float r = RANDOM.nextFloat() * 0.5f + 0.1f;
100 float g = RANDOM.nextFloat() * 0.5f + 0.4f;
101 float b = RANDOM.nextFloat() * 0.5f + 0.5f;
102 if (i == 0) r = g = b = 1;
103 t->color(r * br, g * br, b * br, 1.0f);
104 t->vertex(x, y + hoff, z);
105 t->vertex(x, y + hoff, z + 1);
106 t->vertex(x + 1, y + hoff, z + 1);
107 t->vertex(x + 1, y + hoff, z);
108 t->end();
109
110 t->useProjectedTexture(false); // 4J added
111 glPopMatrix();
112 glMatrixMode(GL_MODELVIEW);
113 }
114 glDisable(GL_BLEND);
115
116 glDisable(GL_TEXTURE_GEN_S);
117 glDisable(GL_TEXTURE_GEN_T);
118 glDisable(GL_TEXTURE_GEN_R);
119 glDisable(GL_TEXTURE_GEN_Q);
120 glEnable(GL_LIGHTING);
121}
122
123TheEndPortalRenderer::TheEndPortalRenderer()
124{
125 lb = MemoryTracker::createFloatBuffer(16);
126}
127
128FloatBuffer *TheEndPortalRenderer::getBuffer(float a, float b, float c, float d)
129{
130 lb->clear();
131 lb->put(a)->put(b)->put(c)->put(d);
132 lb->flip();
133 return lb;
134}