Skip to content

Commit

Permalink
make self-contained injector directional
Browse files Browse the repository at this point in the history
  • Loading branch information
OgelGames committed May 20, 2020
1 parent f83ad4f commit f99148f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions technic/machines/other/injector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ local fs_helpers = pipeworks.fs_helpers

local tube_entry = "^pipeworks_tube_connection_metallic.png"

local function inject_items (pos)
local param2_to_under = {
[0] = {x= 0,y=-1,z= 0}, [1] = {x= 0,y= 0,z=-1},
[2] = {x= 0,y= 0,z= 1}, [3] = {x=-1,y= 0,z= 0},
[4] = {x= 1,y= 0,z= 0}, [5] = {x= 0,y= 1,z= 0}
}

local function inject_items(pos, dir)
local meta=minetest.get_meta(pos)
local inv = meta:get_inventory()
local mode=meta:get_string("mode")
Expand All @@ -17,7 +23,7 @@ local function inject_items (pos)
local item0=stack:to_table()
if item0 then
item0["count"] = 1
technic.tube_inject_item(pos, pos, vector.new(0, -1, 0), item0)
technic.tube_inject_item(pos, pos, dir, item0)
stack:take_item(1)
inv:set_stack("main", i, stack)
return
Expand All @@ -32,7 +38,7 @@ local function inject_items (pos)
if stack then
local item0=stack:to_table()
if item0 then
technic.tube_inject_item(pos, pos, vector.new(0, -1, 0), item0)
technic.tube_inject_item(pos, pos, dir, item0)
stack:clear()
inv:set_stack("main", i, stack)
return
Expand Down Expand Up @@ -141,10 +147,11 @@ minetest.register_abm({
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local pos1 = vector.add(pos, vector.new(0, -1, 0))
local dir = param2_to_under[math.floor(node.param2/4)]
local pos1 = vector.add(pos, dir)
local node1 = minetest.get_node(pos1)
if minetest.get_item_group(node1.name, "tubedevice") > 0 then
inject_items(pos)
inject_items(pos, dir)
end
end,
})

0 comments on commit f99148f

Please sign in to comment.