Skip to content

Commit

Permalink
fix: fix NpcCmd(#1158) & Actor::isOnGround
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Mar 25, 2023
1 parent cf2b389 commit 56fc851
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
5 changes: 2 additions & 3 deletions LiteLoader/include/llapi/mc/Actor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Actor {
LIAPI float quickEvalMolangScript(const string& expression);
LIAPI Biome* getBiome();
LIAPI float getRealSpeed() const;
LIAPI class EntityContext* getEntityContext() const;
LIAPI class EntityContext& getEntityContext() const;
//LIAPI Json::Value quickEvalMolangScriptAsJson(const string& expression);

inline Vec3 getPos()
Expand All @@ -98,8 +98,7 @@ class Actor {

// template<class T>
// inline T* tryGetComponent() const {
// auto* entityContext = getEntityContext();
// return entityContext->_enttRegistry().try_get<T>(entityContext->_getEntityId());
// return getEntityContext().tryGetComponent<T>();
// }

#undef AFTER_EXTRA
Expand Down
6 changes: 6 additions & 0 deletions LiteLoader/include/llapi/mc/EntityContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class EntityContext : public EntityContextBase {

#define AFTER_EXTRA
// Add Member There
public:
template <class T>
inline T* tryGetComponent() const {
return const_cast<T*>(_enttRegistry().try_get<T>(_getEntityId()));
}

#define DISABLE_CONSTRUCTOR_PREVENTION_ENTITYCONTEXT
#undef AFTER_EXTRA
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_ENTITYCONTEXT
Expand Down
2 changes: 1 addition & 1 deletion LiteLoader/src/llapi/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ TInstanceHook(void,
// IDA NpcComponent::executeCommandAction
// NpcSceneDialogueData data(*this, *ac, a5);

NpcSceneDialogueData data(WeakEntityRef(ac->getEntityContext()->getWeakRef()), a5);
NpcSceneDialogueData data(WeakEntityRef(ac->getEntityContext().getWeakRef()), a5);

auto container = data.getActionsContainer();
auto actionAt = container->getActionAt(a4);
Expand Down
6 changes: 3 additions & 3 deletions LiteLoader/src/llapi/mc/ActorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

class UserEntityIdentifierComponent;

EntityContext* Actor::getEntityContext() const {
return dAccess<EntityContext*, 8>((Actor*)this);
class EntityContext& Actor::getEntityContext() const {
return dAccess<EntityContext, 8>((Actor*)this);
}

class UserEntityIdentifierComponent;
Expand Down Expand Up @@ -82,7 +82,7 @@ bool Actor::isItemActor() const {
#include "llapi/mc/ActorCollision.hpp"

bool Actor::isOnGround() const {
return ActorCollision::isOnGround(*getEntityContext()); // IDA DirectActorProxyImpl<IMobMovementProxy>::isOnGround
return ActorCollision::isOnGround(getEntityContext()); // IDA DirectActorProxyImpl<IMobMovementProxy>::isOnGround
}

std::string Actor::getTypeName() const {
Expand Down

0 comments on commit 56fc851

Please sign in to comment.