Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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 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.
Posts: 313
Threads: 32
Joined: Feb 2012
Thanks: 98
Given 14 thank(s) in 13 post(s)
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"
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
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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.
Posts: 313
Threads: 32
Joined: Feb 2012
Thanks: 98
Given 14 thank(s) in 13 post(s)
Oh, f*ck, I forgot about OreNests feature
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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.
Posts: 313
Threads: 32
Joined: Feb 2012
Thanks: 98
Given 14 thank(s) in 13 post(s)
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?
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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.
Posts: 313
Threads: 32
Joined: Feb 2012
Thanks: 98
Given 14 thank(s) in 13 post(s)
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?
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
06-14-2012, 06:29 AM
(This post was last modified: 06-14-2012, 06:59 AM by xoft.)
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
No will do, too much work for little effort.
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
06-14-2012, 07:03 AM
(This post was last modified: 06-14-2012, 09:47 AM by FakeTruth.)
(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.
|