forked from cuberite/cuberite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added temporary block type mapping for 1.13+ protocols.
- Loading branch information
Showing
16 changed files
with
375 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
Cuberite | ||
Plugins | ||
Prefabs | ||
Protocol | ||
webadmin | ||
BACKERS | ||
brewing.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ Cuberite.exe | |
*.dll | ||
Plugins | ||
Prefabs | ||
Protocol | ||
webadmin | ||
BACKERS | ||
brewing.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#include "Globals.h" | ||
#include "ProtocolPalettes.h" | ||
#include "../BlockTypePalette.h" | ||
|
||
|
||
|
||
|
||
|
||
void ProtocolPalettes::load(const AString & aProtocolFolder) | ||
{ | ||
auto contents = cFile::GetFolderContents(aProtocolFolder); | ||
for (const auto & c: contents) | ||
{ | ||
auto fullName = aProtocolFolder + cFile::PathSeparator() + c; | ||
if (cFile::IsFolder(fullName)) | ||
{ | ||
loadSingleVersion(c, fullName); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
std::shared_ptr<const BlockTypePalette> ProtocolPalettes::blockTypePalette(const AString & aProtocolVersion) const | ||
{ | ||
cCSLock lock(mCS); | ||
auto itr = mPalettes.find(aProtocolVersion); | ||
if (itr == mPalettes.end()) | ||
{ | ||
return nullptr; | ||
} | ||
return itr->second.mBlockTypePalette; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
std::vector<AString> ProtocolPalettes::protocolVersions() const | ||
{ | ||
cCSLock lock(mCS); | ||
|
||
std::vector<AString> res; | ||
for (const auto & p: mPalettes) | ||
{ | ||
res.push_back(p.first); | ||
} | ||
return res; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
void ProtocolPalettes::loadSingleVersion(const AString & aProtocolVersion, const AString & aFolder) | ||
{ | ||
// Get the file list, sort by name | ||
auto contents = cFile::GetFolderContents(aFolder); | ||
std::sort(contents.begin(), contents.end()); | ||
|
||
// Load files into the palettes: | ||
cCSLock lock(mCS); | ||
auto & pal = mPalettes[aProtocolVersion]; | ||
for (const auto & c: contents) | ||
{ | ||
if (c.length() < 8) | ||
{ | ||
// Name too short, can't have the ".btp.txt" etc. suffix | ||
continue; | ||
} | ||
auto fnam = aFolder + cFile::PathSeparator() + c; | ||
if (!cFile::IsFile(fnam)) | ||
{ | ||
continue; | ||
} | ||
auto fileType = c.substr(c.length() - 8); | ||
if ((fileType == ".btp.txt") || (c == "blocks.json")) | ||
{ | ||
try | ||
{ | ||
pal.mBlockTypePalette->loadFromString(cFile::ReadWholeFile(fnam)); | ||
} | ||
catch (...) | ||
{ | ||
// Ignore silently | ||
} | ||
} | ||
else if ((fileType == ".itp.txt") || (c == "items.json")) | ||
{ | ||
// TODO: Load item type palette | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// ProtocolPalettes::Palettes: | ||
|
||
ProtocolPalettes::Palettes::Palettes(): | ||
mBlockTypePalette(new BlockTypePalette) | ||
{ | ||
} |
Oops, something went wrong.