From 9b13a401f60d7bc9d5f0ff8fe326125fe8ab44bc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 12 Oct 2013 18:29:06 +0200 Subject: APIDump: Added an OnBlockToPickups() code example. --- MCServer/Plugins/APIDump/APIDesc.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'MCServer') diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 513af7816..78ae4be1e 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2086,6 +2086,32 @@ World:ForEachEntity( Either way, the server will then spawn pickups specified in the Pickups parameter, so to disable pickups, you need to Clear the object first, then return true. ]], + CodeExamples = + { + { + Title = "Modify pickups", + Desc = "This example callback function makes tall grass drop diamonds when digged by natural causes (washed away by water).", + Code = [[ +function OnBlockToPickups(a_World, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_Pickups) + if (a_Digger ~= nil) then + -- Not a natural cause + return false; + end + if (a_BlockType ~= E_BLOCK_TALL_GRASS) then + -- Not a tall grass being washed away + return false; + end + + -- Remove all pickups suggested by MCServer: + a_Pickups:Clear(); + + -- Drop a diamond: + a_Pickups:Add(cItem(E_ITEM_DIAMOND)); + return true; +end; + ]], + }, + } , -- CodeExamples }, -- HOOK_BLOCK_TO_PICKUPS HOOK_CHAT = -- cgit v1.2.3