the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 216 lines 4.8 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.entity.player.h" 4#include "net.minecraft.world.level.tile.h" 5#include "net.minecraft.h" 6#include "TrapDoorTile.h" 7 8 9TrapDoorTile::TrapDoorTile(int id, Material *material) : Tile(id, material,isSolidRender()) 10{ 11 float r = 0.5f; 12 float h = 1.0f; 13 setShape(0.5f - r, 0, 0.5f - r, 0.5f + r, h, 0.5f + r); 14} 15 16bool TrapDoorTile::blocksLight() 17{ 18 return false; 19} 20 21 22bool TrapDoorTile::isSolidRender(bool isServerLevel) 23{ 24 return false; 25} 26 27 28bool TrapDoorTile::isCubeShaped() 29{ 30 return false; 31} 32 33bool TrapDoorTile::isPathfindable(LevelSource *level, int x, int y, int z) 34{ 35 return !isOpen(level->getData(x, y, z)); 36} 37 38int TrapDoorTile::getRenderShape() 39{ 40 return Tile::SHAPE_BLOCK; 41} 42 43 44AABB *TrapDoorTile::getTileAABB(Level *level, int x, int y, int z) 45{ 46 updateShape(level, x, y, z); 47 return Tile::getTileAABB(level, x, y, z); 48} 49 50 51AABB *TrapDoorTile::getAABB(Level *level, int x, int y, int z) 52{ 53 updateShape(level, x, y, z); 54 return Tile::getAABB(level, x, y, z); 55} 56 57 58void TrapDoorTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param 59{ 60 setShape(level->getData(x, y, z)); 61} 62 63 64void TrapDoorTile::updateDefaultShape() 65{ 66 float r = 3 / 16.0f; 67 setShape(0, 0.5f - r / 2, 0, 1, 0.5f + r / 2, 1); 68} 69 70 71void TrapDoorTile::setShape(int data) 72{ 73 74 float r = 3 / 16.0f; 75 if ((data & TOP_MASK) != 0) 76 { 77 setShape(0, 1 - r, 0, 1, 1, 1); 78 } 79 else 80 { 81 setShape(0, 0, 0, 1, r, 1); 82 } 83 if (isOpen(data)) 84 { 85 if ((data & 3) == 0) setShape(0, 0, 1 - r, 1, 1, 1); 86 if ((data & 3) == 1) setShape(0, 0, 0, 1, 1, r); 87 if ((data & 3) == 2) setShape(1 - r, 0, 0, 1, 1, 1); 88 if ((data & 3) == 3) setShape(0, 0, 0, r, 1, 1); 89 } 90} 91 92 93void TrapDoorTile::attack(Level *level, int x, int y, int z, shared_ptr<Player> player) 94{ 95 //use(level, x, y, z, player, 0, 0, 0, 0); 96} 97 98// 4J-PB - Adding a TestUse for tooltip display 99bool TrapDoorTile::TestUse() 100{ 101 return true; 102} 103 104bool TrapDoorTile::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 105{ 106 if (material == Material::metal) return true; 107 108 if (soundOnly) 109 { 110 // 4J - added - just do enough to play the sound 111 level->levelEvent(player, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0); 112 return false; 113 } 114 115 int dir = level->getData(x, y, z); 116 level->setData(x, y, z, dir ^ 4, Tile::UPDATE_CLIENTS); 117 118 level->levelEvent(player, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0); 119 return true; 120} 121 122 123void TrapDoorTile::setOpen(Level *level, int x, int y, int z, bool shouldOpen) 124{ 125 int dir = level->getData(x, y, z); 126 127 bool wasOpen = (dir & 4) > 0; 128 if (wasOpen == shouldOpen) return; 129 130 level->setData(x, y, z, dir ^ 4, Tile::UPDATE_CLIENTS); 131 132 level->levelEvent(nullptr, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0); 133} 134 135void TrapDoorTile::neighborChanged(Level *level, int x, int y, int z, int type) 136{ 137 if (level->isClientSide) return; 138 139 int data = level->getData(x, y, z); 140 int xt = x; 141 int zt = z; 142 if ((data & 3) == 0) zt++; 143 if ((data & 3) == 1) zt--; 144 if ((data & 3) == 2) xt++; 145 if ((data & 3) == 3) xt--; 146 147 148 if (!attachesTo(level->getTile(xt, y, zt))) 149 { 150 level->removeTile(x, y, z); 151 spawnResources(level, x, y, z, data, 0); 152 } 153 154 bool signal = level->hasNeighborSignal(x, y, z); 155 if( signal || ((type > 0 && Tile::tiles[type]->isSignalSource())) ) 156 { 157 setOpen(level, x, y, z, signal); 158 } 159} 160 161HitResult *TrapDoorTile::clip(Level *level, int xt, int yt, int zt, Vec3 *a, Vec3 *b) 162{ 163 updateShape(level, xt, yt, zt); 164 return Tile::clip(level, xt, yt, zt, a, b); 165} 166 167int TrapDoorTile::getDir(int dir) 168{ 169 if ((dir & 4) == 0) 170 { 171 return ((dir - 1) & 3); 172 } 173 else 174 { 175 return (dir & 3); 176 } 177} 178 179int TrapDoorTile::getPlacedOnFaceDataValue(Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, int itemValue) 180{ 181 int dir = 0; 182 if (face == 2) dir = 0; 183 if (face == 3) dir = 1; 184 if (face == 4) dir = 2; 185 if (face == 5) dir = 3; 186 if (face != Facing::UP && face != Facing::DOWN && clickY > 0.5f) dir |= TOP_MASK; 187 return dir; 188} 189 190bool TrapDoorTile::mayPlace(Level *level, int x, int y, int z, int face) 191{ 192 if (face == 0) return false; 193 if (face == 1) return false; 194 if (face == 2) z++; 195 if (face == 3) z--; 196 if (face == 4) x++; 197 if (face == 5) x--; 198 199 return attachesTo(level->getTile(x, y, z)); 200} 201 202bool TrapDoorTile::isOpen(int data) 203{ 204 return (data & 4) != 0; 205} 206 207bool TrapDoorTile::attachesTo(int id) 208{ 209 if (id <= 0) 210 { 211 return false; 212 } 213 Tile *tile = Tile::tiles[id]; 214 215 return tile != NULL && (tile->material->isSolidBlocking() && tile->isCubeShaped()) || tile == Tile::glowstone || (dynamic_cast<HalfSlabTile *>(tile) != NULL) || (dynamic_cast<StairTile *>(tile) != NULL); 216}