General Help

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

General Help

by Grubler » Post

I wonder if there could be a thread where we can maybe share things we may know and help each other figure out how to do things. If people may have questions and other people may know things that may help. And stuff like that. Maybe this may be redundant, but I don't know.

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

My question would be, I am wondering if it is possible to make it so if I place a specific object onto another specific object, if it can turn that object that it was placed on into a different specific object, and remove the object I placed from my inventory.

User avatar
TenPlus1
Member
Posts: 3700
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: General Help

by TenPlus1 » Post

A little code that creates a dirt block that turns into a diamond block when right-clicked with a gold block, or turns into a mese block when punched with sand :)

Code: Select all

minetest.register_node("test:dirt", {
	description = "My Dirt",
	tiles = {"default_dirt.png"},
	groups = {crumbly = 3},
	sounds = default.node_sound_dirt_defaults(),

	on_punch = function(pos, node, puncher, pointed_thing)

		local itemstack = puncher:get_wielded_item()
		local item = itemstack:get_name()

		if item == "default:sand" then

			itemstack:take_item()

			puncher:set_wielded_item(itemstack)

			minetest.set_node(pos, {name = "default:mese"})
		end
	end,

	on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)

		local item = itemstack:get_name()

		if item == "default:goldblock" then

			itemstack:take_item()

			minetest.set_node(pos, {name = "default:diamondblock"})

			return itemstack
		end
	end
})

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

Oh my goodness, it actually works. I would then ask if there is a way that I could rightclick it with an open hand and get a specific item from it, and change it into a different specific object at the same time. I may be able to take what has already been given and figure out how to do it on my own, but I'm not sure yet. Thank you very much.

Image

I may just make it so it gives something when it is broken and make it breakable by hand and have it change into something else, if that is possible.
(I think I may have managed to figure it out.)
(Actually having a bit of difficulty with trying to make it work for stairs, but maybe you have helped enough, so it may be okay.)
(Pretty tough to figure out. Could maybe use some help. Also having trouble trying to change the textures of stairs.)

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

Do you think it is possible to make something that could make the grass grow on its own?

And is it also possible to make a headlamp? Important questions.

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: General Help

by Skamiz Kazzarch » Post

When asking if something 'is possible' in an open source engine the answer is pretty-much always going to be yes. The question is only how difficult it is to implement.

With this mod:https://github.com/mt-mods/illumination I think you only need to add light_source = 'whatever', to the armor piece definition to make it spread light when worn. Though I haven't tested it myself.

As for grass, do you mean tall grass just growing on dirt_with_grass, or do you mean a node which makes grass grow around itself? I am not sure from the question what you mean?

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

I have tried to use the illumination and stuff and it doesn't seem to work that way. Only for items that are held in the hand and stuff.

The idea of the grass is that you have grass on dirt, and then over time you see small grass appear and then over more time the grass gets taller and until it reaches maximum height. And so you would have grass growing on its own on blocks with grass.

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: General Help

by Skamiz Kazzarch » Post

Riiiight... . Except that the readme specifically mentions that it's compatible with '3d_armor' and I literally looked up the code bit in the code, where it checks all worn armor for the 'light_source' property. Link to armor checking function: https://github.com/mt-mods/illumination ... t.lua#L105

As for the grass, put this in in your code somewhere:

Code: Select all

local next_grass = {
	["default:grass_1"] = "default:grass_2",
	["default:grass_2"] = "default:grass_3",
	["default:grass_3"] = "default:grass_4",
	["default:grass_4"] = "default:grass_5",
}
minetest.register_abm({
	label = "Grass growth",
	nodenames = {
		"default:dirt_with_grass",
		"default:grass_1",
		"default:grass_2",
		"default:grass_3",
		"default:grass_4",
	},
	interval = 60,
	chance = 100,
	min_y = -50,
	max_y = 200,
	catch_up = false,
	action = function(pos, node)
		if node.name == "default:dirt_with_grass" then
			pos.y = pos.y + 1
			if minetest.get_node(pos).name == "air" then
				minetest.set_node(pos, {name = "default:grass_1"})
			end
		else
			minetest.set_node(pos, {name = next_grass[node.name]})
		end
	end
})
You might want to fiddle with the interval and chance parameters to set the growth speed to your preference. Relevant documentation: https://github.com/minetest/minetest/bl ... .txt#L7072

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

You are like a hero of some sort... I want to shed a tear...

Maybe because I am using an "Illumination" mod by Piezo it doesn't have that part in it... I will attempt it...

Update: ... Oh my goodness... it worked.. but now I have smoke coming from torches I am carrying and the illuminated helmet I am wearing... uhh I will try to fix it.. I say thank you..

This is amazing. Time for celebration.

(Maybe we can add something that gives it a small chance to grow a flower instead of grass.)

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

How does a person use a "globalstep" thing?

User avatar
cx384
Member
Posts: 653
Joined: Wed Apr 23, 2014 09:38
GitHub: cx384
IRC: cx384

Re: General Help

by cx384 » Post

Grubler wrote:
Wed Sep 15, 2021 18:51
How does a person use a "globalstep" thing?
It can be used to execute something globally about every 0.1 seconds (the time may depend on server lag)

You should add some kind of timer to keep a good performance.

Example:

Code: Select all

local timer = 0
minetest.register_globalstep(function(dtime)
	timer = timer + dtime
	if timer >= 3 then
		minetest.chat_send_all(timer)
		timer = 0
	end
end)
The areas mod makes use of it:
https://github.com/minetest-mods/areas/ ... hud.lua#L6
Can your read this?

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

One time, a person made a change to a soft leaves mod for me where if you step on the leaves it has a change to break. I think they used the globalstep thing, but I am not sure how they did it. I didn't understand the scripting at the time.

In an unrelated note, I was looking at the minecart mod that lets the minecart move items, but it leaves them sitting inside the cart and maybe they could disappear. I am wondering if since it seems like how it works is when the cart is moving it turns into a different sort of thing than when it is not moving, if it could be made into a chest sort of object instead of leaving things sitting there, but maybe it may be not possible or maybe too hard to do. I also wonder about vertical transportation of items. The sounding line mod seems kind of useful. Not sure if I am going beyond the idea of general help.

Another thing... I tried to use an ABM to make plants turn into air if a footprints trail is below them, but it seems to be turning anything on it into air. Plant or not.

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

I tried to make a thing that is wallmounted like a ladder and changes into another form when a light level is detected and it seems that when it changes, it always wants to be mounted to the top of the block, so it changes positions if it was placed on a different side. Is there a way to make it not change positions when that happens?

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: General Help

by Skamiz Kazzarch » Post

You need to copy the previous nodes 'param2' value. That's where the rotation is stored.
relevant links:
https://github.com/minetest/minetest/bl ... .txt#L5064
https://github.com/minetest/minetest/bl ... .txt#L5045

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

I don't seem to know how to do that.

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

I would want to know how to make it so when I step on a block, it may do something to it.

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: General Help

by Skamiz Kazzarch » Post

Generally you would make a globalstep function which checks what node the player is standing on and triggers an effect if it's the right node.

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

Re: General Help

by Grubler » Post

Then I would maybe like to know how to do that, if that is something that would help, I guess.
And then maybe I could walk on grass and it would go down each time I walked on it until it was gone, and combined with the thing that makes it grow on its own, that may be pretty neat.

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: General Help

by Skamiz Kazzarch » Post

You may be interested in this mod in general: https://content.minetest.net/packages/F ... ootprints/
And in specific the function starting here: https://github.com/minetest-mods/footpr ... t.lua#L463 which does what I described.

Edit:
Since it just so happened to be useful for my own world have this:

Code: Select all

local previous_grass = {
		["default:grass_1"] = "air",
		["default:grass_2"] = "default:grass_1",
		["default:grass_3"] = "default:grass_2",
		["default:grass_4"] = "default:grass_3",
		["default:grass_5"] = "default:grass_4",
}

local players = {}
local timer = 0
minetest.register_globalstep(function(dtime)
	timer = timer + dtime
	if timer >= 0.5 then
		timer = timer - 0.5
	else
		return
	end
	for _, player in ipairs(minetest.get_connected_players()) do
		local player_name = player:get_player_name()
		local pos = vector.round(player:get_pos())
		local pos_string = minetest.pos_to_string(pos)
		if pos_string == players[player_name] then return end

		players[player_name] = pos_string

		local node = minetest.get_node(pos)
		if previous_grass[node.name] then
			node.name = previous_grass[node.name]
			minetest.set_node(pos, node)
		end
	end
end)

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

Re: General Help

by rubenwardy » Post

Grubler wrote:
Thu Sep 09, 2021 17:38
I wonder if there could be a thread where we can maybe share things we may know and help each other figure out how to do things. If people may have questions and other people may know things that may help. And stuff like that. Maybe this may be redundant, but I don't know.
We used to have a modding questions mega thread, but it was eventually closed as it made googling things impossible and it was hard to keep track of conversations - so questions were buried
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Josselin2
Member
Posts: 102
Joined: Thu May 28, 2020 15:32
GitHub: axcore
In-game: Josselin
Location: Tunnelers' Abyss

Re: General Help

by Josselin2 » Post

Before this mini-thread gets buried, how can LUA code in a mod detect that name of the game it's running on? (Specifically, I want to know if I'm running on top of minetest-game or not)

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: General Help

by Skamiz Kazzarch » Post

Check out this thread: viewtopic.php?f=47&t=27379

User avatar
Wizard Of mkdir
Member
Posts: 26
Joined: Tue Aug 17, 2021 14:18
GitHub: wizardofgcc
In-game: Wizard Of mkdir

Re: General Help

by Wizard Of mkdir » Post

Hello! I have a question: how does the number of nodes affect performance? If I want multiple versions of a node, e. g. an item frame or placed potion bottle, is it better to register many nodes or use entities to create visual changes in the node?

User avatar
Mantar
Member
Posts: 582
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: General Help

by Mantar » Post

From what I gather nodes are the kings of speed, and entities are eaters of cpu -- whereas ABMs are the wellspring of lag in multiplayer.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

User avatar
ywwv
Member
Posts: 299
Joined: Mon Jan 18, 2021 11:51

Re: General Help

by ywwv » Post

I want to pack points efficently on the surface of a sphere . the fibonacci lattice can do this. but it doesn't coincide with the platonic solids. I want a lattice that does that.if anyone can help it could be very lucrative for you

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests