Post your modding questions here

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: Post your modding questions here

by stu » Fri Jan 08, 2016 18:14

everamzah wrote:Why doesn't this work? Or, more specifically, why would this make minetest run at 100% CPU and become unresponsive?

I would guess it has something to do with the 3000+ calls to minetest.set_node. This looks more like a job for the LVM ;-)

Edit: nvm 3000, it's actually more like 12000 :O
Last edited by stu on Fri Jan 08, 2016 19:01, edited 1 time in total.
 

RREDesigns
Member
 
Posts: 10
Joined: Fri Jan 08, 2016 04:32
GitHub: rredesigns
IRC: R_R_E_Designs
In-game: R_R_E_Designs

Re: Post your modding questions here

by RREDesigns » Fri Jan 08, 2016 18:51

Ok, thanks for your time.

I think you are the same guy who wrote the mod manual, so, could you include this information there. Apparently, it is hard to figure out just reading from the API reference, so it would be great help for future readers. I can make some images with marks and tags to explain how pieces in a function fit togheter and how they come to get a value from callbacks. :D
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: Post your modding questions here

by paramat » Fri Jan 08, 2016 20:59

everamzah use the lua voxel manipulator to set those nodes in bulk instead of 12800 individual map accesses.
See my lua mapgen mods for examples (strip out all the noise code).
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Fri Jan 08, 2016 22:11

paramat wrote:everamzah use the lua voxel manipulator to set those nodes in bulk instead of 12800 individual map accesses.
See my lua mapgen mods for examples (strip out all the noise code).

Somewhere l read that minetest.set_node works faster when it's used in an on_generated, is it true?
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Sat Jan 09, 2016 02:30

+ Spoiler

This is about as far as I've gotten. I started with the example at http://dev.minetest.net/voxel_manipulation#Example -- Am I close?

Edit: This actually works! I'm quite pleased, but am wondering about making it faster. For example, this line: https://github.com/minetest/minetest/bl ... .txt#L2983 talks about using a flat array to make on_generated faster?
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Sat Jan 09, 2016 09:10

everamzah wrote:
+ Spoiler

This is about as far as I've gotten. I started with the example at http://dev.minetest.net/voxel_manipulation#Example -- Am I close?

Edit: This actually works! I'm quite pleased, but am wondering about making it faster. For example, this line: https://github.com/minetest/minetest/bl ... .txt#L2983 talks about using a flat array to make on_generated faster?

l guess you use singlenode, so you don't need to set air:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
       for z = z0, z1 do
                for x = x0, x1 do
                        data[area:index(x, 14400, z)] = c_cloud
                        data[area:index(x, 14401, z)] = c_plastic_grass
                end
        end

you could also calculate the area index yourself (l think there are 5*16+2*16-1 z, y, and xs) or use the iter function:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
       for vi in area:iter(x0, 14400, z0, x1, 14400, z1) do
              data[vi] = c_cloud
       end
       for vi in area:iter(x0, 14401, z0, x1, 14401, z1) do
              data[vi] = c_plastic_grass
       end

And you could change that limit where it generates.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
if maxp.y < 14400 or
            minp.y > 14401 then
                return
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Sat Jan 09, 2016 09:16

Oh thank you very much HybridDog! I guess I do have to set air though, because I'm using mgv6. Thanks again.

Edit: This is what I've got now:
+ Spoiler


Option 2 seemed to be the fastest. Also, I tried without air and it still works. Were you talking about the singlenode mapgen or the fact that I was only working with a couple of single nodes?
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: Post your modding questions here

by stu » Sat Jan 09, 2016 16:51

What is the best way to make placement of a certain node require a particular privilege? I am sure this one should be easy but I'm just not seeing it.
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Sat Jan 09, 2016 17:13

Server Essentials by Gunship Penguin uses some method to restrict placement of TNT nodes, or whatever node you specify in its config. FireGuard by (indriApollo?) uses a priv "fglava" to restrict placing using a lava bucket. Perhaps one of those might do. My first guess was to use after_place_node, however, and check player privs there.
 

User avatar
Don
Member
 
Posts: 1641
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: Post your modding questions here

by Don » Sat Jan 09, 2016 17:20

I would use on_place and check for priv. If not priv then return else set_node.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!

A list of my mods can be found here
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Sat Jan 09, 2016 17:24

I think using on_place will require managing the itemstack and so on, whereas after_place_node won't.
 

User avatar
Don
Member
 
Posts: 1641
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: Post your modding questions here

by Don » Sat Jan 09, 2016 17:33

everamzah wrote:I think using on_place will require managing the itemstack and so on, whereas after_place_node won't.

If you place a node and then use after_place_node wouldn't that mean that you would have to remove the placed node and return it to the player? I might not understand the process of each enough. Could you expand on what you are saying?
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!

A list of my mods can be found here
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: Post your modding questions here

by stu » Sat Jan 09, 2016 17:52

Don wrote:If you place a node and then use after_place_node wouldn't that mean that you would have to remove the placed node and return it to the player?

Yeah, that's exactly what I am trying to avoid, how does one tell on_place to abort and not actually place anything?

@everamzah, thanks, I will look at those other mods you mentioned.

Edit:To abort on_place you simply return nil, duh :/ Thanks for the replies.
Last edited by stu on Sat Jan 09, 2016 19:59, edited 1 time in total.
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Sat Jan 09, 2016 19:59

Not sure about after_place_node without testing, but I wonder if it only visually shows up to the client, and is not actually added. I would be tempted to look at https://github.com/minetest/minetest/bl ... m.lua#L196 -- But that somehow feels improper.
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

Re: Post your modding questions here

by stu » Sat Jan 09, 2016 20:00

Sorry, I edited just as you posted, see above ^
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: Post your modding questions here

by paramat » Sun Jan 10, 2016 00:06

> Somewhere l read that minetest.set_node works faster when it's used in an on_generated, is it true?

I saw that too, i think it is a little faster inside 'on gen' but still much slower than LVM for a large number of nodes.

everamzah, the lua voxelmanips are already flat arrays.
The voxelmanip index always increases by 1 along the x direction, so instead of calculating index per node, calculate the initial index (for x = x0) before the x loop, then increment it by 1 per node.

The end of your code doesn't reset lighting, it should be:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
   vm:set_data(data)
   vm:set_lighting({day = 0, night = 0})
   vm:calc_lighting()
   vm:write_to_map(data)
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Sun Jan 10, 2016 11:13

everamzah wrote:Oh thank you very much HybridDog! I guess I do have to set air though, because I'm using mgv6. Thanks again.

Edit: This is what I've got now:
+ Spoiler


Option 2 seemed to be the fastest. Also, I tried without air and it still works. Were you talking about the singlenode mapgen or the fact that I was only working with a couple of single nodes?

singlenode mapgen

paramat wrote:> Somewhere l read that minetest.set_node works faster when it's used in an on_generated, is it true?

I saw that too, i think it is a little faster inside 'on gen' but still much slower than LVM for a large number of nodes.

How can l determine the least number of nodes LVM works faster if l know the approximate shape?
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Sun Jan 10, 2016 14:12

paramat wrote:everamzah, the lua voxelmanips are already flat arrays.
The voxelmanip index always increases by 1 along the x direction, so instead of calculating index per node, calculate the initial index (for x = x0) before the x loop, then increment it by 1 per node.

The end of your code doesn't reset lighting, it should be:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
   vm:set_data(data)
   vm:set_lighting({day = 0, night = 0})
   vm:calc_lighting()
   vm:write_to_map(data)


Well I added the bit at the end, but all I noticed change was that the bottom of the cloud is dark. Also, I wonder why write_to_map() worked without passing data to it.

I have to admit I'm pretty lost on what you say about calculating index. I'm using #2:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
for z = z0, z1 do
  for x = x0, x1 do
    data[area:index(x, 14400, z)] = c_cloud
    data[area:index(x, 14401, z)] = c_plastic_grass
  end
end


Are you referring the the third option with area:iter() ?
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Sun Jan 10, 2016 14:16

everamzah wrote:
paramat wrote:everamzah, the lua voxelmanips are already flat arrays.
The voxelmanip index always increases by 1 along the x direction, so instead of calculating index per node, calculate the initial index (for x = x0) before the x loop, then increment it by 1 per node.

The end of your code doesn't reset lighting, it should be:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
   vm:set_data(data)
   vm:set_lighting({day = 0, night = 0})
   vm:calc_lighting()
   vm:write_to_map(data)


Well I added the bit at the end, but all I noticed change was that the bottom of the cloud is dark. Also, I wonder why write_to_map() worked without passing data to it.

I have to admit I'm pretty lost on what you say about calculating index. I'm using #2:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
for z = z0, z1 do
  for x = x0, x1 do
    data[area:index(x, 14400, z)] = c_cloud
    data[area:index(x, 14401, z)] = c_plastic_grass
  end
end


Are you referring the the third option with area:iter() ?

the indices are numbers
https://github.com/UgnilJoZ/lumpmg/blob/master/init.lua
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Post your modding questions here

by everamzah » Sun Jan 10, 2016 15:33

I'm aware that the way I'm doing it is very slow. I'm also aware that figuring out how to use indices to make it faster will take me a great deal of time. I put this project on GitHub and the file is https://github.com/everamzah/kalite/blo ... ldedge.lua
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: Post your modding questions here

by paramat » Sun Jan 10, 2016 22:02

I realised you probably want no shadows cast. Disabling lighting calculations is one way, the 'proper' but slower way is to define your grass and cloud nodes to have 'sunlight_propagates = true'.

I'm referring to the second method of your code, the best method.
For the index trick see https://github.com/minetest/minetest_game/blob/master/mods/default/trees.lua#L312
Lines 312-324.
Your second method isn't slow, with the index trick it will be the fastest lua method there is.
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: Post your modding questions here

by Byakuren » Mon Jan 11, 2016 00:52

Is there a way to make entities ignore lighting for their rendering?
Every time a mod API is left undocumented, a koala dies.
 

User avatar
Evergreen
Member
 
Posts: 2131
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen

Re: Post your modding questions here

by Evergreen » Mon Jan 11, 2016 03:08

Is there a way of triggering a function when someone adds an item to an inventory? (or removes, or any action)
"Help! I searched for a mod but I couldn't find it!"
http://krock-works.16mb.com/MTstuff/modSearch.php
 

User avatar
Nathan.S
Member
 
Posts: 679
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21

Re: Post your modding questions here

by Nathan.S » Mon Jan 11, 2016 04:03

Evergreen wrote:Is there a way of triggering a function when someone adds an item to an inventory? (or removes, or any action)


Yep, check this out. http://dev.minetest.net/minetest.regist ... ntory_move

Just call the function in this callback.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website.
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

How can I save an inventory?

by BrunoMine » Mon Jan 11, 2016 16:13

I can not serialize an inventory.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local player_inv = player:get_inventory()
local list = player_inv:get_list("main")
data_base = minetest.serialize(list)
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: How can I save an inventory?

by rubenwardy » Mon Jan 11, 2016 16:17

BrunoMine wrote:I can not serialize an inventory.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local player_inv = player:get_inventory()
local list = player_inv:get_list("main")
data_base = minetest.serialize(list)



Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local player_inv = player:get_inventory()
local list = player_inv:get_list("main")
local retval = {}
for _, stack in pairs(list) do
    retval[#retval + 1] = stack:to_string()
end
local data_base = minetest.serialize(retval)


then to deserialise

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local list_strings = minetest.deserialize(text)
local list = {}
for _, str in pairs(list_strings) do
    list[#list + 1] = ItemStack(str)
end
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

How can I save an inventory?

by BrunoMine » Mon Jan 11, 2016 16:30

text == data_base ?
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: How can I save an inventory?

by kaeza » Mon Jan 11, 2016 16:38

rubenwardy wrote:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local player_inv = player:get_inventory()
local list = player_inv:get_list("main")
local retval = {}
for _, stack in pairs(list) do
    retval[#retval + 1] = stack:to_string()
end
local data_base = minetest.serialize(retval)

[...]

It can be edited in-place, and you can use the index from `ipairs` to index instead of using `#t`:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local player_inv = player:get_inventory()
local list = player_inv:get_list("main")
for i, stack in ipairs(list) do
  list[i] = stack:to_string()
end

Also, I don't recall if `inv:get_list()` may return `nil` items, so you may want to check for that.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Mon Jan 11, 2016 16:46

paramat wrote:Your second method isn't slow, with the index trick it will be the fastest lua method there is.

Every chunk at that height has the same look, so you could cache (localize it outside the on_generated) the data table and set the cached one (passing it at that manip:set_data l think) instead of recalculating it, couldn't you?
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: How can I save an inventory?

by rubenwardy » Mon Jan 11, 2016 16:48

kaeza wrote:
rubenwardy wrote:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local player_inv = player:get_inventory()
local list = player_inv:get_list("main")
local retval = {}
for _, stack in pairs(list) do
    retval[#retval + 1] = stack:to_string()
end
local data_base = minetest.serialize(retval)

[...]

It can be edited in-place, and you can use the index from `ipairs` to index instead of using `#t`:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local player_inv = player:get_inventory()
local list = player_inv:get_list("main")
for i, stack in ipairs(list) do
  list[i] = stack:to_string()
end

Also, I don't recall if `inv:get_list()` may return `nil` items, so you may want to check for that.


I'm pretty sure it doesn't return nil items, at least it doesn't when you do print(dump(list)). Are you sure that get_list returns a copy?

BrunoMine wrote:text == data_base ?


Yes, it's the same string.
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 30 guests

cron