7 #include "tolua++/include/tolua++.h" 10 #include "ManualBindings.h" 26 a_NextIndex = a_Index + 1;
30 a_NextIndex = a_Index + 3;
77 LOGWARN(
"BroadcastBlockAction with 3 position arguments is deprecated, use vector-parametered version instead.");
126 if (VolumeIndex != 4)
129 LOGWARN(
"BroadcastSoundEffect with 3 position arguments is deprecated, use vector-parametered version instead.");
181 LOGWARN(
"BroadcastSoundParticleEffect with 3 position arguments is deprecated, use vector-parametered version instead.");
219 int OffsetIndex, ParticleDataIndex;
230 if ((OffsetIndex != 4) || (ParticleDataIndex != 5))
233 LOGWARN(
"BroadcastParticleEffect with 3 position and 3 offset arguments is deprecated, use vector-parametered version instead.");
248 !L.
GetStackValues(ParticleDataIndex, ParticleData, ParticleAmount)
257 std::array<int, 2> Data;
258 bool HasData = L.
GetStackValues(ParticleDataIndex + 3, Data[0], Data[1]);
296 if (!L.
GetStackValues(1, world, chunkCoords, onChunkAvailable, onAllChunksAvailable))
298 LOGWARNING(
"cWorld:ChunkStay(): Cannot read parameters, bailing out.");
303 if (world ==
nullptr)
305 LOGWARNING(
"World:ChunkStay(): invalid world parameter");
309 ASSERT(chunkCoords !=
nullptr);
312 auto chunkStay = cpp14::make_unique<cLuaChunkStay>();
313 if (!chunkStay->AddChunks(*chunkCoords))
319 chunkStay.release()->Enable(*world->
GetChunkMap(), std::move(onChunkAvailable), std::move(onAllChunksAvailable));
347 double ExplosionSize;
348 int BlockX, BlockY, BlockZ;
351 if (!L.
GetStackValues(1, World, ExplosionSize, BlockX, BlockY, BlockZ, CanCauseFire, SourceTypeInt))
353 LOGWARNING(
"World:DoExplosionAt(): invalid parameters");
357 if ((SourceTypeInt < 0) || (SourceTypeInt >=
esMax))
359 LOGWARNING(
"World:DoExplosionAt(): Invalid source type");
365 switch (SourceTypeInt)
397 SourceData =
nullptr;
403 LOGWARNING(
"cWorld:DoExplosionAt(): invalid SourceType parameter: %d", SourceTypeInt);
410 World->
DoExplosionAt(ExplosionSize, BlockX, BlockY, BlockZ, CanCauseFire, SourceType, SourceData);
439 if (PlayerUUID.
IsNil())
441 return L.
ApiParamError(
"Expected a non-nil UUID for parameter #1");
445 return L.
ApiParamError(
"Expected a valid callback function for parameter #2");
487 bool CheckLineOfSight =
true, IgnoreSpectators =
true;
488 L.
GetStackValues(1, Self, Position, RangeLimit, FnRef, CheckLineOfSight, IgnoreSpectators);
490 if (Position ==
nullptr)
492 return L.
ApiParamError(
"Expected a non-nil Vector3d for parameter #2");
497 return L.
ApiParamError(
"Expected a valid callback function for parameter #3");
506 }, CheckLineOfSight, IgnoreSpectators);
531 cPluginLua * Plugin = cManualBindings::GetLuaPlugin(tolua_S);
532 if (Plugin ==
nullptr)
539 if (World ==
nullptr)
541 LOGWARNING(
"World:ForEachLoadedChunk(): invalid world parameter");
549 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Could not get function reference of parameter #2");
554 [&L, &FnRef](
int a_ChunkX,
int a_ChunkZ) ->
bool 595 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Invalid 'self'");
600 NIBBLETYPE BlockMeta, BlockSkyLight, BlockBlockLight;
601 bool res = Self->
GetBlockInfo(BlockX, BlockY, BlockZ, BlockType, BlockMeta, BlockSkyLight, BlockBlockLight);
607 L.
Push(BlockType, BlockMeta, BlockSkyLight, BlockBlockLight);
641 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Invalid 'self'");
647 bool res = Self->
GetBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta);
653 L.
Push(BlockType, BlockMeta);
686 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Invalid 'self'");
690 AString Line1, Line2, Line3, Line4;
691 bool res = Self->
GetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
697 L.
Push(Line1, Line2, Line3, Line4);
742 auto Callback = cpp14::make_unique<cCallback>();
743 L.
GetStackValues(1, world, chunkX, chunkZ, Callback->m_LuaCallback);
744 if (world ==
nullptr)
746 LOGWARNING(
"World:PrepareChunk(): invalid world parameter");
752 world->
PrepareChunk(chunkX, chunkZ, std::move(Callback));
778 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Cannot read parameters");
780 if (World ==
nullptr)
782 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Not called on an object instance");
784 if (!Task->IsValid())
786 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Could not store the callback parameter");
791 Task->Call(&a_World);
822 AString Line1, Line2, Line3, Line4;
823 L.
GetStackValues(1, Self, BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
826 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Invalid 'self'");
830 bool res = Self->
SetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
858 auto Task = std::make_shared<cLuaState::cCallback>();
861 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Cannot read parameters");
863 if (World ==
nullptr)
865 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Not called on an object instance");
867 if (!Task->IsValid())
869 return cManualBindings::lua_do_error(tolua_S,
"Error in function call '#funcname#': Could not store the callback parameter");
874 Task->Call(&a_World);
903 tolua_error(tolua_S,
"Invalid 'self' in function 'SpawnSplitExperienceOrbs'",
nullptr);
906 if (Position ==
nullptr)
908 tolua_error(tolua_S,
"Error in function 'SpawnSplitExperienceOrbs' arg #2. Value must not be nil.",
nullptr);
913 L.
Push(self->SpawnExperienceOrb(Position->
x, Position->
y, Position->
z, Reward));
945 tolua_error(tolua_S,
"Invalid 'self' in function 'TryGetHeight'",
nullptr);
951 bool res =
self->TryGetHeight(BlockX, BlockZ, Height);
965 void cManualBindings::BindWorld(lua_State * tolua_S)
967 tolua_beginmodule(tolua_S,
nullptr);
968 tolua_beginmodule(tolua_S,
"cWorld");
975 tolua_function(tolua_S,
"DoWithBeaconAt", DoWithXYZ<cWorld, cBeaconEntity, &cWorld::DoWithBeaconAt>);
976 tolua_function(tolua_S,
"DoWithBedAt", DoWithXYZ<cWorld, cBedEntity, &cWorld::DoWithBedAt>);
977 tolua_function(tolua_S,
"DoWithBlockEntityAt", DoWithXYZ<cWorld, cBlockEntity, &cWorld::DoWithBlockEntityAt>);
978 tolua_function(tolua_S,
"DoWithBrewingstandAt", DoWithXYZ<cWorld, cBrewingstandEntity, &cWorld::DoWithBrewingstandAt>);
979 tolua_function(tolua_S,
"DoWithChestAt", DoWithXYZ<cWorld, cChestEntity, &cWorld::DoWithChestAt>);
980 tolua_function(tolua_S,
"DoWithCommandBlockAt", DoWithXYZ<cWorld, cCommandBlockEntity, &cWorld::DoWithCommandBlockAt>);
981 tolua_function(tolua_S,
"DoWithDispenserAt", DoWithXYZ<cWorld, cDispenserEntity, &cWorld::DoWithDispenserAt>);
982 tolua_function(tolua_S,
"DoWithDropSpenserAt", DoWithXYZ<cWorld, cDropSpenserEntity, &cWorld::DoWithDropSpenserAt>);
983 tolua_function(tolua_S,
"DoWithDropperAt", DoWithXYZ<cWorld, cDropperEntity, &cWorld::DoWithDropperAt>);
984 tolua_function(tolua_S,
"DoWithEntityByID", DoWithID< cWorld, cEntity, &cWorld::DoWithEntityByID>);
985 tolua_function(tolua_S,
"DoWithFlowerPotAt", DoWithXYZ<cWorld, cFlowerPotEntity, &cWorld::DoWithFlowerPotAt>);
986 tolua_function(tolua_S,
"DoWithFurnaceAt", DoWithXYZ<cWorld, cFurnaceEntity, &cWorld::DoWithFurnaceAt>);
987 tolua_function(tolua_S,
"DoWithMobHeadAt", DoWithXYZ<cWorld, cMobHeadEntity, &cWorld::DoWithMobHeadAt>);
989 tolua_function(tolua_S,
"DoWithNoteBlockAt", DoWithXYZ<cWorld, cNoteEntity, &cWorld::DoWithNoteBlockAt>);
990 tolua_function(tolua_S,
"DoWithPlayer", DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>);
992 tolua_function(tolua_S,
"FindAndDoWithPlayer", DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>);
993 tolua_function(tolua_S,
"ForEachBlockEntityInChunk", ForEachInChunk<cWorld, cBlockEntity, &cWorld::ForEachBlockEntityInChunk>);
994 tolua_function(tolua_S,
"ForEachBrewingstandInChunk", ForEachInChunk<cWorld, cBrewingstandEntity, &cWorld::ForEachBrewingstandInChunk>);
995 tolua_function(tolua_S,
"ForEachChestInChunk", ForEachInChunk<cWorld, cChestEntity, &cWorld::ForEachChestInChunk>);
996 tolua_function(tolua_S,
"ForEachEntity", ForEach< cWorld, cEntity, &cWorld::ForEachEntity>);
997 tolua_function(tolua_S,
"ForEachEntityInBox", ForEachInBox< cWorld, cEntity, &cWorld::ForEachEntityInBox>);
998 tolua_function(tolua_S,
"ForEachEntityInChunk", ForEachInChunk<cWorld, cEntity, &cWorld::ForEachEntityInChunk>);
999 tolua_function(tolua_S,
"ForEachFurnaceInChunk", ForEachInChunk<cWorld, cFurnaceEntity, &cWorld::ForEachFurnaceInChunk>);
1001 tolua_function(tolua_S,
"ForEachPlayer", ForEach< cWorld, cPlayer, &cWorld::ForEachPlayer>);
1011 tolua_endmodule(tolua_S);
1012 tolua_endmodule(tolua_S);
static bool CheckParamVectorOr3Numbers(cLuaState &L, const char *a_VectorName, int a_Index, int &a_NextIndex)
Check that a Lua parameter is either a vector or 3 numbers in sequence.
bool CheckParamString(int a_StartParam, int a_EndParam=-1)
Returns true if the specified parameters on the stack are strings; also logs warning if not...
bool ForEachLoadedChunk(cFunctionRef< bool(int, int)> a_Callback)
Calls the callback for each loaded chunk.
static int tolua_cWorld_DoWithNearestPlayer(lua_State *tolua_S)
Same thing as cCallback, but GetStackValue() won't fail if the callback value is nil.
bool Call(const FnT &a_Function, Args &&...args)
Call the specified Lua function.
unsigned char BLOCKTYPE
The datatype used by blockdata.
static int tolua_cWorld_GetBlockInfo(lua_State *tolua_S)
static int tolua_cWorld_BroadcastSoundEffect(lua_State *tolua_S)
bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4, cPlayer *a_Player=nullptr)
Sets the sign text, asking plugins for permission first.
bool CheckParamNumber(int a_StartParam, int a_EndParam=-1)
Returns true if the specified parameters on the stack are numbers; also logs warning if not...
static bool GetStackVectorOr3Numbers(cLuaState &L, int a_Index, Vector3< T > &a_Return)
Get a vector from the stack, which may be represented in lua as either a Vector3<T> or 3 numbers...
bool CheckParamSelf(const char *a_SelfClassName)
Returns true if the first parameter is an instance of the expected class name.
bool CheckParamBool(int a_StartParam, int a_EndParam=-1)
Returns true if the specified parameters on the stack are bools; also logs warning if not...
static int tolua_cWorld_ChunkStay(lua_State *tolua_S)
void LogStackTrace(int a_StartingDepth=0)
Logs all items in the current stack trace to the server console.
bool GetStackValue(int a_StackPos, AString &a_Value)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Encapsulates a Lua state and provides some syntactic sugar for common operations. ...
bool CheckParamFunctionOrNil(int a_StartParam, int a_EndParam=-1)
Returns true if the specified parameters on the stack are functions or nils; also logs warning if not...
void QueueTask(std::function< void(cWorld &)> a_Task)
Queues a task onto the tick thread.
static int tolua_cWorld_ScheduleTask(lua_State *tolua_S)
bool CheckParamTable(int a_StartParam, int a_EndParam=-1)
Returns true if the specified parameters on the stack are tables; also logs warning if not...
void PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_CallAfter={})
Queues the chunk for preparing - making sure that it's generated and lit.
virtual void BroadcastSoundEffect(const AString &a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch, const cClientHandle *a_Exclude=nullptr) override
bool CheckParamUserType(int a_StartParam, const char *a_UserType, int a_EndParam=-1)
Returns true if the specified parameters on the stack are of the specified usertype; also logs warnin...
Utilities to allow casting a cWorld to one of its interfaces without including World.h.
bool CheckParamEnd(int a_Param)
Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) ...
bool GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta)
Retrieves the block type and meta at the specified coords.
virtual void BroadcastSoundParticleEffect(const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle *a_Exclude=nullptr) override
bool GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString &a_Line1, AString &a_Line2, AString &a_Line3, AString &a_Line4)
Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coo...
static int tolua_cWorld_GetSignLines(lua_State *tolua_S)
std::unique_ptr< cOptionalCallback > cOptionalCallbackPtr
bool IsValid(void) const
Returns true if the reference is valid.
static int tolua_cWorld_SpawnSplitExperienceOrbs(lua_State *tolua_S)
static int tolua_cWorld_BroadcastBlockAction(lua_State *tolua_S)
virtual void BroadcastBlockAction(Vector3i a_BlockPos, Byte a_Byte1, Byte a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle *a_Exclude=nullptr) override
bool CheckParamFunction(int a_StartParam, int a_EndParam=-1)
Returns true if the specified parameters on the stack are functions; also logs warning if not...
std::unique_ptr< cStackTable > cStackTablePtr
bool DoWithNearestPlayer(Vector3d a_Pos, double a_RangeLimit, cPlayerListCallback a_Callback, bool a_CheckLineOfSight=true, bool a_IgnoreSpectator=true)
Calls the callback for nearest player for given position, Returns false if player not found...
static int tolua_cWorld_TryGetHeight(lua_State *tolua_S)
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
static int tolua_cWorld_SetSignLines(lua_State *tolua_S)
Used for storing references to object in the global registry.
void ScheduleTask(int a_DelayTicks, std::function< void(cWorld &)> a_Task)
Queues a lambda task onto the tick thread, with the specified delay.
void LogStackValues(const char *a_Header=nullptr)
Logs all the elements' types on the API stack, with an optional header for the listing.
virtual void BroadcastParticleEffect(const AString &a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, const cClientHandle *a_Exclude=nullptr) override
eExplosionSource
The source of an explosion.
static int tolua_cWorld_DoWithPlayerByUUID(lua_State *tolua_S)
cChunkMap * GetChunkMap(void)
static int tolua_cWorld_QueueTask(lua_State *tolua_S)
static int tolua_cWorld_ForEachLoadedChunk(lua_State *tolua_S)
Interface class used as a callback for operations that involve chunk coords.
virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void *a_SourceData) override
Does an explosion with the specified strength at the specified coordinates.
bool IsParamUserType(int a_Param, AString a_UserType)
bool DoWithPlayerByUUID(const cUUID &a_PlayerUUID, cPlayerListCallback a_Callback)
Finds the player over his uuid and calls the callback.
virtual void Call(cChunkCoords a_Coords, bool a_IsSuccess)=0
Called with the chunk's coords, and an optional operation status flag for operations that support it...
bool GetBlockInfo(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_Meta, NIBBLETYPE &a_SkyLight, NIBBLETYPE &a_BlockLight)
Queries the whole block specification from the world.
static int tolua_cWorld_DoExplosionAt(lua_State *tolua_S)
bool GetStackValues(int a_StartStackPos, Arg1 &&a_Arg1, Args &&...args)
Retrieves a list of values from the Lua stack, starting at the specified index.
static int tolua_cWorld_GetBlockTypeMeta(lua_State *tolua_S)
static int tolua_cWorld_PrepareChunk(lua_State *tolua_S)
void Push(Arg1 &&a_Arg1, Arg2 &&a_Arg2, Args &&...a_Args)
Pushes multiple arguments onto the Lua stack.
std::shared_ptr< cCallback > cCallbackSharedPtr
bool CheckParamUUID(int a_StartParam, int a_EndParam=-1)
Returns true if the specified parameters on the stack are UUIDs; also logs warning if not Accepts eit...
bool IsNil() const
Returns true if this contains the "nil" UUID with all bits set to 0.
static int tolua_cWorld_BroadcastSoundParticleEffect(lua_State *tolua_S)
static int tolua_cWorld_BroadcastParticleEffect(lua_State *tolua_S)
int ApiParamError(fmt::StringRef a_Msg)
Prints the message, prefixed with the current function name, then logs the stack contents and raises ...