init commit
This commit is contained in:
commit
1497f114e6
47 files changed
+8358
No files matched your search
@@ -0,0 +1,72 @@
|
||||
diff --git a/botcraft/src/Game/Inventory/InventoryManager.cpp b/botcraft/src/Game/Inventory/InventoryManager.cpp
|
||||
index b35f052b..fdc10155 100644
|
||||
--- a/botcraft/src/Game/Inventory/InventoryManager.cpp
|
||||
+++ b/botcraft/src/Game/Inventory/InventoryManager.cpp
|
||||
@@ -8,6 +8,19 @@ using namespace ProtocolCraft;
|
||||
|
||||
namespace Botcraft
|
||||
{
|
||||
+ namespace
|
||||
+ {
|
||||
+ // Player Inventory indices differ from inventory-menu/window indices.
|
||||
+ short PlayerInventoryToMenuSlot(const int index)
|
||||
+ {
|
||||
+ if (index >= 0 && index < 9) return static_cast<short>(36 + index);
|
||||
+ if (index >= 9 && index < 36) return static_cast<short>(index);
|
||||
+ if (index >= 36 && index < 40) return static_cast<short>(44 - index);
|
||||
+ if (index == 40) return Window::INVENTORY_OFFHAND_INDEX;
|
||||
+ return -1;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
InventoryManager::InventoryManager(const std::shared_ptr<NetworkManager>& network_manager) : network_manager(network_manager)
|
||||
{
|
||||
std::scoped_lock<std::shared_mutex> lock(inventory_manager_mutex);
|
||||
@@ -556,13 +569,10 @@ namespace Botcraft
|
||||
// Slot index is starting in the hotbar, THEN in the main storage in this case :)
|
||||
else if (packet.GetContainerId() == -2)
|
||||
{
|
||||
- if (packet.GetSlot() < Window::INVENTORY_OFFHAND_INDEX - Window::INVENTORY_HOTBAR_START)
|
||||
- {
|
||||
- SetSlot(Window::PLAYER_INVENTORY_INDEX, Window::INVENTORY_HOTBAR_START + packet.GetSlot(), packet.GetItemStack());
|
||||
- }
|
||||
- else
|
||||
+ const short slot = PlayerInventoryToMenuSlot(packet.GetSlot());
|
||||
+ if (slot >= 0)
|
||||
{
|
||||
- SetSlot(Window::PLAYER_INVENTORY_INDEX, packet.GetSlot() + Window::INVENTORY_OFFHAND_INDEX - Window::INVENTORY_HOTBAR_START, packet.GetItemStack());
|
||||
+ SetSlot(Window::PLAYER_INVENTORY_INDEX, slot, packet.GetItemStack());
|
||||
}
|
||||
}
|
||||
else if (packet.GetContainerId() >= 0)
|
||||
@@ -586,6 +596,10 @@ namespace Botcraft
|
||||
window->SetContent(packet.GetItems());
|
||||
}
|
||||
|
||||
+#if PROTOCOL_VERSION > 755
|
||||
+ SetCursor(packet.GetCarriedItem());
|
||||
+#endif
|
||||
+
|
||||
#if PROTOCOL_VERSION > 755 /* > 1.17 */
|
||||
if (packet.GetContainerId() >= 0)
|
||||
{
|
||||
@@ -694,13 +708,16 @@ namespace Botcraft
|
||||
#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
|
||||
void InventoryManager::Handle(ClientboundSetCursorItemPacket& packet)
|
||||
{
|
||||
- // Not sure about this one, I can't figure out when it's sent by the server
|
||||
- SetSlot(Window::PLAYER_INVENTORY_INDEX, Window::INVENTORY_HOTBAR_START + index_hotbar_selected, packet.GetContents());
|
||||
+ SetCursor(packet.GetContents());
|
||||
}
|
||||
|
||||
void InventoryManager::Handle(ProtocolCraft::ClientboundSetPlayerInventoryPacket& packet)
|
||||
{
|
||||
- SetSlot(Window::PLAYER_INVENTORY_INDEX, static_cast<short>(packet.GetSlot()), packet.GetContents());
|
||||
+ const short slot = PlayerInventoryToMenuSlot(packet.GetSlot());
|
||||
+ if (slot >= 0)
|
||||
+ {
|
||||
+ SetSlot(Window::PLAYER_INVENTORY_INDEX, slot, packet.GetContents());
|
||||
+ }
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
diff --git a/botcraft/src/Game/Entities/EntityManager.cpp b/botcraft/src/Game/Entities/EntityManager.cpp
|
||||
index 3925686d..cc401e99 100644
|
||||
--- a/botcraft/src/Game/Entities/EntityManager.cpp
|
||||
+++ b/botcraft/src/Game/Entities/EntityManager.cpp
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "botcraft/Game/Entities/EntityManager.hpp"
|
||||
#include "botcraft/Game/Entities/entities/Entity.hpp"
|
||||
#include "botcraft/Game/Entities/entities/UnknownEntity.hpp"
|
||||
+#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
|
||||
+#include "botcraft/Game/Entities/entities/decoration/ItemFrameEntity.hpp"
|
||||
+#endif
|
||||
#include "botcraft/Game/Entities/LocalPlayer.hpp"
|
||||
#include "botcraft/Network/NetworkManager.hpp"
|
||||
|
||||
@@ -238,6 +241,23 @@ namespace Botcraft
|
||||
entity->SetSpeed(Vector3<double>(packet.GetMovement()));
|
||||
#endif
|
||||
|
||||
+#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
|
||||
+ if (entity->GetType() == EntityType::ItemFrame || entity->GetType() == EntityType::GlowItemFrame)
|
||||
+ {
|
||||
+ // Official 1.21.11 client: ItemFrame.getAddEntityPacket supplies
|
||||
+ // getDirection().get3DDataValue() and getPos() to AddEntityPacket.
|
||||
+ // Its (Entity, int, BlockPos) constructor sends integer anchor XYZ;
|
||||
+ // recreateFromPacket sets direction from Data, not from yaw/pitch.
|
||||
+ // Keep XYZ unchanged and initialize before publishing the entity:
|
||||
+ // metadata may arrive later (or omit the default South direction).
|
||||
+ const int direction = packet.GetData();
|
||||
+ // Do not wrap malformed values into a valid face or retain South:
|
||||
+ // -1 is deliberately invalid so targeting helpers can reject it.
|
||||
+ std::static_pointer_cast<ItemFrameEntity>(entity)->SetDataDirection(
|
||||
+ direction >= 0 && direction <= 5 ? direction : -1);
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
std::scoped_lock<std::shared_mutex> lock(entity_manager_mutex);
|
||||
entities[packet.GetEntityId()] = entity;
|
||||
}
|
||||
diff --git a/botcraft/src/Game/Entities/entities/decoration/HangingEntity.cpp b/botcraft/src/Game/Entities/entities/decoration/HangingEntity.cpp
|
||||
index 8730b02b..0b9f13d2 100644
|
||||
--- a/botcraft/src/Game/Entities/entities/decoration/HangingEntity.cpp
|
||||
+++ b/botcraft/src/Game/Entities/entities/decoration/HangingEntity.cpp
|
||||
@@ -53,7 +53,18 @@ namespace Botcraft
|
||||
else if (index - hierarchy_metadata_count < metadata_count)
|
||||
{
|
||||
std::scoped_lock<std::shared_mutex> lock(entity_mutex);
|
||||
- metadata[metadata_names[index - hierarchy_metadata_count]] = value;
|
||||
+ // DATA_DIRECTION uses the DIRECTION serializer (not INT) in the
|
||||
+ // official 1.21.11 client. Entity::LoadMetadataFromRawArray stores
|
||||
+ // that as Direction; normalize it to our existing int getter/setter
|
||||
+ // representation without wrapping invalid values into valid faces.
|
||||
+ if (const auto* direction = std::any_cast<Direction>(&value))
|
||||
+ {
|
||||
+ metadata[metadata_names[index - hierarchy_metadata_count]] = static_cast<int>(*direction);
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ metadata[metadata_names[index - hierarchy_metadata_count]] = value;
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user