Post your modding questions here

User avatar
Hybrid Dog
Member
Posts: 2834
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

by Hybrid Dog » Post

It looks fairly random to me. Do you also see those strange yellow rings in the picture?
Image

Code: Select all

local load_time_start = os.clock()

-- $ time luajit raan.lua && pnmtopng tmp.ppm > tmp.png && optipng -o7 tmp.png

local path = "./tmp.ppm"
local file = io.open(path,"w")
file:write("")
file:close()
file = io.open(path,"a")

local s = 500
file:write("P3 "..s.." "..s.." 255 ")


local i = 2

local function getcol()
	i = math.abs((math.log(i)*1000)%1)
	return math.floor(i*255+0.5)
end

for y = 1,s do
	for x = 1,s do
		file:write(getcol().." "..getcol().." "..getcol().." ")
	end
end

file:close()

local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
local msg = "fertig nach ca. "..time.."s"
if time > 0.05 then
	print(msg)
end
Attachments
took ca. 0.44s
took ca. 0.44s
tmp.png (733.08 KiB) Viewed 810 times

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
iangp
Member
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp
Location: Brasil - ES

Re: Post your modding questions here

by iangp » Post

That's funny and cool
did you already searched for someone similar idea 'cause this looks really new for me :D
I also plotted (using xmgrace/grace) random points changing the initial value and seems pretty randomized
But I can't tell you if this is less cpu intensive or not, because math.log probably reaches the result through Series Expansion (using loops) and well, you know... the only way, maybe, is make a benchmark using several loops for emphasize these differences...
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):


User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Post your modding questions here

by rubenwardy » Post

You'd hope that math Random would be optimised as a standard library function
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Hybrid Dog
Member
Posts: 2834
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

l set the size to 700 and compared them, using math.random it took ca. 0.72s
and using that logarithm function it took ca. 0.85s
sqrt works better than log, it took ca. 0.76s

Code: Select all

local load_time_start = os.clock()

-- $ time luajit log_rand.lua && pnmtopng tmp.ppm > tmp.png && optipng -o7 -quiet tmp.png

local path = "./tmp.ppm"
local file = io.open(path,"w")
file:write("")
file:close()
file = io.open(path,"a")

local s = 500
file:write("P3 "..s.." "..s.." 255 ")


local i = 2

local function getcol()
	i = math.abs((1000/math.sqrt(i))%1)
	return math.floor(i*255+0.5)
end

for y = 1,s do
	for x = 1,s do
		file:write(getcol().." "..getcol().." "..getcol().." ")
	end
end

file:close()

local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
local msg = "fertig nach ca. "..time.."s"
if time > 0.05 then
	print(msg)
end
Image
Attachments
took ca. 0.39s
took ca. 0.39s
tmp.png (733.08 KiB) Viewed 809 times

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
iangp
Member
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp
Location: Brasil - ES

Re: Post your modding questions here

by iangp » Post

Did you closed all apps before run these scripts? If you did soooo
We have a winner!

1st > Default Random 0.72s
2nd > Sqrt Random 0.76s
3th > Log Random 0.85s
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):


User avatar
Hybrid Dog
Member
Posts: 2834
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

math.random is not coded in lua, so the tests would need to be done in minetest source code

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
BrunoMine
Member
Posts: 1082
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine
Location: SP-Brasil
Contact:

Re: Post your modding questions here

by BrunoMine » Post

How to catch max_stack an item? (Just knowing your ID. example: "default:tree")
I want a method to do this.
I am referring to the default value of an item can be accumulated.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Post your modding questions here

by Byakuren » Post

BrunoMine wrote:How to catch max_stack an item? (Just knowing your ID. example: "default:tree")
I want a method to do this.
I am referring to the default value of an item can be accumulated.
You can look at the item definition in the table minetest.registered_items. E.g.

Code: Select all

 local stack_max = minetest.registered_items["default:tree"].stack_max
.

I am not sure if the definition gets the default 99 filled in if not specified in the definition. To be safe you might want to check if stack_max is nil, and use 99 if it is.
Every time a mod API is left undocumented, a koala dies.

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Post your modding questions here

by rubenwardy » Post

It does get the default value of stack_max in the definition, it's from builtin/game/item.lua or something
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Misadventure
New member
Posts: 5
Joined: Tue Mar 01, 2016 21:36
In-game: Misadventure

Dual Crafting Output?

by Misadventure » Post

I have a recipe that calls for:
  • a tool (named forge_hammer)
    and an ingot (in this example, iron_ingot)
Trying to output : The forge hammer (with less durability) AND the plate.
The problem is, if it consumes my hammer. I have almost solved this by setting the output of the recipe to the hammer.
writing a "register on craft" function to deduct the durability. My question is, how do I write it, so that either
  • A) the forge_hammer stays in the original crafting grid (while now having its updated durability deduction) allowing you to take out the plate as you normally would, then in a separate click, drag the hammer off the grid.
    or
    B) Have it so when the player clicks the plate to craft it, it immediately sends the now less-durable hammer to the inventory, while the player still is holding the plate to drag wherever they please.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Dual Crafting Output?

by Byakuren » Post

Misadventure wrote:I have a recipe that calls for:
  • a tool (named forge_hammer)
    and an ingot (in this example, iron_ingot)
Trying to output : The forge hammer (with less durability) AND the plate.
The problem is, if it consumes my hammer. I have almost solved this by setting the output of the recipe to the hammer.
writing a "register on craft" function to deduct the durability. My question is, how do I write it, so that either
  • A) the forge_hammer stays in the original crafting grid (while now having its updated durability deduction) allowing you to take out the plate as you normally would, then in a separate click, drag the hammer off the grid.
    or
    B) Have it so when the player clicks the plate to craft it, it immediately sends the now less-durable hammer to the inventory, while the player still is holding the plate to drag wherever they please.
the register_on_craft callbacks receive the old craft grid (from before crafting) and the inventory the craft is from. So you should be able to look at the hammer from the old craft grid and insert it back into the inventory with more wear.

You could do something similar to send the hammer to the player's inventory instead, since the callback will receive an ObjectRef to the player as another argument.
Every time a mod API is left undocumented, a koala dies.

User avatar
Neon
Member
Posts: 126
Joined: Thu Aug 15, 2013 02:03
In-game: Neon

Re: Post your modding questions here

by Neon » Post

I'm trying to replace a mod-specific node with a more general one, from a different mod. For some reason, I can't seem to make it work.

From home/.minetest/mods/my_mod/init.lua:

Code: Select all

if minetest.get_modpath("moonrealm") then
  -- Make moonrealm soil the same as dirt
  minetest.register_alias(":moonrealm:soil", "default:dirt")
end
When I log into the server, a pre-existing expanse of moonrealm:soil is still moonrealm:soil and not default:dirt

my_mod is being loaded after the other two, in this case, because of the depends file
home/.minetest/mods/my_mod/depends.txt:

Code: Select all

default
moonrealm?
Any thoughts?

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Post your modding questions here

by rubenwardy » Post

Aliases can't be used on existing nodes, only undeclared ones.

Use an abm, I guess?
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Neon
Member
Posts: 126
Joined: Thu Aug 15, 2013 02:03
In-game: Neon

Re: Post your modding questions here

by Neon » Post

Well, Instead of adding another ABM, can I "overload" (to use a programming term) the function from the original mod? In effect, replace the function in the other mod with one of my own?

Additionally, the code in the above post also does not work:
- on a shiny new server (none of the moonrealm soil has ever been created, yet the alias is in the codebase)
- when the alias code is placed in the moonrealm code before the soil nodes are defined
- with the other three combinations of leading colons in the node names

I suppose I can replace the soil definition with the alias code. That's if I wanted to let edits to the moonrealm code stand, in the final server code. (as opposed to having my own mod that does all of this node editing after the mods are loaded)

EDIT: Could I unload a node definition after it's been loaded? Thus removing the node from the server?

I admit that it's not always a good idea to do, since the mapgen might be creating "unknown nodes", certain crafts might be icky, and certain ABMs might fail. That's things for the mod creator (who told the engine to unload the node) to overload with proper crafts/ABMs.

User avatar
Hybrid Dog
Member
Posts: 2834
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

If you manage to make your mod become loaded before moonrealm, you could simply override minetest.register_node,
else you could use minetest.override_node on the soil node to add an on_construct which sets dirt, but on_construct doesn't work for vmanip (and minetest.swap_node).

Code: Select all

minetest.override_node("moonrealm:soil", {
	on_construct = function(pos)
		minetest.set_node(pos, {name = "default:dirt"})
	end
})
l assume you use paramat's moonrealm mod, the content id of the soil node is fetched every time it's needed for vmanip there: https://github.com/paramat/moonrealm/bl ... ctions.lua
So you could override the minetest.get_content_id function:

Code: Select all

local get_id = minetest.get_content_id
function minetest.get_content_id(name)
	if name == "moonrealm:soil" then
		name = "default:dirt"
	end
	return get_id(name)
end

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
maikerumine
Member
Posts: 1420
Joined: Mon Aug 04, 2014 14:27
GitHub: maikerumine
In-game: maikerumine

Re: Post your modding questions here

by maikerumine » Post

Can a broken mod stuck in a loop cause insane server lag?
Talamh Survival Minetest-->viewtopic.php?f=10&t=12959

User avatar
Hybrid Dog
Member
Posts: 2834
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

maikerumine wrote:Can a broken mod stuck in a loop cause insane server lag?
Not only broken mods can cause infinite or very long loops. Often mod makers do mistakes they don't notice till they use their mod and find out that it doesn't work as it should (the reason why modders have to play enough minetest). I also have this problem sometimes, e.g. my scheduler (or sth like this) mod, which makes it possible to look at a exploding chunk consisting of 200x300x230 tnt and build a house at the same time without having lags, had the problem that the function couldn't be executed in the function passed by it (e.g. minetest.delay_function(4, minetest.delay_function, 2, some_func, some_param)), l found it out by testing and then fixed it: https://github.com/HybridDog/function_d ... 4748da8e37
if l didn't use the mod, l wouldn't have found the infinite loop bug l added without noticing it: https://github.com/HybridDog/function_d ... c6e5553260

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

Misadventure
New member
Posts: 5
Joined: Tue Mar 01, 2016 21:36
In-game: Misadventure

Re: Dual Crafting Output?

by Misadventure » Post

Byakuren wrote: the register_on_craft callbacks receive the old craft grid (from before crafting) and the inventory the craft is from. So you should be able to look at the hammer from the old craft grid and insert it back into the inventory with more wear.

You could do something similar to send the hammer to the player's inventory instead, since the callback will receive an ObjectRef to the player as another argument.
From what ive been able to search and find, I can't seem to locate very much information on the register_on_craft.
so I'm still not entirely sure how id go about using this, and what id write for it to function the way im intending. I know this sounds like im asking "hold my hand through the whole process" but i'm doing my best as a young learner to try and wrap my head around this, however the lack of information i'm able to find and piece together makes this troublesome and difficult to do without me asking silly question, such as these where they imply i need my hand held.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: Dual Crafting Output?

by stu » Post

Misadventure wrote:
Byakuren wrote: the register_on_craft callbacks receive the old craft grid (from before crafting) and the inventory the craft is from. So you should be able to look at the hammer from the old craft grid and insert it back into the inventory with more wear.

You could do something similar to send the hammer to the player's inventory instead, since the callback will receive an ObjectRef to the player as another argument.
From what ive been able to search and find, I can't seem to locate very much information on the register_on_craft.
so I'm still not entirely sure how id go about using this, and what id write for it to function the way im intending. I know this sounds like im asking "hold my hand through the whole process" but i'm doing my best as a young learner to try and wrap my head around this, however the lack of information i'm able to find and piece together makes this troublesome and difficult to do without me asking silly question, such as these where they imply i need my hand held.
I think that Byakuren described that very well so if you do not understand any of that you should perhaps break it down and ask more specific questions like what is a callback or what is an ObjectRef, for example.

IMO, the best way to learn is to study other mods which interest you or have similar functionality to something you want to do. I would also recommend this as good resource for anyone wishing to learn about modding online book teaching how to mod There is of course the official doc's and developer wiki which you should have bookmarked already ;-)

KzoneDD
Member
Posts: 65
Joined: Wed Sep 17, 2014 09:29

Re: Post your modding questions here

by KzoneDD » Post

Hi all,

I've been trying to get water out of a stone... oh, ok, a node... ;-) All I need is for code that lets me do stuff if punched / clicked (I don't really care either way) with an empty bucket.

I found this in the well mod:

if minetest.get_modpath("bucket") then
local original_bucket_on_use = minetest.registered_items["bucket:bucket_empty"].on_use
minetest.override_item("bucket:bucket_empty", {
on_use = function(itemstack, user, pointed_thing)
local inv = user:get_inventory()

if pointed_thing.type == "node" and minetest.get_node(pointed_thing.under).name == "homedecor:well" then
if inv:room_for_item("main", "bucket:bucket_water 1") then
itemstack:take_item()
inv:add_item("main", "bucket:bucket_water 1")
else
minetest.chat_send_player(user:get_player_name(), "No room in your inventory to add a filled bucket!")
end
return itemstack
else if original_bucket_on_use then
return original_bucket_on_use(itemstack, user, pointed_thing)
else return end
end
end
})
end

But obviously it's not all I need as this creates a nill value error on bucket:bucket_empty on startup.

What am I missing? TIA!

KzoneDD
Member
Posts: 65
Joined: Wed Sep 17, 2014 09:29

Re: Post your modding questions here

by KzoneDD » Post

NVM... I had hoped to put off the time when forgetting my 'depends' became an issue, but it's here. ;-) Forgot to declare bucket. :-P

User avatar
Hybrid Dog
Member
Posts: 2834
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

e^(-b) = 2*e^(-b*d)-1

e and d are known, b is not 0. How can l shift the equation to get b?

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
iangp
Member
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp
Location: Brasil - ES

Re: Post your modding questions here

by iangp » Post

Hybrid Dog wrote:e^(-b) = 2*e^(-b*d)-1

e and d are known, b is not 0. How can l shift the equation to get b?
From where do you get this relation?

e**-b == 2*e**(-b*d) - 1
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):


User avatar
Hybrid Dog
Member
Posts: 2834
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

http://freespace.virgin.net/hugo.elias/ ... posure.htm

v(x) = a*[1-e^(-b*x)]

x is in [0, 1], 0 means black, 0.5 means middle grey and 1 means white
d is the middle brightness of the picture (the expectation), so it's also inside [0, 1]
a and b are not 0

v(0) = 0; a*[1-e^(-b*0)] = 0; 1-1 = 0;
v(1) = 1; a*[1-e^(-b)] = 1
v(d) = 0.5; a*[1-e^(-b*d)] = 0.5

1/[1-e^(-b)] = 0.5/[1-e^(-b*d)]; 2*[1-e^(-b*d)] = 1-e^(-b); 1-2*e^(-b*d)] = -e^(-b);
e^(-b) = 2*e^(-b*d)-1

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
iangp
Member
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp
Location: Brasil - ES

Re: Post your modding questions here

by iangp » Post

e^-b = 2*e^(-b*d)-1
derive both sides
-e^-b = -2*d*e^(-b*d)
multiply by -1 both sides
e^-b = 2*d*e^(-b*d)
apply "ln" as a operation on both sides
ln e^-b = ln [2*d*e^(-b*d)]
logarithm properties log (a*b) = log a + log b
-b = ln 2 + ln d - b*d
b-b*d = ln 2 + ln d
b (1-d) = ln 2 + ln d
Finally
b = (ln 2 + ln d) / (1 - d)
Check out please I'm not sure
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):


Locked

Who is online

Users browsing this forum: No registered users and 7 guests