int BlockTracks::searchTrack(int32_t x, int16_t y, int32_t z, int map, uint8_t& meta) { if (isTrack(x, y + 1, z, map, meta)) { return 1; } else if (isTrack(x, y - 1, z, map, meta)) { return -1; } else if (isTrack(x, y, z, map, meta)) { return 0; } return 2; }
void BlockTracks::onPlace(User* user, sint8 newblock, sint32 x, sint8 y, sint32 z, sint8 direction) { uint8 block; uint8 meta; if (!Mineserver::get()->map()->getBlock(x, y, z, &block, &meta)) return; /* Check block below allows blocks placed on top */ if (!this->isBlockStackable(block)) return; /* move the x,y,z coords dependent upon placement direction */ if (!this->translateDirection(&x,&y,&z,direction)) return; if (!this->isBlockEmpty(x,y,z)) return; uint8 metadata = FLAT_NS; // SOUTH if(isTrack(x, y, z-1, meta) && isStartPiece(x, y, z-1)) { Mineserver::get()->screen()->log("SOUTH"); metadata = FLAT_NS; // Rising & falling tracks if(isTrack(x, y+1, z+1, meta) && isStartPiece(x, y+1, z+1)) { metadata = ASCEND_N; } if(isTrack(x+1, y, z, meta) && isStartPiece(x+1, y, z)) { metadata = CORNER_NE; } if(isTrack(x-1, y, z, meta) && isStartPiece(x-1, y, z)) { metadata = CORNER_NW; } // Modify previous trackpiece to form corner if(isTrack(x-1, y, z-1, meta) && meta != FLAT_NS && meta != CORNER_NW && meta != CORNER_SW) { Mineserver::get()->map()->setBlock(x, y, z-1, (char)newblock, CORNER_SW); Mineserver::get()->map()->sendBlockChange(x, y, z-1, (char)newblock, CORNER_SW); } else if(isTrack(x+1, y, z-1, meta) && meta != FLAT_NS && meta != CORNER_NE && meta != CORNER_SE) { Mineserver::get()->map()->setBlock(x, y, z-1, (char)newblock, CORNER_SE); Mineserver::get()->map()->sendBlockChange(x, y, z-1, (char)newblock, CORNER_SE); } } // NORTH if(isTrack(x, y, z+1, meta) && isStartPiece(x, y, z+1)) { Mineserver::get()->screen()->log("NORTH"); metadata = FLAT_NS; // Rising & falling tracks if(isTrack(x, y+1, z-1, meta) && isStartPiece(x, y+1, z-1)) { metadata = ASCEND_S; } if(isTrack(x+1, y, z, meta) && isStartPiece(x+1, y, z)) { metadata = CORNER_SE; } if(isTrack(x-1, y, z, meta) && isStartPiece(x-1, y, z)) { metadata = CORNER_SW; } // Modify previous trackpiece to form corner if(isTrack(x+1, y, z+1, meta) && meta != FLAT_NS && meta != CORNER_NE && meta != CORNER_SE) { Mineserver::get()->map()->setBlock(x, y, z+1, (char)newblock, CORNER_NE); Mineserver::get()->map()->sendBlockChange(x, y, z+1, (char)newblock, CORNER_NE); } else if(isTrack(x-1, y, z+1, meta) && meta != FLAT_NS && meta != CORNER_NW && meta != CORNER_SW) { Mineserver::get()->map()->setBlock(x, y, z+1, (char)newblock, CORNER_NW); Mineserver::get()->map()->sendBlockChange(x, y, z+1, (char)newblock, CORNER_NW); } } // EAST if(isTrack(x-1, y, z, meta) && isStartPiece(x-1, y, z)) { Mineserver::get()->screen()->log("EAST"); metadata = FLAT_EW; // Rising & falling tracks if(isTrack(x+1, y+1, z, meta) && isStartPiece(x+1, y+1, z)) { metadata = ASCEND_W; } else { // Change previous block meta Mineserver::get()->map()->setBlock(x-1, y, z, (char)newblock, FLAT_EW); Mineserver::get()->map()->sendBlockChange(x-1, y, z, (char)newblock, FLAT_EW); } if(isTrack(x, y, z+1, meta) && isStartPiece(x, y, z+1)) { metadata = CORNER_SW; } if(isTrack(x, y, z-1, meta) && isStartPiece(x, y, z-1)) { metadata = CORNER_NW; } // Modify previous trackpiece to form corner if(isTrack(x-1, y, z-1, meta) && meta != FLAT_EW && meta != CORNER_NE && meta != CORNER_NW) { Mineserver::get()->map()->setBlock(x-1, y, z, (char)newblock, CORNER_NE); Mineserver::get()->map()->sendBlockChange(x-1, y, z, (char)newblock, CORNER_NE); } else if(isTrack(x-1, y, z+1, meta) && meta != FLAT_EW && meta != CORNER_SW && meta != CORNER_SE) { Mineserver::get()->map()->setBlock(x-1, y, z, (char)newblock, CORNER_SE); Mineserver::get()->map()->sendBlockChange(x-1, y, z, (char)newblock, CORNER_SE); } } // WEST if(isTrack(x+1, y, z, meta) && isStartPiece(x+1, y, z)) { Mineserver::get()->screen()->log("WEST"); metadata = FLAT_EW; // Change previous block meta // Rising & falling tracks if(isTrack(x-1, y+1, z, meta) && isStartPiece(x-1, y+1, z)) { metadata = ASCEND_E; } else { Mineserver::get()->map()->setBlock(x+1, y, z, (char)newblock, FLAT_EW); Mineserver::get()->map()->sendBlockChange(x+1, y, z, (char)newblock, FLAT_EW); } if(isTrack(x, y, z+1, meta) && isStartPiece(x, y, z+1)) { metadata = CORNER_SE; } if(isTrack(x, y, z-1, meta) && isStartPiece(x, y, z-1)) { metadata = CORNER_NE; } // Modify previous trackpiece to form corner if(isTrack(x+1, y, z-1, meta) && meta != FLAT_EW && meta != CORNER_NW && meta != CORNER_NE) { Mineserver::get()->map()->setBlock(x+1, y, z, (char)newblock, CORNER_NW); Mineserver::get()->map()->sendBlockChange(x+1, y, z, (char)newblock, CORNER_NW); } else if(isTrack(x+1, y, z+1, meta) && meta != FLAT_EW && meta != CORNER_SW && meta != CORNER_SE) { Mineserver::get()->map()->setBlock(x+1, y, z, (char)newblock, CORNER_SW); Mineserver::get()->map()->sendBlockChange(x+1, y, z, (char)newblock, CORNER_SW); } } Mineserver::get()->map()->setBlock(x, y, z, (char)newblock, metadata); Mineserver::get()->map()->sendBlockChange(x, y, z, (char)newblock, metadata); }
bool BlockTracks::onPlace(User* user, int16_t newblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction) { uint8_t block; uint8_t meta; if (!ServerInstance->map(map)->getBlock(x, y, z, &block, &meta)) { revertBlock(user, x, y, z, map); return true; } /* Check block below allows blocks placed on top */ if (!this->isBlockStackable(block)) { revertBlock(user, x, y, z, map); return true; } /* move the x,y,z coords dependent upon placement direction */ if (!this->translateDirection(&x, &y, &z, map, direction)) { revertBlock(user, x, y, z, map); return true; } if (!this->isBlockEmpty(x, y, z, map)) { revertBlock(user, x, y, z, map); return true; } uint8_t metadata = FLAT_NS; uint8_t elevoftrack = 2; // WEST of placed track if (searchTrack(x + 1, y, z, map, meta) != 2 && isStartPiece(x + 1, y, z, map)) { LOG(INFO, "Tracks", "WEST"); metadata = FLAT_EW; elevoftrack = searchTrack(x + 1, y, z, map, meta); if (meta == FLAT_NS && elevoftrack == 0) { ServerInstance->map(map)->setBlock(x + 1, y, z, (char)newblock, FLAT_EW); ServerInstance->map(map)->sendBlockChange(x + 1, y, z, (char)newblock, FLAT_EW); } // Rising & falling tracks if (isTrack(x + 1, y + 1, z, map, meta) && isStartPiece(x + 1, y + 1, z, map)) // Rising & falling tracks { metadata = ASCEND_W; } else if (isTrack(x + 1, y - 1, z, map, meta) && isStartPiece(x + 1, y - 1, z, map)) // Rising & falling tracks { ServerInstance->map(map)->setBlock(x + 1, y - 1, z, (char)newblock, ASCEND_E); ServerInstance->map(map)->sendBlockChange(x + 1, y - 1, z, (char)newblock, ASCEND_E); } // Change previous track, Turns if (searchTrack(x + 1, y, z - 1, map, meta) != 2 && isStartPiece(x + 1, y, z, map) && meta != FLAT_EW) // Left { ServerInstance->map(map)->setBlock(x + 1, y + elevoftrack, z, (char)newblock, CORNER_NW); ServerInstance->map(map)->sendBlockChange(x + 1, y + elevoftrack, z, (char)newblock, CORNER_NW); } if (searchTrack(x + 1, y, z + 1, map, meta) != 2 && isStartPiece(x + 1, y, z, map) && meta != FLAT_EW) // Right { ServerInstance->map(map)->setBlock(x + 1, y + elevoftrack, z, (char)newblock, CORNER_SW); ServerInstance->map(map)->sendBlockChange(x + 1, y + elevoftrack, z, (char)newblock, CORNER_SW); } // Make track you just placed a corner if (isTrack(x, y, z - 1, map, meta) && isStartPiece(x, y, z - 1, map)) { metadata = CORNER_NE; } if (isTrack(x, y, z + 1, map, meta) && isStartPiece(x, y, z + 1, map)) { metadata = CORNER_SE; } } // EAST of placed track else if (searchTrack(x - 1, y, z, map, meta) != 2 && isStartPiece(x - 1, y, z, map)) { LOG(INFO, "Tracks", "EAST"); metadata = FLAT_EW; elevoftrack = searchTrack(x - 1, y, z, map, meta); if (meta == FLAT_NS && elevoftrack == 0) { ServerInstance->map(map)->setBlock(x - 1, y, z, (char)newblock, FLAT_EW); ServerInstance->map(map)->sendBlockChange(x - 1, y, z, (char)newblock, FLAT_EW); } // Rising & falling tracks if (isTrack(x - 1, y + 1, z, map, meta) && isStartPiece(x - 1, y + 1, z, map)) { metadata = ASCEND_E; if (meta != ASCEND_E || meta != CORNER_NW || meta != CORNER_SW) { ServerInstance->map(map)->setBlock(x - 1, y + 1, z, (char)newblock, FLAT_EW); ServerInstance->map(map)->sendBlockChange(x - 1, y + 1, z, (char)newblock, FLAT_EW); } } else if (isTrack(x - 1, y - 1, z, map, meta) && isStartPiece(x - 1, y - 1, z, map)) { ServerInstance->map(map)->setBlock(x - 1, y - 1, z, (char)newblock, ASCEND_W); ServerInstance->map(map)->sendBlockChange(x - 1, y - 1, z, (char)newblock, ASCEND_W); } // Change previous track, Turns if (searchTrack(x - 1, y, z - 1, map, meta) != 2 && isStartPiece(x - 1, y, z, map) && meta != FLAT_EW) // Right { ServerInstance->map(map)->setBlock(x - 1, y + elevoftrack, z, (char)newblock, CORNER_NE); ServerInstance->map(map)->sendBlockChange(x - 1, y + elevoftrack, z, (char)newblock, CORNER_NE); } if (searchTrack(x - 1, y, z + 1, map, meta) != 2 && isStartPiece(x - 1, y, z, map) && meta != FLAT_EW) // Left { ServerInstance->map(map)->setBlock(x - 1, y + elevoftrack, z, (char)newblock, CORNER_SE); ServerInstance->map(map)->sendBlockChange(x - 1, y + elevoftrack, z, (char)newblock, CORNER_SE); } // Make track you just placed a corner if (isTrack(x, y, z - 1, map, meta) && isStartPiece(x, y, z - 1, map)) { metadata = CORNER_NW; } if (isTrack(x, y, z + 1, map, meta) && isStartPiece(x, y, z + 1, map)) { metadata = CORNER_SW; } } // SOUTH of placed track else if (searchTrack(x, y, z - 1, map, meta) != 2 && isStartPiece(x, y, z - 1, map)) { LOG(INFO, "Tracks", "SOUTH"); metadata = FLAT_NS; elevoftrack = searchTrack(x, y, z - 1, map, meta); // Elevation of found track if (meta == FLAT_EW && elevoftrack == 0) { ServerInstance->map(map)->setBlock(x, y, z - 1, (char)newblock, FLAT_NS); ServerInstance->map(map)->sendBlockChange(x, y, z - 1, (char)newblock, FLAT_NS); } // Rising & falling tracks if (isTrack(x, y + 1, z - 1, map, meta) && isStartPiece(x, y + 1, z - 1, map)) // Rising & falling tracks { metadata = ASCEND_S; } else if (isTrack(x, y - 1, z - 1, map, meta) && isStartPiece(x, y - 1, z - 1, map)) // Rising & falling tracks { ServerInstance->map(map)->setBlock(x, y - 1, z - 1, (char)newblock, ASCEND_N); ServerInstance->map(map)->sendBlockChange(x, y - 1, z - 1, (char)newblock, ASCEND_N); } // Change previous track, Turns if (searchTrack(x - 1, y, z - 1, map, meta) != 2 && isStartPiece(x, y, z - 1, map) && meta != FLAT_NS) // Left { ServerInstance->map(map)->setBlock(x, y + elevoftrack, z - 1, (char)newblock, CORNER_SW); ServerInstance->map(map)->sendBlockChange(x, y + elevoftrack, z - 1, (char)newblock, CORNER_SW); } if (searchTrack(x + 1, y, z - 1, map, meta) != 2 && isStartPiece(x, y, z - 1, map) && meta != FLAT_NS) // Right { ServerInstance->map(map)->setBlock(x, y + elevoftrack, z - 1, (char)newblock, CORNER_SE); ServerInstance->map(map)->sendBlockChange(x, y + elevoftrack, z - 1, (char)newblock, CORNER_SE); } // Make track you just placed a corner if (isTrack(x + 1, y, z, map, meta) && isStartPiece(x + 1, y, z, map)) { metadata = CORNER_NE; } if (isTrack(x - 1, y, z, map, meta) && isStartPiece(x - 1, y, z, map)) { metadata = CORNER_NW; } } // NORTH of placed track else if (searchTrack(x, y, z + 1, map, meta) != 2 && isStartPiece(x, y, z + 1, map)) { LOG(INFO, "Tracks", "NORTH"); metadata = FLAT_NS; elevoftrack = searchTrack(x, y, z + 1, map, meta); if (meta == FLAT_EW && elevoftrack == 0) { ServerInstance->map(map)->setBlock(x, y, z + 1, (char)newblock, FLAT_NS); ServerInstance->map(map)->sendBlockChange(x, y, z + 1, (char)newblock, FLAT_NS); } // Rising & falling tracks if (isTrack(x, y - 1, z + 1, map, meta) && isStartPiece(x, y - 1, z + 1, map)) // Rising & falling tracks { ServerInstance->map(map)->setBlock(x, y - 1, z + 1, (char)newblock, ASCEND_S); ServerInstance->map(map)->sendBlockChange(x, y - 1, z + 1, (char)newblock, ASCEND_S); } else if (isTrack(x, y + 1, z + 1, map, meta) && isStartPiece(x, y + 1, z + 1, map)) // Rising & falling tracks { metadata = ASCEND_N; } // Change previous track, Turns if (searchTrack(x + 1, y, z + 1, map, meta) != 2 && isStartPiece(x, y, z + 1, map) && meta != FLAT_NS) // Left { ServerInstance->map(map)->setBlock(x, y + elevoftrack, z + 1, (char)newblock, CORNER_NE); ServerInstance->map(map)->sendBlockChange(x, y + elevoftrack, z + 1, (char)newblock, CORNER_NE); } if (searchTrack(x - 1, y, z + 1, map, meta) != 2 && isStartPiece(x, y, z + 1, map) && meta != FLAT_NS) // Right { ServerInstance->map(map)->setBlock(x, y + elevoftrack, z + 1, (char)newblock, CORNER_NW); ServerInstance->map(map)->sendBlockChange(x, y + elevoftrack, z + 1, (char)newblock, CORNER_NW); } // Make track you just placed a corner if (isTrack(x + 1, y, z, map, meta) && isStartPiece(x + 1, y, z, map)) { metadata = CORNER_SE; } if (isTrack(x - 1, y, z, map, meta) && isStartPiece(x - 1, y, z, map)) { metadata = CORNER_SW; } } ServerInstance->map(map)->setBlock(x, y, z, (char)newblock, metadata); ServerInstance->map(map)->sendBlockChange(x, y, z, (char)newblock, metadata); return false; }