Skip to content

Commit

Permalink
fix: fix Dataitem alignment error
Browse files Browse the repository at this point in the history
  • Loading branch information
Dofes committed Jan 18, 2024
1 parent 93c543b commit 6895366
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
36 changes: 36 additions & 0 deletions src/ll/test/TestDataItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "ll/api/memory/Hook.h"
#include "ll/api/service/Bedrock.h"
#include "mc/deps/core/utility/BinaryStream.h"
#include "mc/network/MinecraftPackets.h"
#include "mc/network/packet/SetActorDataPacket.h"
#include "mc/world/actor/Actor.h"
#include "mc/world/actor/DataItem.h"
#include "mc/world/actor/item/ItemActor.h"
#include "mc/world/actor/player/Player.h"
#include "mc/world/level/Level.h"
#include <memory>
#include <string>

std::shared_ptr<SetActorDataPacket> buildSetActorDataPacketPacket(ItemActor* iac) {
bool viewable = true;
std::vector<std::unique_ptr<DataItem>> DataItems;
DataItems.emplace_back(DataItem::create<const std::string&>(ActorDataIDs::Name, iac->item().getTypeName()));
DataItems.emplace_back(DataItem::create<signed char>(ActorDataIDs::NametagAlwaysShow, (signed char)viewable));
BinaryStream bs;
bs.writeUnsignedVarInt64(iac->getRuntimeID());
bs.writeType(DataItems);
bs.writeUnsignedVarInt(0);
bs.writeUnsignedVarInt(0);
bs.writeUnsignedVarInt64(0);
auto packet = MinecraftPackets::createPacket(MinecraftPacketIds::SetActorData);
packet->read(bs);
return std::static_pointer_cast<SetActorDataPacket>(packet);
}

LL_AUTO_TYPE_INSTANCE_HOOK(ACTickHook, HookPriority::Normal, ItemActor, &ItemActor::postNormalTick, void) {
origin();
ll::service::getLevel()->forEachPlayer([&](Player& player) {
player.sendNetworkPacket(*buildSetActorDataPacketPacket(this));
return true;
});
}
2 changes: 1 addition & 1 deletion src/mc/enums/DataItemType.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "mc/_HeaderOutputPredefine.h"

enum class DataItemType {
enum class DataItemType : byte {
Byte = 0x0,
Short = 0x1,
Int = 0x2,
Expand Down
6 changes: 3 additions & 3 deletions src/mc/world/actor/DataItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class DataItem2 : public DataItem {

[[nodiscard]] constexpr T& value() { return mValue; };

[[nodiscard]] constexpr operator T const&() const { return mValue; };
[[nodiscard]] constexpr explicit operator T const&() const { return mValue; };

[[nodiscard]] constexpr operator T&() { return mValue; };
[[nodiscard]] constexpr explicit operator T&() { return mValue; };

template <class T2>
constexpr void setData(T2&& value) {
Expand All @@ -85,7 +85,7 @@ class DataItem2 : public DataItem {
return *this;
}
template <class... Args>
constexpr DataItem2(ushort key, Args&&... args)
constexpr explicit DataItem2(ushort key, Args&&... args)
: DataItem((::DataItemType)DataItem::TypeList::index<T>, (::ActorDataIDs)key),
mValue(std::forward<Args>(args)...) {}
};
Expand Down

0 comments on commit 6895366

Please sign in to comment.