the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 357 lines 8.8 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.phys.h" 4#include "DoorTile.h" 5#include "LevelEvent.h" 6#include "net.minecraft.world.item.h" 7#include "net.minecraft.world.entity.player.h" 8#include "net.minecraft.world.h" 9#include "net.minecraft.h" 10 11const wstring DoorTile::TEXTURES[] = { L"doorWood_lower", L"doorWood_upper", L"doorIron_lower", L"doorIron_upper" }; 12 13DoorTile::DoorTile(int id, Material *material) : Tile(id, material,isSolidRender()) 14{ 15 if (material == Material::metal) 16 { 17 texBase = 2; 18 } 19 else 20 { 21 texBase = 0; 22 } 23 24 float r = 0.5f; 25 float h = 1.0f; 26 Tile::setShape(0.5f - r, 0, 0.5f - r, 0.5f + r, h, 0.5f + r); 27} 28 29Icon *DoorTile::getTexture(int face, int data) 30{ 31 return iconBottom[TEXTURE_NORMAL]; 32} 33 34Icon *DoorTile::getTexture(LevelSource *level, int x, int y, int z, int face) 35{ 36 if (face == Facing::UP || face == Facing::DOWN) return iconBottom[TEXTURE_NORMAL]; 37 38 int compositeData = getCompositeData(level, x, y, z); 39 int dir = compositeData & C_DIR_MASK; 40 bool isOpen = (compositeData & C_OPEN_MASK) != 0; 41 bool flip = false; 42 bool upper = (compositeData & C_IS_UPPER_MASK) != 0; 43 44 if (isOpen) 45 { 46 if (dir == 0 && face == 2) flip = !flip; 47 else if (dir == 1 && face == 5) flip = !flip; 48 else if (dir == 2 && face == 3) flip = !flip; 49 else if (dir == 3 && face == 4) flip = !flip; 50 } 51 else 52 { 53 if (dir == 0 && face == 5) flip = !flip; 54 else if (dir == 1 && face == 3) flip = !flip; 55 else if (dir == 2 && face == 4) flip = !flip; 56 else if (dir == 3 && face == 2) flip = !flip; 57 if ((compositeData & C_RIGHT_HINGE_MASK) != 0) flip = !flip; 58 } 59 60 if (upper) 61 { 62 return iconTop[flip ? TEXTURE_FLIPPED : TEXTURE_NORMAL]; 63 } 64 else 65 { 66 return iconBottom[flip ? TEXTURE_FLIPPED : TEXTURE_NORMAL]; 67 } 68} 69 70void DoorTile::registerIcons(IconRegister *iconRegister) 71{ 72 iconTop[TEXTURE_NORMAL] = iconRegister->registerIcon(getIconName() + L"_upper"); 73 iconBottom[TEXTURE_NORMAL] = iconRegister->registerIcon(getIconName() + L"_lower"); 74 iconTop[TEXTURE_FLIPPED] = new FlippedIcon(iconTop[TEXTURE_NORMAL], true, false); 75 iconBottom[TEXTURE_FLIPPED] = new FlippedIcon(iconBottom[TEXTURE_NORMAL], true, false); 76} 77 78bool DoorTile::blocksLight() 79{ 80 return false; 81} 82 83bool DoorTile::isSolidRender(bool isServerLevel) 84{ 85 return false; 86} 87 88bool DoorTile::isCubeShaped() 89{ 90 return false; 91} 92 93int DoorTile::getRenderShape() 94{ 95 return Tile::SHAPE_DOOR; 96} 97 98AABB *DoorTile::getTileAABB(Level *level, int x, int y, int z) 99{ 100 updateShape(level, x, y, z); 101 AABB *retval = Tile::getTileAABB(level, x, y, z); 102 return retval; 103} 104 105AABB *DoorTile::getAABB(Level *level, int x, int y, int z) 106{ 107 updateShape(level, x, y, z); 108 AABB *retval = Tile::getAABB(level, x, y, z); 109 return retval; 110} 111 112void DoorTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param 113{ 114 setShape(getCompositeData(level,x, y, z)); 115} 116 117int DoorTile::getDir(LevelSource *level, int x, int y, int z) 118{ 119 return getCompositeData(level, x, y, z) & C_DIR_MASK; 120} 121 122bool DoorTile::isOpen(LevelSource *level, int x, int y, int z) 123{ 124 return (getCompositeData(level, x, y, z) & C_OPEN_MASK) != 0; 125} 126 127void DoorTile::setShape(int compositeData) 128{ 129 float r = 3 / 16.0f; 130 Tile::setShape(0, 0, 0, 1, 2, 1); 131 int dir = compositeData & C_DIR_MASK; 132 bool open = (compositeData & C_OPEN_MASK) != 0; 133 bool hasRightHinge = (compositeData & C_RIGHT_HINGE_MASK) != 0; 134 if (dir == 0) 135 { 136 if (open) 137 { 138 if (!hasRightHinge) setShape(0, 0, 0, 1, 1, r); 139 else setShape(0, 0, 1 - r, 1, 1, 1); 140 } 141 else setShape(0, 0, 0, r, 1, 1); 142 } 143 else if (dir == 1) 144 { 145 if (open) 146 { 147 if (!hasRightHinge) setShape(1 - r, 0, 0, 1, 1, 1); 148 else setShape(0, 0, 0, r, 1, 1); 149 } 150 else setShape(0, 0, 0, 1, 1, r); 151 } 152 else if (dir == 2) 153 { 154 if (open) 155 { 156 if (!hasRightHinge) setShape(0, 0, 1 - r, 1, 1, 1); 157 else setShape(0, 0, 0, 1, 1, r); 158 } 159 else setShape(1 - r, 0, 0, 1, 1, 1); 160 } 161 else if (dir == 3) 162 { 163 if (open) 164 { 165 if (!hasRightHinge) setShape(0, 0, 0, r, 1, 1); 166 else setShape(1 - r, 0, 0, 1, 1, 1); 167 } 168 else setShape(0, 0, 1 - r, 1, 1, 1); 169 } 170} 171 172void DoorTile::attack(Level *level, int x, int y, int z, shared_ptr<Player> player) 173{ 174 // Fix for #92957 - TU11: Content: Multiplayer: Wooden Doors splits in half and glitch in open / close motion while being mined. 175 // In lastest PC version this is commented out, so do that now to fix bug above 176 //use(level, x, y, z, player); 177} 178 179// 4J-PB - Adding a TestUse for tooltip display 180bool DoorTile::TestUse() 181{ 182 return id == Tile::door_wood_Id; 183} 184 185bool DoorTile::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 186{ 187 if (soundOnly) 188 { 189 // 4J - added - just do enough to play the sound 190 if (material != Material::metal) 191 { 192 level->levelEvent(player, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0); 193 } 194 return false; 195 } 196 197 if (material == Material::metal) return true; 198 199 int compositeData = getCompositeData(level, x, y, z); 200 int lowerData = compositeData & C_LOWER_DATA_MASK; 201 lowerData ^= 4; 202 if ((compositeData & C_IS_UPPER_MASK) == 0) 203 { 204 level->setData(x, y, z, lowerData, Tile::UPDATE_CLIENTS); 205 level->setTilesDirty(x, y, z, x, y, z); 206 } 207 else 208 { 209 level->setData(x, y - 1, z, lowerData, Tile::UPDATE_CLIENTS); 210 level->setTilesDirty(x, y - 1, z, x, y, z); 211 } 212 213 level->levelEvent(player, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0); 214 return true; 215} 216 217void DoorTile::setOpen(Level *level, int x, int y, int z, bool shouldOpen) 218{ 219 int compositeData = getCompositeData(level, x, y, z); 220 bool isOpen = (compositeData & C_OPEN_MASK) != 0; 221 if (isOpen == shouldOpen) return; 222 223 int lowerData = compositeData & C_LOWER_DATA_MASK; 224 lowerData ^= 4; 225 if ((compositeData & C_IS_UPPER_MASK) == 0) 226 { 227 level->setData(x, y, z, lowerData, Tile::UPDATE_CLIENTS); 228 level->setTilesDirty(x, y, z, x, y, z); 229 } 230 else 231 { 232 level->setData(x, y - 1, z, lowerData, Tile::UPDATE_CLIENTS); 233 level->setTilesDirty(x, y - 1, z, x, y, z); 234 } 235 236 level->levelEvent(nullptr, LevelEvent::SOUND_OPEN_DOOR, x, y, z, 0); 237} 238 239void DoorTile::neighborChanged(Level *level, int x, int y, int z, int type) 240{ 241 int data = level->getData(x, y, z); 242 if ((data & UPPER_BIT) == 0) 243 { 244 bool spawn = false; 245 if (level->getTile(x, y + 1, z) != id) 246 { 247 level->removeTile(x, y, z); 248 spawn = true; 249 } 250 if (!level->isSolidBlockingTile(x, y - 1, z)) 251 { 252 level->removeTile(x, y, z); 253 spawn = true; 254 if (level->getTile(x, y + 1, z) == id) 255 { 256 level->removeTile(x, y + 1, z); 257 } 258 } 259 if (spawn) 260 { 261 if (!level->isClientSide) 262 { 263 spawnResources(level, x, y, z, data, 0); 264 } 265 } 266 else 267 { 268 bool signal = level->hasNeighborSignal(x, y, z) || level->hasNeighborSignal(x, y + 1, z); 269 if ((signal || (type > 0 && Tile::tiles[type]->isSignalSource())) && type != id) 270 { 271 setOpen(level, x, y, z, signal); 272 } 273 } 274 } 275 else 276 { 277 if (level->getTile(x, y - 1, z) != id) 278 { 279 level->removeTile(x, y, z); 280 } 281 if (type > 0 && type != id) 282 { 283 neighborChanged(level, x, y - 1, z, type); 284 } 285 } 286} 287 288int DoorTile::getResource(int data, Random *random, int playerBonusLevel) 289{ 290 if ((data & 8) != 0) return 0; 291 if (material == Material::metal) return Item::door_iron->id; 292 return Item::door_wood->id; 293} 294 295HitResult *DoorTile::clip(Level *level, int xt, int yt, int zt, Vec3 *a, Vec3 *b) 296{ 297 updateShape(level, xt, yt, zt); 298 return Tile::clip(level, xt, yt, zt, a, b); 299} 300 301bool DoorTile::mayPlace(Level *level, int x, int y, int z) 302{ 303 if (y >= Level::maxBuildHeight - 1) return false; 304 305 return (level->isTopSolidBlocking(x, y - 1, z) && Tile::mayPlace(level, x, y, z) && Tile::mayPlace(level, x, y + 1, z)); 306} 307 308bool DoorTile::isOpen(int data) 309{ 310 return (data & 4) != 0; 311} 312 313int DoorTile::getPistonPushReaction() 314{ 315 return Material::PUSH_DESTROY; 316} 317 318int DoorTile::getCompositeData(LevelSource *level, int x, int y, int z) 319{ 320 int data = level->getData(x, y, z); 321 bool isUpper = (data & UPPER_BIT) != 0; 322 int lowerData; 323 int upperData; 324 if (isUpper) 325 { 326 lowerData = level->getData(x, y - 1, z); 327 upperData = data; 328 } 329 else 330 { 331 lowerData = data; 332 upperData = level->getData(x, y + 1, z); 333 } 334 335 // bits: dir, dir, open/closed, isUpper, isRightHinge 336 bool isRightHinge = (upperData & 1) != 0; 337 return (lowerData & C_LOWER_DATA_MASK) | (isUpper ? 8 : 0) | (isRightHinge ? 16 : 0); 338} 339 340int DoorTile::cloneTileId(Level *level, int x, int y, int z) 341{ 342 return material == Material::metal ? Item::door_iron_Id : Item::door_wood_Id; 343} 344 345void DoorTile::playerWillDestroy(Level *level, int x, int y, int z, int data, shared_ptr<Player> player) 346{ 347 if (player->abilities.instabuild) 348 { 349 if ((data & UPPER_BIT) != 0) 350 { 351 if (level->getTile(x, y - 1, z) == id) 352 { 353 level->removeTile(x, y - 1, z); 354 } 355 } 356 } 357}