mesecons_x/mesecons_autowire/auto_delete.lua
2020-07-14 18:26:42 +02:00

363 lines
11 KiB
Lua

function delete_node(pos, direction_from)
if( not is_wire(pos)) then
return
end
local node = minetest.get_node(pos)
local name = node.name
local param2 = node.param2
if( (name == "mesecons_insulated:insulated_off") or (name == "mesecons_insulated:insulated_on") ) then
-- wire
if( (param2 == 0 ) or (param2 == 2) ) then
if( direction_from == "u" ) then
--nothing
return
elseif( direction_from == "d" ) then
--nothing
return
elseif( direction_from == "r" ) then
minetest.set_node(pos,{name="air"})
local next_pos = { x = pos.x - 1, y = pos.y, z = pos.z }
delete_node(next_pos,"r")
return
elseif( direction_from == "l" ) then
minetest.set_node(pos,{name="air"})
local next_pos = {x=pos.x+1,y=pos.y,z=pos.z}
delete_node(next_pos,"l")
return
end
end
if( (param2 == 1 ) or (param2 == 3) ) then
if( direction_from == "l" ) then
--nothing
return
elseif( direction_from == "r" ) then
--nothing
return
elseif( direction_from == "u" ) then
minetest.set_node(pos,{name="air"})
local next_pos = { x = pos.x , y = pos.y, z = pos.z -1}
delete_node(next_pos,"u")
return
elseif( direction_from == "d" ) then
minetest.set_node(pos,{name="air"})
local next_pos = {x=pos.x,y=pos.y,z=pos.z+1}
delete_node(next_pos,"d")
return
end
end
elseif (name == "mesecons_extrawires:corner_off") or (name == "mesecons_extrawires:corner_on") then
-- corner
if( param2 == 0 ) then
if( direction_from == "u" ) then
--nothing
return
elseif(direction_from == "r" ) then
--nothing
return
elseif(direction_from == "l" ) then
minetest.set_node(pos,{name="air"})
local next_pos = {x=pos.x,y=pos.y,z=pos.z-1}
delete_node(next_pos,"u")
return
elseif(direction_from == "d" ) then
minetest.set_node(pos,{name="air"})
local next_pos = {x=pos.x-1,y=pos.y,z=pos.z}
delete_node(next_pos,"r")
return
end
elseif (param2 == 1) then
if( direction_from == "d" ) then
--nothing
return
elseif(direction_from == "r" ) then
--nothing
return
elseif(direction_from == "l" ) then
minetest.set_node(pos,{name="air"})
local next_pos = {x=pos.x,y=pos.y,z=pos.z+1}
delete_node(next_pos,"d")
return
elseif(direction_from == "u" ) then
minetest.set_node(pos,{name="air"})
local next_pos = {x=pos.x-1,y=pos.y,z=pos.z}
delete_node(next_pos,"r")
return
end
elseif( param2 == 2 ) then
if( direction_from == "l" ) then
--nothing
return
elseif(direction_from == "d" ) then
--nothing
return
elseif(direction_from == "u" ) then
minetest.set_node(pos,{name="air"})
local next_pos = {x=pos.x+1,y=pos.y,z=pos.z}
delete_node(next_pos,"l")
return
elseif(direction_from == "r" ) then
minetest.set_node(pos,{name="air"})
local next_pos = {x=pos.x,y=pos.y,z=pos.z+1}
delete_node(next_pos,"d")
return
end
elseif( param2 == 3 ) then
if( direction_from == "l" ) then
--nothing
return
elseif(direction_from == "u" ) then
--nothing
return
elseif(direction_from == "d" ) then
minetest.set_node(pos,{name="air"})
local next_pos = {x=pos.x+1,y=pos.y,z=pos.z}
delete_node(next_pos,"l")
return
elseif(direction_from == "r" ) then
minetest.set_node(pos,{name="air"})
local next_pos = {x=pos.x,y=pos.y,z=pos.z-1}
delete_node(next_pos,"u")
return
end
end
elseif( name=="mesecons_extrawires:crossover_off") then
if( direction_from == "l" ) then
local next_pos = {x=pos.x+1,y=pos.y,z=pos.z}
minetest.set_node(pos,{name="mesecons_insulated:insulated_off", param2=1})
delete_node(next_pos,"l")
return
elseif(direction_from == "u" ) then
local next_pos = {x=pos.x,y=pos.y,z=pos.z-1}
minetest.set_node(pos,{name="mesecons_insulated:insulated_off", param2=0})
delete_node(next_pos,"u")
return
elseif(direction_from == "d" ) then
local next_pos = {x=pos.x,y=pos.y,z=pos.z+1}
minetest.set_node(pos,{name="mesecons_insulated:insulated_off", param2=0})
delete_node(next_pos,"d")
return
elseif(direction_from == "r" ) then
local next_pos = {x=pos.x-1,y=pos.y,z=pos.z}
minetest.set_node(pos,{name="mesecons_insulated:insulated_off", param2=1})
delete_node(next_pos,"r")
return
end
elseif (name=="mesecons_extrawires:crossover_10") then
if( direction_from == "l" ) then
local next_pos = {x=pos.x+1,y=pos.y,z=pos.z}
minetest.set_node(pos,{name="mesecons_insulated:insulated_on", param2=1})
delete_node(next_pos,"l")
return
elseif(direction_from == "u" ) then
local next_pos = {x=pos.x,y=pos.y,z=pos.z-1}
minetest.set_node(pos,{name="mesecons_insulated:insulated_off", param2=0})
delete_node(next_pos,"u")
return
elseif(direction_from == "d" ) then
local next_pos = {x=pos.x,y=pos.y,z=pos.z+1}
minetest.set_node(pos,{name="mesecons_insulated:insulated_off", param2=0})
delete_node(next_pos,"d")
return
elseif(direction_from == "r" ) then
local next_pos = {x=pos.x-1,y=pos.y,z=pos.z}
minetest.set_node(pos,{name="mesecons_insulated:insulated_on", param2=1})
delete_node(next_pos,"r")
return
end
elseif (name=="mesecons_extrawires:crossover_01") then
if( direction_from == "l" ) then
local next_pos = {x=pos.x+1,y=pos.y,z=pos.z}
minetest.set_node(pos,{name="mesecons_insulated:insulated_off", param2=1})
delete_node(next_pos,"l")
return
elseif(direction_from == "u" ) then
local next_pos = {x=pos.x,y=pos.y,z=pos.z-1}
minetest.set_node(pos,{name="mesecons_insulated:insulated_on", param2=0})
delete_node(next_pos,"u")
return
elseif(direction_from == "d" ) then
local next_pos = {x=pos.x,y=pos.y,z=pos.z+1}
minetest.set_node(pos,{name="mesecons_insulated:insulated_on", param2=0})
delete_node(next_pos,"d")
return
elseif(direction_from == "r" ) then
local next_pos = {x=pos.x-1,y=pos.y,z=pos.z}
minetest.set_node(pos,{name="mesecons_insulated:insulated_off", param2=1})
delete_node(next_pos,"r")
return
end
elseif (name=="mesecons_extrawires:crossover_on") then
if( direction_from == "l" ) then
local next_pos = {x=pos.x+1,y=pos.y,z=pos.z}
minetest.set_node(pos,{name="mesecons_insulated:insulated_on", param2=1})
delete_node(next_pos,"l")
return
elseif(direction_from == "u" ) then
local next_pos = {x=pos.x,y=pos.y,z=pos.z-1}
minetest.set_node(pos,{name="mesecons_insulated:insulated_on", param2=0})
delete_node(next_pos,"u")
return
elseif(direction_from == "d" ) then
local next_pos = {x=pos.x,y=pos.y,z=pos.z+1}
minetest.set_node(pos,{name="mesecons_insulated:insulated_on", param2=0})
delete_node(next_pos,"d")
return
elseif(direction_from == "r" ) then
local next_pos = {x=pos.x-1,y=pos.y,z=pos.z}
minetest.set_node(pos,{name="mesecons_insulated:insulated_on", param2=1})
delete_node(next_pos,"r")
return
end
elseif (name=="mesecons_morewires:xjunction_off") then
if( direction_from == "l" ) then
minetest.set_node(pos,{name="mesecons_extrawires:tjunction_off", param2=3})
return
elseif(direction_from == "u" ) then
minetest.set_node(pos,{name="mesecons_extrawires:tjunction_off", param2=0})
return
elseif(direction_from == "d" ) then
minetest.set_node(pos,{name="mesecons_extrawires:tjunction_off", param2=2})
return
elseif(direction_from == "r" ) then
minetest.set_node(pos,{name="mesecons_extrawires:tjunction_off", param2=1})
return
end
elseif (name=="mesecons_morewires:xjunction_on") then
if( direction_from == "l" ) then
minetest.set_node(pos,{name="mesecons_extrawires:tjunction_on", param2=3})
return
elseif(direction_from == "u" ) then
minetest.set_node(pos,{name="mesecons_extrawires:tjunction_on", param2=0})
return
elseif(direction_from == "d" ) then
minetest.set_node(pos,{name="mesecons_extrawires:tjunction_on", param2=2})
return
elseif(direction_from == "r" ) then
minetest.set_node(pos,{name="mesecons_extrawires:tjunction_on", param2=1})
return
end
elseif( name == "mesecons_extrawires:tjunction_off" ) or ( name == "mesecons_extrawires:tjunction_on" )then
local state = "on"
if ( name == "mesecons_extrawires:tjunction_off" ) then
state = "off"
end
if( param2 == 0 ) then
if( direction_from == "l" ) then
minetest.set_node(pos,{name="mesecons_extrawires:corner_"..state, param2 = 3})
return
elseif(direction_from == "u" ) then
--nothing
return
elseif(direction_from == "d" ) then
minetest.set_node(pos,{name="mesecons_insulated:insulated_"..state, param2 = 0})
return
elseif(direction_from == "r" ) then
minetest.set_node(pos,{name="mesecons_extrawires:corner_"..state, param2 = 0})
return
end
elseif( param2 == 1 ) then
if( direction_from == "u" ) then
minetest.set_node(pos,{name="mesecons_extrawires:corner_"..state, param2 = 0})
return
elseif(direction_from == "r" ) then
--nothing
return
elseif(direction_from == "l" ) then
minetest.set_node(pos,{name="mesecons_insulated:insulated_"..state, param2 = 1})
return
elseif(direction_from == "d" ) then
minetest.set_node(pos,{name="mesecons_extrawires:corner_"..state, param2 = 1})
return
end
elseif( param2 == 2 ) then
if( direction_from == "l" ) then
minetest.set_node(pos,{name="mesecons_extrawires:corner_"..state, param2 = 2})
return
elseif(direction_from == "d" ) then
--nothing
return
elseif(direction_from == "u" ) then
minetest.set_node(pos,{name="mesecons_insulated:insulated_"..state, param2 = 0})
return
elseif(direction_from == "r" ) then
minetest.set_node(pos,{name="mesecons_extrawires:corner_"..state, param2 = 1})
return
end
elseif( param2 == 3) then
if( direction_from == "u" ) then
minetest.set_node(pos,{name="mesecons_extrawires:corner_"..state, param2 = 3})
return
elseif(direction_from == "l" ) then
--nothing
return
elseif(direction_from == "r" ) then
minetest.set_node(pos,{name="mesecons_insulated:insulated_"..state, param2 = 1})
return
elseif(direction_from == "d" ) then
minetest.set_node(pos,{name="mesecons_extrawires:corner_"..state, param2 = 2})
return
end
end
end
end
function delete(pos)
-- local p = get_pins(pos)
local p = get_pins_sticky(pos)
if(p.u==1) then
delete_node(up_node(pos),"d")
end
if(p.d==1) then
delete_node(down_node(pos),"u")
end
if(p.l==1) then
delete_node(left_node(pos),"r")
end
if(p.r==1) then
delete_node(right_node(pos),"l")
end
minetest.set_node(pos,{ name = "air" } )
end
minetest.register_craftitem("mesecons_autowire:delete", {
description = "Tool Autodelete",
inventory_image = "tool_autodelete.png",
stack_max = 1,
groups = { tool =1 },
on_place = function(itemstack, user, pointed_thing)
local pos = pointed_thing.under
if( is_wire(pos) ) then
delete(pos)
elseif( is_sticky(pos) ) then
delete(pos)
end
end
})