File tree Expand file tree Collapse file tree 9 files changed +30
-47
lines changed
Expand file tree Collapse file tree 9 files changed +30
-47
lines changed Original file line number Diff line number Diff line change 1111#include " mc/world/actor/player/Player.h"
1212#include " mc/world/level/dimension/Dimension.h"
1313
14- #include < magic_enum.hpp>
15-
1614// ////////////////// Class Definition ////////////////////
1715ClassDefine<void > OriginTypeStaticBuilder = EnumDefineBuilder<CommandOriginType>::build(" OriginType" );
1816
Original file line number Diff line number Diff line change @@ -34,23 +34,21 @@ ClassDefine<DeviceClass> DeviceClassBuilder = defineClass<DeviceClass>("LLSE_Dev
3434// ////////////////// Classes ////////////////////
3535
3636// 生成函数
37- Local<Object> DeviceClass::newDevice (Player* player) {
38- auto newp = new DeviceClass (player);
39- return newp->getScriptObject ();
40- }
41-
42- // 成员函数
43- void DeviceClass::setPlayer (Player* player) {
37+ DeviceClass::DeviceClass (Player* player) : ScriptClass(ScriptClass::ConstructFromCpp<DeviceClass>{}) {
4438 try {
4539 if (player) {
4640 mWeakEntity = player->getWeakEntity ();
4741 mValid = true ;
4842 }
49- } catch (...) {
50- mValid = false ;
51- }
43+ } catch (...) {}
5244}
5345
46+ Local<Object> DeviceClass::newDevice (Player* player) {
47+ auto newp = new DeviceClass (player);
48+ return newp->getScriptObject ();
49+ }
50+
51+ // 成员函数
5452Player* DeviceClass::getPlayer () {
5553 if (mValid ) {
5654 return mWeakEntity .tryUnwrap <Player>().as_ptr ();
Original file line number Diff line number Diff line change @@ -11,11 +11,8 @@ class DeviceClass : public ScriptClass {
1111 bool mValid ;
1212
1313public:
14- explicit DeviceClass (Player* player) : ScriptClass(ScriptClass::ConstructFromCpp<DeviceClass>{}) {
15- setPlayer (player);
16- }
14+ explicit DeviceClass (Player* player);
1715
18- void setPlayer (Player* player);
1916 Player* getPlayer ();
2017
2118 static Local<Object> newDevice (Player* player);
Original file line number Diff line number Diff line change @@ -161,6 +161,15 @@ ClassDefine<EntityClass> EntityClassBuilder =
161161
162162// ////////////////// Classes ////////////////////
163163
164+ EntityClass::EntityClass (Actor* actor) : ScriptClass(ScriptClass::ConstructFromCpp<EntityClass>{}) {
165+ try {
166+ if (actor) {
167+ mWeakEntity = actor->getWeakEntity ();
168+ mValid = true ;
169+ }
170+ } catch (...) {}
171+ }
172+
164173// 生成函数
165174Local<Object> EntityClass::newEntity (Actor* actor) {
166175 auto newp = new EntityClass (actor);
@@ -180,17 +189,6 @@ Actor* EntityClass::tryExtractActor(Local<Value> v) {
180189}
181190
182191// 成员函数
183- void EntityClass::set (Actor* actor) {
184- try {
185- if (actor) {
186- mWeakEntity = actor->getWeakEntity ();
187- mValid = true ;
188- }
189- } catch (...) {
190- mValid = false ;
191- }
192- }
193-
194192Actor* EntityClass::get () {
195193 if (mValid ) {
196194 return mWeakEntity .tryUnwrap <Actor>().as_ptr ();
Original file line number Diff line number Diff line change 11#pragma once
22#include " api/APIHelp.h"
3- #include " mc/legacy/ActorRuntimeID.h"
43#include " mc/deps/ecs/WeakEntityRef.h"
4+ #include " mc/legacy/ActorRuntimeID.h"
55
66// ////////////////// Classes ////////////////////
77class Actor ;
88class EntityClass : public ScriptClass {
99private:
1010 WeakRef<EntityContext> mWeakEntity ;
11- bool mValid ;
11+ bool mValid = false ;
1212
1313public:
14- explicit EntityClass (Actor* actor) : ScriptClass(ScriptClass::ConstructFromCpp<EntityClass>{}) { set (actor); }
14+ explicit EntityClass (Actor* actor);
1515
16- void set (Actor* actor);
1716 Actor* get ();
1817
1918 static Local<Object> newEntity (Actor* actor);
Original file line number Diff line number Diff line change 55#include " mc/nbt/ByteArrayTag.h"
66#include " mc/nbt/ByteTag.h"
77#include " mc/nbt/CompoundTag.h"
8- #include " mc/nbt/CompoundTagVariant.h"
98#include " mc/nbt/DoubleTag.h"
109#include " mc/nbt/EndTag.h"
1110#include " mc/nbt/FloatTag.h"
1918#include < memory>
2019#include < string>
2120#include < string_view>
22- #include < vector>
2321
2422using magic_enum::enum_cast;
2523
Original file line number Diff line number Diff line change @@ -340,7 +340,14 @@ ClassDefine<PlayerClass> PlayerClassBuilder =
340340// ////////////////// Classes ////////////////////
341341
342342// 生成函数
343- PlayerClass::PlayerClass (Player* player) : ScriptClass(ScriptClass::ConstructFromCpp<PlayerClass>{}) { set (player); }
343+ PlayerClass::PlayerClass (Player* player) : ScriptClass(ScriptClass::ConstructFromCpp<PlayerClass>{}) {
344+ try {
345+ if (player) {
346+ mWeakEntity = player->getWeakEntity ();
347+ mValid = true ;
348+ }
349+ } catch (...) {}
350+ }
344351
345352Local<Object> PlayerClass::newPlayer (Player* player) {
346353 auto newp = new PlayerClass (player);
@@ -742,17 +749,6 @@ Local<Value> McClass::broadcast(const Arguments& args) {
742749}
743750
744751// 成员函数
745- void PlayerClass::set (Player* player) {
746- try {
747- if (player) {
748- mWeakEntity = player->getWeakEntity ();
749- mValid = true ;
750- }
751- } catch (...) {
752- mValid = false ;
753- }
754- }
755-
756752Player* PlayerClass::get () {
757753 if (mValid ) {
758754 return mWeakEntity .tryUnwrap <Player>().as_ptr ();
Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ class PlayerClass : public ScriptClass {
1515public:
1616 explicit PlayerClass (Player* player);
1717
18- void set (Player* player);
1918 Player* get ();
2019 SimulatedPlayer* asSimulatedPlayer ();
2120
Original file line number Diff line number Diff line change @@ -9,5 +9,5 @@ class AttributeHelper {
99 static void setCurrentValue (MutableAttributeWithContext& attribute, float value);
1010 static void setMaxValue (MutableAttributeWithContext& attribute, float value);
1111 static void setDefaultValue (MutableAttributeWithContext& attribute, float value);
12- }
12+ };
1313} // namespace lse::api
You can’t perform that action at this time.
0 commit comments