commit 557a8cefd5d9a159b5a460aa9469a78face5ae7b Author: Drew Lemmy <24c2e295@opayq.com> Date: Fri Sep 12 23:53:49 2014 +0100 like initial commit init diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..eb930e9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,17 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + +---------- + +This license is commonly known as "WTFPL". diff --git a/contributors.txt b/contributors.txt new file mode 100644 index 0000000..a174684 --- /dev/null +++ b/contributors.txt @@ -0,0 +1 @@ +Drew Lemmy diff --git a/crafting.lua b/crafting.lua new file mode 100644 index 0000000..b9f2f33 --- /dev/null +++ b/crafting.lua @@ -0,0 +1,212 @@ +minetest.register_craft({ + output = "factory:belt 12", + recipe = { + {"", "default:gold_ingot", ""}, + {"default:stone", "factory:small_steel_gear", "default:stone"}, + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"} + } +}) + +minetest.register_craft({ + output = "factory:arm", + recipe = { + {"default:steel_ingot", "default:steel_ingot", "farming:hoe_steel"}, + {"default:steel_ingot", "default:gold_ingot", "factory:small_steel_gear"}, + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"} + } +}) + +minetest.register_craft({ + output = "factory:smoke_tube", + recipe = { + {"default:steel_ingot", "", "default:steel_ingot"}, + {"default:steel_ingot", "", "default:steel_ingot"}, + {"default:steel_ingot", "", "default:steel_ingot"} + } +}) + +minetest.register_craft({ + output = "factory:ind_furnace", + recipe = { + {"factory:small_steel_gear", "default:steel_ingot", "factory:small_steel_gear"}, + {"default:steel_ingot", "default:furnace", "default:steel_ingot"}, + {"default:stonebrick", "default:obsidian", "default:stonebrick"} + } +}) + +minetest.register_craft({ + output = "factory:small_steel_gear 3", + recipe = { + {"default:steel_ingot", "", "default:steel_ingot"}, + {"", "default:steel_ingot", ""}, + {"default:steel_ingot", "", "default:steel_ingot"} + } +}) + +minetest.register_craft({ + output = "factory:small_gold_gear 2", + recipe = { + {"default:gold_ingot", "", "default:gold_ingot"}, + {"", "factory:small_steel_gear", ""}, + {"default:gold_ingot", "", "default:gold_ingot"} + } +}) + +minetest.register_craft({ + output = "factory:small_diamond_gear 2", + recipe = { + {"default:diamond", "", "default:diamond"}, + {"", "factory:small_gold_gear", ""}, + {"default:diamond", "", "default:diamond"} + } +}) + +minetest.register_craft({ + output = "factory:taker", + recipe = { + {"default:shovel_steel", "default:steel_ingot", "default:gold_ingot"}, + {"factory:small_steel_gear", "factory:small_steel_gear", "default:gold_ingot"}, + {"default:steel_ingot", "default:steelblock", "default:steel_ingot"} + } +}) + +minetest.register_craft({ + type = "shapeless", + output = "factory:taker_gold", + recipe = {"factory:taker", "default:goldblock", "factory:small_gold_gear"} +}) + +minetest.register_craft({ + type = "shapeless", + output = "factory:taker_diamond", + recipe = {"factory:taker_gold", "default:diamondblock", "factory:small_diamond_gear"} +}) + +minetest.register_craft({ + type = "shapeless", + output = "factory:queuedarm", + recipe = {"factory:arm", "default:chest", "factory:small_gold_gear"} +}) + +factory.register_craft({ + type = "ind_squeezer", + output = "factory:tree_sap", + recipe = {{"default:tree"}} +}) + +factory.register_craft({ + type = "ind_squeezer", + output = "factory:tree_sap", + recipe = {{"default:jungle_tree"}} +}) + +factory.register_craft({ + type = "ind_squeezer", + output = "factory:compressed_clay", + recipe = {{"default:clay_lump"}} +}) + +minetest.register_craft({ + type = "cooking", + output = "factory:factory_lump", + recipe = "factory:compressed_clay" +}) + +minetest.register_craft({ + output = 'factory:factory_brick 6', + recipe = { + {'factory:factory_lump', 'factory:factory_lump'}, + {'factory:factory_lump', 'factory:factory_lump'}, + } +}) + +minetest.register_craft({ + output = "factory:ind_squeezer", + recipe = { + {"default:glass", "default:stick", "default:glass"}, + {"default:glass", "default:steelblock", "default:glass"}, + {"factory:small_gold_gear", "factory:ind_furnace", "factory:small_gold_gear"} + } +}) + +minetest.register_craft({ + output = "factory:scanner_chip", + recipe = { + {"default:steel_ingot", "default:stick", "default:mese_crystal"}, + {"", "factory:tree_sap", ""}, + {"default:mese_crystal", "", "default:steel_ingot"} + } +}) + +minetest.register_craft({ + output = "factory:swapper", + recipe = { + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, + {"factory:arm", "factory:scanner_chip", "factory:arm"}, + {"default:mese_crystal", "", "default:mese_crystal"} + } +}) + +minetest.register_craft({ + type = "shapeless", + output = "factory:fan_blade", + recipe = { + "default:steel_ingot", + "factory:tree_sap", + "default:stick" + } +}) + +minetest.register_craft({ + output = "factory:fan_on", + recipe = { + {"default:steel_ingot", "factory:fan_blade", "default:steel_ingot"}, + {"factory:fan_blade", "factory:small_gold_gear", "factory:fan_blade"}, + {"default:steel_ingot", "factory:fan_blade", "default:steel_ingot"} + } +}) + +minetest.register_craft({ + output = "factory:fan_wall_on", + recipe = { + {"factory:fan_on", "", ""}, + {"", "", ""}, + {"", "", ""} + } +}) + +minetest.register_craft({ + output = "factory:storage_tank", + recipe = { + {"default:glass", "default:steel_ingot", "default:glass"}, + {"default:glass", "", "default:glass"}, + {"default:glass", "default:steel_ingot", "default:glass"} + } +}) + +minetest.register_craft({ + output = "factory:miner_on", + recipe = { + {"default:steel_ingot", "factory:fan_on", "default:steel_ingot"}, + {"factory:small_gold_gear", "factory:taker_on", "factory:small_gold_gear"}, + {"default:steel_ingot", "default:pick_mese", "default:steel_ingot"} + } +}) + +minetest.register_craft({ + output = "factory:miner_upgraded_on", + recipe = { + {"", "factory:small_diamond_gear", ""}, + {"factory:small_gold_gear", "factory:miner_on", "factory:small_gold_gear"}, + {"default:gold_ingot", "default:pick_diamond", "default:gold_ingot"} + } +}) + +minetest.register_craft({ + output = "factory:vacuum_on", + recipe = { + {"default:steel_ingot", "factory:taker_on", "default:steel_ingot"}, + {"factory:small_steel_gear","factory:small_gold_gear", "factory:small_steel_gear"}, + {"", "default:steel_ingot", ""} + } +}) \ No newline at end of file diff --git a/craftitems.lua b/craftitems.lua new file mode 100644 index 0000000..81a3177 --- /dev/null +++ b/craftitems.lua @@ -0,0 +1,40 @@ +minetest.register_craftitem("factory:small_steel_gear", { + description = "Small Steel Gear", + inventory_image = "factory_small_steel_gear.png" +}) + +minetest.register_craftitem("factory:small_gold_gear", { + description = "Small Gold Gear", + inventory_image = "factory_small_gold_gear.png" +}) + +minetest.register_craftitem("factory:small_diamond_gear", { + description = "Small Diamond Gear", + inventory_image = "factory_small_diamond_gear.png" +}) + +minetest.register_craftitem("factory:tree_sap", { + description = "Tree Sap", + inventory_image = "factory_tree_sap.png" +}) + +minetest.register_craftitem("factory:compressed_clay", { + description = "Compressed Clay", + inventory_image = "factory_compressed_clay.png" +}) + +minetest.register_craftitem("factory:factory_lump", { + description = "Factory Lump", + inventory_image = "factory_lump.png" +}) + +minetest.register_craftitem("factory:scanner_chip", { + description = "Item Scanning Microchip", + inventory_image = "factory_scanner_chip.png" +}) + +minetest.register_craftitem("factory:fan_blade", { + description = "Small Fanblade", + inventory_image = "factory_fan_blade.png" +}) + diff --git a/depends b/depends new file mode 100644 index 0000000..331d858 --- /dev/null +++ b/depends @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/fan.lua b/fan.lua new file mode 100644 index 0000000..5801473 --- /dev/null +++ b/fan.lua @@ -0,0 +1,121 @@ +minetest.register_node("factory:fan_on", { + description = "Fan", + tiles = {{name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png", "factory_belt_side.png", + "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"}, + groups = {cracky=3, mesecon_effector_off = 1}, + drawtype = "nodebox", + paramtype = "light", + is_ground_content = true, + node_box = { + type = "fixed", + fixed = {{-0.5,-0.5,-0.5,0.5,0.0625,0.5},} + }, + mesecons = {effector = { + action_on = function(pos, node) + minetest.swap_node(pos, {name = "factory:fan_off", param2 = node.param2}) + end + }} +}) + +minetest.register_node("factory:fan_off", { + description = "Fan", + tiles = {{name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}, "factory_belt_bottom.png", "factory_belt_side.png", + "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"}, + groups = {cracky=3, not_in_creative_inventory=1, mesecon_effector_on = 1}, + drawtype = "nodebox", + paramtype = "light", + is_ground_content = true, + drop="factory:fan_on", + node_box = { + type = "fixed", + fixed = {{-0.5,-0.5,-0.5,0.5,0.0625,0.5},} + }, + mesecons = {effector = { + action_off = function(pos, node) + minetest.swap_node(pos, {name = "factory:fan_on", param2 = node.param2}) + end + }} +}) + +minetest.register_abm({ + nodenames = {"factory:fan_on"}, + neighbors = nil, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local all_objects = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1) + local _,obj + for _,obj in ipairs(all_objects) do + if not obj:is_player() and obj:get_luaentity() and obj:get_luaentity().name == "__builtin:item" then + obj:moveto({x = obj:getpos().x, y = obj:getpos().y + 3, z = obj:getpos().z}) + end + end + end, +}) + + + + +minetest.register_node("factory:fan_wall_on", { + description = "Wall Fan", + tiles = {"factory_belt_side.png^[transformFY", "factory_belt_side.png", "factory_belt_side.png^[transformR90", + "factory_belt_side.png^[transformR270", "factory_belt_bottom.png", {name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}}, + groups = {cracky=3, mesecon_effector_off = 1}, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + is_ground_content = true, + legacy_facedir_simple = true, + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.5}, + } + }, + mesecons = {effector = { + action_on = function(pos, node) + minetest.swap_node(pos, {name = "factory:fan_wall_off", param2 = node.param2}) + end + }} +}) + +minetest.register_node("factory:fan_wall_off", { + description = "Wall Fan", + tiles = {"factory_belt_side.png^[transformFY", "factory_belt_side.png", "factory_belt_side.png^[transformR90", + "factory_belt_side.png^[transformR270", "factory_belt_bottom.png", {name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}}, + groups = {cracky=3, not_in_creative_inventory=1, mesecon_effector_on = 1}, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + is_ground_content = true, + legacy_facedir_simple = true, + drop="factory:fan_wall_on", + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.5}, + } + }, + mesecons = {effector = { + action_off = function(pos, node) + minetest.swap_node(pos, {name = "factory:fan_wall_on", param2 = node.param2}) + end + }} +}) + +minetest.register_abm({ + nodenames = {"factory:fan_wall_on"}, + neighbors = nil, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local a = minetest.facedir_to_dir(minetest.get_node(pos).param2) + local all_objects = minetest.get_objects_inside_radius({x = pos.x - a.x/2, y = pos.y, z = pos.z - a.z/2}, 1) + local _,obj + for _,obj in ipairs(all_objects) do + if not obj:is_player() and obj:get_luaentity() and obj:get_luaentity().name == "__builtin:item" then + obj:moveto({x = obj:getpos().x - a.x*2.0, y = obj:getpos().y, z = obj:getpos().z - a.z*2.0}) + end + end + end, +}) \ No newline at end of file diff --git a/ind_furnace.lua b/ind_furnace.lua new file mode 100644 index 0000000..0ed299d --- /dev/null +++ b/ind_furnace.lua @@ -0,0 +1,327 @@ +function factory.ind_furnace_active(pos, percent, item_percent) + local formspec = + "size[8,8.5]".. + factory_gui_bg.. + factory_gui_bg_img.. + factory_gui_slots.. + "list[current_name;src;2.75,0.5;1,1;]".. + "list[current_name;fuel;2.75,2.5;1,1;]".. + "image[2.75,1.5;1,1;factory_ind_furnace_fire_bg.png^[lowpart:".. + (100-percent)..":factory_ind_furnace_fire_fg.png]".. + "image[3.75,1.5;1,1;gui_ind_furnace_arrow_bg.png^[lowpart:".. + (item_percent*100)..":gui_ind_furnace_arrow_fg.png^[transformR270]".. + "list[current_name;dst;4.75,0.5;2,2;]".. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + factory.get_hotbar_bg(0,4.25) + return formspec + end + +function factory.ind_furnace_active_formspec(pos, percent) + local meta = minetest.get_meta(pos)local inv = meta:get_inventory() + local srclist = inv:get_list("src") + local cooked = nil + local aftercooked = nil + if srclist then + cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + end + local item_percent = 0 + if cooked then + item_percent = meta:get_float("src_time")/cooked.time + end + + return factory.ind_furnace_active(pos, percent, item_percent) +end + +factory.ind_furnace_inactive_formspec = + "size[8,8.5]".. + factory_gui_bg.. + factory_gui_bg_img.. + factory_gui_slots.. + "list[current_name;src;2.75,0.5;1,1;]".. + "list[current_name;fuel;2.75,2.5;1,1;]".. + "image[2.75,1.5;1,1;factory_ind_furnace_fire_bg.png]".. + "image[3.75,1.5;1,1;gui_ind_furnace_arrow_bg.png^[transformR270]".. + "list[current_name;dst;4.75,0.5;2,2;]".. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + factory.get_hotbar_bg(0,4.25) + +minetest.register_node("factory:ind_furnace", { + description = "Industrial Furnace", + tiles = {"factory_machine_brick_1.png", "factory_machine_brick_2.png", "factory_machine_side_1.png", + "factory_machine_side_1.png", "factory_machine_side_1.png", "factory_ind_furnace_front.png"}, + paramtype2 = "facedir", + groups = {cracky=3}, + legacy_facedir_simple = true, + is_ground_content = false, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", factory.ind_furnace_inactive_formspec) + meta:set_string("infotext", "Industrial Furnace") + local inv = meta:get_inventory() + inv:set_size("fuel", 1) + inv:set_size("src", 1) + inv:set_size("dst", 4) + end, + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("fuel") then + return false + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if listname == "fuel" then + if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then + if inv:is_empty("src") then + meta:set_string("infotext","Industrial Furnace is empty") + end + return stack:get_count() + else + return 0 + end + elseif listname == "src" then + return stack:get_count() + elseif listname == "dst" then + return 0 + end + end, + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local stack = inv:get_stack(from_list, from_index) + if to_list == "fuel" then + if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then + if inv:is_empty("src") then + meta:set_string("infotext","Industrial Furnace is empty") + end + return count + else + return 0 + end + elseif to_list == "src" then + return count + elseif to_list == "dst" then + return 0 + end + end, +}) + +minetest.register_node("factory:ind_furnace_active", { + description = "Industrial Furnace", + tiles = { + "factory_machine_brick_1.png", + "factory_machine_brick_2.png", + "factory_machine_side_1.png", + "factory_machine_side_1.png", + "factory_machine_side_1.png", + { + image = "factory_ind_furnace_front_active.png", + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 1.5 + }, + } + }, + paramtype2 = "facedir", + light_source = 14, + drop = "factory:ind_furnace", + groups = {cracky=3, not_in_creative_inventory=1,hot=1}, + legacy_facedir_simple = true, + is_ground_content = false, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", factory.ind_furnace_inactive_formspec) + meta:set_string("infotext", "Industrial Furnace (burning)"); + local inv = meta:get_inventory() + inv:set_size("fuel", 1) + inv:set_size("src", 1) + inv:set_size("dst", 4) + end, + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("fuel") then + return false + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if listname == "fuel" then + if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then + if inv:is_empty("src") then + meta:set_string("infotext","Industrial Furnace is empty") + end + return stack:get_count() + else + return 0 + end + elseif listname == "src" then + return stack:get_count() + elseif listname == "dst" then + return 0 + end + end, + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local stack = inv:get_stack(from_list, from_index) + if to_list == "fuel" then + if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then + if inv:is_empty("src") then + meta:set_string("infotext","Industrial Furnace is empty") + end + return count + else + return 0 + end + elseif to_list == "src" then + return count + elseif to_list == "dst" then + return 0 + end + end, +}) + +minetest.register_abm({ + nodenames = {"factory:ind_furnace","factory:ind_furnace_active"}, + interval = 1.0, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.get_meta(pos) + for i, name in ipairs({ + "fuel_totaltime", + "fuel_time", + "src_totaltime", + "src_time" + }) do + if meta:get_string(name) == "" then + meta:set_float(name, 0.0) + end + end + + local height = 0 + + for i=1,7 do -- SMOKE TUBE CHECK + local dn = minetest.get_node({x = pos.x, y = pos.y + i, z = pos.z}) + if dn.name == "factory:smoke_tube" then + height = height + 1 + else break end + end + + if minetest.get_node({x = pos.x, y = pos.y + height + 1, z = pos.z}).name ~= "air" then return end + + if height < 2 then return else + if minetest.get_node(pos).name == "factory:ind_furnace_active" then + minetest.add_particlespawner({ + amount = 4, + time = 3, + minpos = {x = pos.x - 0.2, y = pos.y + height + 0.3, z = pos.z - 0.2}, + maxpos = {x = pos.x + 0.2, y = pos.y + height + 0.6, z = pos.z + 0.2}, + minvel = {x=-0.4, y=1, z=-0.4}, + maxvel = {x=0.4, y=2, z=0.4}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 0.8, + maxexptime = 2, + minsize = 2, + maxsize = 4, + collisiondetection = false, + vertical = false, + texture = "factory_smoke.png", + playername = nil, + }) + end + end + + local inv = meta:get_inventory() + + local srclist = inv:get_list("src") + local cooked = nil + local aftercooked + + if srclist then + cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + end + + local was_active = false + + if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then + was_active = true + meta:set_float("fuel_time", meta:get_float("fuel_time") + 0.65) + meta:set_float("src_time", meta:get_float("src_time") + 1.2) + if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then + -- check if there's room for output in "dst" list + if inv:room_for_item("dst",cooked.item) then + -- Put result in "dst" list + inv:add_item("dst", cooked.item) + -- take stuff from "src" list + inv:set_stack("src", 1, aftercooked.items[1]) + else + --print("Could not insert '"..cooked.item:to_string().."'") + end + meta:set_string("src_time", 0) + end + end + + if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then + local percent = math.floor(meta:get_float("fuel_time") / + meta:get_float("fuel_totaltime") * 100) + meta:set_string("infotext","Industrial Furnace is smelting, fuel current used: "..percent.."%") + factory.swap_node(pos,"factory:ind_furnace_active") + meta:set_string("formspec",factory.ind_furnace_active_formspec(pos, percent)) + return + end + + local fuel = nil + local afterfuel + local cooked = nil + local fuellist = inv:get_list("fuel") + local srclist = inv:get_list("src") + + if srclist then + cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + end + if fuellist then + fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) + end + + if not fuel or fuel.time <= 0 then + meta:set_string("infotext","Industrial Furnace has nothing to burn with") + factory.swap_node(pos,"factory:ind_furnace") + meta:set_string("formspec", factory.ind_furnace_inactive_formspec) + return + end + + if cooked.item:is_empty() then + if was_active then + meta:set_string("infotext","Furnace is empty") + factory.swap_node(pos,"factory:ind_furnace") + meta:set_string("formspec", factory.ind_furnace_inactive_formspec) + end + return + end + + meta:set_string("fuel_totaltime", fuel.time) + meta:set_string("fuel_time", 0) + + inv:set_stack("fuel", 1, afterfuel.items[1]) + end, +}) \ No newline at end of file diff --git a/ind_squeezer.lua b/ind_squeezer.lua new file mode 100644 index 0000000..b1600a5 --- /dev/null +++ b/ind_squeezer.lua @@ -0,0 +1,329 @@ +minetest.register_alias("factory:compressor", "factory:ind_squeezer") + +function factory.ind_squeezer_active(pos, percent, item_percent) + local formspec = + "size[8,8.5]".. + factory_gui_bg.. + factory_gui_bg_img.. + factory_gui_slots.. + "list[current_name;src;2.75,0.5;1,1;]".. + "list[current_name;fuel;2.75,2.5;1,1;]".. + "image[2.75,1.5;1,1;factory_compressor_drop_bg.png^[lowpart:".. + (100-percent)..":factory_compressor_drop_fg.png]".. + "image[3.75,1.5;1,1;gui_ind_furnace_arrow_bg.png^[lowpart:".. + (item_percent*100)..":gui_ind_furnace_arrow_fg.png^[transformR270]".. + "list[current_name;dst;4.75,0.5;2,2;]".. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + factory.get_hotbar_bg(0,4.25) + return formspec + end + +function factory.ind_squeezer_active_formspec(pos, percent) + local meta = minetest.get_meta(pos)local inv = meta:get_inventory() + local srclist = inv:get_list("src") + local cooked = nil + if srclist then + cooked = factory.get_craft_result({method = "ind_squeezer", width = 1, items = srclist}) + end + local item_percent = 0 + if cooked then + item_percent = meta:get_float("src_time")/cooked.time + end + + return factory.ind_squeezer_active(pos, percent, item_percent) +end + +factory.ind_squeezer_inactive_formspec = + "size[8,8.5]".. + factory_gui_bg.. + factory_gui_bg_img.. + factory_gui_slots.. + "list[current_name;src;2.75,0.5;1,1;]".. + "list[current_name;fuel;2.75,2.5;1,1;]".. + "image[2.75,1.5;1,1;factory_compressor_drop_bg.png]".. + "image[3.75,1.5;1,1;gui_ind_furnace_arrow_bg.png^[transformR270]".. + "list[current_name;dst;4.75,0.5;2,2;]".. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + factory.get_hotbar_bg(0,4.25) + +minetest.register_node("factory:ind_squeezer", { + description = "Industrial Squeezer", + tiles = {"factory_machine_brick_1.png", "factory_machine_brick_2.png", "factory_machine_side_1.png", + "factory_machine_side_1.png", "factory_machine_side_1.png", "factory_compressor_front.png"}, + paramtype2 = "facedir", + groups = {cracky=3}, + legacy_facedir_simple = true, + is_ground_content = false, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", factory.ind_squeezer_inactive_formspec) + meta:set_string("infotext", "Industrial Squeezer") + local inv = meta:get_inventory() + inv:set_size("fuel", 1) + inv:set_size("src", 1) + inv:set_size("dst", 4) + end, + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("fuel") then + return false + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if listname == "fuel" then + if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then + if inv:is_empty("src") then + meta:set_string("infotext","Industrial Squeezer is empty") + end + return stack:get_count() + else + return 0 + end + elseif listname == "src" then + return stack:get_count() + elseif listname == "dst" then + return 0 + end + end, + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local stack = inv:get_stack(from_list, from_index) + if to_list == "fuel" then + if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then + if inv:is_empty("src") then + meta:set_string("infotext","Industrial Squeezer is empty") + end + return count + else + return 0 + end + elseif to_list == "src" then + return count + elseif to_list == "dst" then + return 0 + end + end, +}) + +minetest.register_node("factory:ind_squeezer_active", { + description = "Industrial Squeezer", + tiles = { + "factory_machine_brick_1.png", + "factory_machine_brick_2.png", + "factory_machine_side_1.png", + "factory_machine_side_1.png", + "factory_machine_side_1.png", + { + image = "factory_compressor_front_active.png", + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 4 + }, + } + }, + paramtype2 = "facedir", + light_source = 2, + drop = "factory:ind_squeezer", + groups = {cracky=3, not_in_creative_inventory=1,hot=1}, + legacy_facedir_simple = true, + is_ground_content = false, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", factory.ind_squeezer_inactive_formspec) + meta:set_string("infotext", "Industrial Squeezer (working)"); + local inv = meta:get_inventory() + inv:set_size("fuel", 1) + inv:set_size("src", 1) + inv:set_size("dst", 4) + end, + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("fuel") then + return false + elseif not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if listname == "fuel" then + if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then + if inv:is_empty("src") then + meta:set_string("infotext","Industrial Squeezer is empty") + end + return stack:get_count() + else + return 0 + end + elseif listname == "src" then + return stack:get_count() + elseif listname == "dst" then + return 0 + end + end, + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local stack = inv:get_stack(from_list, from_index) + if to_list == "fuel" then + if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then + if inv:is_empty("src") then + meta:set_string("infotext","Industrial Squeezer is empty") + end + return count + else + return 0 + end + elseif to_list == "src" then + return count + elseif to_list == "dst" then + return 0 + end + end, +}) + +minetest.register_abm({ + nodenames = {"factory:ind_squeezer","factory:ind_squeezer_active"}, + interval = 1.0, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.get_meta(pos) + for i, name in ipairs({ + "fuel_totaltime", + "fuel_time", + "src_totaltime", + "src_time" + }) do + if meta:get_string(name) == "" then + meta:set_float(name, 0.0) + end + end + + local height = 0 + + for i=1,7 do -- SMOKE TUBE CHECK + local dn = minetest.get_node({x = pos.x, y = pos.y + i, z = pos.z}) + if dn.name == "factory:smoke_tube" then + height = height + 1 + else break end + end + + if minetest.get_node({x = pos.x, y = pos.y + height + 1, z = pos.z}).name ~= "air" then return end + + if height < 1 then return else + if minetest.get_node(pos).name == "factory:ind_squeezer_active" then + minetest.add_particlespawner({ + amount = 4, + time = 3, + minpos = {x = pos.x - 0.2, y = pos.y + height + 0.3, z = pos.z - 0.2}, + maxpos = {x = pos.x + 0.2, y = pos.y + height + 0.6, z = pos.z + 0.2}, + minvel = {x=-0.4, y=1, z=-0.4}, + maxvel = {x=0.4, y=2, z=0.4}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 0.8, + maxexptime = 2, + minsize = 2, + maxsize = 4, + collisiondetection = false, + vertical = false, + texture = "factory_smoke.png", + playername = nil, + }) + end + end + + local inv = meta:get_inventory() + + local srclist = inv:get_list("src") + local cooked = nil + + if srclist then + cooked = factory.get_craft_result({method = "ind_squeezer", width = 1, items = srclist}) + end + + local was_active = false + + if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then + was_active = true + meta:set_float("fuel_time", meta:get_float("fuel_time") + 0.9) + meta:set_float("src_time", meta:get_float("src_time") + 0.2) + if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then + -- check if there's room for output in "dst" list + if inv:room_for_item("dst",cooked.item) then + -- Put result in "dst" list + inv:add_item("dst", cooked.item) + -- take stuff from "src" list + local afteritem = inv:get_stack("src", 1) + afteritem:take_item(1) + inv:set_stack("src", 1, afteritem) + else + --print("Could not insert '"..cooked.item:to_string().."'") + end + meta:set_string("src_time", 0) + end + end + + if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then + local percent = math.floor(meta:get_float("fuel_time") / + meta:get_float("fuel_totaltime") * 100) + meta:set_string("infotext","Industrial Squeezer is working, fuel current used: "..percent.."%") + factory.swap_node(pos,"factory:ind_squeezer_active") + meta:set_string("formspec",factory.ind_squeezer_active_formspec(pos, percent)) + return + end + + local fuel = nil + local afterfuel + local cooked = nil + local fuellist = inv:get_list("fuel") + local srclist = inv:get_list("src") + + if srclist then + cooked = factory.get_craft_result({method = "ind_squeezer", width = 1, items = srclist}) + end + if fuellist then + fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) + end + + if not fuel or fuel.time <= 0 then + meta:set_string("infotext","Industrial Squeezer has nothing to burn with") + factory.swap_node(pos,"factory:ind_squeezer") + meta:set_string("formspec", factory.ind_squeezer_inactive_formspec) + return + end + + if cooked.item:is_empty() then + if was_active then + meta:set_string("infotext","Industrial Squeezer is empty") + factory.swap_node(pos,"factory:ind_squeezer") + meta:set_string("formspec", factory.ind_squeezer_inactive_formspec) + end + return + end + + meta:set_string("fuel_totaltime", fuel.time) + meta:set_string("fuel_time", 0) + + inv:set_stack("fuel", 1, afterfuel.items[1]) + end, +}) \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..ae66c28 --- /dev/null +++ b/init.lua @@ -0,0 +1,171 @@ +factory={ + crafts={}, + empty={item=ItemStack(nil),time=0} +} + +factory.worldpath = minetest.get_worldpath() +factory.modpath = minetest.get_modpath("factory") + + +-- Settings +dofile(factory.modpath.."/settings.txt") + +-- This below is the Crafter mod by the legend MasterGollum + +function factory.register_craft(craft) + assert(craft.type ~= nil and craft.recipe ~= nil and craft.output ~= nil, + "Invalid craft definition, it must have type, recipe and output") + assert(type(craft.recipe)=="table" and type(craft.recipe[1])=="table","'recipe' must be a bidimensional table") + minetest.log("verbose","registerCraft ("..craft.type..", output="..craft.output.." recipe="..dump(craft.recipe)) + craft._h=#craft.recipe + craft._w=#craft.recipe[1] + -- TODO check that all the arrays have the same length... + factory.crafts[#factory.crafts+1]=craft +end + +function factory.get_craft_result(data) + assert(data.method ~= nil and data.items ~= nil, "Invalid call, method and items must be provided") + local w = 1 + if data.width ~= nil and data.width>0 then + w=data.width + end + local r=nil + for zz,craft in ipairs(factory.crafts) do + r=factory._check_craft(data,w,craft) + if r ~= nil then + if factory.debug then + print("Craft found, returning "..dump(r.item)) + end + return r + end + end + return factory.empty +end + +function factory._check_craft(data,w,c) + if c.type == data.method then + -- Here we go.. + for i=1,w-c._h+1 do + for j=1,w-c._w+1 do + local p=(i-1)*w+j + if factory.debug then + print("Checking data.items["..dump(i).."]["..dump(j).."]("..dump(p)..")="..dump(data.items[p]:get_name()).." vs craft.recipe[1][1]="..dump(c.recipe[1][1])) + end + if data.items[p]:get_name() == c.recipe[1][1] then + for m=1,c._h do + for n=1,c._w do + local q=(i+m-1-1)*w+j+n-1 + if factory.debug then + print(" Checking data.items["..dump(i+m-1).."]["..dump(j+n-1).."]("..dump(q)..")="..dump(data.items[q]:get_name()).. + " vs craft.recipe["..dump(m).."]["..dump(n).."]="..dump(c.recipe[m][n])) + end + if c.recipe[m][n] ~= data.items[q]:get_name() then + return nil + end + end + end + -- found! we still must check that is not any other stuff outside the limits of the recipe sizes... + -- Checking at right of the matching square + for m=i-c._h+1+1,w do + for n=j+c._w,w do + local q=(m-1)*w+n + if factory.debug then + print(" Checking right data.items["..dump(m).."]["..dump(n).."]("..dump(q)..")="..dump(data.items[q]:get_name())) + end + if data.items[q]:get_name() ~= "" then + return nil + end + end + end + -- Checking at left of the matching square (the first row has been already scanned) + for m=i-c._h+1+1+1,w do + for n=1,j-1 do + local q=(m-1)*w+n + if factory.debug then + print(" Checking left data.items["..dump(m).."]["..dump(n).."]("..dump(q)..")="..dump(data.items[q]:get_name())) + end + if data.items[q]:get_name() ~= "" then + return nil + end + end + end + -- Checking at bottom of the matching square + for m=i+c._h,w do + for n=j,j+c._w do + local q=(m-1)*w+n + if factory.debug then + print(" Checking bottom data.items["..dump(m).."]["..dump(n).."]("..dump(q)..")="..dump(data.items[q]:get_name())) + end + if data.items[q]:get_name() ~= "" then + return nil + end + end + end + if factory.debug then + print("Craft found! "..c.output) + end + return {item=ItemStack(c.output),time=1} + elseif data.items[p] ~= nil and data.items[p]:get_name() ~= "" then + if factory.debug then + print("Invalid data item "..dump(data.items[p]:get_name())) + end + return nil + end + end + end + end +end + +-- GUI related stuff +factory_gui_bg = "bgcolor[#080808BB;true]" +factory_gui_bg_img = "background[5,5;1,1;gui_factoryformbg.png;true]" +factory_gui_bg_img_2 = "background[5,5;1,1;gui_factoryformbg2.png;true]" +factory_gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]" + +function factory.get_hotbar_bg(x,y) + local out = "" + for i=0,7,1 do + out = out .."image["..x+i..","..y..";1,1;gui_hb_bg.png]" + end + return out +end + +function factory.swap_node(pos,name) + local node = minetest.get_node(pos) + if node.name == name then + return + end + node.name = name + minetest.swap_node(pos,node) +end + + +function factory.get_objects_with_square_radius(pos, rad) + rad = rad + .5; + local objs = {} + for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, math.sqrt(3)*rad)) do + if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then + local opos = object:getpos() + if pos.x - rad <= opos.x and opos.x <= pos.x + rad and pos.y - rad <= opos.y and opos.y <= pos.y + rad and pos.z - rad <= opos.z and opos.z <= pos.z + rad then + objs[#objs + 1] = object + end + end + end + return objs +end + + +dofile(factory.modpath.."/nodes.lua") +dofile(factory.modpath.."/craftitems.lua") +dofile(factory.modpath.."/crafting.lua") + +dofile(factory.modpath.."/ind_furnace.lua") +dofile(factory.modpath.."/ind_squeezer.lua") +dofile(factory.modpath.."/swapper.lua") +if factory.enableFan then dofile(factory.modpath.."/fan.lua") end +dofile(factory.modpath.."/storage_tank.lua") + +if factory.enableMiner then dofile(factory.modpath.."/miner.lua") end +if factory.enableVacuum then dofile(factory.modpath.."/vacuum.lua") end + +print("Factory v0.5 is working") \ No newline at end of file diff --git a/miner.lua b/miner.lua new file mode 100644 index 0000000..3c30b2a --- /dev/null +++ b/miner.lua @@ -0,0 +1,200 @@ +minetest.register_node("factory:miner_on", { + description = "Industrial Miner", + tiles = {{name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png", "factory_belt_bottom_clean.png", + "factory_belt_bottom_clean.png", "factory_belt_bottom_clean.png", {name="factory_miner.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.7}}}, + groups = {cracky = 2, mesecon_effector_off = 1}, + paramtype2 = "facedir", + is_ground_content = true, + legacy_facedir_simple = true, + mesecons = {effector = { + action_on = function(pos, node) + minetest.swap_node(pos, {name = "factory:miner_off", param2 = node.param2}) + end + }}, + after_place_node = function(pos, placer, itemstack, pointed_thing) + local meta = minetest:get_meta(pos) + if placer:is_player() then + meta:set_string("owner", placer:get_player_name()) + end + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + for i = 1, factory.minerDigLimit do + local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z}) + if node.name == "factory:miner_drillbit" then + minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="air"}) + end + end + end, +}) + +minetest.register_node("factory:miner_off", { + description = "Industrial Miner", + tiles = {{name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}, "factory_belt_bottom.png", "factory_belt_bottom_clean.png", + "factory_belt_bottom_clean.png", "factory_belt_bottom_clean.png", {name="factory_miner.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}}, + groups = {cracky = 2, not_in_creative_inventory = 1, mesecon_effector_on = 1}, + paramtype2 = "facedir", + is_ground_content = true, + legacy_facedir_simple = true, + drop="factory:miner_on", + mesecons = {effector = { + action_off = function(pos, node) + minetest.swap_node(pos, {name = "factory:miner_on", param2 = node.param2}) + end + }}, + after_place_node = function(pos, placer, itemstack, pointed_thing) + -- not supposed to be placed. switch to factory:miner_on + minetest.swap_node(pos, {name = "factory:miner_on", param2 = node.param2}) + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + for i = 1, factory.minerDigLimit do + local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z}) + if node.name == "factory:miner_drillbit" then + minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="air"}) + end + end + end, +}) + +minetest.register_node("factory:miner_drillbit", { + tiles = {"factory_machine_steel_dark.png"}, + diggable = false, + groups = {not_in_creative_inventory = 1}, + drawtype = "nodebox", + paramtype = "light", + drop = nil, + node_box = { + type = "fixed", + fixed = { + {-0.125, -0.5, -0.125, 0.125, 0.5, 0.125}, + } + } +}) + +minetest.register_abm({ + nodenames = {"factory:miner_on"}, + neighbors = nil, + interval = 4.8, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + for i = 1, factory.minerDigLimit do + local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z}) + local registered = minetest.registered_nodes[node.name] + local meta = minetest.get_meta(pos) + if node.name == "ignore" then + minetest.forceload_block({x = pos.x, y = pos.y-i-2, z = pos.z}) + return + end + if node.name ~= "factory:miner_drillbit" then + if meta:get_string("owner") ~= nil and minetest.is_protected(node.pos, meta:get_string("owner")) then + minetest.swap_node(pos, {name = "factory:miner_off", param2 = node.param2}) + return + end + if node.name ~= "air" and registered.diggable ~= nil and not registered.diggable then + minetest.swap_node(pos, {name = "factory:miner_off", param2 = node.param2}) + return + end + minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="factory:miner_drillbit"}) + if node.name == "air" then return end + local itemstacks = minetest.get_node_drops(node.name) + for _, itemname in ipairs(itemstacks) do + minetest.add_item({x = pos.x, y = pos.y+1, z = pos.z}, itemname) + end + return + end + end + end, +}) + +-- + +minetest.register_node("factory:miner_upgraded_on", { + description = "Upgraded Miner", + tiles = {{name="factory_fan.png^factory_gold_ring_x2.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png^factory_gold_ring.png", "factory_belt_bottom_clean.png^factory_gold_ring.png", + "factory_belt_bottom_clean.png^factory_gold_ring.png", "factory_belt_bottom_clean.png^factory_gold_ring.png", {name="factory_miner_upgraded.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.7}}}, + groups = {cracky = 2, mesecon_effector_off = 1}, + paramtype2 = "facedir", + is_ground_content = true, + legacy_facedir_simple = true, + mesecons = {effector = { + action_on = function(pos, node) + minetest.swap_node(pos, {name = "factory:miner_upgraded_off", param2 = node.param2}) + end + }}, + after_place_node = function(pos, placer, itemstack, pointed_thing) + local meta = minetest:get_meta(pos) + if placer:is_player() then + meta:set_string("owner", placer:get_player_name()) + end + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + for i = 1, factory.minerDigLimit do + local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z}) + if node.name == "factory:miner_drillbit" then + minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="air"}) + end + end + end, +}) + +minetest.register_node("factory:miner_upgraded_off", { + description = "Industrial Miner", + tiles = {{name="factory_fan.png^factory_gold_ring_x2.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}, "factory_belt_bottom.png^factory_gold_ring.png", "factory_belt_bottom_clean.png^factory_gold_ring.png", + "factory_belt_bottom_clean.png^factory_gold_ring.png", "factory_belt_bottom_clean.png^factory_gold_ring.png", {name="factory_miner_upgraded.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}}, + groups = {cracky = 2, not_in_creative_inventory = 1, mesecon_effector_on = 1}, + paramtype2 = "facedir", + is_ground_content = true, + legacy_facedir_simple = true, + drop="factory:miner_on", + mesecons = {effector = { + action_off = function(pos, node) + minetest.swap_node(pos, {name = "factory:miner_upgraded_on", param2 = node.param2}) + end + }}, + after_place_node = function(pos, placer, itemstack, pointed_thing) + -- not supposed to be placed. switch to factory:miner_on + minetest.swap_node(pos, {name = "factory:miner_upgraded_on", param2 = node.param2}) + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + for i = 1, factory.minerDigLimit do + local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z}) + if node.name == "factory:miner_drillbit" then + minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="air"}) + end + end + end, +}) + +minetest.register_abm({ + nodenames = {"factory:miner_upgraded_on"}, + neighbors = nil, + interval = 1.8, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + for i = 1, factory.minerDigLimit do + local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z}) + local registered = minetest.registered_nodes[node.name] + local meta = minetest.get_meta(pos) + if node.name == "ignore" then + minetest.forceload_block({x = pos.x, y = pos.y-i-2, z = pos.z}) + return + end + if node.name ~= "factory:miner_drillbit" then + if meta:get_string("owner") ~= nil and minetest.is_protected(node.pos, meta:get_string("owner")) then + minetest.swap_node(pos, {name = "factory:miner_upgraded_off", param2 = node.param2}) + return + end + if node.name ~= "air" and registered.diggable ~= nil and not registered.diggable then + minetest.swap_node(pos, {name = "factory:miner_upgraded_off", param2 = node.param2}) + return + end + minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="factory:miner_drillbit"}) + if node.name == "air" then return end + local itemstacks = minetest.get_node_drops(node.name) + for _, itemname in ipairs(itemstacks) do + minetest.add_item({x = pos.x, y = pos.y+1, z = pos.z}, itemname) + end + return + end + end + end, +}) \ No newline at end of file diff --git a/nodes.lua b/nodes.lua new file mode 100644 index 0000000..1308459 --- /dev/null +++ b/nodes.lua @@ -0,0 +1,513 @@ +minetest.register_node("factory:belt", { + description = "Conveyor Belt", + tiles = {{name="factory_belt_top_animation.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.4}}, "factory_belt_bottom.png", "factory_belt_side.png", + "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"}, + groups = {cracky=1}, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + is_ground_content = true, + legacy_facedir_simple = true, + node_box = { + type = "fixed", + fixed = {{-0.5,-0.5,-0.5,0.5,0.0625,0.5},} + }, +}) + +minetest.register_abm({ + nodenames = {"factory:belt"}, + neighbors = nil, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local all_objects = minetest.get_objects_inside_radius(pos, 1) + local _,obj + for _,obj in ipairs(all_objects) do + if not obj:is_player() and obj:get_luaentity() and obj:get_luaentity().name == "__builtin:item" then + local a = minetest.facedir_to_dir(minetest.get_node(pos).param2) + local b = {x = obj:getpos().x + (a.x / 3.5), y = pos.y + 0.175, z = obj:getpos().z + (a.z / 3.5),} + obj:moveto(b, false) + end + end + end, +}) + +minetest.register_node("factory:arm",{ + drawtype = "nodebox", + tiles = {"factory_steel_noise.png"}, + paramtype = "light", + description = "Pneumatic Mover", + groups = {cracky=3}, + paramtype2 = "facedir", + legacy_facedir_simple = true, + node_box = { + type = "fixed", + fixed = { + {-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1 + {-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2 + {-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube + {-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3 + {-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2 + {-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6 + {-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7 + {0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8 + {-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9 + } + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5,-0.5,-0.5,0.5,0.5,0.5}, + } + }, +}) + +minetest.register_abm({ + nodenames = {"factory:arm"}, + neighbors = nil, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local all_objects = minetest.get_objects_inside_radius(pos, 0.8) + local _,obj + for _,obj in ipairs(all_objects) do + if not obj:is_player() and obj:get_luaentity() and obj:get_luaentity().name == "__builtin:item" then + local a = minetest.facedir_to_dir(minetest.get_node(pos).param2) + local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,} + local target = minetest.get_node(b) + local stack = ItemStack(obj:get_luaentity().itemstring) + if target.name == "default:chest" or target.name == "default:chest_locked" then + local meta = minetest.env:get_meta(b) + local inv = meta:get_inventory() + if inv:room_for_item("main", stack) then + inv:add_item("main", stack) + obj:remove() + else + obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) + end + end + if target.name == "factory:swapper" then + local meta = minetest.env:get_meta(b) + local inv = meta:get_inventory() + if inv:room_for_item("input", stack) then + inv:add_item("input", stack) + obj:remove() + else + obj:moveto({x = pos.x + a.x, y = pos.y + 1, z = pos.z + a.z}, false) + end + end + for i,v in ipairs(armDevicesFurnacelike) do + if target.name == v then + local a = minetest.facedir_to_dir(minetest.get_node(pos).param2) + local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,} + local meta = minetest.env:get_meta(b) + local inv = meta:get_inventory() + + if minetest.dir_to_facedir({x = -a.x, y = -a.y, z = -a.z}) == minetest.get_node(b).param2 then + -- back, fuel + if inv:room_for_item("fuel", stack) then + inv:add_item("fuel", stack) + obj:remove() + else + obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) + end + else + -- everytin else, src + if inv:room_for_item("src", stack) then + inv:add_item("src", stack) + obj:remove() + else + obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) + end + end + end + end + end + end + end, +}) + +function factory.register_taker(prefix, suffix, speed, name, ctiles) + -- Backwards compatiblity for any version below 0.5 + minetest.register_alias("factory:"..prefix.."taker"..suffix, "factory:"..prefix.."taker"..suffix.."_on") + + local nodeon = { + drawtype = "nodebox", + tiles = ctiles, + paramtype = "light", + description = name, + groups = {cracky=3, mesecon_effector_off = 1}, + paramtype2 = "facedir", + legacy_facedir_simple = true, + node_box = { + type = "fixed", + fixed = { + {-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1 + {-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2 + {-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube + {-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3 + {-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2 + {-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6 + {-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7 + {0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8 + {-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9 + } + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5,-0.5,-0.5,0.5,0.5,0.5}, + } + }, + mesecons = {effector = { + action_on = function(pos, node) + minetest.swap_node(pos, {name="factory:"..prefix.."taker"..suffix.."_off", param2 = node.param2}) + end + }} + } + + local nodeoff = { + drawtype = "nodebox", + tiles = ctiles, + paramtype = "light", + description = name, + groups = {cracky=3, not_in_creative_inventory=1, mesecon_effector_on = 1}, + paramtype2 = "facedir", + legacy_facedir_simple = true, + drop="factory:"..prefix.."taker"..suffix.."_on", + node_box = { + type = "fixed", + fixed = { + {-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1 + {-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2 + {-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube + {-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3 + {-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2 + {-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6 + {-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7 + {0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8 + {-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9 + } + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5,-0.5,-0.5,0.5,0.5,0.5}, + } + }, + mesecons = {effector = { + action_off = function(pos, node) + minetest.swap_node(pos, {name="factory:"..prefix.."taker"..suffix.."_on", param2 = node.param2}) + end + }} + } + minetest.register_node("factory:"..prefix.."taker"..suffix.."_on", nodeon) + minetest.register_node("factory:"..prefix.."taker"..suffix.."_off", nodeoff) + + minetest.register_abm({ + nodenames = {"factory:"..prefix.."taker"..suffix.."_on"}, + neighbors = nil, + interval = speed, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local facedir = minetest.get_node(pos).param2 + local a = minetest.facedir_to_dir(minetest.get_node(pos).param2) + local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,} + local target = minetest.get_node(b) + if target.name == "default:chest" or target.name == "default:chest_locked" then + local meta = minetest.env:get_meta(b) + local inv = meta:get_inventory() + if not inv:is_empty("main") then + local list = inv:get_list("main") + local i,item + for i,item in ipairs(inv:get_list("main")) do + if item:get_name() ~= "" then + local droppos = {x = pos.x - (a.x/1.5), y = pos.y + 0.5, z = pos.z - (a.z/1.5)} + if factory.logTaker then print(name.." at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from "..target.name) end + minetest.item_drop(item:peek_item(1), "", droppos) + item:take_item() + inv:set_stack("main", i, item) + return + end + end + end + end + local targetp + if facedir == 1 then + targetp = {x = pos.x + 1, y = pos.y, z = pos.z} + elseif facedir == 2 then + targetp = {x = pos.x, y = pos.y, z = pos.z - 1} + elseif facedir == 3 then + targetp = {x = pos.x - 1, y = pos.y, z = pos.z} + elseif facedir == 0 then + targetp = {x = pos.x, y = pos.y, z = pos.z + 1} + end + taker_from_swapper(pos, targetp, facedir, a) + for i,v in ipairs(takerDevicesFurnacelike) do + if target.name == v then + local meta = minetest.env:get_meta(b) + local inv = meta:get_inventory() + if not inv:is_empty("dst") then + local list = inv:get_list("dst") + for k,item in ipairs(inv:get_list("dst")) do + if item:get_name() ~= "" then + local droppos = {x = pos.x - (a.x/1.5), y = pos.y + 0.5, z = pos.z - (a.z/1.5)} + if factory.logTaker then print(name.." at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from "..target.name) end + minetest.item_drop(item:peek_item(1), "", droppos) + item:take_item() + inv:set_stack("dst", k, item) + return + end + end + end + end + end + end, + }) +end + +function taker_from_swapper(pos, target, facedir, offset) + local node = minetest.get_node(target) + local takefrom = "" + -- 0 = none + -- 1 = left + -- 2 = middle + -- 3 = right + if node == nil or node.name ~= "factory:swapper" then return end + if facedir == 1 then + if node.param2 == 0 then takefrom = "loverflow" end + if node.param2 == 3 then takefrom = "overflow" end + if node.param2 == 2 then takefrom = "roverflow" end + end + if facedir == 2 then + if node.param2 == 1 then takefrom = "loverflow" end + if node.param2 == 0 then takefrom = "overflow" end + if node.param2 == 3 then takefrom = "roverflow" end + end + if facedir == 3 then + if node.param2 == 2 then takefrom = "loverflow" end + if node.param2 == 1 then takefrom = "overflow" end + if node.param2 == 0 then takefrom = "roverflow" end + end + if facedir == 0 then + if node.param2 == 3 then takefrom = "loverflow" end + if node.param2 == 2 then takefrom = "overflow" end + if node.param2 == 1 then takefrom = "roverflow" end + end + local meta = minetest.env:get_meta(target) + local inv = meta:get_inventory() + if takefrom ~= "" then + if not inv:is_empty(takefrom) then + local list = inv:get_list(takefrom) + for k,item in ipairs(inv:get_list(takefrom)) do + if not item:is_empty() and item:get_name() ~= "" then + local droppos = {x = pos.x - (offset.x/1.5), y = pos.y + 0.5, z = pos.z - (offset.z/1.5)} + if factory.logTaker then print("Taker at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from swapper") end + minetest.item_drop(item:peek_item(1), "", droppos) + item:take_item() + inv:set_stack(takefrom, k, item) + return + end + end + end + end +end + +factory.register_taker("", "", 2.5, "Pneumatic Taker", {"factory_steel_noise_red.png"}) +factory.register_taker("", "_gold", 1.8, "Pneumatic Taker Mk II", {"factory_steel_noise_gold.png"}) +factory.register_taker("", "_diamond", 1.2, "Pneumatic Taker Mk III", {"factory_steel_noise_diamond.png"}) + +minetest.register_node("factory:smoke_tube", { + drawtype = "nodebox", + tiles = {"factory_machine_brick_1.png"}, + paramtype = "light", + description = "Smoke Tube", + groups = {cracky=3}, + node_box = { + type = "fixed", + fixed = { + {-0.125,-0.5,0.3125,0.125,0.5,0.375}, + {-0.125,-0.5,-0.375,0.125,0.5,-0.3125}, + {0.3125,-0.5,-0.125,0.375,0.5,0.125}, + {-0.375,-0.5,-0.125,-0.3125,0.5,0.125}, + {0.125,-0.5,0.25,0.25,0.5,0.3125}, + {0.25,-0.5,0.125,0.3125,0.5,0.25}, + {0.25,-0.5,-0.25,0.3125,0.5,-0.125}, + {0.125,-0.5,-0.3125,0.25,0.5,-0.25}, + {-0.25,-0.5,-0.3125,-0.125,0.5,-0.25}, + {-0.3125,-0.5,-0.25,-0.25,0.5,-0.125}, + {-0.3125,-0.5,0.125,-0.25,0.5,0.25}, + {-0.25,-0.5,0.25,-0.125,0.5,0.3125}, + } + }, + selection_box = { + type = "fixed", + fixed = { + {-0.375,-0.5,-0.375,0.375,0.5,0.375}, + } + }, +}) + +function qarm_handle (a, b, target, stack, minv, obj) + if target.name == "default:chest" or target.name == "default:chest_locked" then + local meta = minetest.env:get_meta(b) + local inv = meta:get_inventory() + + if inv:room_for_item("main", stack) then + inv:add_item("main", stack) + if obj~=nil then obj:remove() end + elseif minv:room_for_item("main", stack) then + minv:add_item("main", stack) + if obj~=nil then obj:remove() end + else + if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end + end + end + if target.name == "factory:swapper" then + local meta = minetest.env:get_meta(b) + local inv = meta:get_inventory() + + if inv:room_for_item("input", stack) then + inv:add_item("input", stack) + if obj~=nil then obj:remove() end + elseif minv:room_for_item("input", stack) then + minv:add_item("input", stack) + if obj~=nil then obj:remove() end + else + if obj~=nil then obj:moveto({x = pos.x + a.x, y = pos.y + 1, z = pos.z + a.z }, false) end + end + end + for i,v in ipairs(armDevicesFurnacelike) do + if target.name == v then + local meta = minetest.env:get_meta(b) + local inv = meta:get_inventory() + + if minetest.dir_to_facedir({x = -a.x, y = -a.y, z = -a.z}) == minetest.get_node(b).param2 then + -- back, fuel + if inv:room_for_item("fuel", stack) then + inv:add_item("fuel", stack) + if obj~=nil then obj:remove() end + elseif minv:room_for_item("main", stack) then + minv:add_item("main", stack) + if obj~=nil then obj:remove() end + else + if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end + end + else + -- everytin else, src + if inv:room_for_item("src", stack) then + inv:add_item("src", stack) + if obj~=nil then obj:remove() end + elseif minv:room_for_item("main", stack) then + minv:add_item("main", stack) + if obj~=nil then obj:remove() end + else + if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end + end + end + end + end +end + +factory.qformspec = + "size[8,8.5]".. + factory_gui_bg.. + factory_gui_bg_img.. + factory_gui_slots.. + "list[current_name;main;0,0.3;8,3;]".. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + factory.get_hotbar_bg(0,4.25) + +minetest.register_node("factory:queuedarm",{ + drawtype = "nodebox", + tiles = {"factory_steel_noise.png"}, + paramtype = "light", + description = "Queued Pneumatic Mover", + groups = {cracky=3}, + paramtype2 = "facedir", + legacy_facedir_simple = true, + node_box = { + type = "fixed", + fixed = { + {-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1 + {-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2 + {-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube + {-0.375,-0.5,-0.1875,0.375,0.0625,0.0625}, --base3 + {-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2 + {-0.125,0.0625,0.3125,0.125,0.25,0.375}, --nodebox6 + {-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --nodebox7 + {0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --nodebox8 + {-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --nodebox9 + {-0.25,0.3125,-0.125,0.25,0.8,0.375}, --NodeBox10 + {-0.1875,0.1875,-0.5,-0.125,0.3125,0.375}, --NodeBox11 + {0.125,0.1875,-0.5,0.1875,0.3125,0.375}, --NodeBox12 + {-0.125,0.3125,-0.4375,0.125,0.5,-0.125}, --NodeBox13 + } + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5,-0.5,-0.5,0.5,0.5,0.5}, + } + }, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec",factory.qformspec) + meta:set_string("infotext", "Queued Pneumatic Mover") + local inv = meta:get_inventory() + inv:set_size("main", 8*3) + end, + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + return inv:is_empty("main") + end, + on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + minetest.log("action", player:get_player_name().. + " moves stuff in queued mover at "..minetest.pos_to_string(pos)) + end, + on_metadata_inventory_put = function(pos, listname, index, stack, player) + minetest.log("action", player:get_player_name().. + " moves stuff to queued mover at "..minetest.pos_to_string(pos)) + end, + on_metadata_inventory_take = function(pos, listname, index, stack, player) + minetest.log("action", player:get_player_name().. + " takes stuff from queued mover at "..minetest.pos_to_string(pos)) + end, +}) + +minetest.register_abm({ + nodenames = {"factory:queuedarm"}, + neighbors = nil, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local mmeta = minetest.env:get_meta(pos) + local minv = mmeta:get_inventory() + local all_objects = minetest.get_objects_inside_radius(pos, 0.8) + local a = minetest.facedir_to_dir(minetest.get_node(pos).param2) + local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,} + local target = minetest.get_node(b) + for _,obj in ipairs(all_objects) do + if not obj:is_player() and obj:get_luaentity() and obj:get_luaentity().name == "__builtin:item" then + local stack = ItemStack(obj:get_luaentity().itemstring) + qarm_handle(a, b, target, stack, minv, obj) + end + end + for i,stack in ipairs(minv:get_list("main")) do + if stack:get_name() ~= "" then + minv:remove_item("main", stack) + qarm_handle(a, b, target, stack, minv, nil) + return + end + end + end, +}) + +minetest.register_node("factory:factory_brick", { + description = "Factory Brick", + tiles = {"factory_brick.png"}, + is_ground_content = true, + groups = {cracky=3, stone=1} +}) \ No newline at end of file diff --git a/settings.txt b/settings.txt new file mode 100644 index 0000000..a991fbc --- /dev/null +++ b/settings.txt @@ -0,0 +1,23 @@ +-- LemonLake's Factories: Config + +-- Logging +factory.logTaker = true + +-- NB: miners require fans in the crafting recipe. recommended to enable fans if miners are enabled. +-- alternatively change the crafting recipe manually in crafting.lua + +factory.enableMiner = true +factory.enableFan = true +factory.enableVacuum = true + +factory.minerDigLimit = 256 + +-- Defines the furnace types for movers and takers. +-- Requires fuel, src and dst inventory types. +-- Don't change unless you know what you're doing. +armDevicesFurnacelike = {"default:furnace", "default:furnace_active", "factory:ind_furnace", "factory:ind_furnace_active", "factory:compressor", "factory:compressor_active", "pipeworks:autocrafter"} +takerDevicesFurnacelike = {"default:furnace", "default:furnace_active", "factory:ind_furnace", "factory:ind_furnace_active", "factory:compressor", "factory:compressor_active", "pipeworks:autocrafter"} + +-- Fuel types for the generator +generatorFuel = {{name = "factory:tree_sap", value = 20}} +-- TODO: Add items for other Technic blocks \ No newline at end of file diff --git a/storage_tank.lua b/storage_tank.lua new file mode 100644 index 0000000..cc520f4 --- /dev/null +++ b/storage_tank.lua @@ -0,0 +1,133 @@ +minetest.register_node("factory:storage_tank", { + description = "Storage Tank", + drawtype = "glasslike_framed", + tiles = {"factory_steel_noise.png","factory_glass.png^factory_measure.png","factory_glass.png^factory_port.png", "factory_steel_noise.png"}, + inventory_image = "factory_storage_tank.png", + paramtype = "light", + sunlight_propagates = true, + groups = {oddly_breakable_by_hand = 2}, + on_rightclick = function(pos, node, player, itemstack, pointed_thing) + local stack = ItemStack(itemstack) + if stack:get_name() == "bucket:bucket_water" then + minetest.swap_node(pos, {name = "factory:storage_tank_water", param2 = 3 + 64 + 128}) + local meta = minetest.get_meta(pos) + meta:set_int("stored", 3) + return ItemStack("bucket:bucket_empty") + end + if stack:get_name() == "bucket:bucket_lava" then + minetest.swap_node(pos, {name = "factory:storage_tank_lava", param2 = 7 + 64 + 128}) + local meta = minetest.get_meta(pos) + meta:set_int("stored", 7) + return ItemStack("bucket:bucket_empty") + end + end, +}) + +function factory.register_storage_tank(name, increment, tiles, plaintile, light, bucket_full, bucket_empty) + minetest.register_node("factory:storage_tank_" .. name, { + drawtype = "glasslike_framed", + tiles = {"factory_steel_noise.png","factory_glass.png^factory_measure.png","factory_glass.png^factory_port.png", "factory_steel_noise.png"}, + special_tiles = tiles, + paramtype = "light", + sunlight_propagates = true, + light_source = light, + groups = {oddly_breakable_by_hand = 2, not_in_creative_inventory = 1}, + drop = nil, + on_dig = function(pos, node, digger) + local inv = digger:get_inventory() + local meta = minetest.get_meta(pos) + local stored = meta:get_int("stored") + local stack = ItemStack({name="factory:storage_tank_" .. name .. "_inventory", count=1, metadata=stored}) + if inv:room_for_item("main", stack) then + inv:add_item("main", stack) + else + minetest.add_item(pos, stack) + end + minetest.set_node(pos, {name = "air"}) + end, + on_rightclick = function(pos, node, player, itemstack, pointed_thing) + local stack = ItemStack(itemstack) + if stack:get_name() == bucket_full then + local meta = minetest.get_meta(pos) + local stored = meta:get_int("stored") + if stored < 63 then + stored = stored + increment + meta:set_int("stored", stored) + meta:set_string("infotext", "Storage Tank (" .. name .. "): "..math.floor((100/63)*stored).."% full") + minetest.swap_node(pos, {name = "factory:storage_tank_" .. name, param2 = stored + 64 + 128}) + return ItemStack(bucket_empty) + end + end + if stack:get_name() == bucket_empty then + local meta = minetest.get_meta(pos) + local stored = meta:get_int("stored") + if stored > increment then + stored = stored - increment + meta:set_int("stored", stored) + meta:set_string("infotext", "Storage Tank (" .. name .. "): "..math.floor((100/63)*stored).."% full") + minetest.swap_node(pos, {name = "factory:storage_tank_" .. name, param2 = stored + 64 + 128}) + return ItemStack(bucket_full) + elseif stored <= increment then + meta:set_string("infotext", nil) + minetest.swap_node(pos, {name = "factory:storage_tank"}) + return ItemStack(bucket_full) + end + end + end, + }) + + minetest.register_abm({ + nodenames = {"factory:storage_tank_" .. name}, + neighbors = nil, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.get_meta(pos) + local stored = meta:get_int("stored") + minetest.swap_node(pos, {name = "factory:storage_tank_" .. name, param2 = stored + 64 + 128}) + end, + }) + + minetest.register_craftitem("factory:storage_tank_" .. name .. "_inventory", { + description = "Storage Tank (" .. name .. ")", + inventory_image = plaintile .. "^factory_storage_tank.png", + wield_image = "factory_storage_tank.png", + groups = {not_in_creative_inventory = 1}, + stack_max = 1, + on_place = function(itemstack, placer, pointed_thing) + local pt = pointed_thing + if not pt then + return + end + if pt.type ~= "node" then + return + end + local under = minetest.get_node(pt.under) + local above = minetest.get_node(pt.above) + if not minetest.registered_nodes[under.name] then + return + end + if not minetest.registered_nodes[above.name] then + return + end + if pt.above.y ~= pt.under.y+1 then + return + end + if not minetest.registered_nodes[above.name].buildable_to then + return + end + + minetest.place_node(pt.above, {name="factory:storage_tank_" .. name, param2 = tonumber(itemstack:get_metadata()) + 64 + 128}) + local meta = minetest.get_meta(pt.above) + meta:set_int("stored", tonumber(itemstack:get_metadata())) + meta:set_string("infotext", "Storage Tank (" .. name .. "): "..math.floor((100/63)*tonumber(itemstack:get_metadata())).."% full") + return "" + end + }) +end + +-- don't forget to add your liquid to the initial node around line 10 +-- I may improve this later + +factory.register_storage_tank("water", 4, {{name="default_water_source_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}}}, "default_water.png", 0, "bucket:bucket_water", "bucket:bucket_empty") +factory.register_storage_tank("lava", 8, {{name="default_lava_source_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}}}, "default_lava.png", 13, "bucket:bucket_lava", "bucket:bucket_empty") \ No newline at end of file diff --git a/swapper.lua b/swapper.lua new file mode 100644 index 0000000..f18205e --- /dev/null +++ b/swapper.lua @@ -0,0 +1,96 @@ +factory.swapper_formspec = + "size[8,9.5]".. + factory_gui_bg.. + factory_gui_bg_img_2.. + factory_gui_slots.. + "list[current_name;left;0,1.25;2,4;]".. + "list[current_name;right;6,1.25;2,4;]".. + "list[current_name;loverflow;0,0;3,1;]".. + "list[current_name;roverflow;5,0;3,1;]".. + "list[current_name;overflow;3,1.25;2,1;]".. + "list[current_name;input;3,3.25;2,2;]".. + "image[3.5,0;1,1;factory_square_white.png]".. + "image[2,1.25;1,1;factory_square_yellow.png]".. + "image[5,1.25;1,1;factory_square_blue.png]".. + "list[current_player;main;0,5.5;8,1;]".. + "list[current_player;main;0,6.75;8,3;8]" + +minetest.register_node("factory:swapper", { + description = "Swapper", + tiles = {"factory_machine_steel_dark.png", "factory_machine_steel_dark.png", "factory_machine_steel_dark.png^factory_square_blue.png", + "factory_machine_steel_dark.png^factory_square_yellow.png", "factory_machine_steel_dark.png^factory_square_white.png", "factory_machine_steel_dark.png^factory_square_red.png"}, + paramtype2 = "facedir", + groups = {cracky=3}, + legacy_facedir_simple = true, + is_ground_content = false, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", factory.swapper_formspec) + meta:set_string("infotext", "Swapper") + local inv = meta:get_inventory() + inv:set_size("left", 8) + inv:set_size("right", 8) + inv:set_size("loverflow", 3) + inv:set_size("roverflow", 3) + inv:set_size("overflow", 2) + inv:set_size("input", 4) + end, + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("left") then + return false + elseif not inv:is_empty("right") then + return false + elseif not inv:is_empty("loverflow") then + return false + elseif not inv:is_empty("roverflow") then + return false + elseif not inv:is_empty("overflow") then + return false + elseif not inv:is_empty("input") then + return false + end + return true + end +}) + +minetest.register_abm({ + nodenames = {"factory:swapper"}, + neighbors = nil, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if not inv:is_empty("input") then + for i,item in ipairs(inv:get_list("input")) do + if not item:is_empty() and item:get_name() ~= "" then + local item_to_move = item:peek_item() + for _,litem in ipairs(inv:get_list("left")) do + if litem:get_name() == item:get_name() and inv:room_for_item("loverflow", item_to_move) then + item:take_item() + inv:set_stack("input", i, item) + inv:add_item("loverflow", item_to_move) + return + end + end + for _,ritem in ipairs(inv:get_list("right")) do + if ritem:get_name() == item:get_name() and inv:room_for_item("roverflow", item_to_move) then + item:take_item() + inv:set_stack("input", i, item) + inv:add_item("roverflow", item_to_move) + return + end + end + if inv:room_for_item("overflow", item_to_move) then + item:take_item() + inv:set_stack("input", i, item) + inv:add_item("overflow", item_to_move) + return + end + end + end + end + end +}) \ No newline at end of file diff --git a/textures/factory_8x8_black_square_32x32.png b/textures/factory_8x8_black_square_32x32.png new file mode 100644 index 0000000..41167e2 Binary files /dev/null and b/textures/factory_8x8_black_square_32x32.png differ diff --git a/textures/factory_belt_bottom.png b/textures/factory_belt_bottom.png new file mode 100644 index 0000000..42a7fb1 Binary files /dev/null and b/textures/factory_belt_bottom.png differ diff --git a/textures/factory_belt_bottom_clean.png b/textures/factory_belt_bottom_clean.png new file mode 100644 index 0000000..e513ea0 Binary files /dev/null and b/textures/factory_belt_bottom_clean.png differ diff --git a/textures/factory_belt_side.png b/textures/factory_belt_side.png new file mode 100644 index 0000000..6d60e06 Binary files /dev/null and b/textures/factory_belt_side.png differ diff --git a/textures/factory_belt_top.png b/textures/factory_belt_top.png new file mode 100644 index 0000000..fe55359 Binary files /dev/null and b/textures/factory_belt_top.png differ diff --git a/textures/factory_belt_top_animation.png b/textures/factory_belt_top_animation.png new file mode 100644 index 0000000..d703e3b Binary files /dev/null and b/textures/factory_belt_top_animation.png differ diff --git a/textures/factory_brick.png b/textures/factory_brick.png new file mode 100644 index 0000000..3355162 Binary files /dev/null and b/textures/factory_brick.png differ diff --git a/textures/factory_compressed_clay.png b/textures/factory_compressed_clay.png new file mode 100644 index 0000000..646bc11 Binary files /dev/null and b/textures/factory_compressed_clay.png differ diff --git a/textures/factory_compressor_drop_bg.png b/textures/factory_compressor_drop_bg.png new file mode 100644 index 0000000..f6e9beb Binary files /dev/null and b/textures/factory_compressor_drop_bg.png differ diff --git a/textures/factory_compressor_drop_fg.png b/textures/factory_compressor_drop_fg.png new file mode 100644 index 0000000..dbb9993 Binary files /dev/null and b/textures/factory_compressor_drop_fg.png differ diff --git a/textures/factory_compressor_front.png b/textures/factory_compressor_front.png new file mode 100644 index 0000000..1e07f34 Binary files /dev/null and b/textures/factory_compressor_front.png differ diff --git a/textures/factory_compressor_front_active.png b/textures/factory_compressor_front_active.png new file mode 100644 index 0000000..2643858 Binary files /dev/null and b/textures/factory_compressor_front_active.png differ diff --git a/textures/factory_crack.png b/textures/factory_crack.png new file mode 100644 index 0000000..8ed7bb2 Binary files /dev/null and b/textures/factory_crack.png differ diff --git a/textures/factory_fan.png b/textures/factory_fan.png new file mode 100644 index 0000000..309bfd6 Binary files /dev/null and b/textures/factory_fan.png differ diff --git a/textures/factory_fan_blade.png b/textures/factory_fan_blade.png new file mode 100644 index 0000000..45bbd63 Binary files /dev/null and b/textures/factory_fan_blade.png differ diff --git a/textures/factory_fuel_pipe_end.png b/textures/factory_fuel_pipe_end.png new file mode 100644 index 0000000..a7d4f09 Binary files /dev/null and b/textures/factory_fuel_pipe_end.png differ diff --git a/textures/factory_fuel_pipe_inv.png b/textures/factory_fuel_pipe_inv.png new file mode 100644 index 0000000..7285879 Binary files /dev/null and b/textures/factory_fuel_pipe_inv.png differ diff --git a/textures/factory_glass.png b/textures/factory_glass.png new file mode 100644 index 0000000..6ad9629 Binary files /dev/null and b/textures/factory_glass.png differ diff --git a/textures/factory_gold_ring.png b/textures/factory_gold_ring.png new file mode 100644 index 0000000..1958392 Binary files /dev/null and b/textures/factory_gold_ring.png differ diff --git a/textures/factory_gold_ring_x2.png b/textures/factory_gold_ring_x2.png new file mode 100644 index 0000000..74682c6 Binary files /dev/null and b/textures/factory_gold_ring_x2.png differ diff --git a/textures/factory_ind_furnace_fire_bg.png b/textures/factory_ind_furnace_fire_bg.png new file mode 100644 index 0000000..e98a4f6 Binary files /dev/null and b/textures/factory_ind_furnace_fire_bg.png differ diff --git a/textures/factory_ind_furnace_fire_fg.png b/textures/factory_ind_furnace_fire_fg.png new file mode 100644 index 0000000..66aab65 Binary files /dev/null and b/textures/factory_ind_furnace_fire_fg.png differ diff --git a/textures/factory_ind_furnace_front.png b/textures/factory_ind_furnace_front.png new file mode 100644 index 0000000..a91e792 Binary files /dev/null and b/textures/factory_ind_furnace_front.png differ diff --git a/textures/factory_ind_furnace_front_active.png b/textures/factory_ind_furnace_front_active.png new file mode 100644 index 0000000..0d620f6 Binary files /dev/null and b/textures/factory_ind_furnace_front_active.png differ diff --git a/textures/factory_lump.png b/textures/factory_lump.png new file mode 100644 index 0000000..38e2f99 Binary files /dev/null and b/textures/factory_lump.png differ diff --git a/textures/factory_machine_brick_1.png b/textures/factory_machine_brick_1.png new file mode 100644 index 0000000..b504d60 Binary files /dev/null and b/textures/factory_machine_brick_1.png differ diff --git a/textures/factory_machine_brick_2.png b/textures/factory_machine_brick_2.png new file mode 100644 index 0000000..abaa93d Binary files /dev/null and b/textures/factory_machine_brick_2.png differ diff --git a/textures/factory_machine_side_1.png b/textures/factory_machine_side_1.png new file mode 100644 index 0000000..f719d62 Binary files /dev/null and b/textures/factory_machine_side_1.png differ diff --git a/textures/factory_machine_steel.png b/textures/factory_machine_steel.png new file mode 100644 index 0000000..ab657e1 Binary files /dev/null and b/textures/factory_machine_steel.png differ diff --git a/textures/factory_machine_steel_dark.png b/textures/factory_machine_steel_dark.png new file mode 100644 index 0000000..8734af0 Binary files /dev/null and b/textures/factory_machine_steel_dark.png differ diff --git a/textures/factory_measure.png b/textures/factory_measure.png new file mode 100644 index 0000000..adaeb5a Binary files /dev/null and b/textures/factory_measure.png differ diff --git a/textures/factory_miner.png b/textures/factory_miner.png new file mode 100644 index 0000000..e05f965 Binary files /dev/null and b/textures/factory_miner.png differ diff --git a/textures/factory_miner_upgrade_item.png b/textures/factory_miner_upgrade_item.png new file mode 100644 index 0000000..4b16d78 Binary files /dev/null and b/textures/factory_miner_upgrade_item.png differ diff --git a/textures/factory_miner_upgraded.png b/textures/factory_miner_upgraded.png new file mode 100644 index 0000000..0af37f2 Binary files /dev/null and b/textures/factory_miner_upgraded.png differ diff --git a/textures/factory_port.png b/textures/factory_port.png new file mode 100644 index 0000000..c10a525 Binary files /dev/null and b/textures/factory_port.png differ diff --git a/textures/factory_ring_green.png b/textures/factory_ring_green.png new file mode 100644 index 0000000..97f4d2e Binary files /dev/null and b/textures/factory_ring_green.png differ diff --git a/textures/factory_ring_red.png b/textures/factory_ring_red.png new file mode 100644 index 0000000..8d256bd Binary files /dev/null and b/textures/factory_ring_red.png differ diff --git a/textures/factory_scanner_chip.png b/textures/factory_scanner_chip.png new file mode 100644 index 0000000..c398f89 Binary files /dev/null and b/textures/factory_scanner_chip.png differ diff --git a/textures/factory_small_diamond_gear.png b/textures/factory_small_diamond_gear.png new file mode 100644 index 0000000..6fc32cc Binary files /dev/null and b/textures/factory_small_diamond_gear.png differ diff --git a/textures/factory_small_gold_gear.png b/textures/factory_small_gold_gear.png new file mode 100644 index 0000000..6a33e7b Binary files /dev/null and b/textures/factory_small_gold_gear.png differ diff --git a/textures/factory_small_steel_gear.png b/textures/factory_small_steel_gear.png new file mode 100644 index 0000000..a512e00 Binary files /dev/null and b/textures/factory_small_steel_gear.png differ diff --git a/textures/factory_smoke.png b/textures/factory_smoke.png new file mode 100644 index 0000000..ea622a8 Binary files /dev/null and b/textures/factory_smoke.png differ diff --git a/textures/factory_square_blue.png b/textures/factory_square_blue.png new file mode 100644 index 0000000..0816550 Binary files /dev/null and b/textures/factory_square_blue.png differ diff --git a/textures/factory_square_red.png b/textures/factory_square_red.png new file mode 100644 index 0000000..de6f6ad Binary files /dev/null and b/textures/factory_square_red.png differ diff --git a/textures/factory_square_white.png b/textures/factory_square_white.png new file mode 100644 index 0000000..99e4dfb Binary files /dev/null and b/textures/factory_square_white.png differ diff --git a/textures/factory_square_yellow.png b/textures/factory_square_yellow.png new file mode 100644 index 0000000..f23fb2f Binary files /dev/null and b/textures/factory_square_yellow.png differ diff --git a/textures/factory_steel_noise.png b/textures/factory_steel_noise.png new file mode 100644 index 0000000..6ccca44 Binary files /dev/null and b/textures/factory_steel_noise.png differ diff --git a/textures/factory_steel_noise_diamond.png b/textures/factory_steel_noise_diamond.png new file mode 100644 index 0000000..0f51263 Binary files /dev/null and b/textures/factory_steel_noise_diamond.png differ diff --git a/textures/factory_steel_noise_gold.png b/textures/factory_steel_noise_gold.png new file mode 100644 index 0000000..32295ea Binary files /dev/null and b/textures/factory_steel_noise_gold.png differ diff --git a/textures/factory_steel_noise_red.png b/textures/factory_steel_noise_red.png new file mode 100644 index 0000000..84a4237 Binary files /dev/null and b/textures/factory_steel_noise_red.png differ diff --git a/textures/factory_steel_plain_red.png b/textures/factory_steel_plain_red.png new file mode 100644 index 0000000..6471b01 Binary files /dev/null and b/textures/factory_steel_plain_red.png differ diff --git a/textures/factory_storage_tank.png b/textures/factory_storage_tank.png new file mode 100644 index 0000000..4b0529a Binary files /dev/null and b/textures/factory_storage_tank.png differ diff --git a/textures/factory_transparent.png b/textures/factory_transparent.png new file mode 100644 index 0000000..9f5992e Binary files /dev/null and b/textures/factory_transparent.png differ diff --git a/textures/factory_tree_sap.png b/textures/factory_tree_sap.png new file mode 100644 index 0000000..08721b8 Binary files /dev/null and b/textures/factory_tree_sap.png differ diff --git a/textures/factory_windowed_empty.png b/textures/factory_windowed_empty.png new file mode 100644 index 0000000..769e217 Binary files /dev/null and b/textures/factory_windowed_empty.png differ diff --git a/textures/factory_windowed_loaded.png b/textures/factory_windowed_loaded.png new file mode 100644 index 0000000..d4e51a0 Binary files /dev/null and b/textures/factory_windowed_loaded.png differ diff --git a/textures/gui_factoryformbg.png b/textures/gui_factoryformbg.png new file mode 100644 index 0000000..5b2f6f4 Binary files /dev/null and b/textures/gui_factoryformbg.png differ diff --git a/textures/gui_factoryformbg2.png b/textures/gui_factoryformbg2.png new file mode 100644 index 0000000..16f77c0 Binary files /dev/null and b/textures/gui_factoryformbg2.png differ diff --git a/textures/gui_ind_furnace_arrow_bg.png b/textures/gui_ind_furnace_arrow_bg.png new file mode 100644 index 0000000..6ffc980 Binary files /dev/null and b/textures/gui_ind_furnace_arrow_bg.png differ diff --git a/textures/gui_ind_furnace_arrow_fg.png b/textures/gui_ind_furnace_arrow_fg.png new file mode 100644 index 0000000..3439c35 Binary files /dev/null and b/textures/gui_ind_furnace_arrow_fg.png differ diff --git a/vacuum.lua b/vacuum.lua new file mode 100644 index 0000000..8e16eec --- /dev/null +++ b/vacuum.lua @@ -0,0 +1,109 @@ +minetest.register_node("factory:vacuum_on", { + description = "Vacuum", + tiles = {"factory_machine_steel_dark.png^factory_ring_green.png", "factory_machine_steel_dark.png^factory_8x8_black_square_32x32.png", "factory_machine_steel_dark.png", + "factory_machine_steel_dark.png", "factory_machine_steel_dark.png", "factory_machine_steel_dark.png"}, + groups = {cracky=2}, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + is_ground_content = true, + legacy_facedir_simple = true, + node_box = { + type = "fixed", + fixed = {{-0.25, 0.3125, -0.25, 0.25, 0.375, 0.25}, + {-0.3125, 0.4375, -0.375, 0.3125, 0.5, -0.3125}, + {-0.3125, 0.4375, 0.3125, 0.3125, 0.5, 0.375}, + {0.3125, 0.4375, -0.375, 0.375, 0.5, 0.375}, + {-0.375, 0.4375, -0.375, -0.3125, 0.5, 0.375}, + {-0.3125, 0.375, 0.25, 0.3125, 0.4375, 0.3125}, + {-0.3125, 0.375, -0.3125, 0.3125, 0.4375, -0.25}, + {0.25, 0.375, -0.25, 0.3125, 0.4375, 0.25}, + {-0.3125, 0.375, -0.25, -0.25, 0.4375, 0.25}, + {-0.25, 0.375, 0.3125, -0.1875, 0.4375, 0.5}, + {0.1875, 0.375, 0.25, 0.25, 0.4375, 0.5}, + {-0.25, 0.375, -0.5, -0.1875, 0.4375, -0.3125}, + {0.1875, 0.375, -0.5, 0.25, 0.4375, -0.3125}, + {0.3125, 0.375, -0.25, 0.5, 0.4375, -0.1875}, + {0.3125, 0.375, 0.1875, 0.5, 0.4375, 0.25}, + {-0.5, 0.375, 0.1875, -0.3125, 0.4375, 0.25}, + {-0.5, 0.375, -0.25, -0.3125, 0.4375, -0.1875}, + {-0.125, -0.4375, -0.125, 0.125, 0.3125, 0.125}, + {-0.125, 0, -0.1875, 0.1875, 0.0625, -0.125}, + {0.125, 0.0625, -0.1875, 0.1875, 0.25, -0.125}, + {0.125, 0.1875, -0.25, 0.1875, 0.3125, -0.1875}, + {0.125, 0, -0.1875, 0.1875, 0.0625, 0.125}, + {-0.125, -0.375, -0.1875, -0.0625, 0, -0.125},} + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5,-0.5,-0.5,0.5,0.5,0.5}, + } + }, + on_rightclick = function(pos, node, player, itemstack, pointed_thing) + minetest.swap_node(pos, {name = "factory:vacuum_off", param2 = node.param2}) + end, +}) + +minetest.register_node("factory:vacuum_off", { + description = "Vacuum", + tiles = {"factory_machine_steel_dark.png^factory_ring_red.png", "factory_machine_steel_dark.png^factory_8x8_black_square_32x32.png", "factory_machine_steel_dark.png", + "factory_machine_steel_dark.png", "factory_machine_steel_dark.png", "factory_machine_steel_dark.png"}, + groups = {cracky=2, not_in_creative_inventory = 1}, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + is_ground_content = true, + legacy_facedir_simple = true, + node_box = { + type = "fixed", + fixed = {{-0.25, 0.3125, -0.25, 0.25, 0.375, 0.25}, + {-0.3125, 0.4375, -0.375, 0.3125, 0.5, -0.3125}, + {-0.3125, 0.4375, 0.3125, 0.3125, 0.5, 0.375}, + {0.3125, 0.4375, -0.375, 0.375, 0.5, 0.375}, + {-0.375, 0.4375, -0.375, -0.3125, 0.5, 0.375}, + {-0.3125, 0.375, 0.25, 0.3125, 0.4375, 0.3125}, + {-0.3125, 0.375, -0.3125, 0.3125, 0.4375, -0.25}, + {0.25, 0.375, -0.25, 0.3125, 0.4375, 0.25}, + {-0.3125, 0.375, -0.25, -0.25, 0.4375, 0.25}, + {-0.25, 0.375, 0.3125, -0.1875, 0.4375, 0.5}, + {0.1875, 0.375, 0.25, 0.25, 0.4375, 0.5}, + {-0.25, 0.375, -0.5, -0.1875, 0.4375, -0.3125}, + {0.1875, 0.375, -0.5, 0.25, 0.4375, -0.3125}, + {0.3125, 0.375, -0.25, 0.5, 0.4375, -0.1875}, + {0.3125, 0.375, 0.1875, 0.5, 0.4375, 0.25}, + {-0.5, 0.375, 0.1875, -0.3125, 0.4375, 0.25}, + {-0.5, 0.375, -0.25, -0.3125, 0.4375, -0.1875}, + {-0.125, -0.4375, -0.125, 0.125, 0.3125, 0.125}, + {-0.125, 0, -0.1875, 0.1875, 0.0625, -0.125}, + {0.125, 0.0625, -0.1875, 0.1875, 0.25, -0.125}, + {0.125, 0.1875, -0.25, 0.1875, 0.3125, -0.1875}, + {0.125, 0, -0.1875, 0.1875, 0.0625, 0.125}, + {-0.125, -0.375, -0.1875, -0.0625, 0, -0.125},} + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5,-0.5,-0.5,0.5,0.5,0.5}, + } + }, + on_rightclick = function(pos, node, player, itemstack, pointed_thing) + minetest.swap_node(pos, {name = "factory:vacuum_on", param2 = node.param2}) + end, +}) + +minetest.register_abm({ + nodenames = {"factory:vacuum_on"}, + neighbors = nil, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local all_objects = factory.get_objects_with_square_radius({x = pos.x, y = pos.y + 3, z = pos.z}, 2) + local _,obj + for _,obj in ipairs(all_objects) do + if not obj:is_player() and obj:get_luaentity() and obj:get_luaentity().name == "__builtin:item" then + obj:moveto({x = pos.x, y = pos.y - 0.5, z = pos.z}) + end + end + end, +}) \ No newline at end of file