the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 230 lines 6.5 kB view raw
1#include "stdafx.h" 2#include "PistonExtensionTile.h" 3#include "PistonBaseTile.h" 4#include "Facing.h" 5#include "net.minecraft.world.level.h" 6 7PistonExtensionTile::PistonExtensionTile(int id) : Tile(id, Material::piston,isSolidRender() ) 8{ 9 // 4J added initialiser 10 overrideTopTexture = NULL; 11 12 setSoundType(SOUND_STONE); 13 setDestroyTime(0.5f); 14} 15 16void PistonExtensionTile::setOverrideTopTexture(Icon *overrideTopTexture) 17{ 18 this->overrideTopTexture = overrideTopTexture; 19} 20 21void PistonExtensionTile::clearOverrideTopTexture() 22{ 23 this->overrideTopTexture = NULL; 24} 25 26void PistonExtensionTile::playerWillDestroy(Level *level, int x, int y, int z, int data, shared_ptr<Player> player) 27{ 28 if (player->abilities.instabuild) 29 { 30 int facing = getFacing(data); 31 int tile = level->getTile(x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing]); 32 if (tile == Tile::pistonBase_Id || tile == Tile::pistonStickyBase_Id) 33 { 34 level->removeTile(x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing]); 35 } 36 } 37 Tile::playerWillDestroy(level, x, y, z, data, player); 38} 39 40void PistonExtensionTile::onRemove(Level *level, int x, int y, int z, int id, int data) 41{ 42 Tile::onRemove(level, x, y, z, id, data); 43 int facing = Facing::OPPOSITE_FACING[getFacing(data)]; 44 x += Facing::STEP_X[facing]; 45 y += Facing::STEP_Y[facing]; 46 z += Facing::STEP_Z[facing]; 47 48 int t = level->getTile(x, y, z); 49 50 if (t == Tile::pistonBase_Id || t == Tile::pistonStickyBase_Id) 51 { 52 data = level->getData(x, y, z); 53 if (PistonBaseTile::isExtended(data)) 54 { 55 Tile::tiles[t]->spawnResources(level, x, y, z, data, 0); 56 level->removeTile(x, y, z); 57 58 } 59 } 60} 61 62Icon *PistonExtensionTile::getTexture(int face, int data) 63{ 64 int facing = getFacing(data); 65 66 if (face == facing) 67 { 68 if (overrideTopTexture != NULL) 69 { 70 return overrideTopTexture; 71 } 72 if ((data & STICKY_BIT) != 0) 73 { 74 return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_STICKY_TEX); 75 } 76 return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_TEX); 77 } 78 if (facing < 6 && face == Facing::OPPOSITE_FACING[facing]) 79 { 80 return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_TEX); 81 } 82 return PistonBaseTile::getTexture(PistonBaseTile::EDGE_TEX); // edge and arms 83} 84 85void PistonExtensionTile::registerIcons(IconRegister *iconRegister) 86{ 87 // None 88} 89 90int PistonExtensionTile::getRenderShape() 91{ 92 return SHAPE_PISTON_EXTENSION; 93} 94 95bool PistonExtensionTile::isSolidRender(bool isServerLevel) 96{ 97 return false; 98} 99 100bool PistonExtensionTile::isCubeShaped() 101{ 102 return false; 103} 104 105bool PistonExtensionTile::mayPlace(Level *level, int x, int y, int z) 106{ 107 return false; 108} 109 110bool PistonExtensionTile::mayPlace(Level *level, int x, int y, int z, int face) 111{ 112 return false; 113} 114 115int PistonExtensionTile::getResourceCount(Random *random) 116{ 117 return 0; 118} 119 120void PistonExtensionTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source) 121{ 122 int data = level->getData(x, y, z); 123 124 const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f; 125 const float smallEdge1 = (8.0f - (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f; 126 const float smallEdge2 = (8.0f + (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f; 127 const float largeEdge1 = (8.0f - PistonBaseTile::PLATFORM_THICKNESS) / 16.0f; 128 const float largeEdge2 = (8.0f + PistonBaseTile::PLATFORM_THICKNESS) / 16.0f; 129 130 switch (getFacing(data)) 131 { 132 case Facing::DOWN: 133 setShape(0, 0, 0, 1, thickness, 1); 134 Tile::addAABBs(level, x, y, z, box, boxes, source); 135 setShape(smallEdge1, thickness, smallEdge1, smallEdge2, 1, smallEdge2); 136 Tile::addAABBs(level, x, y, z, box, boxes, source); 137 break; 138 case Facing::UP: 139 setShape(0, 1 - thickness, 0, 1, 1, 1); 140 Tile::addAABBs(level, x, y, z, box, boxes, source); 141 setShape(smallEdge1, 0, smallEdge1, smallEdge2, 1 - thickness, smallEdge2); 142 Tile::addAABBs(level, x, y, z, box, boxes, source); 143 break; 144 case Facing::NORTH: 145 setShape(0, 0, 0, 1, 1, thickness); 146 Tile::addAABBs(level, x, y, z, box, boxes, source); 147 setShape(largeEdge1, smallEdge1, thickness, largeEdge2, smallEdge2, 1); 148 Tile::addAABBs(level, x, y, z, box, boxes, source); 149 break; 150 case Facing::SOUTH: 151 setShape(0, 0, 1 - thickness, 1, 1, 1); 152 Tile::addAABBs(level, x, y, z, box, boxes, source); 153 setShape(largeEdge1, smallEdge1, 0, largeEdge2, smallEdge2, 1 - thickness); 154 Tile::addAABBs(level, x, y, z, box, boxes, source); 155 break; 156 case Facing::WEST: 157 setShape(0, 0, 0, thickness, 1, 1); 158 Tile::addAABBs(level, x, y, z, box, boxes, source); 159 setShape(smallEdge1, largeEdge1, thickness, smallEdge2, largeEdge2, 1); 160 Tile::addAABBs(level, x, y, z, box, boxes, source); 161 break; 162 case Facing::EAST: 163 setShape(1 - thickness, 0, 0, 1, 1, 1); 164 Tile::addAABBs(level, x, y, z, box, boxes, source); 165 setShape(0, smallEdge1, largeEdge1, 1 - thickness, smallEdge2, largeEdge2); 166 Tile::addAABBs(level, x, y, z, box, boxes, source); 167 break; 168 } 169 setShape(0, 0, 0, 1, 1, 1); 170 171} 172 173void PistonExtensionTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param 174{ 175 int data = (forceData == -1 ) ? level->getData(x, y, z) : forceData; 176 177 const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f; 178 179 switch (getFacing(data)) 180 { 181 case Facing::DOWN: 182 setShape(0, 0, 0, 1, thickness, 1); 183 break; 184 case Facing::UP: 185 setShape(0, 1 - thickness, 0, 1, 1, 1); 186 break; 187 case Facing::NORTH: 188 setShape(0, 0, 0, 1, 1, thickness); 189 break; 190 case Facing::SOUTH: 191 setShape(0, 0, 1 - thickness, 1, 1, 1); 192 break; 193 case Facing::WEST: 194 setShape(0, 0, 0, thickness, 1, 1); 195 break; 196 case Facing::EAST: 197 setShape(1 - thickness, 0, 0, 1, 1, 1); 198 break; 199 } 200} 201 202void PistonExtensionTile::neighborChanged(Level *level, int x, int y, int z, int type) 203{ 204 int facing = getFacing(level->getData(x, y, z)); 205 int tile = level->getTile(x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing]); 206 if (tile != Tile::pistonBase_Id && tile != Tile::pistonStickyBase_Id) 207 { 208 level->removeTile(x, y, z); 209 } 210 else 211 { 212 Tile::tiles[tile]->neighborChanged(level, x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing], type); 213 } 214} 215 216int PistonExtensionTile::getFacing(int data) 217{ 218 return data & 0x7; 219} 220 221int PistonExtensionTile::cloneTileId(Level *level, int x, int y, int z) 222{ 223 int data = level->getData(x, y, z); 224 if ((data & STICKY_BIT) != 0) 225 { 226 return Tile::pistonStickyBase_Id; 227 } 228 return Tile::pistonBase_Id; 229 return 0; 230}