the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 528 lines 12 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.h" 3#include "net.minecraft.world.phys.h" 4#include "net.minecraft.world.level.h" 5#include "net.minecraft.h" 6#include "StairTile.h" 7 8int StairTile::DEAD_SPACES[8][2] = { 9 {2, 6}, {3, 7}, {2, 3}, {6, 7}, 10 {0, 4}, {1, 5}, {0, 1}, {4, 5} 11}; 12 13StairTile::StairTile(int id, Tile *base,int basedata) : Tile(id, base->material, isSolidRender()) 14{ 15 this->base = base; 16 this->basedata = basedata; 17 isClipping = false; 18 clipStep = 0; 19 setDestroyTime(base->destroySpeed); 20 setExplodeable(base->explosionResistance / 3); 21 setSoundType(base->soundType); 22 setLightBlock(255); 23} 24 25void StairTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param 26{ 27 if (isClipping) 28 { 29 setShape(0.5f * (clipStep % 2), 0.5f * (clipStep / 2 % 2), 0.5f * (clipStep / 4 % 2), 0.5f + 0.5f * (clipStep % 2), 0.5f + 0.5f * (clipStep / 2 % 2), 0.5f + 0.5f * (clipStep / 4 % 2)); 30 } 31 else 32 { 33 setShape(0, 0, 0, 1, 1, 1); 34 } 35} 36 37bool StairTile::isSolidRender(bool isServerLevel) 38{ 39 return false; 40} 41 42bool StairTile::isCubeShaped() 43{ 44 return false; 45} 46 47int StairTile::getRenderShape() 48{ 49 return Tile::SHAPE_STAIRS; 50} 51 52void StairTile::setBaseShape(LevelSource *level, int x, int y, int z) 53{ 54 int data = level->getData(x, y, z); 55 56 if ((data & UPSIDEDOWN_BIT) != 0) 57 { 58 setShape(0, .5f, 0, 1, 1, 1); 59 } 60 else 61 { 62 setShape(0, 0, 0, 1, .5f, 1); 63 } 64} 65 66bool StairTile::isStairs(int id) 67{ 68 StairTile *st = dynamic_cast<StairTile *>(Tile::tiles[id]); 69 return id > 0 && st != NULL; //Tile::tiles[id] instanceof StairTile; 70} 71 72bool StairTile::isLockAttached(LevelSource *level, int x, int y, int z, int data) 73{ 74 int lockTile = level->getTile(x, y, z); 75 if (isStairs(lockTile) && level->getData(x, y, z) == data) 76 { 77 return true; 78 } 79 80 return false; 81} 82 83bool StairTile::setStepShape(LevelSource *level, int x, int y, int z) 84{ 85 int data = level->getData(x, y, z); 86 int dir = data & 0x3; 87 88 float bottom = 0.5f; 89 float top = 1.0f; 90 91 if ((data & UPSIDEDOWN_BIT) != 0) 92 { 93 bottom = 0; 94 top = .5f; 95 } 96 97 float west = 0; 98 float east = 1; 99 float north = 0; 100 float south = .5f; 101 102 bool checkInnerPiece = true; 103 104 if (dir == DIR_EAST) 105 { 106 west = .5f; 107 south = 1; 108 109 int backTile = level->getTile(x + 1, y, z); 110 int backData = level->getData(x + 1, y, z); 111 if (isStairs(backTile) && ((data & UPSIDEDOWN_BIT) == (backData & UPSIDEDOWN_BIT))) 112 { 113 int backDir = backData & 0x3; 114 if (backDir == DIR_NORTH && !isLockAttached(level, x, y, z + 1, data)) 115 { 116 south = .5f; 117 checkInnerPiece = false; 118 } 119 else if (backDir == DIR_SOUTH && !isLockAttached(level, x, y, z - 1, data)) 120 { 121 north = .5f; 122 checkInnerPiece = false; 123 } 124 } 125 } 126 else if (dir == DIR_WEST) 127 { 128 east = .5f; 129 south = 1; 130 131 int backTile = level->getTile(x - 1, y, z); 132 int backData = level->getData(x - 1, y, z); 133 if (isStairs(backTile) && ((data & UPSIDEDOWN_BIT) == (backData & UPSIDEDOWN_BIT))) 134 { 135 int backDir = backData & 0x3; 136 if (backDir == DIR_NORTH && !isLockAttached(level, x, y, z + 1, data)) 137 { 138 south = .5f; 139 checkInnerPiece = false; 140 } 141 else if (backDir == DIR_SOUTH && !isLockAttached(level, x, y, z - 1, data)) 142 { 143 north = .5f; 144 checkInnerPiece = false; 145 } 146 } 147 } 148 else if (dir == DIR_SOUTH) 149 { 150 north = .5f; 151 south = 1; 152 153 int backTile = level->getTile(x, y, z + 1); 154 int backData = level->getData(x, y, z + 1); 155 if (isStairs(backTile) && ((data & UPSIDEDOWN_BIT) == (backData & UPSIDEDOWN_BIT))) 156 { 157 int backDir = backData & 0x3; 158 if (backDir == DIR_WEST && !isLockAttached(level, x + 1, y, z, data)) 159 { 160 east = .5f; 161 checkInnerPiece = false; 162 } 163 else if (backDir == DIR_EAST && !isLockAttached(level, x - 1, y, z, data)) 164 { 165 west = .5f; 166 checkInnerPiece = false; 167 } 168 } 169 } 170 else if (dir == DIR_NORTH) 171 { 172 int backTile = level->getTile(x, y, z - 1); 173 int backData = level->getData(x, y, z - 1); 174 if (isStairs(backTile) && ((data & UPSIDEDOWN_BIT) == (backData & UPSIDEDOWN_BIT))) 175 { 176 int backDir = backData & 0x3; 177 if (backDir == DIR_WEST && !isLockAttached(level, x + 1, y, z, data)) 178 { 179 east = .5f; 180 checkInnerPiece = false; 181 } 182 else if (backDir == DIR_EAST && !isLockAttached(level, x - 1, y, z, data)) 183 { 184 west = .5f; 185 checkInnerPiece = false; 186 } 187 } 188 } 189 190 setShape(west, bottom, north, east, top, south); 191 return checkInnerPiece; 192} 193 194/* 195* This method adds an extra 1/8 block if the stairs can attach as an 196* "inner corner." 197*/ 198bool StairTile::setInnerPieceShape(LevelSource *level, int x, int y, int z) 199{ 200 int data = level->getData(x, y, z); 201 int dir = data & 0x3; 202 203 float bottom = 0.5f; 204 float top = 1.0f; 205 206 if ((data & UPSIDEDOWN_BIT) != 0) 207 { 208 bottom = 0; 209 top = .5f; 210 } 211 212 float west = 0; 213 float east = .5f; 214 float north = .5f; 215 float south = 1.0f; 216 217 bool hasInnerPiece = false; 218 219 if (dir == DIR_EAST) 220 { 221 int frontTile = level->getTile(x - 1, y, z); 222 int frontData = level->getData(x - 1, y, z); 223 if (isStairs(frontTile) && ((data & UPSIDEDOWN_BIT) == (frontData & UPSIDEDOWN_BIT))) 224 { 225 int frontDir = frontData & 0x3; 226 if (frontDir == DIR_NORTH && !isLockAttached(level, x, y, z - 1, data)) 227 { 228 north = 0; 229 south = .5f; 230 hasInnerPiece = true; 231 } 232 else if (frontDir == DIR_SOUTH && !isLockAttached(level, x, y, z + 1, data)) 233 { 234 north = .5f; 235 south = 1; 236 hasInnerPiece = true; 237 } 238 } 239 } 240 else if (dir == DIR_WEST) 241 { 242 int frontTile = level->getTile(x + 1, y, z); 243 int frontData = level->getData(x + 1, y, z); 244 if (isStairs(frontTile) && ((data & UPSIDEDOWN_BIT) == (frontData & UPSIDEDOWN_BIT))) 245 { 246 west = .5f; 247 east = 1.0f; 248 int frontDir = frontData & 0x3; 249 if (frontDir == DIR_NORTH && !isLockAttached(level, x, y, z - 1, data)) 250 { 251 north = 0; 252 south = .5f; 253 hasInnerPiece = true; 254 } 255 else if (frontDir == DIR_SOUTH && !isLockAttached(level, x, y, z + 1, data)) 256 { 257 north = .5f; 258 south = 1; 259 hasInnerPiece = true; 260 } 261 } 262 } 263 else if (dir == DIR_SOUTH) 264 { 265 int frontTile = level->getTile(x, y, z - 1); 266 int frontData = level->getData(x, y, z - 1); 267 if (isStairs(frontTile) && ((data & UPSIDEDOWN_BIT) == (frontData & UPSIDEDOWN_BIT))) 268 { 269 north = 0; 270 south = .5f; 271 272 int frontDir = frontData & 0x3; 273 if (frontDir == DIR_WEST && !isLockAttached(level, x - 1, y, z, data)) 274 { 275 hasInnerPiece = true; 276 } 277 else if (frontDir == DIR_EAST && !isLockAttached(level, x + 1, y, z, data)) 278 { 279 west = .5f; 280 east = 1.0f; 281 hasInnerPiece = true; 282 } 283 } 284 } 285 else if (dir == DIR_NORTH) 286 { 287 int frontTile = level->getTile(x, y, z + 1); 288 int frontData = level->getData(x, y, z + 1); 289 if (isStairs(frontTile) && ((data & UPSIDEDOWN_BIT) == (frontData & UPSIDEDOWN_BIT))) 290 { 291 int frontDir = frontData & 0x3; 292 if (frontDir == DIR_WEST && !isLockAttached(level, x - 1, y, z, data)) 293 { 294 hasInnerPiece = true; 295 } 296 else if (frontDir == DIR_EAST && !isLockAttached(level, x + 1, y, z, data)) 297 { 298 west = .5f; 299 east = 1.0f; 300 hasInnerPiece = true; 301 } 302 } 303 } 304 305 if (hasInnerPiece) 306 { 307 setShape(west, bottom, north, east, top, south); 308 } 309 return hasInnerPiece; 310} 311 312void StairTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source) 313{ 314 setBaseShape(level, x, y, z); 315 Tile::addAABBs(level, x, y, z, box, boxes, source); 316 317 bool checkInnerPiece = setStepShape(level, x, y, z); 318 Tile::addAABBs(level, x, y, z, box, boxes, source); 319 320 if (checkInnerPiece) 321 { 322 if (setInnerPieceShape(level, x, y, z)) 323 { 324 Tile::addAABBs(level, x, y, z, box, boxes, source); 325 } 326 } 327 328 setShape(0, 0, 0, 1, 1, 1); 329} 330 331/** DELEGATES: **/ 332 333 334void StairTile::addLights(Level *level, int x, int y, int z) 335{ 336 base->addLights(level, x, y, z); 337} 338 339void StairTile::animateTick(Level *level, int x, int y, int z, Random *random) 340{ 341 base->animateTick(level, x, y, z, random); 342} 343 344void StairTile::attack(Level *level, int x, int y, int z, shared_ptr<Player> player) 345{ 346 base->attack(level, x, y, z, player); 347} 348 349void StairTile::destroy(Level *level, int x, int y, int z, int data) 350{ 351 base->destroy(level, x, y, z, data); 352} 353 354// 4J - brought forward from 1.8.2 355int StairTile::getLightColor(LevelSource *level, int x, int y, int z, int tileId/*=-1*/) 356{ 357 return base->getLightColor(level, x, y, z, tileId); 358} 359 360float StairTile::getBrightness(LevelSource *level, int x, int y, int z) 361{ 362 return base->getBrightness(level, x, y, z); 363} 364 365float StairTile::getExplosionResistance(shared_ptr<Entity> source) 366{ 367 return base->getExplosionResistance(source); 368} 369 370int StairTile::getRenderLayer() 371{ 372 return base->getRenderLayer(); 373} 374 375Icon *StairTile::getTexture(int face, int data) 376{ 377 return base->getTexture(face, basedata); 378} 379 380int StairTile::getTickDelay(Level *level) 381{ 382 return base->getTickDelay(level); 383} 384 385AABB *StairTile::getTileAABB(Level *level, int x, int y, int z) 386{ 387 return base->getTileAABB(level, x, y, z); 388} 389 390void StairTile::handleEntityInside(Level *level, int x, int y, int z, shared_ptr<Entity> e, Vec3 *current) 391{ 392 base->handleEntityInside(level, x, y, z, e, current); 393} 394 395bool StairTile::mayPick() 396{ 397 return base->mayPick(); 398} 399 400bool StairTile::mayPick(int data, bool liquid) 401{ 402 return base->mayPick(data, liquid); 403} 404 405bool StairTile::mayPlace(Level *level, int x, int y, int z) 406{ 407 return base->mayPlace(level, x, y, z); 408} 409 410void StairTile::onPlace(Level *level, int x, int y, int z) 411{ 412 neighborChanged(level, x, y, z, 0); 413 base->onPlace(level, x, y, z); 414} 415 416void StairTile::onRemove(Level *level, int x, int y, int z, int id, int data) 417{ 418 base->onRemove(level, x, y, z, id, data); 419} 420 421void StairTile::prepareRender(Level *level, int x, int y, int z) 422{ 423 base->prepareRender(level, x, y, z); 424} 425 426void StairTile::stepOn(Level *level, int x, int y, int z, shared_ptr<Entity> entity) 427{ 428 base->stepOn(level, x, y, z, entity); 429} 430 431void StairTile::tick(Level *level, int x, int y, int z, Random *random) 432{ 433 base->tick(level, x, y, z, random); 434} 435 436// 4J-HEG - Removed this to prevent weird tooltips (place steak on stairs!?) 437//// 4J-PB - Adding a TestUse for tooltip display 438//bool StairTile::TestUse() 439//{ 440// return true; 441//} 442 443bool StairTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly/*=false*/) // 4J added soundOnly param 444{ 445 if (soundOnly) return false; 446 return base->use(level, x, y, z, player, 0, 0, 0, 0); 447} 448 449void StairTile::wasExploded(Level *level, int x, int y, int z, Explosion *explosion) 450{ 451 base->wasExploded(level, x, y, z, explosion); 452} 453 454void StairTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance) 455{ 456 int dir = ( Mth::floor(by->yRot * 4 / (360) + 0.5) ) & 3; 457 int usd = level->getData(x, y, z) & UPSIDEDOWN_BIT; 458 459 if (dir == 0) level->setData(x, y, z, DIR_SOUTH | usd, Tile::UPDATE_CLIENTS); 460 if (dir == 1) level->setData(x, y, z, DIR_WEST | usd, Tile::UPDATE_CLIENTS); 461 if (dir == 2) level->setData(x, y, z, DIR_NORTH | usd, Tile::UPDATE_CLIENTS); 462 if (dir == 3) level->setData(x, y, z, DIR_EAST | usd, Tile::UPDATE_CLIENTS); 463} 464 465int StairTile::getPlacedOnFaceDataValue(Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, int itemValue) 466{ 467 if (face == Facing::DOWN || (face != Facing::UP && clickY > 0.5)) 468 { 469 return itemValue | UPSIDEDOWN_BIT; 470 } 471 return itemValue; 472} 473 474HitResult *StairTile::clip(Level *level, int xt, int yt, int zt, Vec3 *a, Vec3 *b) 475{ 476 HitResult *results[8]; 477 for(unsigned int i = 0; i < 8; ++i) 478 { 479 results[i] = NULL; 480 } 481 int data = level->getData(xt, yt, zt); 482 int dir = data & 0x3; 483 bool upsideDown = (data & UPSIDEDOWN_BIT) == UPSIDEDOWN_BIT; 484 int *deadSpaces = DEAD_SPACES[dir + (upsideDown ? 4 : 0)]; 485 486 isClipping = true; 487 for (int i = 0; i < 8; i++) 488 { 489 clipStep = i; 490 491 for(unsigned int j = 0; j < DEAD_SPACE_COLUMN_COUNT; ++j) 492 { 493 if (deadSpaces[j] == i) continue; 494 } 495 496 results[i] = Tile::clip(level, xt, yt, zt, a, b); 497 } 498 499 for(unsigned int j = 0; j < DEAD_SPACE_COLUMN_COUNT; ++j) 500 { 501 results[deadSpaces[j]] = NULL; 502 } 503 504 HitResult *closest = NULL; 505 double closestDist = 0; 506 507 for (unsigned int i = 0; i < 8; ++i) 508 { 509 HitResult *result = results[i]; 510 if (result != NULL) 511 { 512 double dist = result->pos->distanceToSqr(b); 513 514 if (dist > closestDist) 515 { 516 closest = result; 517 closestDist = dist; 518 } 519 } 520 } 521 522 return closest; 523} 524 525void StairTile::registerIcons(IconRegister *iconRegister) 526{ 527 // None 528}