Files
bilicraft-bot/include/ActionExecutor.h
T

63 lines
2.7 KiB
C++

#pragma once
#include <memory>
#include "botcraft/AI/Status.hpp"
#include "botcraft/Game/Enums.hpp"
namespace Botcraft
{
class Window;
class Blockstate;
}
namespace ProtocolCraft
{
class Packet;
class ServerboundContainerClickPacket;
class Slot;
}
namespace Bilicraft
{
class BilicraftClient;
struct ActionCommand;
// Call only from the cooperative action runner (or a Botcraft behaviour leaf).
// std::exception failures gain source:line context; Botcraft's non-standard
// interruption exceptions are intentionally allowed to unwind unchanged.
Botcraft::Status ExecuteAction(BilicraftClient &client, const ActionCommand &command);
// The runner must call this at each Yield while executing an action. Botcraft
// clears player inputs every physics tick, so a scoped shift needs refreshing.
void MaintainActionInputs(BilicraftClient &client);
// Validated, zero-based protocol indices. GUI rows refer ONLY to the container
// area, never to the player inventory appended below it.
short ActionGuiSlot(Botcraft::InventoryType type, int row, int col);
short ActionBackpackSlot(int row, int col);
short ActionHotbarIndex(int slot);
int CountWaterBuckets(const Botcraft::Window &window);
std::shared_ptr<ProtocolCraft::Packet> MakeBlockRightClickPacket(const ActionCommand &command,
const Botcraft::Blockstate &block, const ProtocolCraft::Slot &mainHand, float yaw, float pitch, int sequence);
void ValidateActionPosition(int x, int y, int z);
enum class FrameAttackIntent { None, TakeItem, RemoveFrame };
// Ordinary left click never intentionally attacks a known-empty frame. Creative
// attacks break filled frames too, so item-only clicks must reject that mode.
FrameAttackIntent PlanFrameAttack(bool destroy, bool hasItem, bool creative);
void ValidateFrameAttack(FrameAttackIntent expected, bool destroy, bool hasItem, bool creative);
// Empty-cursor player-inventory number-key SWAP. No local prediction; the
// deliberately stale state id requests authoritative server synchronization.
std::shared_ptr<ProtocolCraft::ServerboundContainerClickPacket> MakeBackpackSwapPacket(int row, int col, int slot);
// Resolve a drop target to 1..9; requested slot 0 uses the current zero-based selection.
// THROW (mode 4) targets a slot directly without changing the selected hotbar.
short ActionDropSlot(int requestedSlot, int selectedHotbarIndex);
std::shared_ptr<ProtocolCraft::ServerboundContainerClickPacket> MakeHotbarDropPacket(int slot, bool all);
ProtocolCraft::Slot RemainingAfterDrop(const ProtocolCraft::Slot &before, bool all);
// Unlike Window::GetSlot, missing/reset inventory data is an error, not an empty slot.
ProtocolCraft::Slot ReadDropSlot(const Botcraft::Window &window, short slot);
} // namespace Bilicraft