summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Block.cpp32
-rw-r--r--src/Block.hpp9
-rw-r--r--src/Plugin.cpp8
3 files changed, 35 insertions, 14 deletions
diff --git a/src/Block.cpp b/src/Block.cpp
index 85870f6..8af5a4b 100644
--- a/src/Block.cpp
+++ b/src/Block.cpp
@@ -1,25 +1,29 @@
#include "Block.hpp"
#include <map>
-#include <vector>
-#include "Plugin.hpp"
+static std::map<BlockId, BlockInfo> blocks;
+static std::map<BlockId, LiquidInfo> liquids;
-static std::vector<BlockInfo> blocks;
-static std::map<BlockId, size_t> staticBlockInfo;
-
-BlockInfo WTFBlock{ true, "", "" };
+static BlockInfo UnknownBlock{ true, "", "" };
+static LiquidInfo UnknownLiquid{ "", "" };
void RegisterStaticBlockInfo(BlockId blockId, BlockInfo blockInfo) {
- //NOTE: It can be made thread-safe by using atomic incrementer
- staticBlockInfo[blockId] = blocks.size();
- blocks.push_back(blockInfo);
+ blocks.emplace(blockId, blockInfo);
+}
+
+void RegisterStaticLiquidInfo(BlockId blockId, LiquidInfo liquidInfo) {
+ liquids[blockId] = liquidInfo;
+ for (uint8_t i = 0; i < 16; i++)
+ blocks.emplace(BlockId{ blockId.id, i }, BlockInfo{ true, "@liquid", liquidInfo.stillTexture });
}
BlockInfo* GetBlockInfo(BlockId blockId) {
- auto it = staticBlockInfo.find(blockId);
- if (it != staticBlockInfo.end())
- return &blocks.data()[it->second];
- else
- return &WTFBlock;
+ auto it = blocks.find(blockId);
+ return it != blocks.end() ? &it->second : &UnknownBlock;
+}
+
+const LiquidInfo& GetBlockLiquidInfo(BlockId blockId) {
+ auto it = liquids.find(blockId);
+ return it != liquids.end() ? it->second : UnknownLiquid;
}
diff --git a/src/Block.hpp b/src/Block.hpp
index 0fd0e89..535ae68 100644
--- a/src/Block.hpp
+++ b/src/Block.hpp
@@ -47,6 +47,15 @@ struct BlockInfo {
std::string variant;
};
+struct LiquidInfo {
+ std::string flowTexture;
+ std::string stillTexture;
+};
+
void RegisterStaticBlockInfo(BlockId blockId, BlockInfo blockInfo);
+void RegisterStaticLiquidInfo(BlockId blockId, LiquidInfo liquidInfo);
+
BlockInfo* GetBlockInfo(BlockId blockId);
+
+const LiquidInfo& GetBlockLiquidInfo(BlockId blockId);
diff --git a/src/Plugin.cpp b/src/Plugin.cpp
index 3e06b0c..7a3b716 100644
--- a/src/Plugin.cpp
+++ b/src/Plugin.cpp
@@ -78,6 +78,13 @@ namespace PluginApi {
});
}
+ void RegisterLiquid(BlockId blockId, std::string flowTexture, std::string stillTexture) {
+ RegisterStaticLiquidInfo(blockId, LiquidInfo{
+ flowTexture,
+ stillTexture
+ });
+ }
+
void RegisterDimension(int dimId, Dimension dim) {
RegisterNewDimension(dimId, dim);
}
@@ -286,6 +293,7 @@ void PluginSystem::Init() {
apiTable["LogError"] = PluginApi::LogError;
apiTable["GetGameState"] = PluginApi::GetGameState;
apiTable["RegisterBlock"] = PluginApi::RegisterBlock;
+ apiTable["RegisterLiquid"] = PluginApi::RegisterLiquid;
apiTable["RegisterDimension"] = PluginApi::RegisterDimension;
apiTable["ConnectToServer"] = PluginApi::ConnectToServer;
apiTable["Exit"] = PluginApi::Exit;