Post your modding questions here

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

Re: Post your modding questions here

by Hybrid Dog » Post

swordpaint12 wrote:
Hybrid Dog wrote: If they did, building roofs with slabs would become far more annoying.
Actually, that's WHY I asked. I'm trying to make a tall roof using 'walls.'
try screwdriver and the Sokomine's replacer mod (or my version which adds more than just single node mode https://github.com/HybridDog/replacer)

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

User avatar
Ben
Member
Posts: 160
Joined: Tue Mar 31, 2015 20:09

Re: Post your modding questions here

by Ben » Post

Hi, can I restrict actions on player inventories somehow? Like the allow_* callbacks on detached inventories, or the allow_metadata_inventory_* callbacks on nodes. The idea is to show the player an formspec of a player-based inventory that they can take items from, but not insert items to.

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

Re: Post your modding questions here

by Don » Post

Ben wrote:Hi, can I restrict actions on player inventories somehow? Like the allow_* callbacks on detached inventories, or the allow_metadata_inventory_* callbacks on nodes. The idea is to show the player an formspec of a player-based inventory that they can take items from, but not insert items to.
deleted - miss read your post
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
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: Post your modding questions here

by Nathan.S » Post

Well I don't know how the inventory is being populated but you could do something like this

Code: Select all

allow_metadata_inventory_put = function(pos, listname, index, stack, player)
		if listname == 'sap' then
			if stack:get_name() == ('bucket:bucket_empty') then
				return 1
			else
				return 0
			end
		end
	end,
Of course you'd have to change the variables: sap, and bucket:bucket_empty. Maybe just change it to air or cloud. Then if a player tries to put anything in it will just get spit back at them. Unless they cheat to get clouds or air. You might even be able to use a non-existent string in place of the bucket:bucket_empty which would just return everything.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

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

Re: Post your modding questions here

by Don » Post

Untested but I think this should work

Code: Select all

allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
		local meta = minetest.get_meta(pos)
			return 0
		end
		return count
	end,
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
Ben
Member
Posts: 160
Joined: Tue Mar 31, 2015 20:09

Re: Post your modding questions here

by Ben » Post

Thanks Nathan and Don, but those are for node inventories, right? I'm dealing with player inventories here.

Digging through mod code has not turned anything up, so far. Does anyone know where something like this has been done before?

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

Re: Post your modding questions here

by Don » Post

@Ben - The mod "creative" in minetest_game might help.
https://github.com/minetest/minetest_ga ... e/init.lua
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
Ben
Member
Posts: 160
Joined: Tue Mar 31, 2015 20:09

Re: Post your modding questions here

by Ben » Post

Don wrote:The mod "creative" in minetest_game might help.
No, sorry. The creative inventory is a detached inventory – the same for all players. And the "craftpreview" inventory slot seems to be special-cased in the engine?

I'm beginning to feel it's not possible in the current MT?

User avatar
ArguablySane
Member
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: Post your modding questions here

by ArguablySane » Post

Does anyone know why these two methods of perlin noise generation give different results?

Code: Select all

local perlin_map = minetest.get_perlin_map(params, {x=sidelen, y=sidelen, z=sidelen}):get2dMap_flat({x=minp.x, y=minp.z})
local index = (x-minp.x+1) + (z-minp.z)*sidelen
return perlin_map[index]

Code: Select all

return PerlinNoise(params):get2d{x=x, y=z}
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your modding questions here

by paramat » Post

Try:
local index = (x - minp.x) + (z - minp.z) * sidelen
I'm not sure if the map indexes from 0 or 1.
And / or try:
return minetest.get_perlin(params):get2d{x = x, y = z}

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

Re: Post your modding questions here

by Hybrid Dog » Post

ArguablySane wrote:Does anyone know why these two methods of perlin noise generation give different results?

Code: Select all

local perlin_map = minetest.get_perlin_map(params, {x=sidelen, y=sidelen, z=sidelen}):get2dMap_flat({x=minp.x, y=minp.z})
local index = (x-minp.x+1) + (z-minp.z)*sidelen
return perlin_map[index]

Code: Select all

return PerlinNoise(params):get2d{x=x, y=z}
maybe you need to set z to 1 to make it really flat

Code: Select all

local perlin_map = minetest.get_perlin_map(params, {x=sidelen, y=sidelen, z=1}):get2dMap_flat({x=minp.x, y=minp.z})

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

User avatar
ArguablySane
Member
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: Post your modding questions here

by ArguablySane » Post

paramat wrote:return minetest.get_perlin(params):get2d{x = x, y = z}
That worked, thanks!
It turns out that the PerlinNoise[Map] objects ignore the map seed but minetest.get_perlin[_map] includes it somehow. That discrepancy made them produce different noise.
Thanks for your suggestion too, Hybrid Dog.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.

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

Re: Post your modding questions here

by Hybrid Dog » Post

ArguablySane wrote:
paramat wrote:return minetest.get_perlin(params):get2d{x = x, y = z}
That worked, thanks!
It turns out that the PerlinNoise[Map] objects ignore the map seed but minetest.get_perlin[_map] includes it somehow. That discrepancy made them produce different noise.
Thanks for your suggestion too, Hybrid Dog.
What happens if l use the functions somewhere outside generation, e.g. when the mods become loaded?

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

User avatar
ArguablySane
Member
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: Post your modding questions here

by ArguablySane » Post

Hybrid Dog wrote:
ArguablySane wrote:
paramat wrote:return minetest.get_perlin(params):get2d{x = x, y = z}
That worked, thanks!
It turns out that the PerlinNoise[Map] objects ignore the map seed but minetest.get_perlin[_map] includes it somehow. That discrepancy made them produce different noise.
Thanks for your suggestion too, Hybrid Dog.
What happens if l use the functions somewhere outside generation, e.g. when the mods become loaded?
You can't use minetest.get_perlin or minetest.get_perlin_map until the game has finished loading. If you put them in the body of your init.lua file, then they won't work. You can use them anywhere else though. They aren't restricted to being used in the on_generated callback, although that's the most obvious place to put them.

Also, I have another question: Does anyone know how to implement a version of minetest.hash_node_position(pos) which actually works to seed PcgRandom or PseudoRandom?
I've been testing the following code (part of a much larger mapgen project) and the image shows what it returns:

Code: Select all

local prng = PcgRandom(minetest.hash_node_position(pos) + self.seed)
minetest.chat_send_all(pos.x..","..pos.y..","..pos.z.." goes to "..prng:next())
Image
As you can see, similar values of x give the same result from the PRNG, which leads to repeating patterns on the map.

EDIT: Turns out it was a problem with adding the map seed (a very large number) to the result from minetest.hash_node_position(pos). When I removed that it started working again. I still need to figure out a good way to include the map seed though. Maybe I could just take the lower ~8 bits of it and add those. That should provide sufficient randomness.

EDIT2: Yep, that fixed it. I now only add the lower 16 bits of the map seed.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.

User avatar
Ferk
Member
Posts: 337
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Post

What would be the best way for me to store all the entities of an area in a table that I can save to a file so it can later be loaded back?

I tried to serialize ``minetest.luaentities``, but it crashes the game.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

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

Re: Post your modding questions here

by Hybrid Dog » Post

ArguablySane wrote:EDIT: Turns out it was a problem with adding the map seed (a very large number) to the result from minetest.hash_node_position(pos). When I removed that it started working again. I still need to figure out a good way to include the map seed though. Maybe I could just take the lower ~8 bits of it and add those. That should provide sufficient randomness.

EDIT2: Yep, that fixed it. I now only add the lower 16 bits of the map seed.
l'm using this code https://github.com/HybridDog/vines/blob ... t.lua#L193, what are the disadvantages?

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

User avatar
Ferk
Member
Posts: 337
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Post

Ok after some struggle I found out what I think is the way to serialize minetest.luaentitites

It seems a bit awkward to have to pass self to the entity all the time. Maybe I'm accessing the functions the wrong way, I don't know...

Code: Select all

		local entities = {}
		for id,entity in pairs(minetest.luaentities) do
			table.insert(entities, {
				pos = entity.object.getpos(entity.object),
				name = entity.name,
				staticdata = entity.object.get_luaentity(entity.object).get_staticdata(entity.object)
			})
		end
		local str = minetest.serialize(entities)
So, I store position, name (which according to the documentation is the identifier used in register_entity and already determines the initial_properties) and staticdata (according to the docs should hold any changes in state that are not covered already by the initial_properties).

The thing is that after doing this, I get a lot of entities with name "__builtin:item" for the items that are dropped down in the map.

I don't know if it's because they are "__builtin:*" but these items don't seem to expose any properties in the staticdata that determine what kind of item it is.

I can access some values if I directly use the entity as a table (there's for example "entity.stringitem"), but it's not clear to me how would I restore those entities when I try to deserialize the file, since minetest.add_entity(pos, "name") doesn't have enough parameters to specify this, and the only other method to change its state seems to be on_activate(self, staticdata) which requires a staticdata that is not present.

I see that there is a "minetest.add_item" function, which seems to suggest that items dropped are a special kind of entity (__builtin:item) that doesn't really follow the rules of standard entities. But even if I made an exception in the code for this entity name, I wouldn't know how to obtain the name of the item to be used in add_item. Or is it safe to assume that all items will have an "entity.stringitem" property that would always correspond to the item identifier? And are there other entities I have to add exceptions for?
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

User avatar
ArguablySane
Member
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: Post your modding questions here

by ArguablySane » Post

Hybrid Dog wrote: l'm using this code https://github.com/HybridDog/vines/blob ... t.lua#L193, what are the disadvantages?
It will produce identical results for certain positions. For y = 0, there will be a set of points corresponding to x = -z^5 where the seed is just vine_seed, but there will be lots of other sets of identical points too. Using math.abs actually makes things worse because it doubles the number of symmetric points. You can seed the PRGN with a negative number just as effectively as with a positive number.
Also, you might want to do some testing with PseudoRandom. In my experience it gave similar results from similar seeds, but that might have been a programming error on my part. I usually use PcgRandom.

Depending on your particular use it might not matter. From looking at your code, the only thing it's going to do is make vines which appear at those symmetry points the same length, but that shouldn't be noticeable to the player.

I did notice a different possible problem though. On line 311 that PRNG is going to return the same result every time it's run. That means that 25% of rotten vines simply won't disappear no matter how long they are left. Is that the intended behaviour?
The same is true of the ABM on line 199. It will always immediately return for 25% of vines.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.

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

Re: Post your modding questions here

by Don » Post

How do you do a check for nodes when placing a schematic? I want to do if not air then return.
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
GunshipPenguin
Member
Posts: 94
Joined: Tue Jan 28, 2014 00:38
GitHub: GunshipPenguin
IRC: GunshipPenguin
In-game: GunshipPenguin
Location: Vancouver, BC

Re: Post your modding questions here

by GunshipPenguin » Post

I'm having trouble with a mod that utilizes minetest.after heavily.

Basically what I want to happen is this. A function is called through the use of minetest.after which does something and then uses minetest.after to call itself again sometime in the future. It will then continue to do something and call itself sometime in the future indefinitely.

Here is a very simple example.

Code: Select all

local timerfunction
timerfunction = function()
	minetest.log("action", "timerfunction called, calling again in 5 seconds")
	minetest.after(5, timerfunction)
end

minetest.log("action", "Calling timerfunction in 5 seconds")
minetest.after(5, timerfunction)
This code calls timerfunction 5 seconds in the future through the use of minetest.after. timerfunction then logs a message, and uses minetest.after to call itself 5 seconds in the future. This cycle goes on indefinitely.

The problem is, all calls to timerfunction through minetest.after besides the first one seem to be executed after 10 seconds rather than 5 seconds. Here is the output from minetest with this mod running.

Code: Select all

2015-09-08 17:32:59: ACTION[main]: Calling timerfunction in 5 seconds
2015-09-08 17:32:59: ACTION[main]:         .__               __                   __   
2015-09-08 17:32:59: ACTION[main]:   _____ |__| ____   _____/  |_  ____   _______/  |_ 
2015-09-08 17:32:59: ACTION[main]:  /     \|  |/    \_/ __ \   __\/ __ \ /  ___/\   __\
2015-09-08 17:32:59: ACTION[main]: |  Y Y  \  |   |  \  ___/|  | \  ___/ \___ \  |  |  
2015-09-08 17:32:59: ACTION[main]: |__|_|  /__|___|  /\___  >__|  \___  >____  > |__|  
2015-09-08 17:32:59: ACTION[main]:       \/        \/     \/          \/     \/        
2015-09-08 17:32:59: ACTION[main]: World at [/home/rhys/Desktop/minetest-0.4.13/bin/../worlds/asdf]
2015-09-08 17:32:59: ACTION[main]: Server for gameid="minetest" listening on 0.0.0.0:54258.
2015-09-08 17:32:59: ACTION[ServerThread]: singleplayer [127.0.0.1] joins game. 
2015-09-08 17:32:59: ACTION[ServerThread]: singleplayer joins game. List of players: singleplayer
2015-09-08 17:33:00: ACTION[main]: Irrlicht: Could not open file of texture: character.png
2015-09-08 17:33:00: ACTION[main]: Irrlicht: Could not open file of texture: character.png
2015-09-08 17:33:04: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
2015-09-08 17:33:14: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
2015-09-08 17:33:24: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
2015-09-08 17:33:34: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
2015-09-08 17:33:44: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
2015-09-08 17:33:54: ACTION[ServerThread]: timerfunction called, calling again in 5 seconds
Notice how the first log message "Calling timerfunction in 5 seconds" appears at 17:32:59 and then the message "timerfunction called, calling again in 5 seconds" is logged at 17:33:04. These two messages are separated by 5 seconds, which makes sense, given that the call to minetest.after specified that timerfunction was to be called 5 seconds in the future.

What I don't understand however, is why all the remaining log messages are separated by 10 seconds. This presents a large problem in my mod, as the correct timing of actions is very important.

I'm pretty stumped here. Can anybody tell me why this is happening? Many thanks in advance.

User avatar
rubenwardy
Moderator
Posts: 6972
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's possible that the messages aren't flushed immediately, but that wouldn't explain the 10 second gap.

Here is the minetest.after code: https://github.com/minetest/minetest/bl ... lua#L7-L75
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

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

Re: Post your modding questions here

by Hybrid Dog » Post

ArguablySane wrote:On line 311 that PRNG is going to return the same result every time it's run. That means that 25% of rotten vines simply won't disappear no matter how long they are left. Is that the intended behaviour?
The same is true of the ABM on line 199. It will always immediately return for 25% of vines.
I use PseudoRandom to reduce lag, originally it used math.random and the abms made the vines grow and die repeatedly.

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

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

Re: Post your modding questions here

by Hybrid Dog » Post

rubenwardy wrote:It's possible that the messages aren't flushed immediately, but that wouldn't explain the 10 second gap.

Here is the minetest.after code: https://github.com/minetest/minetest/bl ... lua#L7-L75
https://github.com/minetest/minetest/bl ... sc.lua#L18
https://github.com/minetest/minetest/bl ... sc.lua#L60
l think delay needs to be set to 0 but before a temporary copy of it needs to be set and used then for executing the function(s)

Edit: https://github.com/minetest/minetest/pull/3163/files
Last edited by Hybrid Dog on Wed Sep 09, 2015 11:56, 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 » Post

How do I delete all weird characters - particularly spaces - from any text entered as param in this chat command:
Spoiler

Code: Select all

minetest.register_chatcommand("setwarp", {
	params = "name",
	description = "Set a warp location to the players location",
	privs = { warp_admin = true },
	func = function(name, param)
		local h = "created"
		for i = 1,table.getn(warps) do
			if warps[i].name == param then
				table.remove(warps, i)
				h = "changed"
				break
			end
		end
		local player = minetest.get_player_by_name(name)
		local pos = player:getpos()
		table.insert(warps, { name = param, x = pos.x, y = pos.y, z = pos.z, yaw = player:get_look_yaw(), pitch = player:get_look_pitch() })
		save()
		minetest.log("action", name .. " " .. h .. " warp \"" .. param .. "\": " .. pos.x .. ", " .. pos.y .. ", " .. pos.z)
		return true, h .. " warp \"" .. param .. "\""
	end,
})
Thanks for any tips!

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

Re: Post your modding questions here

by Hybrid Dog » Post

everamzah wrote:How do I delete all weird characters - particularly spaces - from any text entered as param in this chat command:
Spoiler

Code: Select all

minetest.register_chatcommand("setwarp", {
	params = "name",
	description = "Set a warp location to the players location",
	privs = { warp_admin = true },
	func = function(name, param)
		local h = "created"
		for i = 1,table.getn(warps) do
			if warps[i].name == param then
				table.remove(warps, i)
				h = "changed"
				break
			end
		end
		local player = minetest.get_player_by_name(name)
		local pos = player:getpos()
		table.insert(warps, { name = param, x = pos.x, y = pos.y, z = pos.z, yaw = player:get_look_yaw(), pitch = player:get_look_pitch() })
		save()
		minetest.log("action", name .. " " .. h .. " warp \"" .. param .. "\": " .. pos.x .. ", " .. pos.y .. ", " .. pos.z)
		return true, h .. " warp \"" .. param .. "\""
	end,
})
Thanks for any tips!
maybe param = string.trim(param)

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

Locked

Who is online

Users browsing this forum: No registered users and 9 guests