Lua hooks needed!
#11
I prepared those constants (so that they're together logically), but haven't implemented the two hooks yet. I'm not good enough with Lua interfacing for those two, so I'm guessing it's up to FakeTruth to provide them.

I don't know how to pass the needed values. For BlockToDrops, The C++ code passes, among others, a pointer to an array of drops, into which the drops are added; I have no idea how to simulate that in Lua. For ChunkGenerating, the whole chunk data needs to be passed back and forth reasonably fast. That's 64K blocks, 64K metas, heightmap, biome map, entities and tile entities.

I thought I did the OnCrafting constant, too, but I guess I didn't Smile That one in C++ uses an array of items in the crafting grid, the grid dimensions, the output item and a parameter to say that the ingredients for one result are to be removed from the grid. (cCraftingRecipes::Offer() vs cCraftingRecipes::Craft() ). Again, no idea on how to interface to that in Lua.
Reply
Thanks given by:
#12
A bit more information would be useful:
OnChat is called AFTER checking message to be a binded command, am I right?
If chat message IS a binded command (for example, "/help 1") - will OnChat be called or not?

As for passing values...
BlockToDrops: I have no idea... Probably a custom structure with an array inside will work, but that's not really "elegant" Smile
as for ChunkGenerating - could we have a cChunk structure in Lua? That would be nice...
And one more thing: when it will be called? What it would contain and what it won't? I know that original Minecraft splits chunk generation into "generating" and "block populating", and the last one places ores in generated chunk...
If MCS does the same, probably it's a good idea to have:
OnChunkGenerating
OnChunkGenerated
OnChunkPopulating
OnChunkPopulated
(executed in that order)

Let's wait fome Truth Smile
Reply
Thanks given by:
#13
MCServer doesn't have a split chunk generation, as such. So there's no good way to split those callbacks. But we have a highly customizable generator, so any plugin may instruct the user to turn of a particular generator feature (such as OreNests) and use the post-generation hook.
It is theoretically possible to let the plugins manipulate the generator, such that it could disable the ores etc., but it's quite a lot of work with very little on the plus side, so I quite doubt it will be done in any near future.
Reply
Thanks given by:
#14
Oh, f*ck, I forgot about OreNests featureBig Grin
Reply
Thanks given by:
#15
I have just finished the crafting hooks (there are 3, in the end), and FakeTruth committed some OnChunkGenerating code, though I'm not sure if it's safe to use, there were some crashes with it, so it may yet change.
Reply
Thanks given by:
#16
Can I have cCraftingGrid:GetItems() to be exported in Lua?
It would be really waaaaay more easy to operate with cItem array rather than manually collect data with GetItem(x, y) for shapeless recipes.
I think that should be possible (because somehow PluginManager:GetAllPlugins() is possible), and even if not - could I have ForEachItem() similar to cRoot:ForEachWorld() then?
Reply
Thanks given by:
#17
I don't know how to handle 2-dimensional arrays in Lua. And I really don't want to export the array single-dimensionally, a plugin could then easily crash the server.
ForEachItem is possible, but quite a lot of work.
Reply
Thanks given by:
#18
Quote:I really don't want to export the array single-dimensionally, a plugin could then easily crash the server.
Holy buckets of lava, HOW?! How is that possible?Big Grin
Reply
Thanks given by:
#19
Simple - if it is exported as a bare-metal array and the plugin accesses an element that's beyond the array's boundaries. I don't know if Lua can do that, but I don't think there's any limit to stop it from doing so.
I guess I'll do the ForEachItem, then. I'll soon remember that piece of code by heart Wink
No will do, too much work for little effort.
Reply
Thanks given by:
#20
(06-14-2012, 05:48 AM)Taugeshtu Wrote: Can I have cCraftingGrid:GetItems() to be exported in Lua?
It would be really waaaaay more easy to operate with cItem array rather than manually collect data with GetItem(x, y) for shapeless recipes.
I think that should be possible (because somehow PluginManager:GetAllPlugins() is possible), and even if not - could I have ForEachItem() similar to cRoot:ForEachWorld() then?

Sorry man, but I'm against using a ForEach() function for the crafting grid.

Just use this piece of code to iterate over all the items in the grid
Code:
for x=0, Grid:GetWidth()-1 do
    for y=0, Grid:GetHeight()-1 do
        local Item = Grid:GetItem(x, y)
    end
end


I could export a function so Lua can easily iterate over the items in a linear fashion like this
Code:
for i, Item in ipairs( Grid:GetItems() ) do
    -- Item contains the item
end
But this makes it unclear what coordinate the current item has, and to figure it out you'd need to do some magic with the i variable, with might obfuscate your code even more.

I just recommend the regular iterating over the grid.
Reply
Thanks given by:




Users browsing this thread: 27 Guest(s)