diff options
author | LNJ <git@lnj.li> | 2017-04-02 21:29:32 +0200 |
---|---|---|
committer | LNJ <git@lnj.li> | 2017-04-05 14:53:16 +0200 |
commit | d3d29fb4979f720fc1eed793b74b18d5dd0d521f (patch) | |
tree | 64843a0d7fc1a35318998c61bbe0df727165bb04 /lua/helpers.lua | |
parent | 06beee465248de2e37923db8553daf6c9893bc67 (diff) |
Add basic 2x2 Drawers
They're still missing some functionality as pipeworks and drops after dug.
This will be done in the next commit(s).
Diffstat (limited to 'lua/helpers.lua')
-rwxr-xr-x | lua/helpers.lua | 82 |
1 files changed, 73 insertions, 9 deletions
diff --git a/lua/helpers.lua b/lua/helpers.lua index 3718da3..87adbae 100755 --- a/lua/helpers.lua +++ b/lua/helpers.lua @@ -68,20 +68,84 @@ end function drawers.spawn_visual(pos) local node = core.get_node(pos) + local ndef = core.registered_nodes[node.name] + local drawerType = ndef.groups.drawer -- data for the new visual drawers.last_drawer_pos = pos - drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name")) + drawers.last_drawer_type = drawerType - local bdir = core.facedir_to_dir(node.param2) - local fdir = vector.new(-bdir.x, 0, -bdir.z) - local pos2 = vector.add(pos, vector.multiply(fdir, 0.438)) + if drawerType == 1 then -- 1x1 drawer + drawers.last_visual_id = "" + drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name")) - obj = core.add_entity(pos2, "drawers:visual") + local bdir = core.facedir_to_dir(node.param2) + local fdir = vector.new(-bdir.x, 0, -bdir.z) + local pos2 = vector.add(pos, vector.multiply(fdir, 0.438)) - if bdir.x < 0 then obj:setyaw(0.5 * math.pi) end - if bdir.z < 0 then obj:setyaw(math.pi) end - if bdir.x > 0 then obj:setyaw(1.5 * math.pi) end + obj = core.add_entity(pos2, "drawers:visual") - drawers.last_texture = nil + if bdir.x < 0 then obj:setyaw(0.5 * math.pi) end + if bdir.z < 0 then obj:setyaw(math.pi) end + if bdir.x > 0 then obj:setyaw(1.5 * math.pi) end + + drawers.last_texture = nil + else -- 2x2 drawer + local bdir = core.facedir_to_dir(node.param2) + + local fdir1 + local fdir2 + local fdir3 + local fdir4 + if node.param2 == 2 then + fdir1 = vector.new(-bdir.x + 0.5, 0.5, -bdir.z) + fdir2 = vector.new(-bdir.x - 0.5, 0.5, -bdir.z) + fdir3 = vector.new(-bdir.x + 0.5, -0.5, -bdir.z) + fdir4 = vector.new(-bdir.x - 0.5, -0.5, -bdir.z) + elseif node.param2 == 0 then + fdir1 = vector.new(-bdir.x - 0.5, 0.5, -bdir.z) + fdir2 = vector.new(-bdir.x + 0.5, 0.5, -bdir.z) + fdir3 = vector.new(-bdir.x - 0.5, -0.5, -bdir.z) + fdir4 = vector.new(-bdir.x + 0.5, -0.5, -bdir.z) + elseif node.param2 == 1 then + fdir1 = vector.new(-bdir.x, 0.5, -bdir.z + 0.5) + fdir2 = vector.new(-bdir.x, 0.5, -bdir.z - 0.5) + fdir3 = vector.new(-bdir.x, -0.5, -bdir.z + 0.5) + fdir4 = vector.new(-bdir.x, -0.5, -bdir.z - 0.5) + else + fdir1 = vector.new(-bdir.x, 0.5, -bdir.z - 0.5) + fdir2 = vector.new(-bdir.x, 0.5, -bdir.z + 0.5) + fdir3 = vector.new(-bdir.x, -0.5, -bdir.z - 0.5) + fdir4 = vector.new(-bdir.x, -0.5, -bdir.z + 0.5) + end + + objs = {} + + drawers.last_visual_id = 1 + drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name1")) + local pos1 = vector.add(pos, vector.multiply(fdir1, 0.438)) + objs[1] = core.add_entity(pos1, "drawers:visual") + + drawers.last_visual_id = 2 + drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name2")) + local pos2 = vector.add(pos, vector.multiply(fdir2, 0.438)) + objs[2] = core.add_entity(pos2, "drawers:visual") + + drawers.last_visual_id = 3 + drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name3")) + local pos3 = vector.add(pos, vector.multiply(fdir3, 0.438)) + objs[3] = core.add_entity(pos3, "drawers:visual") + + drawers.last_visual_id = 4 + drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name4")) + local pos4 = vector.add(pos, vector.multiply(fdir4, 0.438)) + objs[4] = core.add_entity(pos4, "drawers:visual") + + + for i,obj in pairs(objs) do + if bdir.x < 0 then obj:setyaw(0.5 * math.pi) end + if bdir.z < 0 then obj:setyaw(math.pi) end + if bdir.x > 0 then obj:setyaw(1.5 * math.pi) end + end + end end |