123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- local fdir_table = {
- { 1, 0 },
- { 0, -1 },
- { -1, 0 },
- { 0, 1 },
- { 1, 0 },
- { 0, -1 },
- { -1, 0 },
- { 0, 1 },
- }
- local laser_gate = {
- type = 'fixed',
- fixed = {
- {-.5, -.3, -.2, .5, .3, .2},},}
- minetest.register_node('ship:laser_gate', {
- description = 'Laser Gate',
- drawtype = 'mesh',
- mesh = 'ship_laser_gate.obj',
- paramtype = 'light',
- paramtype2 = 'facedir',
- light_source = 10,
- tiles = {'ship_laser_gate.png'},
- groups = {breakable=1},
- selection_box = laser_gate,
- collision_box = laser_gate,
- after_place_node = function(pos, placer, itemstack)
- local node = minetest.get_node(pos)
- local fdir = node.param2
- local length = 0
- if fdir == 1 then -- negative z
- local pos1 = {x=pos.x, y=pos.y, z=pos.z-1}
- local pos1_name = minetest.get_node(pos1).name
- while pos1_name == 'air' and length <= 10 do
- length = length + 1
- pos1 = {x=pos1.x, y=pos1.y, z=pos1.z-1}
- pos1_name = minetest.get_node(pos1).name
- end
- if length >= 1 then
- minetest.set_node(pos, {name = 'ship:laser_gate_l', param2 = fdir})
- for i = 1, (length-1) do
- local place_pos = {x=pos.x, y=pos.y, z=pos.z-i}
- minetest.set_node(place_pos, {name = 'ship:laser_gate_m', param2 = fdir})
- end
- local end_pos = {x=pos.x, y=pos.y, z=pos.z-length}
- minetest.set_node(end_pos, {name = 'ship:laser_gate_r', param2 = fdir})
- end
- elseif fdir == 2 then -- negative x
- local pos1 = {x=pos.x-1, y=pos.y, z=pos.z}
- local pos1_name = minetest.get_node(pos1).name
- while pos1_name == 'air' and length <= 10 do
- length = length + 1
- pos1 = {x=pos1.x-1, y=pos1.y, z=pos1.z}
- pos1_name = minetest.get_node(pos1).name
- end
- if length >= 1 then
- minetest.set_node(pos, {name = 'ship:laser_gate_l', param2 = fdir})
- for i = 1, (length-1) do
- local place_pos = {x=pos.x-i, y=pos.y, z=pos.z}
- minetest.set_node(place_pos, {name = 'ship:laser_gate_m', param2 = fdir})
- end
- local end_pos = {x=pos.x-length, y=pos.y, z=pos.z}
- minetest.set_node(end_pos, {name = 'ship:laser_gate_r', param2 = fdir})
- end
- elseif fdir == 3 then -- positive z
- local pos1 = {x=pos.x, y=pos.y, z=pos.z+1}
- local pos1_name = minetest.get_node(pos1).name
- while pos1_name == 'air' and length <= 10 do
- length = length + 1
- pos1 = {x=pos1.x, y=pos1.y, z=pos1.z+1}
- pos1_name = minetest.get_node(pos1).name
- end
- if length >= 1 then
- minetest.set_node(pos, {name = 'ship:laser_gate_l', param2 = fdir})
- for i = 1, (length-1) do
- local place_pos = {x=pos.x, y=pos.y, z=pos.z+i}
- minetest.set_node(place_pos, {name = 'ship:laser_gate_m', param2 = fdir})
- end
- local end_pos = {x=pos.x, y=pos.y, z=pos.z+length}
- minetest.set_node(end_pos, {name = 'ship:laser_gate_r', param2 = fdir})
- end
- elseif fdir == 0 then -- positive x
- local pos1 = {x=pos.x+1, y=pos.y, z=pos.z}
- local pos1_name = minetest.get_node(pos1).name
- while pos1_name == 'air' and length <= 10 do
- length = length + 1
- pos1 = {x=pos1.x+1, y=pos1.y, z=pos1.z}
- pos1_name = minetest.get_node(pos1).name
- end
- if length >= 1 then
- minetest.set_node(pos, {name = 'ship:laser_gate_l', param2 = fdir})
- for i = 1, (length-1) do
- local place_pos = {x=pos.x+i, y=pos.y, z=pos.z}
- minetest.set_node(place_pos, {name = 'ship:laser_gate_m', param2 = fdir})
- end
- local end_pos = {x=pos.x+length, y=pos.y, z=pos.z}
- minetest.set_node(end_pos, {name = 'ship:laser_gate_r', param2 = fdir})
- end
- end
- end,
- })
- minetest.register_node('ship:laser_gate_l', {
- drawtype = 'mesh',
- mesh = 'ship_laser_gate_L.obj',
- paramtype = 'light',
- paramtype2 = 'facedir',
- light_source = 10,
- tiles = {'ship_laser_gate.png'},
- groups = {breakable=1, not_in_creative_inventory=1},
- drop = 'ship:laser_gate',
- selection_box = laser_gate,
- collision_box = laser_gate,
- })
- minetest.register_node('ship:laser_gate_r', {
- drawtype = 'mesh',
- mesh = 'ship_laser_gate_R.obj',
- paramtype = 'light',
- paramtype2 = 'facedir',
- light_source = 10,
- tiles = {'ship_laser_gate.png'},
- groups = {breakable=1, not_in_creative_inventory=1},
- drop = 'ship:laser_gate',
- selection_box = laser_gate,
- collision_box = laser_gate,
- })
- minetest.register_node('ship:laser_gate_m', {
- drawtype = 'mesh',
- mesh = 'ship_laser_gate_M.obj',
- paramtype = 'light',
- paramtype2 = 'facedir',
- light_source = 10,
- tiles = {'ship_laser_gate.png'},
- groups = {breakable=1, not_in_creative_inventory=1},
- drop = 'ship:laser_gate',
- selection_box = laser_gate,
- collision_box = laser_gate,
- })
|