Botcraft 1.21.4
Loading...
Searching...
No Matches
RecipeBookSettings.hpp
Go to the documentation of this file.
1#pragma once
2
4#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
6
7#include <map>
8#endif
9
10namespace ProtocolCraft
11{
12#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
13 enum class RecipeBookType
14 {
16 Furnace,
18 Smoker,
20 };
21#endif
22
24 {
25#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
26 public:
28 {
29 bool open = false;
30 bool filtering = false;
31 };
32 private:
34
35 std::map<RecipeBookType, TypeSettings> ReadStates(ReadIterator& iter, size_t& length) const
36 {
37 std::map<RecipeBookType, TypeSettings> output;
38
39 for (int i = 0; i < static_cast<int>(RecipeBookType::NUM_RECIPEBOOKTYPE); ++i)
40 {
41 const bool b1 = ReadData<bool>(iter, length);
42 const bool b2 = ReadData<bool>(iter, length);
43 if (b1 || b2)
44 {
45 output[static_cast<RecipeBookType>(i)] = TypeSettings{ b1, b2 };
46 }
47 }
48
49 return output;
50 }
51
52 void WriteStates(const std::map<RecipeBookType, TypeSettings>& states, WriteContainer& container) const
53 {
54 for (int i = 0; i < static_cast<int>(RecipeBookType::NUM_RECIPEBOOKTYPE); ++i)
55 {
56 TypeSettings written_values;
57 if (auto it = states.find(static_cast<RecipeBookType>(i)); it != states.end())
58 {
59 written_values = it->second;
60 }
61 WriteData<bool>(written_values.open, container);
62 WriteData<bool>(written_values.filtering, container);
63 }
64 }
65
66 std::optional<Json::Value> SerializeStates(const std::map<RecipeBookType, TypeSettings>& states) const
67 {
68 Json::Value output;
69
70 for (const auto& [k, v] : states)
71 {
72 output[std::to_string(static_cast<int>(k))] = {
73 { "open", v.open },
74 { "filtering", v.filtering }
75 };
76 }
77
78 return output;
79 }
80#endif
81
82#if PROTOCOL_VERSION < 768 /* < 1.21.2*/
83 SERIALIZED_FIELD(IsGuiOpen, bool);
84 SERIALIZED_FIELD(IsFilteringCraftable, bool);
85#endif
86#if PROTOCOL_VERSION > 356 /* > 1.12.2 */ && PROTOCOL_VERSION < 768 /* < 1.21.2*/
87 SERIALIZED_FIELD(IsFurnaceGuiOpen, bool);
88 SERIALIZED_FIELD(IsFurnaceFilteringOpen, bool);
89#endif
90#if PROTOCOL_VERSION > 736 /* > 1.16.1 */ && PROTOCOL_VERSION < 768 /* < 1.21.2*/
91 SERIALIZED_FIELD(IsBlastingFurnaceGuiOpen, bool);
92 SERIALIZED_FIELD(IsBlastingFurnaceFilteringCraftable, bool);
93 SERIALIZED_FIELD(IsSmokerGuiOpen, bool);
94 SERIALIZED_FIELD(IsSmokerFilteringCraftable, bool);
95#endif
96
97#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
99#endif
100
102 };
103}
#define SERIALIZED_FIELD(Name,...)
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45
std::optional< Json::Value > SerializeStates(const std::map< RecipeBookType, TypeSettings > &states) const
SERIALIZED_FIELD(States, Internal::CustomType< std::map< RecipeBookType, TypeSettings >, &THIS::ReadStates, &THIS::WriteStates, &THIS::SerializeStates >)
std::map< RecipeBookType, TypeSettings > ReadStates(ReadIterator &iter, size_t &length) const
void WriteStates(const std::map< RecipeBookType, TypeSettings > &states, WriteContainer &container) const
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator