Skip to content

Commit

Permalink
refactor: change offset to member variable
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamguxiang committed Dec 30, 2024
1 parent ad08af0 commit f2a0816
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 35 deletions.
19 changes: 2 additions & 17 deletions src-client/mc/world/actor/Actor.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
#include "mc/world/actor/Actor.h"

#include <functional>
#include <optional>
#include <string>

#include "ll/api/memory/Memory.h"

#include "mc/_HeaderOutputPredefine.h"
#include "mc/deps/core/math/Vec2.h"
#include "mc/deps/core/math/Vec3.h"
#include "mc/deps/core/utility/optional_ref.h"
#include "mc/deps/ecs/gamerefs_entity/EntityContext.h"
#include "mc/entity/components/FlagComponent.h"
#include "mc/entity/systems/OnFireSystem.h"
#include "mc/server/ServerLevel.h"
#include "mc/server/commands/CommandUtils.h"
#include "mc/server/commands/standard/TeleportCommand.h"
#include "mc/server/commands/standard/TeleportTarget.h" // IWYU pragma: keep for TeleportCommand::computeTarget
#include "mc/util/ExpressionNode.h"
#include "mc/util/rotation_command_utils/RotationData.h"
#include "mc/world//actor/player/Player.h"
#include "mc/world/actor/ActorDamageByActorSource.h"
#include "mc/world/actor/ActorDamageCause.h"
#include "mc/world/actor/ActorDefinitionIdentifier.h"
#include "mc/world/actor/ActorLocation.h"
#include "mc/world/actor/provider/ActorCollision.h"
#include "mc/world/level/BlockPos.h"
#include "mc/world/level/BlockSource.h"
#include "mc/world/level/ClipDefaults.h"
#include "mc/world/level/ShapeType.h"
#include "mc/world/level/dimension/Dimension.h"
#include "mc/world/phys/HitDetection.h"
#include "mc/world/phys/HitResult.h"

class EntityContext& Actor::getEntityContext() { return ll::memory::dAccess<EntityContext>(this, 8); }
class EntityContext const& Actor::getEntityContext() const { return ll::memory::dAccess<EntityContext>(this, 8); }
class EntityContext& Actor::getEntityContext() { return mEntityContext.get(); }
class EntityContext const& Actor::getEntityContext() const { return mEntityContext.get(); }

void Actor::refresh() { _sendDirtyActorData(); }

Expand Down
9 changes: 3 additions & 6 deletions src/mc/world/actor/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <optional>
#include <string>

#include "ll/api/memory/Memory.h"

#include "mc/_HeaderOutputPredefine.h"
#include "mc/deps/core/math/Vec2.h"
#include "mc/deps/core/math/Vec3.h"
Expand Down Expand Up @@ -34,10 +32,9 @@
#include "mc/world/phys/HitDetection.h"
#include "mc/world/phys/HitResult.h"

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

void Actor::refresh() { _sendDirtyActorData(); }
class EntityContext& Actor::getEntityContext() { return mEntityContext.get(); }
class EntityContext const& Actor::getEntityContext() const { return mEntityContext.get(); }
void Actor::refresh() { _sendDirtyActorData(); }

optional_ref<Actor> Actor::clone(Vec3 const& pos, std::optional<DimensionType> dimId) const {
WeakRef<Dimension> dim{};
Expand Down
13 changes: 2 additions & 11 deletions src/mc/world/actor/player/Player.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#include "mc/world/actor/player/Player.h"

#include "ll/api/memory/Memory.h"
#include "ll/api/service/Bedrock.h"

#include "mc/certificates/ExtendedCertificate.h"
#include "mc/certificates/WebToken.h"
#include "mc/common/ActorUniqueID.h"
#include "mc/deps/core/utility/BinaryStream.h"
#include "mc/deps/ecs/gamerefs_entity/EntityContext.h"
#include "mc/deps/json/Value.h"
#include "mc/locale/I18n.h"
#include "mc/locale/Localization.h"
#include "mc/nbt/CompoundTag.h"
#include "mc/network/ConnectionRequest.h"
#include "mc/network/MinecraftPackets.h"
#include "mc/network/NetworkIdentifier.h"
#include "mc/network/NetworkPeer.h"
#include "mc/network/NetworkSystem.h"
Expand Down Expand Up @@ -119,10 +113,7 @@ bool Player::addAndRefresh(class ItemStack& item) {
}

optional_ref<EnderChestContainer> Player::getEnderChestContainer() {
return ll::memory::dAccess<EnderChestContainer*>(this, sizeof(Actor) + 2072);
// ida: Player::Player : EnderChestContainer::EnderChestContainer
return const_cast<EnderChestContainer*>(mEnderChestInventory.get());
}

optional_ref<EnderChestContainer const> Player::getEnderChestContainer() const {
return const_cast<Player*>(this)->getEnderChestContainer();
}
optional_ref<EnderChestContainer const> Player::getEnderChestContainer() const { return mEnderChestInventory.get(); }
2 changes: 1 addition & 1 deletion src/mc/world/level/block/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Block {

[[nodiscard]] inline short getBlockItemId() const { return getLegacyBlock().getBlockItemId(); }

[[nodiscard]] inline short getData() const { return ll::memory::dAccess<ushort>(this, 8); }
[[nodiscard]] inline ushort getData() const { return mData; }

public:
// member variables
Expand Down

0 comments on commit f2a0816

Please sign in to comment.