Added mese filter (takes full stack).
authorNovatux <nathanael.courant@laposte.net>
Mon, 28 Jan 2013 17:41:14 +0000 (18:41 +0100)
committerNovatux <nathanael.courant@laposte.net>
Mon, 28 Jan 2013 17:41:14 +0000 (18:41 +0100)
crafts.lua
item_transport.lua
textures/pipeworks_mese_filter_input.png [new file with mode: 0644]
textures/pipeworks_mese_filter_output.png [new file with mode: 0644]
textures/pipeworks_mese_filter_side.png [new file with mode: 0644]
textures/pipeworks_mese_filter_top.png [new file with mode: 0644]

index e5adc4ebaa6a5cd32c484e6f83180133c63dee71..8bbc580392c7737587d3f2db59cc9b0a5578b96c 100644 (file)
@@ -155,6 +155,15 @@ if io.open(minetest.get_modpath("pipeworks").."/../technic/init.lua", "r") == ni
                        { "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
                },
        })
+       
+       minetest.register_craft( {
+               output = "pipeworks:mese_filter 2",
+               recipe = {
+                       { "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" },
+                       { "default:stick", "default:mese", "homedecor:plastic_sheeting" },
+                       { "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
+               },
+       })
 
        minetest.register_craft( {
         output = "pipeworks:entry_panel 2",
index 665516e6d9eeaebbc04736b40bd62c632439fb35..305a459714e4d2a394f54109fdcef6778bfc4d50 100644 (file)
@@ -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)
diff --git a/textures/pipeworks_mese_filter_input.png b/textures/pipeworks_mese_filter_input.png
new file mode 100644 (file)
index 0000000..b8aed3e
Binary files /dev/null and b/textures/pipeworks_mese_filter_input.png differ
diff --git a/textures/pipeworks_mese_filter_output.png b/textures/pipeworks_mese_filter_output.png
new file mode 100644 (file)
index 0000000..b2ee77a
Binary files /dev/null and b/textures/pipeworks_mese_filter_output.png differ
diff --git a/textures/pipeworks_mese_filter_side.png b/textures/pipeworks_mese_filter_side.png
new file mode 100644 (file)
index 0000000..6bdb507
Binary files /dev/null and b/textures/pipeworks_mese_filter_side.png differ
diff --git a/textures/pipeworks_mese_filter_top.png b/textures/pipeworks_mese_filter_top.png
new file mode 100644 (file)
index 0000000..990116e
Binary files /dev/null and b/textures/pipeworks_mese_filter_top.png differ