Skip to content

Commit b1b29d1

Browse files
committed
fix: fix some PlayerAPI
1 parent 7d28ac4 commit b1b29d1

File tree

6 files changed

+291
-171
lines changed

6 files changed

+291
-171
lines changed

src/legacy/api/EntityAPI.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "api/PlayerAPI.h"
1111
#include "ll/api/memory/Memory.h"
1212
#include "ll/api/service/Bedrock.h"
13+
#include "lse/api/AttributeHelper.h"
1314
#include "lse/api/MoreGlobal.h"
1415
#include "mc/deps/core/math/Vec2.h"
1516
#include "mc/deps/shared_types/legacy/actor/ActorDamageCause.h"
@@ -24,7 +25,6 @@
2425
#include "mc/nbt/CompoundTag.h"
2526
#include "mc/server/commands/CommandUtils.h"
2627
#include "mc/util/BlockUtils.h"
27-
#include "mc/util/IDType.h"
2828
#include "mc/world/SimpleContainer.h"
2929
#include "mc/world/actor/ActorDamageByActorSource.h"
3030
#include "mc/world/actor/ActorDamageSource.h"
@@ -37,9 +37,7 @@
3737
#include "mc/world/actor/provider/ActorAttribute.h"
3838
#include "mc/world/actor/provider/ActorEquipment.h"
3939
#include "mc/world/actor/provider/SynchedActorDataAccess.h"
40-
#include "mc/world/attribute/AttributeInstance.h"
4140
#include "mc/world/attribute/AttributeModificationContext.h"
42-
#include "mc/world/attribute/BaseAttributeMap.h"
4341
#include "mc/world/attribute/MutableAttributeWithContext.h"
4442
#include "mc/world/attribute/SharedAttributes.h"
4543
#include "mc/world/effect/EffectDuration.h"
@@ -58,6 +56,7 @@
5856
#include <climits>
5957
#include <memory>
6058

59+
using lse::api::AttributeHelper;
6160
using magic_enum::enum_integer;
6261

6362
//////////////////// Class Definition ////////////////////
@@ -1019,12 +1018,6 @@ Local<Value> EntityClass::heal(const Arguments& args) {
10191018
CATCH("Fail in heal!");
10201019
}
10211020

1022-
void SetAttributeCurrentValue(MutableAttributeWithContext& attribute, float value) {
1023-
auto& instance = attribute.mInstance;
1024-
instance->mCurrentValue = value;
1025-
attribute.mContext->mAttributeMap->_onAttributeModified(*instance);
1026-
}
1027-
10281021
Local<Value> EntityClass::setHealth(const Arguments& args) {
10291022
CHECK_ARGS_COUNT(args, 1);
10301023
CHECK_ARG_TYPE(args[0], ValueKind::kNumber);
@@ -1034,7 +1027,7 @@ Local<Value> EntityClass::setHealth(const Arguments& args) {
10341027
if (!entity) return Local<Value>();
10351028

10361029
MutableAttributeWithContext attribute = entity->getMutableAttribute(SharedAttributes::HEALTH());
1037-
SetAttributeCurrentValue(attribute, args[0].asNumber().toFloat());
1030+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
10381031
return Boolean::newBoolean(true);
10391032
}
10401033
CATCH("Fail in setHealth!");
@@ -1049,7 +1042,7 @@ Local<Value> EntityClass::setAbsorption(const Arguments& args) {
10491042
if (!entity) return Local<Value>();
10501043

10511044
MutableAttributeWithContext attribute = entity->getMutableAttribute(SharedAttributes::ABSORPTION());
1052-
SetAttributeCurrentValue(attribute, args[0].asNumber().toFloat());
1045+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
10531046

10541047
return Boolean::newBoolean(true);
10551048
}
@@ -1065,7 +1058,7 @@ Local<Value> EntityClass::setAttackDamage(const Arguments& args) {
10651058
if (!entity) return Local<Value>();
10661059

10671060
MutableAttributeWithContext attribute = entity->getMutableAttribute(SharedAttributes::ATTACK_DAMAGE());
1068-
SetAttributeCurrentValue(attribute, args[0].asNumber().toFloat());
1061+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
10691062

10701063
return Boolean::newBoolean(true);
10711064
}
@@ -1081,7 +1074,7 @@ Local<Value> EntityClass::setMaxAttackDamage(const Arguments& args) {
10811074
if (!entity) return Local<Value>();
10821075

10831076
MutableAttributeWithContext attribute = entity->getMutableAttribute(SharedAttributes::ATTACK_DAMAGE());
1084-
SetAttributeCurrentValue(attribute, args[0].asNumber().toFloat());
1077+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
10851078

10861079
return Boolean::newBoolean(true);
10871080
}
@@ -1097,7 +1090,7 @@ Local<Value> EntityClass::setFollowRange(const Arguments& args) {
10971090
if (!entity) return Local<Value>();
10981091

10991092
MutableAttributeWithContext attribute = entity->getMutableAttribute(SharedAttributes::FOLLOW_RANGE());
1100-
SetAttributeCurrentValue(attribute, args[0].asNumber().toFloat());
1093+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
11011094

11021095
return Boolean::newBoolean(true);
11031096
}
@@ -1113,7 +1106,7 @@ Local<Value> EntityClass::setKnockbackResistance(const Arguments& args) {
11131106
if (!entity) return Local<Value>();
11141107

11151108
MutableAttributeWithContext attribute = entity->getMutableAttribute(SharedAttributes::KNOCKBACK_RESISTANCE());
1116-
SetAttributeCurrentValue(attribute, args[0].asNumber().toFloat());
1109+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
11171110

11181111
return Boolean::newBoolean(true);
11191112
}
@@ -1129,7 +1122,7 @@ Local<Value> EntityClass::setLuck(const Arguments& args) {
11291122
if (!entity) return Local<Value>();
11301123

11311124
MutableAttributeWithContext attribute = entity->getMutableAttribute(SharedAttributes::LUCK());
1132-
SetAttributeCurrentValue(attribute, args[0].asNumber().toFloat());
1125+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
11331126

11341127
return Boolean::newBoolean(true);
11351128
}
@@ -1145,7 +1138,7 @@ Local<Value> EntityClass::setMovementSpeed(const Arguments& args) {
11451138
if (!entity) return Local<Value>();
11461139

11471140
MutableAttributeWithContext attribute = entity->getMutableAttribute(SharedAttributes::MOVEMENT_SPEED());
1148-
SetAttributeCurrentValue(attribute, args[0].asNumber().toFloat());
1141+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
11491142

11501143
return Boolean::newBoolean(false);
11511144
}
@@ -1162,9 +1155,8 @@ Local<Value> EntityClass::setUnderwaterMovementSpeed(const Arguments& args) {
11621155

11631156
MutableAttributeWithContext attribute =
11641157
entity->getMutableAttribute(SharedAttributes::UNDERWATER_MOVEMENT_SPEED());
1165-
auto& instance = attribute.mInstance;
1166-
instance->mCurrentValue = args[0].asNumber().toFloat();
1167-
attribute.mContext->mAttributeMap->_onAttributeModified(*instance);
1158+
auto& instance = attribute.mInstance;
1159+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
11681160

11691161
return Boolean::newBoolean(true);
11701162
}
@@ -1180,7 +1172,7 @@ Local<Value> EntityClass::setLavaMovementSpeed(const Arguments& args) {
11801172
if (!entity) return Local<Value>();
11811173

11821174
MutableAttributeWithContext attribute = entity->getMutableAttribute(SharedAttributes::LAVA_MOVEMENT_SPEED());
1183-
SetAttributeCurrentValue(attribute, args[0].asNumber().toFloat());
1175+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
11841176

11851177
return Boolean::newBoolean(true);
11861178
}
@@ -1196,7 +1188,7 @@ Local<Value> EntityClass::setMaxHealth(const Arguments& args) {
11961188
if (!entity) return Local<Value>();
11971189

11981190
MutableAttributeWithContext attribute = entity->getMutableAttribute(SharedAttributes::HEALTH());
1199-
SetAttributeCurrentValue(attribute, args[0].asNumber().toFloat());
1191+
AttributeHelper::setCurrentValue(attribute, args[0].asNumber().toFloat());
12001192

12011193
return Boolean::newBoolean(true);
12021194
}

0 commit comments

Comments
 (0)