LeviLamina
Loading...
Searching...
No Matches
DataItem.h
1#pragma once
2
3#include "ll/api/base/Meta.h"
4#include "mc/_HeaderOutputPredefine.h"
5#include "mc/deps/core/math/Vec2.h"
6#include "mc/deps/core/math/Vec3.h"
7#include "mc/nbt/CompoundTag.h"
8#include "mc/world/actor/ActorDataIDs.h"
9#include "mc/world/level/BlockPos.h"
10
11// auto generated inclusion list
12#include "mc/world/actor/DataItemType.h"
13
14class DataItem {
15public:
16 // DataItem inner types define
17 using ID = ushort;
18
19public:
21
22public:
23 template <typename T>
24 requires(DataItem::TypeList::contains<T>)
25 [[nodiscard]] constexpr optional_ref<T const> getData() const;
26 template <typename T>
27 requires(DataItem::TypeList::contains<T>)
28 [[nodiscard]] constexpr optional_ref<T> getData();
29 template <typename T>
30 requires(DataItem::TypeList::contains<std::remove_cvref_t<T>>)
31 constexpr bool setData(T&& value);
32
33 template <typename T>
34 requires(DataItem::TypeList::contains<std::remove_cvref_t<T>>)
35 [[nodiscard]] static LL_CONSTEXPR23 std::unique_ptr<DataItem> create(ushort key, T&& value);
36 [[nodiscard]] static LL_CONSTEXPR23 std::unique_ptr<DataItem> create(ushort key, bool value) {
37 return create(key, (schar)value);
38 }
39 template <typename T>
40 requires(DataItem::TypeList::contains<std::remove_cvref_t<T>>)
41 [[nodiscard]] static LL_CONSTEXPR23 std::unique_ptr<DataItem> create(::ActorDataIDs key, T&& value) {
42 return create(static_cast<std::underlying_type_t<::ActorDataIDs>>(key), std::forward<T>(value));
43 }
44 [[nodiscard]] static LL_CONSTEXPR23 std::unique_ptr<DataItem> create(::ActorDataIDs key, bool value) {
45 return create(key, (schar)value);
46 }
47
48protected:
49 DataItem() = default;
50
51public:
52 // virtual functions
53 // NOLINTBEGIN
54 // vIndex: 0
55 virtual ~DataItem() = default;
56
57 // vIndex: 1
58 virtual ushort getId() const = 0;
59
60 // vIndex: 2
61 virtual ::DataItemType getType() const = 0;
62
63 // vIndex: 3
64 virtual bool isDataEqual(::DataItem const&) const = 0;
65
66 // vIndex: 4
67 virtual ::std::unique_ptr<::DataItem> clone() const = 0;
68 // NOLINTEND
69
70public:
71 // destructor thunk
72 // NOLINTBEGIN
73
74 // NOLINTEND
75
76public:
77 // virtual function thunks
78 // NOLINTBEGIN
79
80 // NOLINTEND
81};
82
83template <typename T>
84 requires(DataItem::TypeList::contains<T>)
85class DataItem2 : public DataItem {
86public:
87 ::DataItemType mType;
88 ::DataItem::ID mId;
89 T mValue;
90
91public:
92 [[nodiscard]] ::DataItem::ID getId() const override;
93
94 [[nodiscard]] ::DataItemType getType() const override;
95
96 [[nodiscard]] bool isDataEqual(::DataItem const&) const override;
97
98 [[nodiscard]] ::std::unique_ptr<::DataItem> clone() const override;
99
100public:
101 [[nodiscard]] constexpr T const& value() const { return mValue; }
102
103 [[nodiscard]] constexpr T& value() { return mValue; }
104
105 [[nodiscard]] constexpr explicit operator T const&() const { return mValue; }
106
107 [[nodiscard]] constexpr explicit operator T&() { return mValue; }
108
109 template <class T2>
110 constexpr void setData(T2&& value) {
111 mValue = value;
112 }
113 template <class T2>
114 constexpr DataItem2<T>& operator=(T2&& value) {
115 setData(value);
116 return *this;
117 }
118 template <class... Args>
119 constexpr explicit DataItem2(::DataItem::ID key, Args&&... args)
120 : mType((::DataItemType)DataItem::TypeList::index<T>),
121 mId(key),
122 mValue(std::forward<Args>(args)...) {}
123};
124
125template <typename T>
126 requires(DataItem::TypeList::contains<T>)
127constexpr optional_ref<T const> DataItem::getData() const {
128 if (getType() == (::DataItemType)TypeList::index<T>) return ((DataItem2<T>*)this)->mValue;
129 return nullptr;
130}
131
132template <typename T>
133 requires(DataItem::TypeList::contains<T>)
134constexpr optional_ref<T> DataItem::getData() {
135 if (getType() == (::DataItemType)TypeList::index<T>) return ((DataItem2<T>*)this)->mValue;
136 return nullptr;
137}
138
139template <typename T>
140 requires(DataItem::TypeList::contains<std::remove_cvref_t<T>>)
141constexpr bool DataItem::setData(T&& value) {
142 if (getType() == (::DataItemType)TypeList::index<T>) return false;
143 ((DataItem2<T>*)this)->setData(std::forward<T>(value));
144 return true;
145}
146
147template <typename T>
148 requires(DataItem::TypeList::contains<std::remove_cvref_t<T>>)
149LL_CONSTEXPR23 std::unique_ptr<DataItem> DataItem::create(::DataItem::ID key, T&& value) {
150 return std::make_unique<DataItem2<std::remove_cvref_t<T>>>(key, std::forward<T>(value));
151}
Definition DataItem.h:85
Definition DataItem.h:14
Definition Meta.h:197
Definition optional_ref.h:10
STL namespace.