Cuberite Forum
Lua hooks needed! - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Development (https://forum.cuberite.org/forum-13.html)
+--- Thread: Lua hooks needed! (/thread-464.html)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13


RE: Lua hooks needed! - Taugeshtu - 06-14-2012

So, iternal m_Items basically is always 3x3 (or 2x2 in inventory crafting grid case)?
Then x,y iterations are reasonable. I thought it was kind of list ^_^"


RE: Lua hooks needed! - FakeTruth - 06-14-2012

Oh by the way, I changed sample code, in that code x and y went from 0 to the width/height, instead of width/height-1

Use this:
Code:
for x=0, Grid:GetWidth()-1 do
    for y=0, Grid:GetHeight()-1 do
        local Item = Grid:GetItem(x, y)
    end
end



RE: Lua hooks needed! - xoft - 06-14-2012

Isn't Lua usually 1-based, instead of 0-based? I can change the GetItem() function so that it takes number in the 1..Width, 1..Height range, if it makes it more Lua-customary


RE: Lua hooks needed! - Taugeshtu - 06-14-2012

Yes, Lua has 1...n indexes instead on normal 0...n-1 indexes Smile
And yes, such change will be appretiated.


RE: Lua hooks needed! - xoft - 06-15-2012

hmm, I can't even do that, because the same functions are already called from within C++ and are expected to be 0-based. I guess Lua will have to live with thatTongue


RE: Lua hooks needed! - FakeTruth - 06-15-2012

Actually I *think* you can do it by adding lua_State* a_LuaState to the function as the first parameter. Lua will then only call that overload of the function.

I think


RE: Lua hooks needed! - Taugeshtu - 06-15-2012

so, xoft, new crafting hooks seems to be buggy (at least NO_RECIPE one).

Looks like when plugin get such callback and set recipe output, player can get crafting result, but crafting ingridients won't clear!
Try fixies and you'll get what I mean.
Could I suggest one thing about OnChunkGenerated and OnChunkGenerating, please?
Let's sync them and give cLuaChunk to OnChunkGenerated as parameter and give cWorld to OnChunkGenerating as parameter. This will be helpful.


RE: Lua hooks needed! - xoft - 06-15-2012

OnChunkGenerated cannot have a cLuaChunk parameter, because the chunk is already stored in the cWorld and other threads may already be modifying its data.
OnChunkGenerating should probably get the cWorld parameter, because the plugin should care in which world the chunk is generating. I'll take care of that.


RE: Lua hooks needed! - Taugeshtu - 06-15-2012

Quote:OnChunkGenerated cannot have a cLuaChunk parameter, because the chunk is already stored in the cWorld and other threads may already be modifying its data.
So we generally made the whole idea "let generator generate world and then plugin will add structures/custom ores/cumstom finishers" irrealizable? Sad Sad
I appologize, I forgot about cWorld:SetBlock Smile


RE: Lua hooks needed! - xoft - 06-15-2012

World param added:
Code:
OnChunkGenerating(cWorld World, int ChunkX, int ChunkZ, cLuaChunk ChunkData)