From f99148f2c4f76ad92f2c73c4af6202be35a8e833 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Wed, 20 May 2020 20:24:49 +1000 Subject: [PATCH] make self-contained injector directional --- technic/machines/other/injector.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/technic/machines/other/injector.lua b/technic/machines/other/injector.lua index 5dd7361..2fa397e 100644 --- a/technic/machines/other/injector.lua +++ b/technic/machines/other/injector.lua @@ -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") @@ -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 @@ -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 @@ -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, })