Restrict where a node can be placed

Restrict where a node can be placed

Postby jarel » Mon Apr 15, 2019 7:59 pm

Hi, I have two questions.

1. How to restrict a node to be placed only below another nodes, in general.
And in the other hand...

2. How to restrict a node to be placed only below a kind of node in particular.

I'm trying to attach a lamp only to hanger nodes (the hanger node changes to hanger_with_chains to connect the two nodes visually). Hangers can be placed on the floor, on the ceiling or wherever, but I only want the lamps be able to be placed below those on the ceiling.

Code: Select all
minetest.register_node("qnn:lamp", {
   description = "Lamp",
   drawtype = "nodebox",
   tiles = {"qnn_lamp.png"},
   paramtype = "light",
   --paramtype2 = "wallmounted",
   on_rotate = screwdriver.disallow,
   sunlight_propagates = true,
   walkable = false,
   --liquids_pointable = false,   
   groups = {choppy=1},
   node_box = {
      type = "fixed",
      fixed = {
            {-0.25, -0.5, -0.25, 0.25,0.5, 0.25},      
   on_place = function(itemstack, user, pointed_thing)
      local user_name = user:get_player_name()
      local pos = pointed_thing.under
      local name =minetest.get_node(pos).name
      local i=0
      if name=="qnn:hanger" then         
         minetest.set_node(pos, {name="qnn:hanger_with_chain", param2=minetest.get_node(pos).param2 }) --  <--swap_node doesnt keep the rotation of the node here
         minetest.set_node(pos, {name="qnn:lamp"})
         itemstack:take_item(1) --remove 1 lamp from inv.
      return itemstack

I used on_place, and it works... save for the fact that it got glitchy when placing from certain angles and I got fake duplicates of the node around the original. Those duplicates, when I check them with node inspector are "air" although the image and the selection box are from the lamp node.
If I close the game and enter again, those nodes are gone, are air again.

Thanks in advance
New member
Posts: 1
Joined: Sat Apr 13, 2019 8:14 am

Return to Modding Discussion

Who is online

Users browsing this forum: Yandex Bot [Bot] and 0 guests