Posts: 313
Threads: 32
Joined: Feb 2012
Thanks: 98
Given 14 thank(s) in 13 post(s)
06-10-2012, 08:08 AM
Current wiki CONFIG revision: r593
Current wiki API revision: !!mixed!!
So. I'm planning to fill wiki up-to-date, but for easy furthermore corrections and additions I encourage YOU, developers, to post any //tolua_export changes you do in the code in following format:
Quote:r100500 I removed cRoot class from lua export.
Feel free to post configuring-related changes as well (if you're too lazy to write them into wiki)
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
I don't get it, are we supposed to post in this thread?
Posts: 313
Threads: 32
Joined: Feb 2012
Thanks: 98
Given 14 thank(s) in 13 post(s)
Yes. Post any changes you make to API and .ini keys/values there, please. This will help.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
Rev 598, big change
Added hook names with HOOK prefix (but kept the E_PLUGIN_ -prefixed names for compatibility)
Added three hooks: HOOK_PRE_CRAFTING, HOOK_CRAFTING_NO_RECIPE and HOOK_POST_CRAFTING
Added two new objects: cCraftingGrid and cCraftingRecipe
Crafting is now fully customizable in plugins, example code:
Code: function Initialize( Plugin )
...
PluginManager = cRoot:Get():GetPluginManager()
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PRE_CRAFTING)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_POST_CRAFTING)
end
function OnPreCrafting(Player, Grid, Recipe)
LOG("Test: Pre-crafting for player " .. Player:GetName() .. ".")
return false
end
function OnCraftingNoRecipe(Player, Grid, Recipe)
LOG("Test: Crafting-no-recipe for player " .. Player:GetName() .. ".")
return false
end
function OnPostCrafting(Player, Grid, Recipe)
LOG("Test: Post-crafting for player " .. Player:GetName() .. ".")
local Item = Recipe:GetResult();
-- Mess with the result, have fun:
Recipe:SetResult(Item.m_ItemID + 1, Item.m_ItemCount + 1, Item.m_ItemHealth);
return true
end
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
Rev 602 has a new hook, HOOK_BLOCK_TO_PICKUP, that is called each time a player breaks a block and it can modify the pickups that they receive. It is called when MCServer has already decided what the standard pickups should be, and the hook can add / modify / remove them.
Hook parameters: BlockType, BlockMeta, cPlayer, cItem (equipped), cItems (pickups)
Example code that makes grass drop 4 diamonds:
Code: PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_TO_PICKUP)
...
function OnBlockToPickup(BlockType, BlockMeta, Player, EquippedItem, Pickups)
if (BlockType == E_BLOCK_GRASS) then
Pickups:Clear()
Pickups:Add(E_ITEM_DIAMOND, 4, 0)
return true
end
return false
end
Posts: 313
Threads: 32
Joined: Feb 2012
Thanks: 98
Given 14 thank(s) in 13 post(s)
Could you please describe when crafting hooks are called?
If I'll change recipe output in HOOK_PRE_CRAFTING - will crafting operation return changed item?
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
06-14-2012, 04:00 AM
(This post was last modified: 06-14-2012, 04:02 AM by FakeTruth.)
HOOK_PRE_CRAFTING is not called yet, it's not implemented
EDIT:
SORRY!! it is implemented
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
PRE_CRAFTING: before the built-in recipes are checked. If it returns true, builtins are not checked and no other crafting hooks are called
CRAFTING_NO_RECIPE: called only when no built-in recipe is found. Return value is ignored by MCServer (but if there are multiple plugins hooked, the first one returning true breaks the chain of calls, no other plugin will be called, just like with all the other hooks)
POST_CRAFTING: called after the built-in recipes are checked and a recipe was found. Return value ignored, but returning true means no more plugins are called for that hook.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
Rev 620: Added cWorld:ForEachEntity and cWorld:ForEachEntityInChunk API functions. I have no idea if they work correctly, though - didn't do any testing. And additionally, I have no idea if there's a way for Lua to convert a cEntity into the more specific class, such as cPlayer, cPassiveMob or whatever. We might need to add these when needed.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
Rev 622: Added HOOK_UPDATING_SIGN and HOOK_UPDATED_SIGN hooks. They both receive the same arguments:
cWorld - the world where the sign is
x, y, z - the block coords of the sign
line1, line2, line3, line4 - the four lines of text in the sign
HOOK_UPDATING_SIGN is called before the sign text is updated. If the hook returns true, the sign text won't get updated. The hook can also return up to four texts, after the "false", those values will override the lines of text that the sign will receive. For example, the following Lua code flips the lines - the last line will become the first etc.:
Code: function OnUpdatingSign(World, BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4)
return false, Line4, Line3, Line2, Line1
end
HOOK_UPDATED_SIGN is called after the sign text is updated, it is just a notification. Plugins cannot change the text anymore. When the callback returns true, no more plugins will be called with the notification (not recommended).
|