summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-12-27 18:49:09 +0100
committerLaG1924 <lag1924@gmail.com>2021-12-27 18:49:09 +0100
commitbb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c (patch)
treea98514dcbd52cabbe28344ea3e9dc5636cfe9af0
parentRemoved previous liquids implementation (diff)
downloadAltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar
AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar.gz
AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar.bz2
AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar.lz
AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar.xz
AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar.zst
AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.zip
-rw-r--r--cwd/assets/altcraft/scripts/blocks.lua6
-rw-r--r--src/Block.cpp32
-rw-r--r--src/Block.hpp9
-rw-r--r--src/Plugin.cpp8
4 files changed, 41 insertions, 14 deletions
diff --git a/cwd/assets/altcraft/scripts/blocks.lua b/cwd/assets/altcraft/scripts/blocks.lua
index 72a1599..dde4b57 100644
--- a/cwd/assets/altcraft/scripts/blocks.lua
+++ b/cwd/assets/altcraft/scripts/blocks.lua
@@ -33,6 +33,12 @@ local function RegisterBlocks()
AC.RegisterBlock(BlockId.new(7,0), true, "bedrock", "normal")
+ AC.RegisterLiquid(BlockId.new(8,0), "blocks/water_flow", "blocks/water_still")
+ AC.RegisterLiquid(BlockId.new(9,0), "blocks/water_flow", "blocks/water_still")
+
+ AC.RegisterLiquid(BlockId.new(10,0), "blocks/lava_flow", "blocks/lava_still")
+ AC.RegisterLiquid(BlockId.new(11,0), "blocks/lava_flow", "blocks/lava_still")
+
AC.RegisterBlock(BlockId.new(12,0), true, "sand", "normal")
AC.RegisterBlock(BlockId.new(12,1), true, "red_sand", "normal")
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;