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 "ChestRenderer.h"
3#include "ChestModel.h"
4#include "LargeChestModel.h"
5#include "ModelPart.h"
6#include "..\Minecraft.World\net.minecraft.world.level.tile.entity.h"
7#include "..\Minecraft.World\net.minecraft.world.level.tile.h"
8#include "..\Minecraft.World\Calendar.h"
9
10ResourceLocation ChestRenderer::CHEST_LARGE_TRAP_LOCATION = ResourceLocation(TN_TILE_LARGE_TRAP_CHEST);
11//ResourceLocation ChestRenderer::CHEST_LARGE_XMAS_LOCATION = ResourceLocation(TN_TILE_LARGE_XMAS_CHEST);
12ResourceLocation ChestRenderer::CHEST_LARGE_LOCATION = ResourceLocation(TN_TILE_LARGE_CHEST);
13ResourceLocation ChestRenderer::CHEST_TRAP_LOCATION = ResourceLocation(TN_TILE_TRAP_CHEST);
14//ResourceLocation ChestRenderer::CHEST_XMAS_LOCATION = ResourceLocation(TN_TILE_XMAS_CHEST);
15ResourceLocation ChestRenderer::CHEST_LOCATION = ResourceLocation(TN_TILE_CHEST);
16
17ChestRenderer::ChestRenderer() : TileEntityRenderer()
18{
19 chestModel = new ChestModel();
20 largeChestModel = new LargeChestModel();
21
22 xmasTextures = false;
23
24 // 4J Stu - Disable this
25#if 0
26 if (Calendar::GetMonth() + 1 == 12 && Calendar::GetDayOfMonth() >= 24 && Calendar::GetDayOfMonth() <= 26)
27 {
28 xmasTextures = true;
29 }
30#endif
31}
32
33ChestRenderer::~ChestRenderer()
34{
35 delete chestModel;
36 delete largeChestModel;
37}
38
39void ChestRenderer::render(shared_ptr<TileEntity> _chest, double x, double y, double z, float a, bool setColor, float alpha, bool useCompiled)
40{
41 // 4J Convert as we aren't using a templated class
42 shared_ptr<ChestTileEntity> chest = dynamic_pointer_cast<ChestTileEntity>(_chest);
43
44 int data;
45
46 if (!chest->hasLevel())
47 {
48 data = 0;
49 }
50 else
51 {
52 Tile *tile = chest->getTile();
53 data = chest->getData();
54
55 if (dynamic_cast<ChestTile*>(tile) != NULL && data == 0)
56 {
57 ((ChestTile *) tile)->recalcLockDir(chest->getLevel(), chest->x, chest->y, chest->z);
58 data = chest->getData();
59 }
60
61 chest->checkNeighbors();
62 }
63 if (chest->n.lock() != NULL || chest->w.lock() != NULL) return;
64
65
66 ChestModel *model;
67 if (chest->e.lock() != NULL || chest->s.lock() != NULL)
68 {
69 model = largeChestModel;
70
71 if (chest->getType() == ChestTile::TYPE_TRAP)
72 {
73 bindTexture(&CHEST_LARGE_TRAP_LOCATION);
74 }
75 //else if (xmasTextures)
76 //{
77 // bindTexture(&CHEST_LARGE_XMAS_LOCATION);
78 //}
79 else
80 {
81 bindTexture(&CHEST_LARGE_LOCATION);
82 }
83 }
84 else
85 {
86 model = chestModel;
87 if (chest->getType() == ChestTile::TYPE_TRAP)
88 {
89 bindTexture(&CHEST_TRAP_LOCATION);
90 }
91 //else if (xmasTextures)
92 //{
93 // bindTexture(&CHEST_XMAS_LOCATION);
94 //}
95 else
96 {
97 bindTexture(&CHEST_LOCATION);
98 }
99 }
100
101 glPushMatrix();
102 glEnable(GL_RESCALE_NORMAL);
103 //if( setColor ) glColor4f(1, 1, 1, 1);
104 if( setColor ) glColor4f(1, 1, 1, alpha);
105 glTranslatef((float) x, (float) y + 1, (float) z + 1);
106 glScalef(1, -1, -1);
107
108 glTranslatef(0.5f, 0.5f, 0.5f);
109 int rot = 0;
110 if (data == 2) rot = 180;
111 if (data == 3) rot = 0;
112 if (data == 4) rot = 90;
113 if (data == 5) rot = -90;
114
115 if (data == 2 && chest->e.lock() != NULL)
116 {
117 glTranslatef(1, 0, 0);
118 }
119 if (data == 5 && chest->s.lock() != NULL)
120 {
121 glTranslatef(0, 0, -1);
122 }
123 glRotatef(rot, 0, 1, 0);
124 glTranslatef(-0.5f, -0.5f, -0.5f);
125
126 float open = chest->oOpenness + (chest->openness - chest->oOpenness) * a;
127 if (chest->n.lock() != NULL)
128 {
129 float open2 = chest->n.lock()->oOpenness + (chest->n.lock()->openness - chest->n.lock()->oOpenness) * a;
130 if (open2 > open) open = open2;
131 }
132 if (chest->w.lock() != NULL)
133 {
134 float open2 = chest->w.lock()->oOpenness + (chest->w.lock()->openness - chest->w.lock()->oOpenness) * a;
135 if (open2 > open) open = open2;
136 }
137
138 open = 1 - open;
139 open = 1 - open * open * open;
140
141 model->lid->xRot = -(open * PI / 2);
142 model->render(useCompiled);
143 glDisable(GL_RESCALE_NORMAL);
144 glPopMatrix();
145 if( setColor ) glColor4f(1, 1, 1, 1);
146}