summaryrefslogtreecommitdiffstats
path: root/src/Protocol/ProtocolBlockTypePalette.h
diff options
context:
space:
mode:
authorE14 <1640391+E14@users.noreply.github.com>2019-09-22 22:57:54 +0200
committerMattes D <github@xoft.cz>2019-09-22 22:57:54 +0200
commitd1c95742ddd83899bb35051de9d731d38aba80a4 (patch)
tree74be95b8f98def76a47c5fc81cca59a12bee4c00 /src/Protocol/ProtocolBlockTypePalette.h
parentAdded missing closing } in message output (diff)
downloadcuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar
cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar.gz
cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar.bz2
cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar.lz
cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar.xz
cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.tar.zst
cuberite-d1c95742ddd83899bb35051de9d731d38aba80a4.zip
Diffstat (limited to '')
-rw-r--r--src/Protocol/ProtocolBlockTypePalette.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Protocol/ProtocolBlockTypePalette.h b/src/Protocol/ProtocolBlockTypePalette.h
new file mode 100644
index 000000000..fb156cfd5
--- /dev/null
+++ b/src/Protocol/ProtocolBlockTypePalette.h
@@ -0,0 +1,40 @@
+#pragma once
+#include <unordered_map>
+#include "../BlockState.h"
+
+
+/** Parses and holds a collection of block types and their possible states
+together with their corresponding Id within the Minecraft network protocol. */
+class ProtocolBlockTypePalette
+{
+public:
+ static const UInt32 NOT_FOUND = UINT32_MAX;
+
+ /** Create a new empty instance. */
+ ProtocolBlockTypePalette();
+
+ /** Loads the palette from a string.
+ See loadFromStream() for further details. */
+ bool loadFromString(const AString & aMapping);
+
+ /** Loads the palette from an input stream.
+ Returns `true` on success, `false` otherwise. Sucessive calls to this method
+ will _add_ data to the palette. If duplicate keys are encountered, they will
+ be ignored and an info message logged. */
+ bool loadFromStream(std::istream & aInputStream);
+
+ /** Returns the defined index corresponding of the given aBlockTypeName and
+ aBlockState.
+ Returns ProtocolBlockTypePalette::NOT_FOUND if the tuple is not found. */
+ UInt32 index(const AString & aBlockTypeName, const BlockState & aBlockState) const;
+
+ /** Clears the palette. */
+ void clear();
+
+
+protected:
+
+ /** The palette index. Each item in the map represents a single block state
+ palette entry. The value is the block state ID. */
+ std::unordered_map<AString, std::map<BlockState, UInt32>> mIndex;
+};