Difference between revisions of "User:Hybrid Dog"

From Minetest Developer Wiki
Jump to navigation Jump to search
(Redirected page to Main Page)
(move minetest.on_place)
Line 1: Line 1:
 
#REDIRECT [[Main_Page]]
 
#REDIRECT [[Main_Page]]
ڡ
 
http://forum.minetest.net/profile.php?id=3419
 
  
 +
== minetest.on_place ==
  
== mods and textures ==
 
  
https://github.com/HybridDog?tab=repositories
+
=== Syntax ===
 +
<source>minetest.on_place(nodename, func)</source>
 +
 
 +
=== Description ===
 +
This changes on_place of a node after it was defined.<br/>
 +
It is not implemented into minetest but can be added via mod(s):
 +
<source>minetest.on_place = minetest.on_place or function(name, func)
 +
local previous_on_place = minetest.registered_nodes[name].on_place
 +
minetest.override_item(name, {
 +
on_place = function(itemstack, placer, pointed_thing)
 +
if func(itemstack, placer, pointed_thing) then
 +
return previous_on_place(itemstack, placer, pointed_thing)
 +
end
 +
end
 +
})
 +
end</source>
 +
 
 +
==== nodename ====
 +
The name of the node which should become changed
 +
 
 +
==== func ====
 +
should return true if the node becomes set
 +
<source>function(itemstack, placer, pointed_thing)</source>
 +
 
 +
=== Example ===
 +
<source>minetest.on_place("hydro:growlamp", function(itemstack, placer, pointed_thing)
 +
if not pointed_thing then
 +
return
 +
end
 +
local pos = minetest.get_pointed_thing_position(pointed_thing, true)
 +
if not pos then
 +
return
 +
end
 +
local nd_above = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
 +
local nd_above_info = minetest.registered_nodes[nd_above]
 +
if nd_above == "air"
 +
or nd_above == "hydro:growlamp"
 +
or not nd_above_info.walkable
 +
or nd_above_info.buildable_to then
 +
return
 +
end
 +
return true
 +
end)</source>

Revision as of 16:51, 27 May 2014

Redirect to:

minetest.on_place

Syntax

minetest.on_place(nodename, func)

Description

This changes on_place of a node after it was defined.
It is not implemented into minetest but can be added via mod(s):

minetest.on_place = minetest.on_place or function(name, func)
	local previous_on_place = minetest.registered_nodes[name].on_place
	minetest.override_item(name, {
		on_place = function(itemstack, placer, pointed_thing)
			if func(itemstack, placer, pointed_thing) then
				return previous_on_place(itemstack, placer, pointed_thing)
			end
		end
	})
end

nodename

The name of the node which should become changed

func

should return true if the node becomes set

function(itemstack, placer, pointed_thing)

Example

minetest.on_place("hydro:growlamp", function(itemstack, placer, pointed_thing)
	if not pointed_thing then
		return
	end
	local pos = minetest.get_pointed_thing_position(pointed_thing, true)
	if not pos then
		return
	end
	local nd_above = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
	local nd_above_info = minetest.registered_nodes[nd_above]
	if nd_above == "air"
	or nd_above == "hydro:growlamp"
	or not nd_above_info.walkable
	or nd_above_info.buildable_to then
		return
	end
	return true
end)