Skip to content

Commit 98bdafb

Browse files
committed
feat: adapt some files
1 parent 0f82099 commit 98bdafb

File tree

13 files changed

+66
-34
lines changed

13 files changed

+66
-34
lines changed

src/legacy/api/CommandOutputAPI.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ Local<Object> CommandOutputClass::newCommandOutput(CommandOutput* p) {
3232
// MCAPI bool empty() const;
3333
Local<Value> CommandOutputClass::empty() {
3434
try {
35-
return Boolean::newBoolean(get()->hasErrorMessage());
35+
return Boolean::newBoolean(get()->mMessages.empty());
3636
}
3737
CATCH("Fail in empty!");
3838
}
3939

4040
// MCAPI int getSuccessCount() const;
4141
Local<Value> CommandOutputClass::getSuccessCount() {
4242
try {
43-
return Number::newNumber(get()->getSuccessCount());
43+
return Number::newNumber(get()->mSuccessCount);
4444
}
4545
CATCH("Fail in getSuccessCount!");
4646
};
@@ -60,7 +60,7 @@ Local<Value> CommandOutputClass::getSuccessCount() {
6060
Local<Value> CommandOutputClass::success(const Arguments& args) {
6161
try {
6262
if (args.size() == 0) {
63-
get()->success();
63+
++get()->mSuccessCount;
6464
return Boolean::newBoolean(true);
6565
}
6666
CHECK_ARG_TYPE(args[0], ValueKind::kString);
@@ -70,7 +70,7 @@ Local<Value> CommandOutputClass::success(const Arguments& args) {
7070
std::vector<CommandOutputParameter> param{};
7171
auto paramArr = args[1].asArray();
7272
for (int i = 0; i < paramArr.size(); ++i) {
73-
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString()));
73+
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString().c_str()));
7474
}
7575
get()->success(msg, param);
7676
return Boolean::newBoolean(true);
@@ -90,7 +90,7 @@ Local<Value> CommandOutputClass::addMessage(const Arguments& args) {
9090
std::vector<CommandOutputParameter> param{};
9191
auto paramArr = args[1].asArray();
9292
for (int i = 0; i < paramArr.size(); ++i) {
93-
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString()));
93+
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString().c_str()));
9494
}
9595
if (args.size() >= 3) {
9696
CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
@@ -118,7 +118,7 @@ Local<Value> CommandOutputClass::error(const Arguments& args) {
118118
std::vector<CommandOutputParameter> param{};
119119
auto paramArr = args[1].asArray();
120120
for (int i = 0; i < paramArr.size(); ++i) {
121-
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString()));
121+
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString().c_str()));
122122
}
123123
get()->error(msg, param);
124124
return Boolean::newBoolean(true);

src/legacy/api/DeviceAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "ll/api/service/Bedrock.h"
55
#include "magic_enum.hpp"
66
#include "mc/certificates/WebToken.h"
7-
#include "mc/common/ActorRuntimeID.h"
7+
#include "mc/legacy/ActorRuntimeID.h"
88
#include "mc/deps/input/InputMode.h"
99
#include "mc/deps/json/Value.h"
1010
#include "mc/network/ConnectionRequest.h"

src/legacy/api/DeviceAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include "api/APIHelp.h"
3-
#include "mc/common/ActorRuntimeID.h"
3+
#include "mc/legacy/ActorRuntimeID.h"
44
#include "mc/deps/ecs/WeakEntityRef.h"
55

66
//////////////////// Classes ////////////////////

src/legacy/api/EntityAPI.cpp

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,38 @@
1111
#include "ll/api/memory/Memory.h"
1212
#include "ll/api/service/Bedrock.h"
1313
#include "lse/api/MoreGlobal.h"
14-
#include "mc/common/ActorUniqueID.h"
1514
#include "mc/deps/core/math/Vec2.h"
1615
#include "mc/deps/core/string/HashedString.h"
16+
#include "mc/deps/shared_types/legacy/actor/ActorDamageCause.h"
17+
#include "mc/deps/vanilla_components/StateVectorComponent.h"
18+
#include "mc/entity/components/ActorRotationComponent.h"
19+
#include "mc/entity/components/InsideBlockComponent.h"
1720
#include "mc/entity/components/IsOnHotBlockFlagComponent.h"
1821
#include "mc/entity/utilities/ActorMobilityUtils.h"
22+
#include "mc/legacy/ActorRuntimeID.h"
23+
#include "mc/legacy/ActorUniqueID.h"
1924
#include "mc/nbt/CompoundTag.h"
2025
#include "mc/world/SimpleContainer.h"
21-
#include "mc/world/actor/ActorDamageCause.h"
2226
#include "mc/world/actor/ActorDefinitionIdentifier.h"
2327
#include "mc/world/actor/ActorType.h"
28+
#include "mc/world/actor/BuiltInActorComponents.h"
2429
#include "mc/world/actor/Mob.h"
2530
#include "mc/world/actor/item/ItemActor.h"
2631
#include "mc/world/actor/player/Player.h"
32+
#include "mc/world/actor/provider/ActorAttribute.h"
2733
#include "mc/world/actor/provider/ActorEquipment.h"
2834
#include "mc/world/actor/provider/SynchedActorDataAccess.h"
2935
#include "mc/world/attribute/AttributeInstance.h"
36+
#include "mc/world/attribute/AttributeModificationContext.h"
37+
#include "mc/world/attribute/MutableAttributeWithContext.h"
3038
#include "mc/world/attribute/SharedAttributes.h"
3139
#include "mc/world/effect/EffectDuration.h"
3240
#include "mc/world/effect/MobEffectInstance.h"
3341
#include "mc/world/level/BlockSource.h"
3442
#include "mc/world/level/Spawner.h"
3543
#include "mc/world/level/biome/Biome.h"
3644
#include "mc/world/level/block/Block.h"
45+
#include "mc/world/level/block/VanillaBlockTypeIds.h"
3746
#include "mc/world/level/material/Material.h"
3847
#include "mc/world/phys/AABB.h"
3948
#include "mc/world/phys/HitResult.h"
@@ -216,7 +225,14 @@ Local<Value> EntityClass::isInsidePortal() {
216225
Actor* entity = get();
217226
if (!entity) return Local<Value>();
218227

219-
return Boolean::newBoolean(entity->isInsidePortal());
228+
auto component = entity->getEntityContext().tryGetComponent<InsideBlockComponent>();
229+
if (component) {
230+
auto& fullName = component->mInsideBlock->getLegacyBlock().mNameInfo->mFullName;
231+
return Boolean::newBoolean(
232+
*fullName == VanillaBlockTypeIds::Portal() || *fullName == VanillaBlockTypeIds::EndPortal()
233+
);
234+
}
235+
return Boolean::newBoolean(false);
220236
}
221237
CATCH("Fail in isInsidePortal!")
222238
}
@@ -226,7 +242,9 @@ Local<Value> EntityClass::isTrusting() {
226242
Actor* entity = get();
227243
if (!entity) return Local<Value>();
228244

229-
return Boolean::newBoolean(entity->isTrusting());
245+
return Boolean::newBoolean(
246+
SynchedActorDataAccess::getActorFlag(entity->getEntityContext(), ActorFlags::Trusting)
247+
);
230248
}
231249
CATCH("Fail in isTrusting!")
232250
}
@@ -316,7 +334,7 @@ Local<Value> EntityClass::isAngry() {
316334
Actor* entity = get();
317335
if (!entity) return Local<Value>();
318336

319-
return Boolean::newBoolean(entity->isAngry());
337+
return Boolean::newBoolean(SynchedActorDataAccess::getActorFlag(entity->getEntityContext(), ActorFlags::Angry));
320338
}
321339
CATCH("Fail in isAngry!")
322340
}
@@ -336,7 +354,9 @@ Local<Value> EntityClass::isMoving() {
336354
Actor* entity = get();
337355
if (!entity) return Local<Value>();
338356

339-
return Boolean::newBoolean(entity->isMoving());
357+
return Boolean::newBoolean(
358+
SynchedActorDataAccess::getActorFlag(entity->getEntityContext(), ActorFlags::Moving)
359+
);
340360
}
341361
CATCH("Fail in isMoving!")
342362
}
@@ -415,7 +435,7 @@ Local<Value> EntityClass::setPosDelta(const Arguments& args) {
415435
delta.y = args[1].asNumber().toFloat();
416436
delta.z = args[2].asNumber().toFloat();
417437
}
418-
entity->getPosDeltaNonConst() = delta;
438+
entity->mBuiltInComponents->mStateVectorComponent->mPosDelta = delta;
419439

420440
return Boolean::newBoolean(true);
421441
}
@@ -457,7 +477,7 @@ Local<Value> EntityClass::getHealth() {
457477
Actor* entity = get();
458478
if (!entity) return Local<Value>();
459479

460-
return Number::newNumber(entity->getHealth());
480+
return Number::newNumber(ActorAttribute::getHealth(entity->getEntityContext()));
461481
}
462482
CATCH("Fail in GetHealth!")
463483
}
@@ -497,7 +517,7 @@ Local<Value> EntityClass::getCanPickupItems() {
497517
Actor* entity = get();
498518
if (!entity) return Local<Value>();
499519

500-
return Boolean::newBoolean(entity->getCanPickupItems());
520+
return Boolean::newBoolean(entity->mCanPickupItems);
501521
}
502522
CATCH("Fail in getCanPickupItems!")
503523
}
@@ -569,7 +589,11 @@ Local<Value> EntityClass::getInWall() {
569589
Actor* entity = get();
570590
if (!entity) return Local<Value>();
571591

572-
return Boolean::newBoolean(entity->isInWall());
592+
// The original Actor::isInWall() was moved to MobSuffocationSystemImpl::isInWall() in 1.21.60.10, but the later
593+
// needs too many parameters.
594+
return Boolean::newBoolean(entity->getDimensionBlockSource().isInWall(
595+
entity->getAttachPos(SharedTypes::Legacy::ActorLocation::BreathingPoint)
596+
));
573597
}
574598
CATCH("Fail in getInWall!")
575599
}
@@ -609,7 +633,8 @@ Local<Value> EntityClass::getDirection() {
609633
Actor* entity = get();
610634
if (!entity) return Local<Value>();
611635

612-
Vec2 vec = entity->getRotation();
636+
// getRotation()
637+
Vec2 vec = entity->mBuiltInComponents->mActorRotationComponent->mRotationDegree;
613638
return DirectionAngle::newAngle(vec.x, vec.y);
614639
}
615640
CATCH("Fail in getDirection!")
@@ -675,7 +700,8 @@ Local<Value> EntityClass::teleport(const Arguments& args) {
675700
return Boolean::newBoolean(false);
676701
}
677702
if (!rotationIsValid) {
678-
ang = entity->getRotation();
703+
// getRotation()
704+
ang = entity->mBuiltInComponents->mActorRotationComponent->mRotationDegree;
679705
}
680706
entity->teleport(pos.getVec3(), pos.dim, ang);
681707
return Boolean::newBoolean(true);
@@ -969,10 +995,12 @@ Local<Value> EntityClass::hurt(const Arguments& args) {
969995
if (!source) {
970996
return Boolean::newBoolean(false);
971997
}
972-
ActorDamageByActorSource damageBySource = ActorDamageByActorSource(*source.value(), (ActorDamageCause)type);
998+
ActorDamageByActorSource damageBySource =
999+
ActorDamageByActorSource(*source.value(), (SharedTypes::Legacy::ActorDamageCause)type);
9731000
return Boolean::newBoolean(entity->_hurt(damageBySource, damage, true, false));
9741001
}
975-
ActorDamageSource damageSource = ActorDamageSource((ActorDamageCause)type);
1002+
ActorDamageSource damageSource;
1003+
damageSource.mCause = (SharedTypes::Legacy::ActorDamageCause)type;
9761004
return Boolean::newBoolean(entity->_hurt(damageSource, damage, true, false));
9771005
}
9781006
CATCH("Fail in hurt!");
@@ -999,7 +1027,7 @@ Local<Value> EntityClass::setHealth(const Arguments& args) {
9991027
Actor* entity = get();
10001028
if (!entity) return Local<Value>();
10011029

1002-
AttributeInstance* healthAttribute = entity->getMutableAttribute(SharedAttributes::HEALTH());
1030+
MutableAttributeWithContext healthAttribute = entity->getMutableAttribute(SharedAttributes::HEALTH());
10031031

10041032
healthAttribute->setCurrentValue(args[0].asNumber().toFloat());
10051033

src/legacy/api/EntityAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include "api/APIHelp.h"
3-
#include "mc/common/ActorRuntimeID.h"
3+
#include "mc/legacy/ActorRuntimeID.h"
44
#include "mc/deps/ecs/WeakEntityRef.h"
55

66
//////////////////// Classes ////////////////////

src/legacy/api/EventAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#include "lse/events/OtherEvents.h"
4848
#include "lse/events/PlayerEvents.h"
4949
#include "main/Global.h"
50-
#include "mc/common/ActorUniqueID.h"
50+
#include "mc/legacy/ActorRuntimeID.h"
5151
#include "mc/deps/core/string/HashedString.h"
5252
#include "mc/server/commands/CommandOriginType.h"
5353
#include "mc/world/actor/ActorType.h"

src/legacy/api/PlayerAPI.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929
#include "main/EconomicSystem.h"
3030
#include "main/SafeGuardRecord.h"
3131
#include "mc/certificates/WebToken.h"
32-
#include "mc/common/ActorUniqueID.h"
3332
#include "mc/deps/core/math/Vec2.h"
3433
#include "mc/deps/core/string/HashedString.h"
3534
#include "mc/deps/core/utility/MCRESULT.h"
3635
#include "mc/entity/components/IsOnHotBlockFlagComponent.h"
3736
#include "mc/entity/utilities/ActorMobilityUtils.h"
37+
#include "mc/legacy/ActorRuntimeID.h"
38+
#include "mc/legacy/ActorUniqueID.h"
3839
#include "mc/nbt/CompoundTag.h"
3940
#include "mc/nbt/ListTag.h"
4041
#include "mc/network/ConnectionRequest.h"

src/legacy/api/PlayerAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include "api/APIHelp.h"
3-
#include "mc/common/ActorRuntimeID.h"
3+
#include "mc/legacy/ActorRuntimeID.h"
44
#include "mc/deps/ecs/WeakEntityRef.h"
55

66
class SimulatedPlayer;

src/lse/events/BlockEvents.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include "ll/api/memory/Hook.h"
88
#include "ll/api/memory/Memory.h"
99
#include "ll/api/service/Bedrock.h"
10-
#include "mc/common/ActorUniqueID.h"
10+
#include "mc/legacy/ActorRuntimeID.h"
11+
#include "mc/legacy/ActorUniqueID.h"
1112
#include "mc/server/commands/CommandOrigin.h"
1213
#include "mc/server/commands/CommandOriginType.h"
1314
#include "mc/world/actor/ArmorStand.h"

src/lse/events/EntityEvents.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
#include "ll/api/memory/Memory.h"
88
#include "ll/api/service/Bedrock.h"
99
#include "ll/api/service/GamingStatus.h"
10-
#include "mc/common/ActorUniqueID.h"
1110
#include "mc/deps/core/string/HashedString.h"
11+
#include "mc/deps/shared_types/legacy/actor/ActorDamageCause.h"
1212
#include "mc/entity/components_json_legacy/NpcComponent.h"
1313
#include "mc/entity/components_json_legacy/ProjectileComponent.h"
1414
#include "mc/entity/components_json_legacy/TransformationComponent.h"
15-
#include "mc/world/actor/ActorDamageCause.h"
15+
#include "mc/legacy/ActorRuntimeID.h"
16+
#include "mc/legacy/ActorUniqueID.h"
1617
#include "mc/world/actor/ActorDamageSource.h"
1718
#include "mc/world/actor/ActorDefinitionIdentifier.h"
1819
#include "mc/world/actor/ActorType.h"

0 commit comments

Comments
 (0)