mirror of
https://github.com/D00Med/scifi_nodes.git
synced 2024-12-23 00:20:17 +01:00
add pot-lid protection-check and fix lid-toggle code
This commit is contained in:
parent
53d9659051
commit
5b9431ea18
@ -337,6 +337,7 @@ minetest.register_node("scifi_nodes:pot_lid", {
|
|||||||
wield_image = "scifi_nodes_pod_inv.png",
|
wield_image = "scifi_nodes_pod_inv.png",
|
||||||
use_texture_alpha = "blend",
|
use_texture_alpha = "blend",
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
|
drop = "", -- part of the pot, don't let it in players inventory
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
groups = {cracky=1, not_in_creative_inventory=1},
|
groups = {cracky=1, not_in_creative_inventory=1},
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
@ -364,6 +365,42 @@ minetest.register_node("scifi_nodes:pot_lid", {
|
|||||||
sounds = default.node_sound_glass_defaults()
|
sounds = default.node_sound_glass_defaults()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local lid_offset = {x=0, y=2, z=0}
|
||||||
|
|
||||||
|
local function toggle_lid(pot_pos, player)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local player_name = player:get_player_name()
|
||||||
|
local lid_pos = vector.add(pot_pos, lid_offset)
|
||||||
|
local lid_node = minetest.get_node(lid_pos)
|
||||||
|
if minetest.is_protected(lid_pos, player_name) then
|
||||||
|
-- lid is in a protected area
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if lid_node.name == "scifi_nodes:pot_lid" then
|
||||||
|
minetest.set_node(lid_pos, {name="air"})
|
||||||
|
elseif lid_node.name == "air" then
|
||||||
|
minetest.set_node(lid_pos, {name="scifi_nodes:pot_lid"})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function remove_lid(pot_pos, player)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local player_name = player:get_player_name()
|
||||||
|
local lid_pos = vector.add(pot_pos, lid_offset)
|
||||||
|
local lid_node = minetest.get_node(lid_pos)
|
||||||
|
if minetest.is_protected(lid_pos, player_name) then
|
||||||
|
-- lid is in protected area
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if lid_node.name == "scifi_nodes:pot_lid" then
|
||||||
|
minetest.set_node(lid_pos, {name="air"})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("scifi_nodes:pot", {
|
minetest.register_node("scifi_nodes:pot", {
|
||||||
description = "metal plant pot (right click for lid, shift+rightclick to plant)",
|
description = "metal plant pot (right click for lid, shift+rightclick to plant)",
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -387,16 +424,11 @@ minetest.register_node("scifi_nodes:pot", {
|
|||||||
{0.1875, -0.5, -0.5, 0.5, -0.25, -0.1875}, -- NodeBox5
|
{0.1875, -0.5, -0.5, 0.5, -0.25, -0.1875}, -- NodeBox5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
on_rightclick = function(pos, node, clicker, item, _)
|
on_rightclick = function(pos, _, player)
|
||||||
local lid_node = minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z})
|
toggle_lid(pos, player)
|
||||||
if lid_node.name == "scifi_nodes:pot_lid" then
|
|
||||||
minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="air", param2=lid_node.param2})
|
|
||||||
elseif lid_node.name ~= "scifi_nodes:pot_lid" and node.name == "air" then
|
|
||||||
minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="scifi_nodes:pot_lid", param2=lid_node.param2})
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos, node, _)
|
after_dig_node = function(pos, _, _, player)
|
||||||
minetest.remove_node({x=pos.x, y=pos.y+2, z=pos.z})
|
remove_lid(pos, player)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -423,16 +455,11 @@ minetest.register_node("scifi_nodes:pot2", {
|
|||||||
{0.1875, -0.5, -0.5, 0.5, -0.25, -0.1875}, -- NodeBox5
|
{0.1875, -0.5, -0.5, 0.5, -0.25, -0.1875}, -- NodeBox5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
on_rightclick = function(pos, node, clicker, item, _)
|
on_rightclick = function(pos, _, player)
|
||||||
local lid_node = minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z})
|
toggle_lid(pos, player)
|
||||||
if lid_node.name == "scifi_nodes:pot_lid" then
|
|
||||||
minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="air", param2=lid_node.param2})
|
|
||||||
elseif lid_node.name ~= "scifi_nodes:pot_lid" and node.name == "air" then
|
|
||||||
minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="scifi_nodes:pot_lid", param2=lid_node.param2})
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos, node, _)
|
after_dig_node = function(pos, _, _, player)
|
||||||
minetest.remove_node({x=pos.x, y=pos.y+2, z=pos.z})
|
remove_lid(pos, player)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user