Skip to content

Commit 7d28ac4

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

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

src/legacy/api/EntityAPI.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "ll/api/service/Bedrock.h"
1313
#include "lse/api/MoreGlobal.h"
1414
#include "mc/deps/core/math/Vec2.h"
15-
#include "mc/deps/core/string/HashedString.h"
1615
#include "mc/deps/shared_types/legacy/actor/ActorDamageCause.h"
1716
#include "mc/deps/vanilla_components/StateVectorComponent.h"
1817
#include "mc/entity/components/ActorRotationComponent.h"

src/legacy/api/PlayerAPI.cpp

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "mc/deps/core/math/Vec2.h"
3333
#include "mc/deps/core/string/HashedString.h"
3434
#include "mc/deps/core/utility/MCRESULT.h"
35+
#include "mc/entity/components/ActorRotationComponent.h"
36+
#include "mc/entity/components/InsideBlockComponent.h"
3537
#include "mc/entity/components/IsOnHotBlockFlagComponent.h"
3638
#include "mc/entity/utilities/ActorMobilityUtils.h"
3739
#include "mc/legacy/ActorRuntimeID.h"
@@ -67,12 +69,14 @@
6769
#include "mc/world/SimpleContainer.h"
6870
#include "mc/world/actor/Actor.h"
6971
#include "mc/world/actor/ActorDamageByActorSource.h"
72+
#include "mc/world/actor/BuiltInActorComponents.h"
7073
#include "mc/world/actor/SynchedActorData.h"
7174
#include "mc/world/actor/SynchedActorDataEntityWrapper.h"
7275
#include "mc/world/actor/ai/util/BossBarColor.h"
7376
#include "mc/world/actor/ai/util/BossEventUpdateType.h"
7477
#include "mc/world/actor/player/LayeredAbilities.h"
7578
#include "mc/world/actor/player/Player.h"
79+
#include "mc/world/actor/provider/ActorAttribute.h"
7680
#include "mc/world/actor/provider/ActorEquipment.h"
7781
#include "mc/world/actor/provider/SynchedActorDataAccess.h"
7882
#include "mc/world/attribute/Attribute.h"
@@ -85,6 +89,7 @@
8589
#include "mc/world/level/ChunkPos.h"
8690
#include "mc/world/level/biome/Biome.h"
8791
#include "mc/world/level/block/Block.h"
92+
#include "mc/world/level/block/VanillaBlockTypeIds.h"
8893
#include "mc/world/level/material/Material.h"
8994
#include "mc/world/level/storage/AdventureSettings.h"
9095
#include "mc/world/level/storage/DBStorage.h"
@@ -665,7 +670,7 @@ Local<Value> McClass::getPlayer(const Arguments& args) {
665670
found = &player;
666671
return false;
667672
}
668-
std::string pName = player.getName();
673+
std::string pName = player.mName;
669674
transform(pName.begin(), pName.end(), pName.begin(), ::tolower);
670675

671676
if (pName.find(target) == 0) {
@@ -747,7 +752,7 @@ Local<Value> PlayerClass::getName() {
747752
Player* player = get();
748753
if (!player) return Local<Value>();
749754

750-
return String::newString(player->getName());
755+
return String::newString(player->mName);
751756
}
752757
CATCH("Fail in getPlayerName!")
753758
}
@@ -899,7 +904,11 @@ Local<Value> PlayerClass::getCanBeSeenOnMap() {
899904
return Local<Value>();
900905
}
901906

902-
return Boolean::newBoolean(player->canBeSeenOnMap());
907+
if (!player->isAlive() || player->isSpectator()) {
908+
return Boolean::newBoolean(false);
909+
}
910+
ItemStack const& item = player->getItemSlot(SharedTypes::Legacy::EquipmentSlot::Legs);
911+
return Boolean::newBoolean(item.isHumanoidWearableBlockItem());
903912
}
904913
CATCH("Fail in getCanBeSeenOnMap!")
905914
}
@@ -959,7 +968,7 @@ Local<Value> PlayerClass::getCanPickupItems() {
959968
return Local<Value>();
960969
}
961970

962-
return Boolean::newBoolean(player->getCanPickupItems());
971+
return Boolean::newBoolean(player->mCanPickupItems);
963972
}
964973
CATCH("Fail in getCanPickupItems!")
965974
}
@@ -969,7 +978,9 @@ Local<Value> PlayerClass::isSneaking() {
969978
Player* player = get();
970979
if (!player) return Local<Value>();
971980

972-
return Boolean::newBoolean(player->isSneaking());
981+
return Boolean::newBoolean(
982+
SynchedActorDataAccess::getActorFlag(player->getEntityContext(), ActorFlags::Sneaking)
983+
);
973984
}
974985
CATCH("Fail in isSneaking!")
975986
}
@@ -989,8 +1000,9 @@ Local<Value> PlayerClass::getDirection() {
9891000
Player* player = get();
9901001
if (!player) return Local<Value>();
9911002

992-
Vec2 rot = player->getRotation();
993-
return DirectionAngle::newAngle(rot.x, rot.y);
1003+
// getRotation()
1004+
Vec2 vec = player->mBuiltInComponents->mActorRotationComponent->mRotationDegree;
1005+
return DirectionAngle::newAngle(vec.x, vec.y);
9941006
}
9951007
CATCH("Fail in getDirection!")
9961008
}
@@ -1010,7 +1022,7 @@ Local<Value> PlayerClass::getHealth() {
10101022
Player* player = get();
10111023
if (!player) return Local<Value>();
10121024

1013-
return Number::newNumber(player->getHealth());
1025+
return Number::newNumber(ActorAttribute::getHealth(player->getEntityContext()));
10141026
}
10151027
CATCH("Fail in GetHealth!")
10161028
}
@@ -1072,7 +1084,11 @@ Local<Value> PlayerClass::getInWall() {
10721084
Player* player = get();
10731085
if (!player) return Local<Value>();
10741086

1075-
return Boolean::newBoolean(player->isInWall());
1087+
// The original Actor::isInWall() was moved to MobSuffocationSystemImpl::isInWall() in 1.21.60.10, but the later
1088+
// needs too many parameters.
1089+
return Boolean::newBoolean(player->getDimensionBlockSource().isInWall(
1090+
player->getAttachPos(SharedTypes::Legacy::ActorLocation::BreathingPoint)
1091+
));
10761092
}
10771093
CATCH("Fail in getInWall!")
10781094
}
@@ -1129,9 +1145,7 @@ Local<Value> PlayerClass::getRuntimeID() {
11291145

11301146
Local<Value> PlayerClass::getLangCode() {
11311147
try {
1132-
Json::Value& requestJson = ll::service::getServerNetworkHandler()
1133-
->fetchConnectionRequest(get()->getNetworkIdentifier())
1134-
.mRawToken->mDataInfo;
1148+
Json::Value& requestJson = get()->getConnectionRequest()->mRawToken->mDataInfo;
11351149

11361150
return String::newString(requestJson.get("LanguageCode", "unknown").asString("unknown"));
11371151
}
@@ -1169,7 +1183,13 @@ Local<Value> PlayerClass::isInsidePortal() {
11691183
return Local<Value>();
11701184
}
11711185

1172-
return Boolean::newBoolean(player->isInsidePortal());
1186+
auto component = player->getEntityContext().tryGetComponent<InsideBlockComponent>();
1187+
if (component) {
1188+
auto& fullName = component->mInsideBlock->getLegacyBlock().mNameInfo->mFullName;
1189+
return Boolean::newBoolean(
1190+
*fullName == VanillaBlockTypeIds::Portal() || *fullName == VanillaBlockTypeIds::EndPortal()
1191+
);
1192+
}
11731193
}
11741194
CATCH("Fail in isInsidePortal!")
11751195
}

0 commit comments

Comments
 (0)