summaryrefslogtreecommitdiff
path: root/deployer.lua
diff options
context:
space:
mode:
Diffstat (limited to 'deployer.lua')
-rw-r--r--deployer.lua143
1 files changed, 125 insertions, 18 deletions
diff --git a/deployer.lua b/deployer.lua
index c944331..01d4df2 100644
--- a/deployer.lua
+++ b/deployer.lua
@@ -9,6 +9,81 @@ end
minetest.register_alias("technic:deployer_off", "pipeworks:deployer_off")
minetest.register_alias("technic:deployer_on", "pipeworks:deployer_on")
+--define the functions from https://github.com/minetest/minetest/pull/834 while waiting for the devs to notice it
+local function dir_to_facedir(dir, is6d)
+ --account for y if requested
+ if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
+
+ --from above
+ if dir.y < 0 then
+ if math.abs(dir.x) > math.abs(dir.z) then
+ if dir.x < 0 then
+ return 19
+ else
+ return 13
+ end
+ else
+ if dir.z < 0 then
+ return 10
+ else
+ return 4
+ end
+ end
+
+ --from below
+ else
+ if math.abs(dir.x) > math.abs(dir.z) then
+ if dir.x < 0 then
+ return 15
+ else
+ return 17
+ end
+ else
+ if dir.z < 0 then
+ return 6
+ else
+ return 8
+ end
+ end
+ end
+
+ --otherwise, place horizontally
+ elseif math.abs(dir.x) > math.abs(dir.z) then
+ if dir.x < 0 then
+ return 3
+ else
+ return 1
+ end
+ else
+ if dir.z < 0 then
+ return 2
+ else
+ return 0
+ end
+ end
+end
+
+local function facedir_to_dir(facedir)
+ --a table of possible dirs
+ return ({{x=0, y=0, z=1},
+ {x=1, y=0, z=0},
+ {x=0, y=0, z=-1},
+ {x=-1, y=0, z=0},
+ {x=0, y=-1, z=0},
+ {x=0, y=1, z=0}})
+
+ --indexed into by a table of correlating facedirs
+ [({[0]=1, 2, 3, 4,
+ 5, 2, 6, 4,
+ 6, 2, 5, 4,
+ 1, 5, 3, 6,
+ 1, 6, 3, 5,
+ 1, 4, 3, 2})
+
+ --indexed into by the facedir in question
+ [facedir]]
+end
+
minetest.register_craft({
output = 'pipeworks:deployer_off 1',
recipe = {
@@ -32,18 +107,10 @@ deployer_on = function(pos, node)
if node.name ~= "pipeworks:deployer_off" then
return
end
-
- local pos1 = {x=pos.x, y=pos.y, z=pos.z}
- local pos2 = {x=pos.x, y=pos.y, z=pos.z}
- if node.param2 == 3 then
- pos1.x, pos2.x = pos1.x + 1, pos2.x + 2
- elseif node.param2 == 2 then
- pos1.z, pos2.z = pos1.z + 1, pos2.z + 2
- elseif node.param2 == 1 then
- pos1.x, pos2.x = pos1.x - 1, pos2.x - 2
- elseif node.param2 == 0 then
- pos1.z, pos2.z = pos1.z - 1, pos2.z - 2
- end
+
+ --locate the above and under positions
+ local dir = facedir_to_dir(node.param2)
+ local pos_under, pos_above = {x=pos.x - dir.x, y=pos.y - dir.y, z=pos.z - dir.z}, {x=pos.x - 2*dir.x, y=pos.y - 2*dir.y, z=pos.z - 2*dir.z}
hacky_swap_node(pos,"pipeworks:deployer_on")
nodeupdate(pos)
@@ -51,13 +118,13 @@ deployer_on = function(pos, node)
local inv = minetest.get_meta(pos):get_inventory()
local invlist = inv:get_list("main")
for i, stack in ipairs(invlist) do
- if stack:get_name() ~= nil and stack:get_name() ~= "" and minetest.get_node(pos1).name == "air" then --obtain the first non-empty item slow
+ if stack:get_name() ~= nil and stack:get_name() ~= "" and minetest.get_node(pos_under).name == "air" then --obtain the first non-empty item slot
local placer = {
get_player_name = function() return "deployer" end,
getpos = function() return pos end,
get_player_control = function() return {jump=false,right=false,left=false,LMB=false,RMB=false,sneak=false,aux1=false,down=false,up=false} end,
}
- local stack2 = minetest.item_place(stack, placer, {type="node", under=pos1, above=pos2})
+ local stack2 = minetest.item_place(stack, placer, {type="node", under=pos_under, above=pos_above})
if minetest.setting_getbool("creative_mode") and not minetest.get_modpath("unified_inventory") then --infinite stacks ahoy!
stack2:take_item()
end
@@ -90,7 +157,8 @@ minetest.register_node("pipeworks:deployer_off", {
local inv=meta:get_inventory()
return inv:room_for_item("main",stack)
end,
- input_inventory="main"},
+ input_inventory="main",
+ connect_sides={back=1}},
is_ground_content = true,
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, tubedevice_receiver=1},
@@ -111,7 +179,26 @@ minetest.register_node("pipeworks:deployer_off", {
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
- after_place_node = tube_scanforobjects,
+ after_place_node = function (pos, placer)
+ tube_scanforobjects(pos, placer)
+ local placer_pos = placer:getpos()
+
+ --correct for the player's height
+ if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
+
+ --correct for 6d facedir
+ if placer_pos then
+ local dir = {
+ x = pos.x - placer_pos.x,
+ y = pos.y - placer_pos.y,
+ z = pos.z - placer_pos.z
+ }
+ local node = minetest.get_node(pos)
+ node.param2 = dir_to_facedir(dir, true)
+ minetest.set_node(pos, node)
+ minetest.log("action", "real (6d) facedir: " .. node.param2)
+ end
+ end,
after_dig_node = tube_scanforobjects,
})
@@ -130,7 +217,8 @@ minetest.register_node("pipeworks:deployer_on", {
local inv=meta:get_inventory()
return inv:room_for_item("main",stack)
end,
- input_inventory="main"},
+ input_inventory="main",
+ connect_sides={back=1}},
is_ground_content = true,
paramtype2 = "facedir",
tubelike=1,
@@ -152,6 +240,25 @@ minetest.register_node("pipeworks:deployer_on", {
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
- after_place_node = tube_scanforobjects,
+ after_place_node = function (pos, placer)
+ tube_scanforobjects(pos, placer)
+ local placer_pos = placer:getpos()
+
+ --correct for the player's height
+ if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
+
+ --correct for 6d facedir
+ if placer_pos then
+ local dir = {
+ x = pos.x - placer_pos.x,
+ y = pos.y - placer_pos.y,
+ z = pos.z - placer_pos.z
+ }
+ local node = minetest.get_node(pos)
+ node.param2 = dir_to_facedir(dir, true)
+ minetest.set_node(pos, node)
+ minetest.log("action", "real (6d) facedir: " .. node.param2)
+ end
+ end,
after_dig_node = tube_scanforobjects,
})