Skip to content

Commit

Permalink
Merge pull request #28 from S-S-X/injectors
Browse files Browse the repository at this point in the history
#1 Pipeworks injectors
Worked for me so must be almost okayish, merging
  • Loading branch information
S-S-X committed Jun 7, 2020
2 parents 4053a9e + 47b3cf7 commit bd3c925
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tubetool/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ minetest.register_alias('tubetool:wand', 'metatool:tubetool')
tool:load_node_definition(dofile(modpath .. '/nodes/mese_tube.lua'))
tool:load_node_definition(dofile(modpath .. '/nodes/teleport_tube.lua'))
-- tool:load_node_definition(dofile(modpath .. '/nodes/sand_tube.lua')
-- tool:load_node_definition(dofile(modpath .. '/nodes/injector.lua')
tool:load_node_definition(dofile(modpath .. '/nodes/injector.lua'))
81 changes: 61 additions & 20 deletions tubetool/nodes/injector.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,66 @@
--
-- Register injectors for tubetool
-- Register injectors tube for tubetool
--

-- TODO: Register injectors for tubetool

--luacheck: ignore unused argument node player
local tooldef = {
group = 'injector',

copy = function(node, pos, player)
-- useless stuff to remove luacheck warnings
print(type(pos))
-- return data required for replicating this tube settings
return { description = 'Not implemented' }
end,

paste = function(node, pos, player, data)
-- useless stuff to remove luacheck warnings
print(type(pos))
print(type(data))
end,
}
return {
nodes = {
"pipeworks:filter",
"pipeworks:mese_filter",
},
tooldef = {
group = 'injector',

copy = function(node, pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()

-- get and store inventories data
local inv_data = {}
table.insert(inv_data, {})
for slot=1,inv:get_size("main") do
local stack = inv:get_stack("main", slot)
local item
if not stack:is_empty() then
item = stack:to_table()
end
-- add item or empty
table.insert(inv_data, item or "")
end

local slotseq_mode = meta:get_int("slotseq_mode")
local slotseq_index = meta:get_int("slotseq_index")
local exmatch_mode = meta:get_int("exmatch_mode")
local description = meta:get_string("infotext")

metatool:register_node('pipeworks:injector', tooldef)
-- return data required for replicating this injector settings
return {
description = description,
inventory = inv_data,
slotseq_mode = slotseq_mode,
slotseq_index = slotseq_index,
exmatch_mode = exmatch_mode,
}
end,

paste = function(node, pos, player, data)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()

-- restore inventories data
for index,item in ipairs(data.inventory) do
inv:set_stack("main", index-1, ItemStack(item))
end

meta:set_int("slotseq_mode", data.slotseq_mode)
meta:set_int("slotseq_index", data.slotseq_index)
if node.name == "pipeworks:filter" then
meta:set_int("exmatch_mode", data.exmatch_mode)
end

-- update injector formspec
local nodedef = minetest.registered_nodes[node.name]
nodedef.on_receive_fields(pos, "", {}, player)
end,
}
}

0 comments on commit bd3c925

Please sign in to comment.