the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 136 lines 3.3 kB view raw
1#include "stdafx.h" 2#include "DoorTile_SPU.h" 3#include "Facing_SPU.h" 4#include "ChunkRebuildData.h" 5 6 7 8Icon_SPU *DoorTile_SPU::getTexture(int face, int data) 9{ 10 int texBase; 11 if (getMaterial()->getID() == Material_SPU::metal_Id) 12 texBase = 2; 13 else 14 texBase = 0; 15 16 return &ms_pTileData->doorTile_Icons[texBase]; 17} 18 19Icon_SPU *DoorTile_SPU::getTexture(ChunkRebuildData *level, int x, int y, int z, int face) 20{ 21 int texBase; 22 if (getMaterial()->getID() == Material_SPU::metal_Id) 23 texBase = 2; 24 else 25 texBase = 0; 26 27 if (face == Facing::UP || face == Facing::DOWN) return &ms_pTileData->doorTile_Icons[texBase]; 28 29 int compositeData = getCompositeData(level, x, y, z); 30 int dir = compositeData & C_DIR_MASK; 31 bool isOpen = (compositeData & C_OPEN_MASK) != 0; 32 bool flip = false; 33 bool upper = (compositeData & C_IS_UPPER_MASK) != 0; 34 35 if (isOpen) 36 { 37 if (dir == 0 && face == 2) flip = !flip; 38 else if (dir == 1 && face == 5) flip = !flip; 39 else if (dir == 2 && face == 3) flip = !flip; 40 else if (dir == 3 && face == 4) flip = !flip; 41 } 42 else 43 { 44 if (dir == 0 && face == 5) flip = !flip; 45 else if (dir == 1 && face == 3) flip = !flip; 46 else if (dir == 2 && face == 4) flip = !flip; 47 else if (dir == 3 && face == 2) flip = !flip; 48 if ((compositeData & C_RIGHT_HINGE_MASK) != 0) flip = !flip; 49 } 50 51 return &ms_pTileData->doorTile_Icons[texBase + (flip ? DOOR_TILE_TEXTURE_COUNT : 0) + (upper ? 1 : 0)]; 52} 53 54void DoorTile_SPU::updateShape(ChunkRebuildData *level, int x, int y, int z, int forceData, TileEntity* forceEntity) // 4J added forceData, forceEntity param 55{ 56 setShape(getCompositeData(level,x, y, z)); 57} 58 59bool DoorTile_SPU::isOpen(ChunkRebuildData *level, int x, int y, int z) 60{ 61 return (getCompositeData(level, x, y, z) & C_OPEN_MASK) != 0; 62} 63 64void DoorTile_SPU::setShape(int compositeData) 65{ 66 float r = 3 / 16.0f; 67 Tile_SPU::setShape(0, 0, 0, 1, 2, 1); 68 int dir = compositeData & C_DIR_MASK; 69 bool open = (compositeData & C_OPEN_MASK) != 0; 70 bool hasRightHinge = (compositeData & C_RIGHT_HINGE_MASK) != 0; 71 if (dir == 0) 72 { 73 if (open) 74 { 75 if (!hasRightHinge) setShape(0, 0, 0, 1, 1, r); 76 else setShape(0, 0, 1 - r, 1, 1, 1); 77 } 78 else setShape(0, 0, 0, r, 1, 1); 79 } 80 else if (dir == 1) 81 { 82 if (open) 83 { 84 if (!hasRightHinge) setShape(1 - r, 0, 0, 1, 1, 1); 85 else setShape(0, 0, 0, r, 1, 1); 86 } 87 else setShape(0, 0, 0, 1, 1, r); 88 } 89 else if (dir == 2) 90 { 91 if (open) 92 { 93 if (!hasRightHinge) setShape(0, 0, 1 - r, 1, 1, 1); 94 else setShape(0, 0, 0, 1, 1, r); 95 } 96 else setShape(1 - r, 0, 0, 1, 1, 1); 97 } 98 else if (dir == 3) 99 { 100 if (open) 101 { 102 if (!hasRightHinge) setShape(0, 0, 0, r, 1, 1); 103 else setShape(1 - r, 0, 0, 1, 1, 1); 104 } 105 else setShape(0, 0, 1 - r, 1, 1, 1); 106 } 107} 108 109 110bool DoorTile_SPU::isOpen(int data) 111{ 112 return (data & 4) != 0; 113} 114 115 116int DoorTile_SPU::getCompositeData(ChunkRebuildData *level, int x, int y, int z) 117{ 118 int data = level->getData(x, y, z); 119 bool isUpper = (data & UPPER_BIT) != 0; 120 int lowerData; 121 int upperData; 122 if (isUpper) 123 { 124 lowerData = level->getData(x, y - 1, z); 125 upperData = data; 126 } 127 else 128 { 129 lowerData = data; 130 upperData = level->getData(x, y + 1, z); 131 } 132 133 // bits: dir, dir, open/closed, isUpper, isRightHinge 134 bool isRightHinge = (upperData & 1) != 0; 135 return lowerData & C_LOWER_DATA_MASK | (isUpper ? 8 : 0) | (isRightHinge ? 16 : 0); 136}