Skip to content

Commit

Permalink
feat: #1011 (#1105)
Browse files Browse the repository at this point in the history
* Feat #1011

* Update ScriptEngine/src/api/PlayerAPI.cpp

Co-authored-by: Jasonzyt <[email protected]>

* Update PlayerAPI.cpp

---------

Co-authored-by: Jasonzyt <[email protected]>
  • Loading branch information
KobeBryant114514 and Jasonzyt authored Mar 4, 2023
1 parent 380123e commit 2aca737
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
61 changes: 60 additions & 1 deletion ScriptEngine/src/api/PlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ ClassDefine<PlayerClass> PlayerClassBuilder =
.instanceFunction("getBiomeId", &PlayerClass::getBiomeId)
.instanceFunction("getBiomeName", &PlayerClass::getBiomeName)

.instanceFunction("getAllEffects", &PlayerClass::getAllEffects)
.instanceFunction("addEffect", &PlayerClass::addEffect)
.instanceFunction("removeEffect", &PlayerClass::removeEffect)

.instanceFunction("sendSimpleForm", &PlayerClass::sendSimpleForm)
.instanceFunction("sendModalForm", &PlayerClass::sendModalForm)
.instanceFunction("sendCustomForm", &PlayerClass::sendCustomForm)
Expand Down Expand Up @@ -3153,4 +3157,59 @@ Local<Value> PlayerClass::getBiomeName() {
return String::newString(bio->getName());
}
CATCH("Fail in getBiomeName!");
}
}

Local<Value> PlayerClass::getAllEffects() {
try {
Player* player = get();
if (!player) {
return Local<Value>();
}
auto effects = player->getAllEffects();
if (effects.size() == 0) {
return Local<Value>();
}
Local<Array> effectList = Array::newArray();
for (auto effect : effects)
effectList.add(Number::newNumber((int)effect.getId()));
return effectList;
}
CATCH("Fail in getAllEffects!")
}

Local<Value> PlayerClass::addEffect(const Arguments& args) {
CHECK_ARGS_COUNT(args, 4);
CHECK_ARG_TYPE(args[0], ValueKind::kNumber);
CHECK_ARG_TYPE(args[1], ValueKind::kNumber);
CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
CHECK_ARG_TYPE(args[3], ValueKind::kBoolean);
try {
Player* player = get();
if (!player) {
return Boolean::newBoolean(false);
}
unsigned int id = args[0].asNumber().toInt32();
int tick = args[1].asNumber().toInt32();
int level = args[2].asNumber().toInt32();
bool showParticles = args[3].asBoolean().value();
MobEffectInstance effect = MobEffectInstance(id, tick, level, false, showParticles, false);
player->addEffect(effect);
return Boolean::newBoolean(true);
}
CATCH("Fail in addEffect!");
}

Local<Value> PlayerClass::removeEffect(const Arguments& args) {
CHECK_ARGS_COUNT(args, 1);
CHECK_ARG_TYPE(args[0], ValueKind::kNumber);
try {
Player* player = get();
if (!player) {
return Boolean::newBoolean(false);
}
int id = args[0].asNumber().toInt32();
player->removeEffect(id);
return Boolean::newBoolean(true);
}
CATCH("Fail in removeEffect!");
}
4 changes: 4 additions & 0 deletions ScriptEngine/src/api/PlayerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ class PlayerClass : public ScriptClass {
Local<Value> isSimulatedPlayer(const Arguments& args);
Local<Value> quickEvalMolangScript(const Arguments& args);

Local<Value> getAllEffects();
Local<Value> addEffect(const Arguments& args);
Local<Value> removeEffect(const Arguments& args);

// LLMoney

Local<Value> getMoney(const Arguments& args);
Expand Down

0 comments on commit 2aca737

Please sign in to comment.