Skip to content

Commit

Permalink
Added message for snapshot support
Browse files Browse the repository at this point in the history
  • Loading branch information
spoutn1k committed Nov 1, 2021
1 parent b752954 commit e3ac116
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PROJECT(mcmap LANGUAGES CXX VERSION 3.0.1)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

OPTION(DEBUG_BUILD "Debug build" OFF)
OPTION(SNAPSHOT "Support snapshot versions" OFF)

IF(STATIC_BUILD)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
Expand Down Expand Up @@ -35,6 +36,10 @@ ELSE()
ADD_DEFINITIONS(-O3)
ENDIF()

IF(SNAPSHOT)
ADD_DEFINITIONS(-DSNAPSHOT_SUPPORT)
ENDIF()

IF(WIN32)
# 100M stack + 3.5G heap on windows
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:104857600 /HEAP:3758096384")
Expand Down
6 changes: 6 additions & 0 deletions src/chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace mcmap {

namespace versions {
namespace assert_versions {
#ifdef SNAPSHOT_SUPPORT
bool v2844(const nbt::NBT &chunk) {
// Snapshot 21w43a
return chunk.contains("sections") // No sections mean no blocks
Expand All @@ -19,6 +20,7 @@ bool v2840(const nbt::NBT &chunk) {
&& chunk["Level"].contains("Status") // Ensure the status is `full`
&& chunk["Level"]["Status"].get<nbt::NBT::tag_string_t>() == "full";
}
#endif

bool v1976(const nbt::NBT &chunk) {
// From 1.14 onwards
Expand Down Expand Up @@ -55,13 +57,17 @@ nbt::NBT catchall(const nbt::NBT &chunk) {
} // namespace sections_versions

std::map<int, std::function<bool(const nbt::NBT &)>> assert = {
#ifdef SNAPSHOT_SUPPORT
{2844, assert_versions::v2844}, {2840, assert_versions::v2840},
#endif
{1976, assert_versions::v1976}, {1628, assert_versions::v1628},
{0, assert_versions::catchall},
};

std::map<int, std::function<nbt::NBT(const nbt::NBT &)>> sections = {
#ifdef SNAPSHOT_SUPPORT
{2844, sections_versions::v2844},
#endif
{1628, sections_versions::v1628},
{0, sections_versions::catchall},
};
Expand Down
8 changes: 7 additions & 1 deletion src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ SETUP_LOGGER
#define SUCCESS 0
#define ERROR 1

#ifdef SNAPSHOT_SUPPORT
#define SNAPSHOT " Snapshots enabled "
#else
#define SNAPSHOT ""
#endif

void printHelp(char *binary) {
logger::info(
"Usage: {} <options> WORLDPATH\n\n"
Expand Down Expand Up @@ -54,7 +60,7 @@ int main(int argc, char **argv) {
logger::info("{}", json(colors).dump());
return 0;
} else {
logger::info(VERSION " {}bit (" COMMENT ")\n",
logger::info(VERSION " {}bit (" COMMENT ")" SNAPSHOT "\n",
8 * static_cast<int>(sizeof(size_t)));
}

Expand Down
4 changes: 4 additions & 0 deletions src/section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void v2534(Section *target, const nbt::NBT &raw_section) {
}
}

#ifdef SNAPSHOT_SUPPORT
void v2840(Section *target, const nbt::NBT &raw_section) {
if (raw_section.contains("block_states") &&
raw_section["block_states"].contains("data") &&
Expand All @@ -165,14 +166,17 @@ void v2840(Section *target, const nbt::NBT &raw_section) {
block_states_versions::post116(blockBitLength, blockStates, target->blocks);
}
}
#endif

void catchall(Section *, const nbt::NBT &) {
logger::deep_debug("Unsupported DataVersion\n");
}
} // namespace init_versions

std::map<int, std::function<void(Section *, const nbt::NBT &)>> init = {
#ifdef SNAPSHOT_SUPPORT
{2840, init_versions::v2840},
#endif
{2534, init_versions::v2534},
{1628, init_versions::v1628},
{0, init_versions::catchall},
Expand Down

0 comments on commit e3ac116

Please sign in to comment.