Post your modding questions here

Robsoie
Member
Posts: 98
Joined: Fri Apr 29, 2016 16:22

Re: Post your modding questions here

by Robsoie » Post

I'm not lua competent at all, but for fun i've been trying to remove all water from some worlds.

After looking around i found people saying to use

Code: Select all

minetest.register_alias("mapgen_water_source", "air")
minetest.register_alias("default:water_source", "air")
in a mod to have all the water replaced by air.

So i tried , in a folder i named "nowater", i had made the following file
init.lua

Code: Select all

local path = minetest.get_modpath("nowater")
dofile(path .. "/aliases.lua")
aliases.lua

Code: Select all

minetest.register_alias("mapgen_water_source", "air")
minetest.register_alias("default:water_source", "air")
depends.txt

Code: Select all

default
and mod.conf

Code: Select all

name = nowater
But when i enable it, nothing happens and the only trace i see in the log :
2017-05-02 11:53:32: WARNING[Main]: Not registering alias, item with same name is already defined: mapgen_water_source -> air
2017-05-02 11:53:32: WARNING[Main]: Not registering alias, item with same name is already defined: default:water_source -> air
So without having any idea of why it does not work, help please ?

User avatar
burli
Member
Posts: 1641
Joined: Fri Apr 10, 2015 13:18

Re: Post your modding questions here

by burli » Post

kaeza wrote:
sofar wrote:local my_data = minetest.get_mod_storage()

then use it like it's a `meta`:

my_data.set_string("foo", "bar")
s = my_data.get_string("foo")

https://github.com/minetest/minetest/bl ... .txt#L2700
Just a minor correction: it should be `my_data:blah(...)` (note the colon instead of a period).
I have a question about mod storage: Will data be loaded on demand or is everything loaded to memory when Minetest starts?

User avatar
Casimir
Member
Posts: 1164
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

Re: Post your modding questions here

by Casimir » Post

Robsoie wrote:So without having any idea of why it does not work, help please ?
You depend on default. But in default the mapgen nodes already get aliased to normal nodes. You would need to load your mod before default (don't know if there is a nice way to do this). Easiest would be to just edit the files in default.

Edit: Or you could try minetest.register_alias_force

Robsoie
Member
Posts: 98
Joined: Fri Apr 29, 2016 16:22

Re: Post your modding questions here

by Robsoie » Post

Thank you very much !
The minetest.register_alias_force works great !

Before :
Image

After enabling the mod with :

Code: Select all

minetest.register_alias_force("mapgen_water_source", "air")
minetest.register_alias_force("default:water_source", "air")
Image
More places to explore now :D
(edit : though it's better to enable the mod before visiting the world for the first time as in the already generated underwater areas will have the dark shadows of the water surface on the ground, while newly generated underwater without water will not be affected by the shadow problem),

(edit 2 , looks like i had to use

Code: Select all

minetest.register_alias_force("default:ice", "air")
too, as the ice sheets in icy biomes seems to require water to not transform into the infinitively high pillars of ice blocks i saw.

User avatar
DS-minetest
Member
Posts: 1137
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: DS-minetest
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: Post your modding questions here

by DS-minetest » Post

@Robsoie: There's a setting called "water_level".
Note that I've recently renamed myself on github and co. to "Desour". (I'm bad at naming things.)
Feel free to call me DS.

Robsoie
Member
Posts: 98
Joined: Fri Apr 29, 2016 16:22

Re: Post your modding questions here

by Robsoie » Post

I didn't knew this, thanks i guess i just learn something everyday with minetest :)

User avatar
pandaro
Member
Posts: 321
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind

Re: Post your modding questions here

by pandaro » Post

I'm trying to overwrite the function

Code: Select all

on use = function(itemstack, user, pointed_thing)
of the hand of the players.
Is possible?
i have try to do this in several manner inside a new mod:
1 through:

Code: Select all

minetest.override_item("", {
	on_use = function(itemstack, user, pointed_thing)
		print(tostring('hello'))
	end
})
2 through:

Code: Select all

local hand = minetest.registered_items[""]
hand.on_use = 'ciao'
print(dump(hand))
hand.on_use = function(itemstack, user, pointed_thing)
		print(tostring('hello'))
	end
3 through:

Code: Select all

minetest.register_item(":", {
	type = "none",
	wield_image = "wieldhand.png",
	wield_scale = {x=1,y=1,z=2.5},
	tool_capabilities = {
		full_punch_interval = 1.0,
		max_drop_level = 0,
		groupcaps = {
			fleshy = {times={[2]=2.00, [3]=1.00}, uses=0, maxlevel=1},
			crumbly = {times={[2]=3.00, [3]=0.70}, uses=0, maxlevel=1},
			snappy = {times={[3]=0.40}, uses=0, maxlevel=1},
			oddly_breakable_by_hand = {times={[1]=7.00,[2]=4.00,[3]=1.40}, uses=0, maxlevel=3},
		}
	},
	on_use = function(itemstack, user, pointed_thing)
		print(tostring('hello'))	
	end,
})
but no one of this attempts work.
The only way that work is modify the hand definition inside:

Code: Select all

/minetest/games/minimal/mods/default/init.lua
if here i add the function

Code: Select all

on_use = function(itemstack, user, pointed_thing)
		print(tostring('hello'))
	end
it work.
There is a way to do what i want to do? What am I doing wrong?

User avatar
RealGoldenHart
Member
Posts: 57
Joined: Fri Dec 23, 2016 23:27
IRC: GoldenHart
In-game: GoldenHart
Location: My office.

Re: Post your modding questions here

by RealGoldenHart » Post

Another noob question from me, as I'm just getting into modding.

I have 2 food items, and upon eating the food, the player gets jump or speed boost for a certain amount of time, depending on the food. I know that crystal boots had the following code in groups, but that required the player to wear the armor for the boosts to take effect(physics_speed=1,physics_jump=0.5,). How would I set it up so that the player eats the food and gets the boost for a certain amount of time.


I am worried the answer will be very simple. Bear with my stupidity :/
K. I'm bored with signatures.

User avatar
Lone_Wolf
Member
Posts: 2341
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Post your modding questions here

by Lone_Wolf » Post

RealGoldenHart wrote:Another noob question from me, as I'm just getting into modding.

I have 2 food items, and upon eating the food, the player gets jump or speed boost for a certain amount of time, depending on the food. I know that crystal boots had the following code in groups, but that required the player to wear the armor for the boosts to take effect(physics_speed=1,physics_jump=0.5,). How would I set it up so that the player eats the food and gets the boost for a certain amount of time.


I am worried the answer will be very simple. Bear with my stupidity :/
Mine's worse, Maybe edit the textures of potions? Then make them placeable?

User avatar
orwell
Member
Posts: 824
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell
Location: Raxacoricofallapatorius

Re: Post your modding questions here

by orwell » Post

RealGoldenHart wrote:Another noob question from me, as I'm just getting into modding.

I have 2 food items, and upon eating the food, the player gets jump or speed boost for a certain amount of time, depending on the food. I know that crystal boots had the following code in groups, but that required the player to wear the armor for the boosts to take effect(physics_speed=1,physics_jump=0.5,). How would I set it up so that the player eats the food and gets the boost for a certain amount of time.


I am worried the answer will be very simple. Bear with my stupidity :/
It's indeed not that simple. The group values in the armor definition are handled by the 3d armor mod internally.
you probably have this in your item definition:

Code: Select all

on_use=minetest.item_eat(2),
you need to execute an additional action on eating the item, like:

Code: Select all

on_use=function(itemstack, user, pointed_thing)
  minetest.do_item_eat(2, nil, itemstack, user, pointed_thing)
  ...action-here...
end,
I would suggest you to depend on the playereffects mod and add an effect using its api.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...

User avatar
Casimir
Member
Posts: 1164
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

Re: Post your modding questions here

by Casimir » Post

Does someone know how fast set_attribute and get_attribute are? Would it be better if I load them in local variables when used a lot?

@ pandaro
As far as I remember there once was an issue about overriding the hand in the minetest issue tracker. But I haven't found it on the fly.

sofar
Developer
Posts: 2130
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Post your modding questions here

by sofar » Post

Casimir wrote:Does someone know how fast set_attribute and get_attribute are? Would it be better if I load them in local variables when used a lot?
Very, very fast. For most operations you should directly use them. I would maybe not use these if you're running code that loops over all players every server tick, but even that should be any noticeable impact on the server load.
Casimir wrote:@ pandaro
As far as I remember there once was an issue about overriding the hand in the minetest issue tracker. But I haven't found it on the fly.
There's a patch in minetest-dev that actually makes this work OK now.

User avatar
Lone_Wolf
Member
Posts: 2341
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Post your modding questions here

by Lone_Wolf » Post

RealGoldenHart wrote:Another noob question from me, as I'm just getting into modding.

I have 2 food items, and upon eating the food, the player gets jump or speed boost for a certain amount of time, depending on the food. I know that crystal boots had the following code in groups, but that required the player to wear the armor for the boosts to take effect(physics_speed=1,physics_jump=0.5,). How would I set it up so that the player eats the food and gets the boost for a certain amount of time.


I am worried the answer will be very simple. Bear with my stupidity :/
Maybe edit/combine the sprinting mod a little?

User avatar
Casimir
Member
Posts: 1164
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

Re: Post your modding questions here

by Casimir » Post

sofar wrote:
Casimir wrote:I would maybe not use these if you're running code that loops over all players every server tick,
Exactly this. It's for a hunger mod. But I can move it behind the other checks and be okay with it for now. Thanks for the answer.

User avatar
swordpaint12
Member
Posts: 191
Joined: Sat Aug 22, 2015 00:50
In-game: [swordpaint12][Belching_Balladeer]
Location: Foobass, isle of Atlantis, castle of Bardvendelle

Re: Post your modding questions here

by swordpaint12 » Post

So, in the bucket mod that comes with the default minetest game, when you use a bucket full of water or lava you are left with an empty bucket. How do I code this? I'm making a small morefood mod and I want to know how to eat the contents of the bowl but leave the empty bowl afterwards.
God's not dead; remember that!
Yay for MT! No MC here!
I am a human. I'm younger than 100 years old.
I've been playing Minetest since December 2014.

I'm amazed that I haven't been on here in so long! My latest minetest accomplishment was mining by hand (well, as close as you can get in a computer game) a circle 30 blocks in diameter. It took forever but it's pretty cool.

User avatar
pandaro
Member
Posts: 321
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind

Re: Post your modding questions here

by pandaro » Post

sofar wrote:
Casimir wrote:@ pandaro
As far as I remember there once was an issue about overriding the hand in the minetest issue tracker. But I haven't found it on the fly.
There's a patch in minetest-dev that actually makes this work OK now.
thanks for infos, i will try to update it at last dev version and check soon.
EDIT:
just installed last unstable dev:
it seems not work, i need to know something about how to use it? Which of the methods I exhibited is correct to use?

User avatar
Lone_Wolf
Member
Posts: 2341
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Post your modding questions here

by Lone_Wolf » Post

I can't mine mese blocks with the rainbow pick? I've tried a few things but have gotten no results. What does the 'cracky' section do?

Code: Select all

minetest.register_tool("nyancats_plus:rainbow_pick",{
   description = "Rainbow Pickaxe",
   inventory_image = "rainbow_pick.png",
   tool_capabilities = {
      full_punch_interval = 0.5,
      max_drop_level=10,
      groupcaps={
         cracky = {times={[1]=1.0, [2]=0.7, [3]

=0.25}, uses=0},
      },
      damage_groups = {fleshy=20},
   },
(I have 0.5% knowledge of lua)
EDIT The mod was modified a little...

User avatar
azekill_DIABLO
Member
Posts: 7494
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: Post your modding questions here

by azekill_DIABLO » Post

how to get the position of a player if i have his name?

EDIT: neverming, i was actually refering to a string instead of an OBJref...

User avatar
yzelast
Member
Posts: 54
Joined: Sun Oct 02, 2016 01:18
GitHub: yzelast
In-game: yzelast
Location: Far Far Away

Re: Post your modding questions here

by yzelast » Post

Hey guys, just some small questions:

I'm planning to create a sickle to destroy leaves in an area but after reading the wiki and the api, i still do not understand how the wear parameter works.

And in my tests, the nodes are being instantly destroyed, if someone could tell me how to dig the nodes in the right way i would be glad.

Code: Select all

minetest.register_tool("real_trees:test", {
	description = "test",
	inventory_image = "example2.png",

	on_use = function(itemstack, player, pointed_thing)
	local pos = minetest.get_pointed_thing_position(pointed_thing)
		if pos == nil then return end

	local pmin = {x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}
	local pmax = {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}
	local area = minetest.find_nodes_in_area(pmin,pmax,"default:leaves")
		for key,value in pairs(area) do
			minetest.set_node(value,{name = "air"})
			minetest.add_item(value,{name = "default:leaves"})
			itemstack:add_wear(256)
		end
		return itemstack
	end
})
G84mU6AQ9dKaNhxn6dq8P5C0y5r8NssE

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

Re: Post your modding questions here

by Byakuren » Post

yzelast wrote:Hey guys, just some small questions:

I'm planning to create a sickle to destroy leaves in an area but after reading the wiki and the api, i still do not understand how the wear parameter works.

And in my tests, the nodes are being instantly destroyed, if someone could tell me how to dig the nodes in the right way i would be glad.

Code: Select all

minetest.register_tool("real_trees:test", {
	description = "test",
	inventory_image = "example2.png",

	on_use = function(itemstack, player, pointed_thing)
	local pos = minetest.get_pointed_thing_position(pointed_thing)
		if pos == nil then return end

	local pmin = {x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}
	local pmax = {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}
	local area = minetest.find_nodes_in_area(pmin,pmax,"default:leaves")
		for key,value in pairs(area) do
			minetest.set_node(value,{name = "air"})
			minetest.add_item(value,{name = "default:leaves"})
			itemstack:add_wear(256)
		end
		return itemstack
	end
})
Instead of on_use, you could use minetest.register_on_dignode and check if the digger is holding a sickle. There is no dig callback for items.
Every time a mod API is left undocumented, a koala dies.

dawgdoc
Member
Posts: 251
Joined: Mon Feb 27, 2017 01:10
GitHub: dawgdoc

Re: Post your modding questions here

by dawgdoc » Post

yzelast wrote:Hey guys, just some small questions:

I'm planning to create a sickle to destroy leaves in an area but after reading the wiki and the api, i still do not understand how the wear parameter works.

And in my tests, the nodes are being instantly destroyed, if someone could tell me how to dig the nodes in the right way i would be glad.
Nathan.S has a sickle in his Survival Sub-Game. You may be able to find some useful information there. (When used on grass the sickle leaves cut grass on top of the dirt/grass node.)
Give a man a fish, feed him for a day. Give a kid a fish, it's going to die.

FaceDeer
Member
Posts: 464
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: Post your modding questions here

by FaceDeer » Post

I'm working on a new crafting system mod. It takes an input inventory filled with raw materials, populates an output inventory with all possible itemstacks that could be crafted from those inputs, and the player picks what output he'd like to craft by taking an item from the output inventory and dropping it into his own inventory.

This is quite straightforward to do when using a crafting table to access this system, I just use the various on_metadata_inventory_* callbacks for the node to detect when the player's moving items between various inventories and apply the crafting rules at that point. However, I'd like to add an option to replace the player's "native" crafting system with this approach and I'm missing a few key pieces.

I can see how to fiddle with a player's formspec and the player's inventory layout, but I need the equivalent of the player's on_metadata_inventory_move method to detect when a player is moving stuff between their inventories. register_on_craft doesn't look like it does what I need, it seems firmly wedded to the existing grid-based crafting system. register_on_player_receive_fields is able to handle button presses in the player inventory formspec but it doesn't appear to be triggered by inventory movement.

Anyone know if what I want to do is even possible? I've never seen a mod that tampers with the default 3*3 crafting grid and recipe system like this before.

User avatar
Casimir
Member
Posts: 1164
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

Re: Post your modding questions here

by Casimir » Post

Maybe a bug in the engine, or maybe I'm just stupid and someone can point me to my mistake: player:get_attributes returns a number as string.

In my drowning mod. Remove "tonumber" and uncomment the print. This will cause this error:

Code: Select all

    h_breath 0, typestring
    2017-05-14 22:13:47: ERROR[Main]: ServerError: AsyncErr: environment_Step: Runtime error from mod '' in callback environment_Step(): ...minetest/bin/../games/Voxelgarden/mods/drowning/init.lua:183: attempt to compare number with string
In my hunger mod, which works similar, there is no problem.

I'm kind of confused.

User avatar
orwell
Member
Posts: 824
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell
Location: Raxacoricofallapatorius

Re: Post your modding questions here

by orwell » Post

This is because the type of player attributes is always "string", you can't save other type's values there
When setting the atttribute, the value is implicitly converted to a string
Fortunately, for Lua, the expression "1" is equal to 1 when doing maths, so "1"+"1" will result in 2
(as well as 1..2 results in "12")

EDIT: I won't comment what you wrote on PHP.
Last edited by orwell on Mon May 15, 2017 20:56, edited 1 time in total.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...

User avatar
azekill_DIABLO
Member
Posts: 7494
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: Post your modding questions here

by azekill_DIABLO » Post

not sure if it is a modding question, but... why no one thought using this:

Code: Select all

collision_removal = true,
in particle definition? It's so useful!

Locked

Who is online

Users browsing this forum: No registered users and 1 guest