diff options
author | VanessaE <vanessaezekowitz@gmail.com> | 2013-01-28 21:19:31 -0800 |
---|---|---|
committer | VanessaE <vanessaezekowitz@gmail.com> | 2013-01-28 21:19:31 -0800 |
commit | 38b8d1a123e2c404e326ebf21c71908ba83f4a48 (patch) | |
tree | 8db510d2454f0d14e6f44954bd235cb94086bcc4 /item_transport.lua | |
parent | ff29717136ded01d4cade2a8f273d2d4234428e4 (diff) | |
parent | 6b511d98f8167bfc20da23a850ba6fcb205950f6 (diff) | |
download | pipeworks-38b8d1a123e2c404e326ebf21c71908ba83f4a48.tar pipeworks-38b8d1a123e2c404e326ebf21c71908ba83f4a48.tar.gz pipeworks-38b8d1a123e2c404e326ebf21c71908ba83f4a48.tar.bz2 pipeworks-38b8d1a123e2c404e326ebf21c71908ba83f4a48.tar.xz pipeworks-38b8d1a123e2c404e326ebf21c71908ba83f4a48.zip |
Merge pull request #16 from Novatux/master
Mese filters: take full stack.
Diffstat (limited to 'item_transport.lua')
-rw-r--r-- | item_transport.lua | 95 |
1 files changed, 93 insertions, 2 deletions
diff --git a/item_transport.lua b/item_transport.lua index 665516e..305a459 100644 --- a/item_transport.lua +++ b/item_transport.lua @@ -8,7 +8,7 @@ minetest.register_craftitem("pipeworks:filter", { }) minetest.register_node("pipeworks:filter", { - description = "filter", + description = "Filter", tiles = {"pipeworks_filter_top.png", "pipeworks_filter_top.png", "pipeworks_filter_output.png", "pipeworks_filter_input.png", "pipeworks_filter_side.png", "pipeworks_filter_top.png"}, paramtype2 = "facedir", @@ -94,6 +94,97 @@ minetest.register_node("pipeworks:filter", { end, }) +minetest.register_craftitem("pipeworks:mese_filter", { + description = "Mese filter", + stack_max = 99, +}) + +minetest.register_node("pipeworks:mese_filter", { + description = "Mese filter", + tiles = {"pipeworks_mese_filter_top.png", "pipeworks_mese_filter_top.png", "pipeworks_mese_filter_output.png", + "pipeworks_mese_filter_input.png", "pipeworks_mese_filter_side.png", "pipeworks_mese_filter_top.png"}, + paramtype2 = "facedir", + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,tubedevice=1,mesecon=2}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("formspec", + "invsize[9,9;]".. + "list[current_name;main;0,2;8,2;]".. + "list[current_player;main;0,5;8,4;]") + meta:set_string("infotext", "Mese filter") + local inv = meta:get_inventory() + inv:set_size("main", 8*4) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + return inv:is_empty("main") + end, + mesecons={effector={action_on=function(pos,node) + minetest.registered_nodes[node.name].on_punch(pos,node,nil) + end}}, + on_punch = function (pos, node, puncher) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + local frompos + local dir + if node.param2==0 then + frompos={x=pos.x-1,y=pos.y,z=pos.z} + dir={x=1,y=0,z=0} + elseif node.param2==1 then + frompos={x=pos.x,y=pos.y,z=pos.z+1} + dir={x=0,y=0,z=-1} + elseif node.param2==2 then + frompos={x=pos.x+1,y=pos.y,z=pos.z} + dir={x=-1,y=0,z=0} + else + frompos={x=pos.x,y=pos.y,z=pos.z-1} + dir={x=0,y=0,z=1} + end + local fromnode=minetest.env:get_node(frompos) + local frominv + if not (minetest.registered_nodes[fromnode.name].tube and + minetest.registered_nodes[fromnode.name].tube.input_inventory) then + return + end + local frommeta=minetest.env:get_meta(frompos) + local frominvname=minetest.registered_nodes[fromnode.name].tube.input_inventory + local frominv=frommeta:get_inventory() + for _,filter in ipairs(inv:get_list("main")) do + local sname=filter:get_name() + if sname ~="" then + for spos,stack in ipairs(frominv:get_list(frominvname)) do + if stack:get_name()==sname then + item=stack:take_item(stack:get_count()) + frominv:set_stack(frominvname,spos,stack) + pos1=pos + item1=tube_item({x=pos1.x,y=pos1.y,z=pos1.z},item) + item1:get_luaentity().start_pos = {x=pos1.x,y=pos1.y,z=pos1.z} + item1:setvelocity(dir) + item1:setacceleration({x=0, y=0, z=0}) + return + end + end + end + end + if inv:is_empty("main") then + for spos,stack in ipairs(frominv:get_list(frominvname)) do + if stack:get_name()~="" then + item=stack:take_item(stack:get_count()) + frominv:set_stack(frominvname,spos,stack) + pos1=pos + item1=tube_item({x=pos1.x,y=pos1.y,z=pos1.z},item) + item1:get_luaentity().start_pos = {x=pos1.x,y=pos1.y,z=pos1.z} + item1:setvelocity(dir) + item1:setacceleration({x=0, y=0, z=0}) + return + end + end + end +end, +}) function tube_item(pos, item) -- Take item in any format @@ -303,7 +394,7 @@ function go_next(pos,velocity,stack) speed=1 end vel.speed=speed - if minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then + if minetest.registered_nodes[cnode.name] and minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then can_go=minetest.registered_nodes[cnode.name].tube.can_go(pos,node,vel,stack) else can_go=notvel(adjlist,vel) |