Skip to content
LeviMC
English
AutoLightDark
LeviLamina
Loading...
Searching...
No Matches
SimulatedPlayer.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4#include "mc/deps/core/math/Vec2.h"
5#include "mc/deps/core/math/Vec3.h"
6#include "mc/server/sim/LookDuration.h"
7#include "mc/world/actor/player/PlayerInventory.h"
8#include "mc/world/actor/provider/SynchedActorDataAccess.h"
9
10// auto generated inclusion list
11#include "mc/certificates/identity/PlayerAuthenticationType.h"
12#include "mc/common/SubClientId.h"
13#include "mc/deps/core/utility/NonOwnerPointer.h"
14#include "mc/scripting/modules/minecraft/ScriptFacing.h"
15#include "mc/server/ServerPlayer.h"
16#include "mc/server/sim/BuildIntent.h"
17#include "mc/server/sim/LookAtIntent.h"
18#include "mc/server/sim/LookDuration.h"
19#include "mc/server/sim/MovementIntent.h"
20#include "mc/world/actor/ActorInitializationMethod.h"
21#include "mc/world/actor/player/PlayerMovementSettings.h"
22#include "mc/world/level/BlockPos.h"
23#include "mc/world/level/GameType.h"
24#include "mc/world/level/storage/PlayerSuspendLevelStorageSaveToken.h"
25
26// auto generated forward declare list
27// clang-format off
28class Actor;
29class ChunkSource;
30class ChunkViewSource;
31class EntityContext;
32class ItemStack;
33class Level;
36class PacketSender;
39class Vec2;
40class Vec3;
41struct ActorUniqueID;
42struct DimensionType;
45namespace ClientBlobCache::Server { class ActiveTransfersManager; }
46namespace ScriptModuleGameTest { struct ScriptNavigationResult; }
47namespace gametest { class BaseGameTestHelper; }
48namespace mce { class UUID; }
49// clang-format on
50
51class SimulatedPlayer : public ::ServerPlayer {
52public:
54 create(std::string const& name, Vec3 const& pos, DimensionType dimId = 0, Vec2 const& rotation = {0, 0});
55
56 bool simulateSneaking() {
57 setSneaking(true);
58 return SynchedActorDataAccess::getActorFlag(mEntityContext, ActorFlags::Sneaking);
59 }
60 bool simulateStopSneaking() {
61 setSneaking(false);
62 return !SynchedActorDataAccess::getActorFlag(mEntityContext, ActorFlags::Sneaking);
63 }
64 bool simulateUseItem() { return simulateUseItemInSlot(mInventory->mSelected); }
65 LLAPI bool simulateUseItem(ItemStack& item);
66
67 LLAPI bool simulateDestroyBlock(BlockPos const&, ScriptModuleMinecraft::ScriptFacing);
68 LLAPI bool simulateDestroyLookAt(float handLength = 5.5f);
69 LLAPI void simulateStopMoving();
70 LLAPI bool simulateAttack(Actor* target);
71 LLAPI void simulateStartBuildInSlot(int slot);
72 LLAPI void simulateStopBuild();
73 LLAPI void simulateStopUsingItem();
74 LLAPI bool simulateGiveItem(ItemStack& item, bool selectSlot);
75 LLAPI bool simulateSetItem(ItemStack const& item, bool selectSlot, int slot);
76 LLAPI bool simulateDropSelectedItem();
77 LLAPI bool simulateInteract(Actor& actor);
78 LLAPI void simulateStopInteracting();
79 LLAPI bool isSimulatingDestroyingBlock();
80 // LLAPI void simulateLookAt(Vec3 const& pos, sim::LookDuration lookType = sim::LookDuration::Instant);
81 LLAPI void simulateLookAt(Actor& actor, sim::LookDuration lookType = sim::LookDuration::Instant);
82 // LLAPI void simulateLookAt(BlockPos const& blockPos, sim::LookDuration lookType = sim::LookDuration::Instant);
83 LLAPI void simulateDisconnect();
84 LLAPI bool simulateRespawn();
85 LLAPI void simulateFly();
86 LLAPI void simulateStopFlying();
87 LLAPI void simulateWorldMove(::Vec3 const& worldDirection, float = 1.0f);
88 LLAPI void simulateLocalMove(::Vec3 const& localDirection, float = 1.0f);
89 LLAPI void simulateMoveToLocation(::Vec3 const& position, float speed, bool faceTarget);
90 LLAPI void simulateStopDestroyingBlock();
91 LLAPI bool simulateInteract(::BlockPos const& pos, ::ScriptModuleMinecraft::ScriptFacing face);
92
93 LLAPI static ::SimulatedPlayer* tryGetFromEntity(::EntityContext& entity, bool includeRemoved);
94
95public:
96 // member variables
97 // NOLINTBEGIN
98 ::ll::TypedStorage<8, 48, ::sim::MovementIntent> mSimulatedMovement;
99 ::ll::TypedStorage<1, 2, ::sim::BuildIntent> mBuildIntention;
100 ::ll::TypedStorage<8, 40, ::sim::LookAtIntent> mLookAtIntent;
101 ::ll::TypedStorage<4, 16, ::std::optional<::BlockPos>> mDestroyingBlockPos;
102 ::ll::TypedStorage<1, 2, ::std::optional<uchar>> mDestroyingBlockFace;
103 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::gametest::BaseGameTestHelper>> mGameTestHelper;
104 ::ll::TypedStorage<8, 16, ::std::optional<uint64>> mInputCooldownTick;
105 ::ll::TypedStorage<8, 64, ::PlayerMovementSettings> mMovementSettings;
106 ::ll::TypedStorage<4, 4, float> mBaseInputSpeed;
107 ::ll::TypedStorage<8, 32, ::std::string> mXuid;
108 ::ll::TypedStorage<8, 40, ::PlayerSuspendLevelStorageSaveToken const> mPlayerSuspendLevelStorageSaveToken;
109 // NOLINTEND
110
111public:
112 // prevent constructor by default
113 SimulatedPlayer();
114
115public:
116 // virtual functions
117 // NOLINTBEGIN
118 virtual void
119 initializeComponents(::ActorInitializationMethod method, ::VariantParameterList const& params) /*override*/;
120
121 virtual void aiStep() /*override*/;
122
123 virtual bool isSimulated() const /*override*/;
124
125 virtual ::std::string getXuid() const /*override*/;
126
127 virtual ::PlayerMovementSettings const& getMovementSettings() const /*override*/;
128
129 virtual void teleportTo(
130 ::Vec3 const& pos,
131 bool shouldStopRiding,
132 int cause,
133 int sourceEntityType,
134 bool keepVelocity
135 ) /*override*/;
136
137 virtual int _getSpawnChunkLimit() const /*override*/;
138
139 virtual ::std::shared_ptr<::ChunkViewSource> _createChunkSource(::ChunkSource& mainChunkSource) /*override*/;
140
141 virtual void _updateChunkPublisherView(::Vec3 const& position, float minDistance) /*override*/;
142 // NOLINTEND
143
144public:
145 // member functions
146 // NOLINTBEGIN
148 ::Level& level,
149 ::PacketSender& packetSender,
150 ::ServerNetworkSystem& network,
152 ::GameType playerGameType,
153 ::NetworkIdentifier const& owner,
154 ::SubClientId subid,
155 ::std::function<void(::ServerPlayer&)> playerLoadedCallback,
156 ::mce::UUID uuid,
157 ::std::string const& deviceId,
158 ::PlayerAuthenticationType authType,
159 ::PlayerAuthenticationInfo const& authInfo,
160 int maxChunkRadius,
161 bool enableItemStackNetManager,
162 ::EntityContext& entityContext
163 );
164
165 MCNAPI void _addMoveComponent();
166
167 MCNAPI ::ScriptModuleGameTest::ScriptNavigationResult
169
170 MCNAPI void _updateDestroyBlock();
171
172 MCNAPI void _updateMovement();
173
175
176 MCNAPI void postAiStep();
177
178 MCNAPI void preAiStep();
179
180 MCAPI void setGameTestHelper(::Bedrock::NonOwnerPointer<::gametest::BaseGameTestHelper> gameTestHelper);
181
182 MCAPI bool simulateAttack();
183
184 MCAPI void simulateChat(::std::string const& message);
185
186 MCAPI bool simulateInteract();
187
188 MCAPI bool simulateJump();
189
190 MCAPI void simulateLookAt(::BlockPos const& blockPos, ::sim::LookDuration lookType);
191
192 MCAPI void simulateLookAt(::Vec3 const& pos, ::sim::LookDuration lookType = sim::LookDuration::Instant);
193
194 MCAPI ::ScriptModuleGameTest::ScriptNavigationResult simulateNavigateToEntity(::Actor& actor, float speed);
195
196 MCAPI ::ScriptModuleGameTest::ScriptNavigationResult
197 simulateNavigateToLocation(::Vec3 const& position, float speed);
198
199 MCAPI void simulateNavigateToLocations(::std::vector<::Vec3>&& positions, float speed);
200
201 MCAPI void simulateSetBodyRotation(float degY);
202
203 MCAPI bool simulateUseItemInSlot(int slot);
204
205 MCAPI bool simulateUseItemInSlotOnBlock(
206 int slot,
207 ::BlockPos const& pos,
208 ::ScriptModuleMinecraft::ScriptFacing face,
209 ::Vec3 const& facePos
210 );
211
212 MCAPI bool simulateUseItemOnBlock(
213 ::ItemStack& item,
214 ::BlockPos const& pos,
215 ::ScriptModuleMinecraft::ScriptFacing face,
216 ::Vec3 const& facePos
217 );
218 // NOLINTEND
219
220public:
221 // static functions
222 // NOLINTBEGIN
223 MCNAPI static ::SimulatedPlayer* create(
224 ::std::string const& name,
225 ::Vec3 const& spawnPos,
226 ::DimensionType dimensionId,
227 ::Bedrock::NotNullNonOwnerPtr<::ServerNetworkHandler> serverNetworkHandler,
228 ::std::string const& xuid,
229 ::std::optional<::ActorUniqueID> idOverride
230 );
231
232 MCAPI static ::SimulatedPlayer* create(
233 ::std::string const& name,
234 ::Vec3 const& spawnPos,
235 ::Vec3 const& spawnPosDelta,
236 ::Vec2 const& spawnRotation,
237 bool spawnLoadedFromSave,
238 ::DimensionType dimensionId,
239 ::Bedrock::NotNullNonOwnerPtr<::ServerNetworkHandler> serverNetworkHandler,
240 ::std::string const& xuid,
241 ::std::optional<::ActorUniqueID> idOverride
242 );
243 // NOLINTEND
244
245public:
246 // constructor thunks
247 // NOLINTBEGIN
248 MCNAPI void* $ctor(
249 ::Level& level,
250 ::PacketSender& packetSender,
251 ::ServerNetworkSystem& network,
253 ::GameType playerGameType,
254 ::NetworkIdentifier const& owner,
255 ::SubClientId subid,
256 ::std::function<void(::ServerPlayer&)> playerLoadedCallback,
257 ::mce::UUID uuid,
258 ::std::string const& deviceId,
259 ::PlayerAuthenticationType authType,
260 ::PlayerAuthenticationInfo const& authInfo,
261 int maxChunkRadius,
262 bool enableItemStackNetManager,
263 ::EntityContext& entityContext
264 );
265 // NOLINTEND
266
267public:
268 // virtual function thunks
269 // NOLINTBEGIN
270 MCNAPI void $initializeComponents(::ActorInitializationMethod method, ::VariantParameterList const& params);
271
272 MCNAPI void $aiStep();
273
274 MCNAPI bool $isSimulated() const;
275
276 MCNAPI ::std::string $getXuid() const;
277
278 MCNAPI ::PlayerMovementSettings const& $getMovementSettings() const;
279
280 MCAPI void
281 $teleportTo(::Vec3 const& pos, bool shouldStopRiding, int cause, int sourceEntityType, bool keepVelocity);
282
283 MCNAPI int $_getSpawnChunkLimit() const;
284
285 MCAPI ::std::shared_ptr<::ChunkViewSource> $_createChunkSource(::ChunkSource& mainChunkSource);
286
287 MCNAPI void $_updateChunkPublisherView(::Vec3 const& position, float minDistance);
288
289
290 // NOLINTEND
291};
Definition Actor.h:116
Definition NonOwnerPointer.h:9
Definition BlockPos.h:14
Definition ChunkSource.h:37
Definition ChunkViewSource.h:23
Definition ActiveTransfersManager.h:19
Definition EntityContext.h:15
Definition ItemStack.h:26
Definition Level.h:255
Definition NavigationComponent.h:18
Definition NetworkIdentifier.h:10
Definition PacketSender.h:17
Definition ServerNetworkHandler.h:191
Definition ServerNetworkSystem.h:34
MCAPI void _updateRidingComponents()
MCAPI void $initializeComponents(::ActorInitializationMethod method, ::VariantParameterList const &params)
MCAPI void preAiStep()
MCAPI void _addMoveComponent()
MCAPI SimulatedPlayer(::Level &level, ::PacketSender &packetSender, ::ServerNetworkSystem &network, ::ClientBlobCache::Server::ActiveTransfersManager &clientCacheMirror, ::GameType playerGameType, ::NetworkIdentifier const &owner, ::SubClientId subid, ::std::function< void(::ServerPlayer &)> playerLoadedCallback, ::mce::UUID uuid, ::std::string const &deviceId, ::PlayerAuthenticationType authType, ::PlayerAuthenticationInfo const &authInfo, int maxChunkRadius, bool enableItemStackNetManager, ::EntityContext &entityContext)
MCAPI int $_getSpawnChunkLimit() const
MCAPI bool $isSimulated() const
MCAPI void * $ctor(::Level &level, ::PacketSender &packetSender, ::ServerNetworkSystem &network, ::ClientBlobCache::Server::ActiveTransfersManager &clientCacheMirror, ::GameType playerGameType, ::NetworkIdentifier const &owner, ::SubClientId subid, ::std::function< void(::ServerPlayer &)> playerLoadedCallback, ::mce::UUID uuid, ::std::string const &deviceId, ::PlayerAuthenticationType authType, ::PlayerAuthenticationInfo const &authInfo, int maxChunkRadius, bool enableItemStackNetManager, ::EntityContext &entityContext)
MCAPI::PlayerMovementSettings const & $getMovementSettings() const
static MCAPI ::SimulatedPlayer * create(::std::string const &name, ::Vec3 const &spawnPos, ::DimensionType dimensionId, ::Bedrock::NotNullNonOwnerPtr<::ServerNetworkHandler > serverNetworkHandler, ::std::string const &xuid, ::std::optional<::ActorUniqueID > idOverride)
MCAPI void $_updateChunkPublisherView(::Vec3 const &position, float minDistance)
MCAPI void _updateMovement()
MCAPI::std::string $getXuid() const
MCAPI void $aiStep()
MCAPI::ScriptModuleGameTest::ScriptNavigationResult _createNavigationResult(::NavigationComponent *navigation) const
MCAPI void postAiStep()
MCAPI void _updateDestroyBlock()
Definition Vec2.h:5
Definition Vec3.h:10
Definition BaseGameTestHelper.h:32
Definition UUID.h:8
Definition optional_ref.h:10
Definition ActorUniqueID.h:5
Definition DimensionType.h:5
Definition PlayerAuthenticationInfo.h:9
Definition ScriptNavigationResult.h:13
Definition VariantParameterList.h:17