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 "net.minecraft.world.phys.h"
3#include "net.minecraft.world.level.h"
4#include "net.minecraft.world.level.tile.h"
5#include "TorchTile.h"
6
7TorchTile::TorchTile(int id) : Tile(id, Material::decoration,isSolidRender())
8{
9 this->setTicking(true);
10}
11
12AABB *TorchTile::getAABB(Level *level, int x, int y, int z)
13{
14 return NULL;
15}
16
17AABB *TorchTile::getTileAABB(Level *level, int x, int y, int z)
18{
19 updateShape(level, x, y, z);
20 return Tile::getTileAABB(level, x, y, z);
21}
22
23void TorchTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param
24{
25 setShape(level->getData(x, y, z));
26}
27
28void TorchTile::setShape(int data)
29{
30 int dir = data & 7;
31
32 float r = 0.15f;
33 if (dir == 1)
34 {
35 setShape(0, 0.2f, 0.5f - r, r * 2, 0.8f, 0.5f + r);
36 }
37 else if (dir == 2)
38 {
39 setShape(1 - r * 2, 0.2f, 0.5f - r, 1, 0.8f, 0.5f + r);
40 }
41 else if (dir == 3)
42 {
43 setShape(0.5f - r, 0.2f, 0, 0.5f + r, 0.8f, r * 2);
44 }
45 else if (dir == 4)
46 {
47 setShape(0.5f - r, 0.2f, 1 - r * 2, 0.5f + r, 0.8f, 1);
48 }
49 else
50 {
51 r = 0.1f;
52 setShape(0.5f - r, 0.0f, 0.5f - r, 0.5f + r, 0.6f, 0.5f + r);
53 }
54}
55
56bool TorchTile::isSolidRender(bool isServerLevel)
57{
58 return false;
59}
60
61bool TorchTile::isCubeShaped()
62{
63 return false;
64}
65
66int TorchTile::getRenderShape()
67{
68 return Tile::SHAPE_TORCH;
69}
70
71bool TorchTile::isConnection(Level *level, int x, int y, int z)
72{
73 if (level->isTopSolidBlocking(x, y, z))
74 {
75 return true;
76 }
77 int tile = level->getTile(x, y, z);
78 if (tile == Tile::fence_Id || tile == Tile::netherFence_Id
79 || tile == Tile::glass_Id || tile == Tile::cobbleWall_Id)
80 {
81 return true;
82 }
83 return false;
84}
85
86bool TorchTile::mayPlace(Level *level, int x, int y, int z)
87{
88 if (level->isSolidBlockingTileInLoadedChunk(x - 1, y, z, true))
89 {
90 return true;
91 }
92 else if (level->isSolidBlockingTileInLoadedChunk(x + 1, y, z, true))
93 {
94 return true;
95 }
96 else if (level->isSolidBlockingTileInLoadedChunk(x, y, z - 1, true))
97 {
98 return true;
99 }
100 else if (level->isSolidBlockingTileInLoadedChunk(x, y, z + 1, true))
101 {
102 return true;
103 }
104 else if (isConnection(level, x, y - 1, z))
105 {
106 return true;
107 }
108 return false;
109}
110
111int TorchTile::getPlacedOnFaceDataValue(Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, int itemValue)
112{
113 int dir = itemValue;
114
115 if (face == 1 && isConnection(level, x, y - 1, z)) dir = 5;
116 if (face == 2 && level->isSolidBlockingTileInLoadedChunk(x, y, z + 1, true)) dir = 4;
117 if (face == 3 && level->isSolidBlockingTileInLoadedChunk(x, y, z - 1, true)) dir = 3;
118 if (face == 4 && level->isSolidBlockingTileInLoadedChunk(x + 1, y, z, true)) dir = 2;
119 if (face == 5 && level->isSolidBlockingTileInLoadedChunk(x - 1, y, z, true)) dir = 1;
120
121 return dir;
122}
123
124void TorchTile::tick(Level *level, int x, int y, int z, Random *random)
125{
126 Tile::tick(level, x, y, z, random);
127 if (level->getData(x, y, z) == 0) onPlace(level, x, y, z);
128}
129
130void TorchTile::onPlace(Level *level, int x, int y, int z)
131{
132 if(level->getData(x,y,z) == 0)
133 {
134 if (level->isSolidBlockingTileInLoadedChunk(x - 1, y, z, true))
135 {
136 level->setData(x, y, z, 1, Tile::UPDATE_CLIENTS);
137 }
138 else if (level->isSolidBlockingTileInLoadedChunk(x + 1, y, z, true))
139 {
140 level->setData(x, y, z, 2, Tile::UPDATE_CLIENTS);
141 }
142 else if (level->isSolidBlockingTileInLoadedChunk(x, y, z - 1, true))
143 {
144 level->setData(x, y, z, 3, Tile::UPDATE_CLIENTS);
145 }
146 else if (level->isSolidBlockingTileInLoadedChunk(x, y, z + 1, true))
147 {
148 level->setData(x, y, z, 4, Tile::UPDATE_CLIENTS);
149 }
150 else if (isConnection(level, x, y - 1, z))
151 {
152 level->setData(x, y, z, 5, Tile::UPDATE_CLIENTS);
153 }
154 }
155 checkCanSurvive(level, x, y, z);
156}
157
158void TorchTile::neighborChanged(Level *level, int x, int y, int z, int type)
159{
160 checkDoPop(level, x, y, z, type);
161}
162
163bool TorchTile::checkDoPop(Level *level, int x, int y, int z, int type)
164{
165 if (checkCanSurvive(level, x, y, z))
166 {
167 int dir = level->getData(x, y, z);
168 bool replace = false;
169
170 if (!level->isSolidBlockingTileInLoadedChunk(x - 1, y, z, true) && dir == 1) replace = true;
171 if (!level->isSolidBlockingTileInLoadedChunk(x + 1, y, z, true) && dir == 2) replace = true;
172 if (!level->isSolidBlockingTileInLoadedChunk(x, y, z - 1, true) && dir == 3) replace = true;
173 if (!level->isSolidBlockingTileInLoadedChunk(x, y, z + 1, true) && dir == 4) replace = true;
174 if (!isConnection(level, x, y - 1, z) && dir == 5) replace = true;
175
176 if (replace)
177 {
178 spawnResources(level, x, y, z, level->getData(x, y, z), 0);
179 level->removeTile(x, y, z);
180 return true;
181 }
182 }
183 else
184 {
185 return true;
186 }
187 return false;
188}
189
190bool TorchTile::checkCanSurvive(Level *level, int x, int y, int z)
191{
192 if (!mayPlace(level, x, y, z))
193 {
194 if (level->getTile(x, y, z) == id)
195 {
196 this->spawnResources(level, x, y, z, level->getData(x, y, z), 0);
197 level->removeTile(x, y, z);
198 }
199 return false;
200 }
201 return true;
202}
203
204HitResult *TorchTile::clip(Level *level, int x, int y, int z, Vec3 *a, Vec3 *b)
205{
206 setShape(level->getData(x, y, z));
207
208 return Tile::clip(level, x, y, z, a, b);
209}
210
211void TorchTile::animateTick(Level *level, int xt, int yt, int zt, Random *random)
212{
213 int dir = level->getData(xt, yt, zt);
214 double x = xt + 0.5f;
215 double y = yt + 0.7f;
216 double z = zt + 0.5f;
217 double h = 0.22f;
218 double r = 0.27f;
219 if (dir == 1)
220 {
221 level->addParticle(eParticleType_smoke, x - r, y + h, z, 0, 0, 0);
222 level->addParticle(eParticleType_flame, x - r, y + h, z, 0, 0, 0);
223 }
224 else if (dir == 2)
225 {
226 level->addParticle(eParticleType_smoke, x + r, y + h, z, 0, 0, 0);
227 level->addParticle(eParticleType_flame, x + r, y + h, z, 0, 0, 0);
228 }
229 else if (dir == 3)
230 {
231 level->addParticle(eParticleType_smoke, x, y + h, z - r, 0, 0, 0);
232 level->addParticle(eParticleType_flame, x, y + h, z - r, 0, 0, 0);
233 }
234 else if (dir == 4)
235 {
236 level->addParticle(eParticleType_smoke, x, y + h, z + r, 0, 0, 0);
237 level->addParticle(eParticleType_flame, x, y + h, z + r, 0, 0, 0);
238 }
239 else
240 {
241 level->addParticle(eParticleType_smoke, x, y, z, 0, 0, 0);
242 level->addParticle(eParticleType_flame, x, y, z, 0, 0, 0);
243 }
244}
245
246bool TorchTile::shouldTileTick(Level *level, int x,int y,int z)
247{
248 return level->getData(x, y, z) == 0;
249}