From 69ae366f6084bcda08d74abb4d3577a42f27a93b Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sun, 14 Apr 2013 06:12:49 +0200 Subject: changes to CraftingGuide --- aaa_recipeshook/depends.txt | 1 - aaa_recipeshook/init.lua | 29 -------- unified_inventory/api.lua | 156 ++++++++++++++------------------------------ 3 files changed, 48 insertions(+), 138 deletions(-) delete mode 100644 aaa_recipeshook/depends.txt delete mode 100644 aaa_recipeshook/init.lua diff --git a/aaa_recipeshook/depends.txt b/aaa_recipeshook/depends.txt deleted file mode 100644 index 8b13789..0000000 --- a/aaa_recipeshook/depends.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/aaa_recipeshook/init.lua b/aaa_recipeshook/init.lua deleted file mode 100644 index 733edd1..0000000 --- a/aaa_recipeshook/init.lua +++ /dev/null @@ -1,29 +0,0 @@ -crafts_table ={} -crafts_table_count=0 -UI_recipes_hook=true - --- override minetest.register_craft -local minetest_register_craft = minetest.register_craft -minetest.register_craft = function (options) - register_craft(options) - if options.type=="alloy" or options.type=="grinding" then return end - minetest_register_craft(options) -end - --- register_craft -register_craft = function(options) - if options.output == nil then - return - end - local itemstack = ItemStack(options.output) - if itemstack:is_empty() then - return - end - if crafts_table[itemstack:get_name()]==nil then - crafts_table[itemstack:get_name()] = {} - end - table.insert(crafts_table[itemstack:get_name()],options) - crafts_table_count=crafts_table_count+1 -end - - diff --git a/unified_inventory/api.lua b/unified_inventory/api.lua index 029ae68..2187f1a 100644 --- a/unified_inventory/api.lua +++ b/unified_inventory/api.lua @@ -10,6 +10,8 @@ unified_inventory.filtered_items_list = {} unified_inventory.activefilter = {} unified_inventory.alternate = {} unified_inventory.current_item = {} +unified_inventory.crafts_table ={} +unified_inventory.crafts_table_count=0 -- default inventory page unified_inventory.default = "craft" @@ -26,8 +28,18 @@ minetest.after(0.01, function() if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0) and def.description and def.description ~= "" then table.insert(unified_inventory.items_list, name) + local recipes=minetest.get_all_craft_recipes(name) + if unified_inventory.crafts_table[name]==nil then + unified_inventory.crafts_table[name] = {} + end + if recipes then + for i=1,#recipes,1 do + table.insert(unified_inventory.crafts_table[name],recipes[i]) + end + end end end + --print(dump(unified_inventory.crafts_table)) table.sort(unified_inventory.items_list) unified_inventory.items_list_size = #unified_inventory.items_list print ("Unified Inventory. inventory size: "..unified_inventory.items_list_size) @@ -37,7 +49,6 @@ end) minetest.register_on_joinplayer(function(player) local player_name = player:get_player_name() unified_inventory.players[player_name]={} - unified_inventory.players[player_name]["sound_volume"]=minetest.setting_get("sound_volume")*10 unified_inventory.current_index[player_name] = 1 unified_inventory.filtered_items_list[player_name] = {} unified_inventory.filtered_items_list[player_name] = unified_inventory.items_list @@ -48,7 +59,7 @@ minetest.register_on_joinplayer(function(player) unified_inventory.current_item[player_name] =nil unified_inventory.set_inventory_formspec(player,unified_inventory.get_formspec(player, unified_inventory.default)) ---crafting guide inventories +--crafting guide inventories local inv = minetest.create_detached_inventory(player:get_player_name().."craftrecipe",{ allow_put = function(inv, listname, index, stack, player) return 0 @@ -206,9 +217,9 @@ unified_inventory.get_formspec = function(player,page) formspec = formspec.."label[2,0;"..item_name.."]" local alternates = 0 local alternate = unified_inventory.alternate[player_name] - local crafts = crafts_table[item_name] + local crafts = unified_inventory.crafts_table[item_name] - if crafts ~= nil then + if crafts ~= nil and #crafts>0 then alternates = #crafts local craft = crafts[alternate] local method = "Crafting" @@ -440,7 +451,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if item_name then local alternates = 0 local alternate=unified_inventory.alternate[player_name] - local crafts = crafts_table[item_name] + local crafts = unified_inventory.crafts_table[item_name] if crafts ~= nil then alternates = #crafts end @@ -537,134 +548,63 @@ end -- update_recipe unified_inventory.update_recipe = function(player, stack_name, alternate) - --print("Lookup:"..stack_name) local inv = minetest.get_inventory({type="detached", name=player:get_player_name().."craftrecipe"}) for i=0,inv:get_size("build"),1 do inv:set_stack("build", i, nil) end - inv:set_stack("cook", 1, nil) - inv:set_stack("fuel", 1, nil) - - inv:set_stack("output", 1, stack_name) - local def + inv:set_stack("output", 1, nil) alternate = tonumber(alternate) or 1 - local crafts = crafts_table[stack_name] - if crafts == nil then - --minetest.chat_send_player(player:get_player_name(), "no recipe available for "..stack_name) - return - end + local crafts = unified_inventory.crafts_table[stack_name] + print(dump(crafts)) + local next=next + if next(crafts) == nil then return end -- no craft recipes if alternate < 1 or alternate > #crafts then alternate = 1 end local craft = crafts[alternate] - --print (dump(craft)) - --minetest.chat_send_player(player:get_player_name(), "recipe for "..stack_name..": "..dump(craft)) - - local itemstack = ItemStack(craft.output) - inv:set_stack("output", 1, itemstack) - + inv:set_stack("output", 1, craft.output) + local items=craft.items -- cook, fuel, grinding recipes if craft.type == "cooking" or craft.type == "fuel" or craft.type == "grinding" then - def=unified_inventory.find_item_def(craft.recipe) + def=unified_inventory.find_item_def(craft["items"][1]) if def then inv:set_stack("build", 1, def) end return end - - -- build (shaped or shapeless) - if craft.recipe[1] then - def=unified_inventory.find_item_def(craft.recipe[1]) - if def then - inv:set_stack("build", 1, def) - else - def=unified_inventory.find_item_def(craft.recipe[1][1]) - if def then - inv:set_stack("build", 1, def) - end - def=unified_inventory.find_item_def(craft.recipe[1][2]) - if def then - inv:set_stack("build", 2, def) - end - def=unified_inventory.find_item_def(craft.recipe[1][3]) - if def then - inv:set_stack("build", 3, def) - end + if craft.width==0 then + local build_table={1,2,3} + for i=1,3,1 do + if craft.items[i] then + def=unified_inventory.find_item_def(craft.items[i]) + if def then inv:set_stack("build", build_table[i], {name=def}) end end end - if craft.recipe[2] then - def=unified_inventory.find_item_def(craft.recipe[2]) - if def then - inv:set_stack("build", 2, def) - else - def=unified_inventory.find_item_def(craft.recipe[2][1]) - if def then - inv:set_stack("build", 4, def) - end - def=unified_inventory.find_item_def(craft.recipe[2][2]) - if def then - inv:set_stack("build", 5, def) - end - def=unified_inventory.find_item_def(craft.recipe[2][3]) - if def then - inv:set_stack("build", 6, def) - end - end - end - - if craft.recipe[3] then - def=unified_inventory.find_item_def(craft.recipe[3]) - if def then - inv:set_stack("build", 3, def) - else - def=unified_inventory.find_item_def(craft.recipe[3][1]) - if def then - inv:set_stack("build", 7, def) - end - def=unified_inventory.find_item_def(craft.recipe[3][2]) - if def then - inv:set_stack("build", 8, def) - end - def=unified_inventory.find_item_def(craft.recipe[3][3]) - if def then - inv:set_stack("build", 9, def) - end - end - end - if craft.recipe[4] then - def=unified_inventory.find_item_def(craft.recipe[4]) - if def then - inv:set_stack("build", 4, def) - end end - if craft.recipe[5] then - def=unified_inventory.find_item_def(craft.recipe[5]) - if def then - inv:set_stack("build", 5, def) + if craft.width==1 then + local build_table={1,4,7} + for i=1,3,1 do + if craft.items[i] then + def=unified_inventory.find_item_def(craft.items[i]) + if def then inv:set_stack("build", build_table[i], {name=def}) end end end - if craft.recipe[6] then - def=unified_inventory.find_item_def(craft.recipe[6]) - if def then - inv:set_stack("build", 6, def) - end end - if craft.recipe[7] then - def=unified_inventory.find_item_def(craft.recipe[7]) - if def then - inv:set_stack("build", 7, def) + if craft.width==2 then + local build_table={1,2,4,5,7,8} + for i=1,6,1 do + if craft.items[i] then + def=unified_inventory.find_item_def(craft.items[i]) + if def then inv:set_stack("build", build_table[i], {name=def}) end end end - if craft.recipe[8] then - def=unified_inventory.find_item_def(craft.recipe[8]) - if def then - inv:set_stack("build", 8, def) - end end - if craft.recipe[9] then - def=unified_inventory.find_item_def(craft.recipe[9]) - if def then - inv:set_stack("build", 9, def) + if craft.width==3 then + for i=1,9,1 do + if craft.items[i] then + def=unified_inventory.find_item_def(craft.items[i]) + if def then inv:set_stack("build", i, {name=def}) end + end end end end -- cgit v1.2.3 From 17fbd2c3353424a5dfdba1b4d92b0a9a2fce4356 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sun, 14 Apr 2013 03:40:34 -0400 Subject: remove aaa_recipeshook from unified inventory depends (it isn't needed anymore) --- unified_inventory/depends.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/unified_inventory/depends.txt b/unified_inventory/depends.txt index 8b79558..c327490 100644 --- a/unified_inventory/depends.txt +++ b/unified_inventory/depends.txt @@ -1,2 +1 @@ -aaa_recipeshook creative -- cgit v1.2.3 From 05131f8b07bab8c8464d37de9d4d589de56ee118 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sun, 14 Apr 2013 22:24:55 -0400 Subject: aliased diamong block back to default one. --- technic_worldgen/nodes.lua | 2 ++ technic_worldgen/nodes.lua~ | 58 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 technic_worldgen/nodes.lua~ diff --git a/technic_worldgen/nodes.lua b/technic_worldgen/nodes.lua index 5952d52..28514f4 100644 --- a/technic_worldgen/nodes.lua +++ b/technic_worldgen/nodes.lua @@ -56,3 +56,5 @@ minetest.register_craft({ {'technic:marble','technic:marble'} } }) + +minetest.register_alias("technic:diamond_block", "default:diamondblock") diff --git a/technic_worldgen/nodes.lua~ b/technic_worldgen/nodes.lua~ new file mode 100644 index 0000000..5952d52 --- /dev/null +++ b/technic_worldgen/nodes.lua~ @@ -0,0 +1,58 @@ +minetest.register_node( ":technic:mineral_uranium", { + description = "Uranium Ore", + tiles = { "default_stone.png^technic_mineral_uranium.png" }, + is_ground_content = true, + groups = {cracky=3}, + sounds = default.node_sound_stone_defaults(), + drop = 'craft "technic:uranium" 1', +}) + +minetest.register_node( ":technic:mineral_chromium", { + description = "Chromium Ore", + tiles = { "default_stone.png^technic_mineral_chromium.png" }, + is_ground_content = true, + groups = {cracky=3}, + sounds = default.node_sound_stone_defaults(), + drop = 'craft "technic:chromium_lump" 1', +}) + +minetest.register_node( ":technic:mineral_zinc", { + description = "Zinc Ore", + tile_images = { "default_stone.png^technic_mineral_zinc.png" }, + is_ground_content = true, + groups = {cracky=3}, + sounds = default.node_sound_stone_defaults(), + drop = 'craft "technic:zinc_lump" 1', +}) + +minetest.register_node( ":technic:granite", { + description = "Granite", + tiles = { "technic_granite.png" }, + is_ground_content = true, + groups = {cracky=3}, + sounds = default.node_sound_stone_defaults(), +}) + +minetest.register_node( ":technic:marble", { + description = "Marble", + tiles = { "technic_marble.png" }, + is_ground_content = true, + groups = {cracky=3}, + sounds = default.node_sound_stone_defaults(), +}) + +minetest.register_node( ":technic:marble_bricks", { + description = "Marble Bricks", + tiles = { "technic_marble_bricks.png" }, + is_ground_content = true, + groups = {cracky=3}, + sounds = default.node_sound_stone_defaults(), +}) + +minetest.register_craft({ + output = 'technic:marble_bricks 4', + recipe = { + {'technic:marble','technic:marble'}, + {'technic:marble','technic:marble'} + } +}) -- cgit v1.2.3 From 106e1816dcd3500b9fe730c16753ec379b92d77a Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sun, 14 Apr 2013 22:53:30 -0400 Subject: deleted undesired backup file --- .gitignore | 4 ++++ technic_worldgen/nodes.lua~ | 58 --------------------------------------------- 2 files changed, 4 insertions(+), 58 deletions(-) delete mode 100644 technic_worldgen/nodes.lua~ diff --git a/.gitignore b/.gitignore index 5ebd21a..716917d 100644 --- a/.gitignore +++ b/.gitignore @@ -161,3 +161,7 @@ pip-log.txt # Mac crap .DS_Store + +#gedit backup files +*~ + diff --git a/technic_worldgen/nodes.lua~ b/technic_worldgen/nodes.lua~ deleted file mode 100644 index 5952d52..0000000 --- a/technic_worldgen/nodes.lua~ +++ /dev/null @@ -1,58 +0,0 @@ -minetest.register_node( ":technic:mineral_uranium", { - description = "Uranium Ore", - tiles = { "default_stone.png^technic_mineral_uranium.png" }, - is_ground_content = true, - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults(), - drop = 'craft "technic:uranium" 1', -}) - -minetest.register_node( ":technic:mineral_chromium", { - description = "Chromium Ore", - tiles = { "default_stone.png^technic_mineral_chromium.png" }, - is_ground_content = true, - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults(), - drop = 'craft "technic:chromium_lump" 1', -}) - -minetest.register_node( ":technic:mineral_zinc", { - description = "Zinc Ore", - tile_images = { "default_stone.png^technic_mineral_zinc.png" }, - is_ground_content = true, - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults(), - drop = 'craft "technic:zinc_lump" 1', -}) - -minetest.register_node( ":technic:granite", { - description = "Granite", - tiles = { "technic_granite.png" }, - is_ground_content = true, - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node( ":technic:marble", { - description = "Marble", - tiles = { "technic_marble.png" }, - is_ground_content = true, - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node( ":technic:marble_bricks", { - description = "Marble Bricks", - tiles = { "technic_marble_bricks.png" }, - is_ground_content = true, - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_craft({ - output = 'technic:marble_bricks 4', - recipe = { - {'technic:marble','technic:marble'}, - {'technic:marble','technic:marble'} - } -}) -- cgit v1.2.3 From cdb368913b471ef2d8a3c8dc681f848548803e13 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Mon, 15 Apr 2013 07:52:11 +0200 Subject: Update recipes --- technic/geothermal.lua | 4 ++-- technic/sonic_screwdriver.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/technic/geothermal.lua b/technic/geothermal.lua index 93aa423..dccabf4 100644 --- a/technic/geothermal.lua +++ b/technic/geothermal.lua @@ -4,8 +4,8 @@ minetest.register_craft({ output = 'technic:geothermal', recipe = { {'default:stone', 'default:stone', 'default:stone'}, - {'moreores:copper_ingot', 'technic:diamond', 'moreores:copper_ingot'}, - {'default:stone', 'moreores:copper_ingot', 'default:stone'}, + {'default:copper_ingot', 'default:diamond', 'default:copper_ingot'}, + {'default:stone', 'default:copper_ingot', 'default:stone'}, } }) diff --git a/technic/sonic_screwdriver.lua b/technic/sonic_screwdriver.lua index 523b253..97ec446 100644 --- a/technic/sonic_screwdriver.lua +++ b/technic/sonic_screwdriver.lua @@ -52,7 +52,7 @@ minetest.register_tool("technic:sonic_screwdriver", { minetest.register_craft({ output = "technic:sonic_screwdriver", recipe = { - {"technic:diamond"}, + {"default:diamond"}, {"technic:battery"}, {"technic:stainless_steel_ingot"} } -- cgit v1.2.3 From 3d8b2a365d2ed654e9b1309b72829281d9b2a694 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Mon, 15 Apr 2013 07:54:00 +0200 Subject: Bugfix --- technic/mining_drill.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/technic/mining_drill.lua b/technic/mining_drill.lua index 86c18ac..33a8e5a 100644 --- a/technic/mining_drill.lua +++ b/technic/mining_drill.lua @@ -217,11 +217,11 @@ minetest.register_tool("technic:mining_drill", { stack_max = 1, on_use = function(itemstack, user, pointed_thing) if pointed_thing.type=="node" then - item=itemstack:to_table() + local item=itemstack:to_table() local meta=get_item_meta(item["metadata"]) if meta==nil then return end --tool not charghed if meta["charge"]==nil then return end - charge=meta["charge"] + local charge=meta["charge"] if charge-mining_drill_power_usage>0 then charge_to_take=drill_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,1,1) charge =charge-mining_drill_power_usage; @@ -287,7 +287,7 @@ function mining_drill_mk2_handler (itemstack,user,pointed_thing) local keys=user:get_player_control() local player_name=user:get_player_name() local item=itemstack:to_table() - meta=get_item_meta(item["metadata"]) + local meta=get_item_meta(item["metadata"]) if meta==nil or keys["sneak"]==true then return mining_drill_mk2_setmode(user,itemstack) end if meta["mode"]==nil then return mining_drill_mk2_setmode(user,itemstack) end if pointed_thing.type~="node" then return end @@ -309,14 +309,13 @@ function mining_drill_mk3_handler (itemstack,user,pointed_thing) local keys=user:get_player_control() local player_name=user:get_player_name() local item=itemstack:to_table() - meta=get_item_meta(item["metadata"]) + local meta=get_item_meta(item["metadata"]) if meta==nil or keys["sneak"]==true then return mining_drill_mk3_setmode(user,itemstack) end if meta["mode"]==nil then return mining_drill_mk3_setmode(user,itemstack) end if pointed_thing.type~="node" then return end if meta["charge"]==nil then return end - charge=meta["charge"] + local charge=meta["charge"] if charge-mining_drill_power_usage>0 then - print(dump(meta)) local charge_to_take=drill_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,3,meta["mode"]) charge=charge-charge_to_take; if charge<0 then charge=0 end -- cgit v1.2.3 From 41af016603f2f6dc0e08bddcec727efe1121c5ca Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Mon, 15 Apr 2013 07:56:31 +0200 Subject: change registering crafting recipes in UI --- technic/alloy_furnaces_commons.lua | 10 ++++------ technic/grinder.lua | 9 ++++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/technic/alloy_furnaces_commons.lua b/technic/alloy_furnaces_commons.lua index e058d56..559d002 100644 --- a/technic/alloy_furnaces_commons.lua +++ b/technic/alloy_furnaces_commons.lua @@ -19,14 +19,12 @@ alloy_recipes[registered_recipes_count].src2_count=count1 alloy_recipes[registered_recipes_count].dst_name=string3 alloy_recipes[registered_recipes_count].dst_count=count3 registered_recipes_count=registered_recipes_count+1 -if UI_recipes_hook then - minetest.register_craft({ +if unified_inventory then + unified_inventory.register_craft({ type = "alloy", output = string3.." "..count3, - recipe = { - {string1.." "..count1}, - {string2.." "..count2}, - } + items = {string1.." "..count1,string2.." "..count2}, + width = 2, }) end end diff --git a/technic/grinder.lua b/technic/grinder.lua index 851352b..b4dbd90 100644 --- a/technic/grinder.lua +++ b/technic/grinder.lua @@ -7,11 +7,12 @@ grinder_recipes[registered_grinder_recipes_count]={} grinder_recipes[registered_grinder_recipes_count].src_name=string1 grinder_recipes[registered_grinder_recipes_count].dst_name=string2 registered_grinder_recipes_count=registered_grinder_recipes_count+1 -if UI_recipes_hook then - minetest.register_craft({ +if unified_inventory then + unified_inventory.register_craft({ type = "grinding", output = string2, - recipe = string1, + items = {string1}, + width = 0, }) end end @@ -22,11 +23,9 @@ register_grinder_recipe("default:gravel","default:dirt") register_grinder_recipe("default:desert_stone","default:desert_sand") register_grinder_recipe("default:iron_lump","technic:iron_dust 2") register_grinder_recipe("default:coal_lump","technic:coal_dust 2") -register_grinder_recipe("moreores:copper_lump","technic:copper_dust 2") register_grinder_recipe("default:copper_lump","technic:copper_dust 2") register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2") register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2") -register_grinder_recipe("moreores:gold_lump","technic:gold_dust 2") register_grinder_recipe("default:gold_lump","technic:gold_dust 2") register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2") register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2") -- cgit v1.2.3 From 642b8bec16ef56a6be1a5abbffb50f479b0fdb1b Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Mon, 15 Apr 2013 08:28:17 +0200 Subject: Update crafting guide --- unified_inventory/api.lua | 45 +++++++++++++++++++++++++++++++++---------- unified_inventory/depends.txt | 1 + 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/unified_inventory/api.lua b/unified_inventory/api.lua index 2187f1a..ab55903 100644 --- a/unified_inventory/api.lua +++ b/unified_inventory/api.lua @@ -577,7 +577,7 @@ unified_inventory.update_recipe = function(player, stack_name, alternate) for i=1,3,1 do if craft.items[i] then def=unified_inventory.find_item_def(craft.items[i]) - if def then inv:set_stack("build", build_table[i], {name=def}) end + if def then inv:set_stack("build", build_table[i], def) end end end end @@ -586,7 +586,7 @@ unified_inventory.update_recipe = function(player, stack_name, alternate) for i=1,3,1 do if craft.items[i] then def=unified_inventory.find_item_def(craft.items[i]) - if def then inv:set_stack("build", build_table[i], {name=def}) end + if def then inv:set_stack("build", build_table[i], def) end end end end @@ -595,7 +595,7 @@ unified_inventory.update_recipe = function(player, stack_name, alternate) for i=1,6,1 do if craft.items[i] then def=unified_inventory.find_item_def(craft.items[i]) - if def then inv:set_stack("build", build_table[i], {name=def}) end + if def then inv:set_stack("build", build_table[i], def) end end end end @@ -603,7 +603,7 @@ unified_inventory.update_recipe = function(player, stack_name, alternate) for i=1,9,1 do if craft.items[i] then def=unified_inventory.find_item_def(craft.items[i]) - if def then inv:set_stack("build", i, {name=def}) end + if def then inv:set_stack("build", i, def) end end end end @@ -614,14 +614,39 @@ if type(def1)=="string" then if string.find(def1, "group:") then def1=string.gsub(def1, "group:", "") def1=string.gsub(def1, '\"', "") - for name,def in pairs(minetest.registered_items) do - if def.groups[def1] == 1 and def.groups.not_in_creative_inventory ~= 1 then - return def - end - end + local items=unified_inventory.items_in_group(def1) + return items[1] else - return def1 + return def1 end end return nil end + +unified_inventory.items_in_group = function(group) + local items = {} + for name, item in pairs(minetest.registered_items) do + for _, g in ipairs(group:split(',')) do + if item.groups[g] then + table.insert(items,name) + end + end + end + return items +end + +-- register_craft +unified_inventory.register_craft = function(options) + if options.output == nil then + return + end + local itemstack = ItemStack(options.output) + if itemstack:is_empty() then + return + end + if unified_inventory.crafts_table[itemstack:get_name()]==nil then + unified_inventory.crafts_table[itemstack:get_name()] = {} + end + table.insert(unified_inventory.crafts_table[itemstack:get_name()],options) + --crafts_table_count=crafts_table_count+1 +end diff --git a/unified_inventory/depends.txt b/unified_inventory/depends.txt index c327490..8b79558 100644 --- a/unified_inventory/depends.txt +++ b/unified_inventory/depends.txt @@ -1 +1,2 @@ +aaa_recipeshook creative -- cgit v1.2.3 From 595ed5045171ac45c92551e093fe582e0ca2508e Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Mon, 15 Apr 2013 08:33:01 +0200 Subject: avoid nil --- item_drop/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/item_drop/init.lua b/item_drop/init.lua index 8cd3b14..f51469b 100644 --- a/item_drop/init.lua +++ b/item_drop/init.lua @@ -8,7 +8,7 @@ minetest.register_globalstep(function(dtime) for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then - if object:get_luaentity().timer > time_pick then + if object:get_luaentity() and object:get_luaentity().timer > time_pick then inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) if object:get_luaentity().itemstring ~= "" then minetest.sound_play("item_drop_pickup", { @@ -137,4 +137,4 @@ minetest.register_on_dieplayer(function(name, pos) end end) ]]-- -print("DROPS LOADED!") \ No newline at end of file +print("DROPS LOADED!") -- cgit v1.2.3 From a9f73e53d909f7a89539cc90cddf195a15004b2f Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Mon, 15 Apr 2013 02:49:22 -0400 Subject: removed aaa_recipeshook from depends.txt as it is not used anymore. --- unified_inventory/depends.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/unified_inventory/depends.txt b/unified_inventory/depends.txt index 8b79558..c327490 100644 --- a/unified_inventory/depends.txt +++ b/unified_inventory/depends.txt @@ -1,2 +1 @@ -aaa_recipeshook creative -- cgit v1.2.3 From 76c2d8132c4b2828067d15bcd55eecca9627885f Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Thu, 18 Apr 2013 00:16:32 +0200 Subject: FIX THAT AGAIN :P --- unified_inventory/depends.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/unified_inventory/depends.txt b/unified_inventory/depends.txt index 8b79558..c327490 100644 --- a/unified_inventory/depends.txt +++ b/unified_inventory/depends.txt @@ -1,2 +1 @@ -aaa_recipeshook creative -- cgit v1.2.3 From 1cbe991a57945033cb38e727e59de8825b710310 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 20 Apr 2013 05:39:41 +0200 Subject: item pick-up overhaul --- item_drop/init.lua | 69 ++++++++++-------------------------------------------- 1 file changed, 13 insertions(+), 56 deletions(-) diff --git a/item_drop/init.lua b/item_drop/init.lua index f51469b..131265c 100644 --- a/item_drop/init.lua +++ b/item_drop/init.lua @@ -5,64 +5,21 @@ minetest.register_globalstep(function(dtime) local pos = player:getpos() pos.y = pos.y+0.5 local inv = player:get_inventory() - for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do - if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then - if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then - if object:get_luaentity() and object:get_luaentity().timer > time_pick then - inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) - if object:get_luaentity().itemstring ~= "" then - minetest.sound_play("item_drop_pickup", { - to_player = player:get_player_name(), - }) - end - object:get_luaentity().itemstring = "" - object:remove() - end - end - end - end - - for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 3)) do - if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then - --print(dump(object:getpos().y-player:getpos().y)) - if object:getpos().y-player:getpos().y > 0 then - if object:get_luaentity().collect then - if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then - if object:get_luaentity().timer > time_pick then - local pos1 = pos - pos1.y = pos1.y+0.2 - local pos2 = object:getpos() - local vec = {x=pos1.x-pos2.x, y=pos1.y-pos2.y, z=pos1.z-pos2.z} - vec.x = vec.x*3 - vec.y = vec.y*3 - vec.z = vec.z*3 - object:setvelocity(vec) - - minetest.after(1, function(args) - local lua = object:get_luaentity() - if object == nil or lua == nil or lua.itemstring == nil then - return - end - if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then - inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) - if object:get_luaentity().itemstring ~= "" then - minetest.sound_play("item_drop_pickup", { - to_player = player:get_player_name(), - }) - end - object:get_luaentity().itemstring = "" - object:remove() - else - object:setvelocity({x=0,y=0,z=0}) - end - end, {player, object}) + for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do + if not object:is_player() and object:get_luaentity() then + local obj=object:get_luaentity() + if obj.name == "__builtin:item" then + if inv:room_for_item("main", ItemStack(obj.itemstring)) then + if obj.timer > time_pick then + inv:add_item("main", ItemStack(obj.itemstring)) + if obj.itemstring ~= "" then + minetest.sound_play("item_drop_pickup") + end + if object:get_luaentity() then + object:get_luaentity().itemstring = "" + object:remove() end - end - else - minetest.after(0.5, function(entity) - entity.collect = true - end, object:get_luaentity()) end end end -- cgit v1.2.3 From 7a94e25e2b3248e3a00672c6c2c5bed39d38b44c Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 20 Apr 2013 06:51:49 +0200 Subject: item drop update --- item_drop/item_entity.lua | 92 ++++++++++++++++++++---- item_drop/item_entity_old.lua | 126 +++++++++++++++++++++++++++++++++ item_drop/sounds/builtin_item_lava.ogg | Bin 0 -> 37367 bytes 3 files changed, 205 insertions(+), 13 deletions(-) create mode 100644 item_drop/item_entity_old.lua create mode 100644 item_drop/sounds/builtin_item_lava.ogg diff --git a/item_drop/item_entity.lua b/item_drop/item_entity.lua index 6e479a1..5c5076d 100644 --- a/item_drop/item_entity.lua +++ b/item_drop/item_entity.lua @@ -24,7 +24,7 @@ minetest.register_entity(":__builtin:item", { itemstring = '', physical_state = true, timer = 0, - + set_item = function(self, itemstring) self.itemstring = itemstring local stack = ItemStack(itemstring) @@ -62,15 +62,21 @@ minetest.register_entity(":__builtin:item", { return minetest.serialize({ itemstring = self.itemstring, always_collect = self.always_collect, + timer = self.timer, }) end, - on_activate = function(self, staticdata) + on_activate = function(self, staticdata, dtime_s) if string.sub(staticdata, 1, string.len("return")) == "return" then local data = minetest.deserialize(staticdata) if data and type(data) == "table" then self.itemstring = data.itemstring self.always_collect = data.always_collect + self.timer = data.timer + if not self.timer then + self.timer = 0 + end + self.timer = self.timer+dtime_s end else self.itemstring = staticdata @@ -80,18 +86,79 @@ minetest.register_entity(":__builtin:item", { self.object:setacceleration({x=0, y=-10, z=0}) self:set_item(self.itemstring) end, - + on_step = function(self, dtime) + local time = minetest.setting_get("remove_items") + if not time then + time = 300 + end + if not self.timer then + self.timer = 0 + end self.timer = self.timer + dtime - if (self.timer > 300) then + if time ~= 0 and (self.timer > time) then self.object:remove() end + local p = self.object:getpos() + + local name = minetest.env:get_node(p).name + if name == "default:lava_flowing" or name == "default:lava_source" then + minetest.sound_play("builtin_item_lava", {pos=self.object:getpos()}) + self.object:remove() + return + end + + if minetest.registered_nodes[name].liquidtype == "flowing" then + get_flowing_dir = function(self) + local pos = self.object:getpos() + local param2 = minetest.env:get_node(pos).param2 + for i,d in ipairs({-1, 1, -1, 1}) do + if i<3 then + pos.x = pos.x+d + else + pos.z = pos.z+d + end + + local name = minetest.env:get_node(pos).name + local par2 = minetest.env:get_node(pos).param2 + if name == "default:water_flowing" and par2 < param2 then + return pos + end + + if i<3 then + pos.x = pos.x-d + else + pos.z = pos.z-d + end + end + end + + local vec = get_flowing_dir(self) + if vec then + local v = self.object:getvelocity() + if vec and vec.x-p.x > 0 then + self.object:setvelocity({x=0.5,y=v.y,z=0}) + elseif vec and vec.x-p.x < 0 then + self.object:setvelocity({x=-0.5,y=v.y,z=0}) + elseif vec and vec.z-p.z > 0 then + self.object:setvelocity({x=0,y=v.y,z=0.5}) + elseif vec and vec.z-p.z < 0 then + self.object:setvelocity({x=0,y=v.y,z=-0.5}) + end + self.object:setacceleration({x=0, y=-10, z=0}) + self.physical_state = true + self.object:set_properties({ + physical = true + }) + return + end + end + p.y = p.y - 0.3 local nn = minetest.env:get_node(p).name - -- If node is not registered or node is walkably solid and resting on nodebox - local v = self.object:getvelocity() - if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable and v.y == 0 then + -- If node is not registered or node is walkably solid + if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable then if self.physical_state then self.object:setvelocity({x=0,y=0,z=0}) self.object:setacceleration({x=0, y=0, z=0}) @@ -114,13 +181,12 @@ minetest.register_entity(":__builtin:item", { on_punch = function(self, hitter) if self.itemstring ~= '' then - local left = hitter:get_inventory():add_item("main", self.itemstring) - if not left:is_empty() then - self.itemstring = left:to_string() - return - end + hitter:get_inventory():add_item("main", self.itemstring) end self.object:remove() end, }) -print("ITEM ENTITY LOADED") + +if minetest.setting_get("log_mods") then + minetest.log("action", "builtin_item loaded") +end diff --git a/item_drop/item_entity_old.lua b/item_drop/item_entity_old.lua new file mode 100644 index 0000000..6e479a1 --- /dev/null +++ b/item_drop/item_entity_old.lua @@ -0,0 +1,126 @@ +-- Minetest: builtin/item_entity.lua + +function minetest.spawn_item(pos, item) + -- Take item in any format + local stack = ItemStack(item) + local obj = minetest.env:add_entity(pos, "__builtin:item") + obj:get_luaentity():set_item(stack:to_string()) + return obj +end + +minetest.register_entity(":__builtin:item", { + initial_properties = { + hp_max = 1, + physical = true, + collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17}, + visual = "sprite", + visual_size = {x=0.5, y=0.5}, + textures = {""}, + spritediv = {x=1, y=1}, + initial_sprite_basepos = {x=0, y=0}, + is_visible = false, + }, + + itemstring = '', + physical_state = true, + timer = 0, + + set_item = function(self, itemstring) + self.itemstring = itemstring + local stack = ItemStack(itemstring) + local itemtable = stack:to_table() + local itemname = nil + if itemtable then + itemname = stack:to_table().name + end + local item_texture = nil + local item_type = "" + if minetest.registered_items[itemname] then + item_texture = minetest.registered_items[itemname].inventory_image + item_type = minetest.registered_items[itemname].type + end + prop = { + is_visible = true, + visual = "sprite", + textures = {"unknown_item.png"} + } + if item_texture and item_texture ~= "" then + prop.visual = "sprite" + prop.textures = {item_texture} + prop.visual_size = {x=0.50, y=0.50} + else + prop.visual = "wielditem" + prop.textures = {itemname} + prop.visual_size = {x=0.20, y=0.20} + prop.automatic_rotate = math.pi * 0.25 + end + self.object:set_properties(prop) + end, + + get_staticdata = function(self) + --return self.itemstring + return minetest.serialize({ + itemstring = self.itemstring, + always_collect = self.always_collect, + }) + end, + + on_activate = function(self, staticdata) + if string.sub(staticdata, 1, string.len("return")) == "return" then + local data = minetest.deserialize(staticdata) + if data and type(data) == "table" then + self.itemstring = data.itemstring + self.always_collect = data.always_collect + end + else + self.itemstring = staticdata + end + self.object:set_armor_groups({immortal=1}) + self.object:setvelocity({x=0, y=2, z=0}) + self.object:setacceleration({x=0, y=-10, z=0}) + self:set_item(self.itemstring) + end, + + on_step = function(self, dtime) + self.timer = self.timer + dtime + if (self.timer > 300) then + self.object:remove() + end + local p = self.object:getpos() + p.y = p.y - 0.3 + local nn = minetest.env:get_node(p).name + -- If node is not registered or node is walkably solid and resting on nodebox + local v = self.object:getvelocity() + if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable and v.y == 0 then + if self.physical_state then + self.object:setvelocity({x=0,y=0,z=0}) + self.object:setacceleration({x=0, y=0, z=0}) + self.physical_state = false + self.object:set_properties({ + physical = false + }) + end + else + if not self.physical_state then + self.object:setvelocity({x=0,y=0,z=0}) + self.object:setacceleration({x=0, y=-10, z=0}) + self.physical_state = true + self.object:set_properties({ + physical = true + }) + end + end + end, + + on_punch = function(self, hitter) + if self.itemstring ~= '' then + local left = hitter:get_inventory():add_item("main", self.itemstring) + if not left:is_empty() then + self.itemstring = left:to_string() + return + end + end + self.object:remove() + end, +}) +print("ITEM ENTITY LOADED") diff --git a/item_drop/sounds/builtin_item_lava.ogg b/item_drop/sounds/builtin_item_lava.ogg new file mode 100644 index 0000000..5c293fe Binary files /dev/null and b/item_drop/sounds/builtin_item_lava.ogg differ -- cgit v1.2.3 From 9b76f5cf27657f30b1ca900bbe8a26afca65214c Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sat, 20 Apr 2013 01:21:23 -0400 Subject: new "sizzling" sound for dropping items into lava --- item_drop/sounds/builtin_item_lava.ogg | Bin 37367 -> 19225 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/item_drop/sounds/builtin_item_lava.ogg b/item_drop/sounds/builtin_item_lava.ogg index 5c293fe..7a53071 100644 Binary files a/item_drop/sounds/builtin_item_lava.ogg and b/item_drop/sounds/builtin_item_lava.ogg differ -- cgit v1.2.3 From 5db0041896c9d01f8edc5b7a2ec86ae9d50eb8e8 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 20 Apr 2013 07:43:49 +0200 Subject: Item drop sounds range fix --- item_drop/init.lua | 2 +- item_drop/item_entity.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/item_drop/init.lua b/item_drop/init.lua index 131265c..5033eca 100644 --- a/item_drop/init.lua +++ b/item_drop/init.lua @@ -13,7 +13,7 @@ minetest.register_globalstep(function(dtime) if obj.timer > time_pick then inv:add_item("main", ItemStack(obj.itemstring)) if obj.itemstring ~= "" then - minetest.sound_play("item_drop_pickup") + minetest.sound_play("item_drop_pickup",gain = 1.0, max_hear_distance = 10) end if object:get_luaentity() then object:get_luaentity().itemstring = "" diff --git a/item_drop/item_entity.lua b/item_drop/item_entity.lua index 5c5076d..83c7ba1 100644 --- a/item_drop/item_entity.lua +++ b/item_drop/item_entity.lua @@ -104,7 +104,7 @@ minetest.register_entity(":__builtin:item", { local name = minetest.env:get_node(p).name if name == "default:lava_flowing" or name == "default:lava_source" then - minetest.sound_play("builtin_item_lava", {pos=self.object:getpos()}) + minetest.sound_play("builtin_item_lava", {pos=self.object:getpos()},gain = 1.0, max_hear_distance = 10) self.object:remove() return end -- cgit v1.2.3 From 0992a6a6fc1a5331ee6cea5ce42adb5cc71c8a86 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 20 Apr 2013 07:53:35 +0200 Subject: bug fix --- item_drop/init.lua | 2 +- item_drop/item_entity.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/item_drop/init.lua b/item_drop/init.lua index 5033eca..8a7afe8 100644 --- a/item_drop/init.lua +++ b/item_drop/init.lua @@ -13,7 +13,7 @@ minetest.register_globalstep(function(dtime) if obj.timer > time_pick then inv:add_item("main", ItemStack(obj.itemstring)) if obj.itemstring ~= "" then - minetest.sound_play("item_drop_pickup",gain = 1.0, max_hear_distance = 10) + minetest.sound_play("item_drop_pickup",{pos, gain = 1.0, max_hear_distance = 10}) end if object:get_luaentity() then object:get_luaentity().itemstring = "" diff --git a/item_drop/item_entity.lua b/item_drop/item_entity.lua index 83c7ba1..3d1a83b 100644 --- a/item_drop/item_entity.lua +++ b/item_drop/item_entity.lua @@ -104,7 +104,7 @@ minetest.register_entity(":__builtin:item", { local name = minetest.env:get_node(p).name if name == "default:lava_flowing" or name == "default:lava_source" then - minetest.sound_play("builtin_item_lava", {pos=self.object:getpos()},gain = 1.0, max_hear_distance = 10) + minetest.sound_play("builtin_item_lava", {pos=self.object:getpos(),gain = 1.0, max_hear_distance = 10}) self.object:remove() return end -- cgit v1.2.3 From 0518993e5db94766b3f921d918dc32161b4e2922 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sat, 20 Apr 2013 02:02:46 -0400 Subject: converted item drop sounds to mono, normalized to -3.0dB --- item_drop/sounds/item_drop_pickup.1 | Bin 0 -> 7584 bytes item_drop/sounds/item_drop_pickup.2 | Bin 0 -> 7635 bytes item_drop/sounds/item_drop_pickup.3 | Bin 0 -> 7146 bytes item_drop/sounds/item_drop_pickup.4 | Bin 0 -> 7250 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 item_drop/sounds/item_drop_pickup.1 create mode 100644 item_drop/sounds/item_drop_pickup.2 create mode 100644 item_drop/sounds/item_drop_pickup.3 create mode 100644 item_drop/sounds/item_drop_pickup.4 diff --git a/item_drop/sounds/item_drop_pickup.1 b/item_drop/sounds/item_drop_pickup.1 new file mode 100644 index 0000000..f5ea6b9 Binary files /dev/null and b/item_drop/sounds/item_drop_pickup.1 differ diff --git a/item_drop/sounds/item_drop_pickup.2 b/item_drop/sounds/item_drop_pickup.2 new file mode 100644 index 0000000..0ed4869 Binary files /dev/null and b/item_drop/sounds/item_drop_pickup.2 differ diff --git a/item_drop/sounds/item_drop_pickup.3 b/item_drop/sounds/item_drop_pickup.3 new file mode 100644 index 0000000..3e2d1e0 Binary files /dev/null and b/item_drop/sounds/item_drop_pickup.3 differ diff --git a/item_drop/sounds/item_drop_pickup.4 b/item_drop/sounds/item_drop_pickup.4 new file mode 100644 index 0000000..13430e2 Binary files /dev/null and b/item_drop/sounds/item_drop_pickup.4 differ -- cgit v1.2.3 From 85f2692ef04fd11de9b21d10f67e352052eb381e Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 20 Apr 2013 08:13:58 +0200 Subject: range fix again --- item_drop/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/item_drop/init.lua b/item_drop/init.lua index 8a7afe8..a25a3b5 100644 --- a/item_drop/init.lua +++ b/item_drop/init.lua @@ -13,7 +13,7 @@ minetest.register_globalstep(function(dtime) if obj.timer > time_pick then inv:add_item("main", ItemStack(obj.itemstring)) if obj.itemstring ~= "" then - minetest.sound_play("item_drop_pickup",{pos, gain = 1.0, max_hear_distance = 10}) + minetest.sound_play("item_drop_pickup",{pos = pos, gain = 1.0, max_hear_distance = 10}) end if object:get_luaentity() then object:get_luaentity().itemstring = "" -- cgit v1.2.3 From a594c5feefa795cd1e1d2764b36482e47d4d9c45 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sat, 20 Apr 2013 02:28:24 -0400 Subject: item pickup files were wrongly named. --- item_drop/sounds/builtin_item_lava.ogg | Bin 19225 -> 0 bytes item_drop/sounds/item_drop_pickup.1 | Bin 7584 -> 0 bytes item_drop/sounds/item_drop_pickup.1.ogg | Bin 9981 -> 7584 bytes item_drop/sounds/item_drop_pickup.2 | Bin 7635 -> 0 bytes item_drop/sounds/item_drop_pickup.2.ogg | Bin 10477 -> 7635 bytes item_drop/sounds/item_drop_pickup.3 | Bin 7146 -> 0 bytes item_drop/sounds/item_drop_pickup.3.ogg | Bin 9586 -> 7146 bytes item_drop/sounds/item_drop_pickup.4 | Bin 7250 -> 0 bytes item_drop/sounds/item_drop_pickup.4.ogg | Bin 9696 -> 7250 bytes 9 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 item_drop/sounds/builtin_item_lava.ogg delete mode 100644 item_drop/sounds/item_drop_pickup.1 delete mode 100644 item_drop/sounds/item_drop_pickup.2 delete mode 100644 item_drop/sounds/item_drop_pickup.3 delete mode 100644 item_drop/sounds/item_drop_pickup.4 diff --git a/item_drop/sounds/builtin_item_lava.ogg b/item_drop/sounds/builtin_item_lava.ogg deleted file mode 100644 index 7a53071..0000000 Binary files a/item_drop/sounds/builtin_item_lava.ogg and /dev/null differ diff --git a/item_drop/sounds/item_drop_pickup.1 b/item_drop/sounds/item_drop_pickup.1 deleted file mode 100644 index f5ea6b9..0000000 Binary files a/item_drop/sounds/item_drop_pickup.1 and /dev/null differ diff --git a/item_drop/sounds/item_drop_pickup.1.ogg b/item_drop/sounds/item_drop_pickup.1.ogg index 2ae432d..f5ea6b9 100644 Binary files a/item_drop/sounds/item_drop_pickup.1.ogg and b/item_drop/sounds/item_drop_pickup.1.ogg differ diff --git a/item_drop/sounds/item_drop_pickup.2 b/item_drop/sounds/item_drop_pickup.2 deleted file mode 100644 index 0ed4869..0000000 Binary files a/item_drop/sounds/item_drop_pickup.2 and /dev/null differ diff --git a/item_drop/sounds/item_drop_pickup.2.ogg b/item_drop/sounds/item_drop_pickup.2.ogg index f58bf08..0ed4869 100644 Binary files a/item_drop/sounds/item_drop_pickup.2.ogg and b/item_drop/sounds/item_drop_pickup.2.ogg differ diff --git a/item_drop/sounds/item_drop_pickup.3 b/item_drop/sounds/item_drop_pickup.3 deleted file mode 100644 index 3e2d1e0..0000000 Binary files a/item_drop/sounds/item_drop_pickup.3 and /dev/null differ diff --git a/item_drop/sounds/item_drop_pickup.3.ogg b/item_drop/sounds/item_drop_pickup.3.ogg index cf57c94..3e2d1e0 100644 Binary files a/item_drop/sounds/item_drop_pickup.3.ogg and b/item_drop/sounds/item_drop_pickup.3.ogg differ diff --git a/item_drop/sounds/item_drop_pickup.4 b/item_drop/sounds/item_drop_pickup.4 deleted file mode 100644 index 13430e2..0000000 Binary files a/item_drop/sounds/item_drop_pickup.4 and /dev/null differ diff --git a/item_drop/sounds/item_drop_pickup.4.ogg b/item_drop/sounds/item_drop_pickup.4.ogg index bfe99d9..13430e2 100644 Binary files a/item_drop/sounds/item_drop_pickup.4.ogg and b/item_drop/sounds/item_drop_pickup.4.ogg differ -- cgit v1.2.3 From 4b0aef17a0d7a834adf31b26fb0418eaca7ea958 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Thu, 25 Apr 2013 18:45:15 +0200 Subject: Add framedglass mod that uses new drawtype --- framedglass/depends.txt | 1 + framedglass/init.lua | 77 +++++++++++++++++++++ .../textures/framedglass_glass_face_clean.png | Bin 0 -> 926 bytes .../textures/framedglass_glass_face_streaks.png | Bin 0 -> 951 bytes framedglass/textures/framedglass_steel_frame.png | Bin 0 -> 740 bytes framedglass/textures/framedglass_wooden_frame.png | Bin 0 -> 387 bytes 6 files changed, 78 insertions(+) create mode 100644 framedglass/depends.txt create mode 100644 framedglass/init.lua create mode 100644 framedglass/textures/framedglass_glass_face_clean.png create mode 100644 framedglass/textures/framedglass_glass_face_streaks.png create mode 100644 framedglass/textures/framedglass_steel_frame.png create mode 100644 framedglass/textures/framedglass_wooden_frame.png diff --git a/framedglass/depends.txt b/framedglass/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/framedglass/depends.txt @@ -0,0 +1 @@ +default diff --git a/framedglass/init.lua b/framedglass/init.lua new file mode 100644 index 0000000..ebe88ea --- /dev/null +++ b/framedglass/init.lua @@ -0,0 +1,77 @@ +-- Minetest 0.4.5 mod: framedglass + +minetest.register_craft({ + output = 'framedglass:wooden_framed_glass 4', + recipe = { + {'default:glass', 'default:glass', 'default:stick'}, + {'default:glass', 'default:glass', 'default:stick'}, + {'default:stick', 'default:stick', ''}, + } +}) + +minetest.register_craft({ + output = 'framedglass:steel_framed_glass 4', + recipe = { + {'default:glass', 'default:glass', 'default:steel_ingot'}, + {'default:glass', 'default:glass', 'default:steel_ingot'}, + {'default:steel_ingot', 'default:steel_ingot', ''}, + } +}) + +minetest.register_craft({ + output = 'framedglass:wooden_framed_obsidian_glass 4', + recipe = { + {'default:obsidian_glass', 'default:obsidian_glass', 'default:stick'}, + {'default:obsidian_glass', 'default:obsidian_glass', 'default:stick'}, + {'default:stick', 'default:stick', ''}, + } +}) + +minetest.register_craft({ + output = 'framedglass:steel_framed_obsidian_glass 4', + recipe = { + {'default:obsidian_glass', 'default:obsidian_glass', 'default:steel_ingot'}, + {'default:obsidian_glass', 'default:obsidian_glass', 'default:steel_ingot'}, + {'default:steel_ingot', 'default:steel_ingot', ''}, + } +}) + +minetest.register_node("framedglass:wooden_framed_glass", { + description = "Wooden-framed Glass", + drawtype = "glasslike_framed", + tiles = {"framedglass_wooden_frame.png","framedglass_glass_face_streaks.png"}, + paramtype = "light", + sunlight_propagates = true, + groups = {cracky=3,oddly_breakable_by_hand=3}, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("framedglass:steel_framed_glass", { + description = "Steel-framed Glass", + drawtype = "glasslike_framed", + tiles = {"framedglass_steel_frame.png","framedglass_glass_face_streaks.png"}, + paramtype = "light", + sunlight_propagates = true, + groups = {cracky=3,oddly_breakable_by_hand=3}, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("framedglass:wooden_framed_obsidian_glass", { + description = "Wooden-framed Obsidian Glass", + drawtype = "glasslike_framed", + tiles = {"framedglass_wooden_frame.png","framedglass_glass_face_clean.png"}, + paramtype = "light", + sunlight_propagates = true, + groups = {cracky=3,oddly_breakable_by_hand=3}, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("framedglass:steel_framed_obsidian_glass", { + description = "Steel-framed Obsidian Glass", + drawtype = "glasslike_framed", + tiles = {"framedglass_steel_frame.png","framedglass_glass_face_clean.png"}, + paramtype = "light", + sunlight_propagates = true, + groups = {cracky=3,oddly_breakable_by_hand=3}, + sounds = default.node_sound_glass_defaults(), +}) diff --git a/framedglass/textures/framedglass_glass_face_clean.png b/framedglass/textures/framedglass_glass_face_clean.png new file mode 100644 index 0000000..385d6d2 Binary files /dev/null and b/framedglass/textures/framedglass_glass_face_clean.png differ diff --git a/framedglass/textures/framedglass_glass_face_streaks.png b/framedglass/textures/framedglass_glass_face_streaks.png new file mode 100644 index 0000000..eb169d1 Binary files /dev/null and b/framedglass/textures/framedglass_glass_face_streaks.png differ diff --git a/framedglass/textures/framedglass_steel_frame.png b/framedglass/textures/framedglass_steel_frame.png new file mode 100644 index 0000000..383eab7 Binary files /dev/null and b/framedglass/textures/framedglass_steel_frame.png differ diff --git a/framedglass/textures/framedglass_wooden_frame.png b/framedglass/textures/framedglass_wooden_frame.png new file mode 100644 index 0000000..66f2b72 Binary files /dev/null and b/framedglass/textures/framedglass_wooden_frame.png differ -- cgit v1.2.3 From 31b1393b21e77898842f0dd4fe7196771550a3c6 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 27 Apr 2013 10:04:17 +0200 Subject: Add HV wireing --- technic/init.lua | 3 + technic/textures/technic_hv_cable.png | Bin 0 -> 1705 bytes technic/textures/technic_hv_cable_wield.png | Bin 0 -> 601 bytes technic/textures/technic_mv_cable_wield.png | Bin 2996 -> 531 bytes technic/wires_hv.lua | 398 ++++++++++++++++++++++++++++ 5 files changed, 401 insertions(+) create mode 100644 technic/textures/technic_hv_cable.png create mode 100644 technic/textures/technic_hv_cable_wield.png create mode 100644 technic/wires_hv.lua diff --git a/technic/init.lua b/technic/init.lua index 58e0488..2b85d26 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -34,6 +34,9 @@ dofile(modpath.."/electric_furnace_mv.lua") dofile(modpath.."/alloy_furnace_mv.lua") dofile(modpath.."/forcefield.lua") +--HV machines +dofile(modpath.."/wires_hv.lua") + --Tools if enable_mining_drill==true then dofile(modpath.."/mining_drill.lua") end if enable_mining_laser==true then dofile(modpath.."/mining_laser_mk1.lua") end diff --git a/technic/textures/technic_hv_cable.png b/technic/textures/technic_hv_cable.png new file mode 100644 index 0000000..7cb368d Binary files /dev/null and b/technic/textures/technic_hv_cable.png differ diff --git a/technic/textures/technic_hv_cable_wield.png b/technic/textures/technic_hv_cable_wield.png new file mode 100644 index 0000000..7b9ca58 Binary files /dev/null and b/technic/textures/technic_hv_cable_wield.png differ diff --git a/technic/textures/technic_mv_cable_wield.png b/technic/textures/technic_mv_cable_wield.png index aca9fd4..2d41e27 100644 Binary files a/technic/textures/technic_mv_cable_wield.png and b/technic/textures/technic_mv_cable_wield.png differ diff --git a/technic/wires_hv.lua b/technic/wires_hv.lua new file mode 100644 index 0000000..b2c9834 --- /dev/null +++ b/technic/wires_hv.lua @@ -0,0 +1,398 @@ +--HV cable node boxes + + +minetest.register_craft({ + output = 'technic:hv_cable 3', + recipe ={ + {'technic:rubber','technic:rubber','technic:rubber'}, + {'technic:mv_cable','technic:mv_cable','technic:mv_cable'}, + {'technic:rubber','technic:rubber','technic:rubber'}, + } +}) + + +minetest.register_craftitem("technic:hv_cable", { + description = "Gigh Voltage Copper Cable", + stack_max = 99, +}) + +minetest.register_node("technic:hv_cable", { + description = "High Voltage Copper Cable", + tiles = {"technic_hv_cable.png"}, + inventory_image = "technic_hv_cable_wield.png", + wield_image = "technic_hv_cable_wield.png", + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + drop = "technic:hv_cable", + hv_cablelike=1, + rules_x1=0, + rules_x2=0, + rules_y1=0, + rules_y2=0, + rules_z1=0, + rules_z2=0, + paramtype = "light", + drawtype = "nodebox", + selection_box = { + type = "fixed", + fixed = { + { -0.1 , -0.1 , -0.1 , 0.1 , 0.1 , 0.1 }, + }}, + node_box = { + type = "fixed", + fixed = { + { -0.125 , -0.125 , -0.125 , 0.125 , 0.125 , 0.125 }, + }}, + on_construct = function(pos) + meta=minetest.env:get_meta(pos) + meta:set_float("hv_cablelike",1) + meta:set_float("x1",0) + meta:set_float("x2",0) + meta:set_float("y1",0) + meta:set_float("y2",0) + meta:set_float("z1",0) + meta:set_float("z2",0) + HV_check_connections (pos) + end, + + after_dig_node = function (pos, oldnode, oldmetadata, digger) + HV_check_connections_on_destroy (pos) + end, + +}) + + +str_y1= { -0.125 , -0.125 , -0.125 , 0.125 , 0.5, 0.125 } --0 y+ +str_x1= { -0.125 , -0.125 , -0.125 , 0.5, 0.125 , 0.125 } --0 x+ +str_z1= { -0.125 , -0.125 , 0.125 , 0.125 , 0.125 , 0.5 } --0 z+ +str_z2= { -0.125 , -0.125, -0.5 , 0.125 , 0.125 , 0.125 } --0 z- +str_y2= { -0.125 , -0.5, -0.125 , 0.125 , 0.125 , 0.125 } --0 y- +str_x2= { -0.5 , -0.125, -0.125 , 0.125 , 0.125 , 0.125 } --0 x- + + + +local x1,x2,y1,y2,z1,z2 +local count=0 + +for x1 = 0, 1, 1 do --x- +for x2 = 0, 1, 1 do --x+ +for y1 = 0, 1, 1 do --y- +for y2 = 0, 1, 1 do --y- +for z1 = 0, 1, 1 do --z- +for z2 = 0, 1, 1 do --z+ + +temp_x1={} temp_x2={} temp_y1={} temp_y2={} temp_z1={} temp_z2={} + +if x1==1 then temp_x1=str_x1 end +if x2==1 then temp_x2=str_x2 end +if y1==1 then temp_y1=str_y1 end +if y2==1 then temp_y2=str_y2 end +if z1==1 then temp_z1=str_z1 end +if z2==1 then temp_z2=str_z2 end + + +minetest.register_node("technic:hv_cable"..count, { + description = "Gigh Voltage Copper Cable", + tiles = {"technic_hv_cable.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + sounds = default.node_sound_wood_defaults(), + drop = "technic:hv_cable", + rules_x1=0, + rules_x2=0, + rules_y1=0, + rules_y2=0, + rules_z1=0, + rules_z2=0, + cablelike=1, + paramtype = "light", + drawtype = "nodebox", + selection_box = { + type = "fixed", + fixed = { + temp_x1,temp_x2,temp_y1,temp_y2,temp_z1,temp_z2, + }}, + + node_box = { + type = "fixed", + fixed = { + temp_x1,temp_x2,temp_y1,temp_y2,temp_z1,temp_z2, + }}, + + after_dig_node = function (pos, oldnode, oldmetadata, digger) + HV_check_connections_on_destroy (pos) + end, + +}) + +count=count+1 end end end end end end + +HV_check_connections = function(pos) + local pos1={} + pos1.x=pos.x + pos1.y=pos.y + pos1.z=pos.z + + pos1.x=pos1.x+1 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + x2=1 + x1=minetest.env:get_meta(pos1):get_float("x1") + y1=minetest.env:get_meta(pos1):get_float("y1") + y2=minetest.env:get_meta(pos1):get_float("y2") + z1=minetest.env:get_meta(pos1):get_float("z1") + z2=minetest.env:get_meta(pos1):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos1,"technic:hv_cable"..rule) + meta=minetest.env:get_meta(pos1) + meta:set_float("x2",x2) + meta=minetest.env:get_meta(pos) + x1=1 + x2=minetest.env:get_meta(pos):get_float("x2") + y1=minetest.env:get_meta(pos):get_float("y1") + y2=minetest.env:get_meta(pos):get_float("y2") + z1=minetest.env:get_meta(pos):get_float("z1") + z2=minetest.env:get_meta(pos):get_float("z2") + meta:set_float("x1",x1) + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos,"technic:hv_cable"..rule) + end + + pos1.x=pos1.x-2 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + x1=1 + x2=minetest.env:get_meta(pos1):get_float("x2") + y1=minetest.env:get_meta(pos1):get_float("y1") + y2=minetest.env:get_meta(pos1):get_float("y2") + z1=minetest.env:get_meta(pos1):get_float("z1") + z2=minetest.env:get_meta(pos1):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos1,"technic:hv_cable"..rule) + meta=minetest.env:get_meta(pos1) + meta:set_float("x1",x1) + meta=minetest.env:get_meta(pos) + x2=1 + x1=minetest.env:get_meta(pos):get_float("x1") + y1=minetest.env:get_meta(pos):get_float("y1") + y2=minetest.env:get_meta(pos):get_float("y2") + z1=minetest.env:get_meta(pos):get_float("z1") + z2=minetest.env:get_meta(pos):get_float("z2") + meta:set_float("x2",x2) + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos,"technic:hv_cable"..rule) + end + + pos1.x=pos1.x+1 + + pos1.y=pos1.y+1 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + y2=1 + x1=minetest.env:get_meta(pos1):get_float("x1") + x2=minetest.env:get_meta(pos1):get_float("x2") + y1=minetest.env:get_meta(pos1):get_float("y1") + z1=minetest.env:get_meta(pos1):get_float("z1") + z2=minetest.env:get_meta(pos1):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos1,"technic:hv_cable"..rule) + meta=minetest.env:get_meta(pos1) + meta:set_float("y2",y2) + meta=minetest.env:get_meta(pos) + y1=1 + x1=minetest.env:get_meta(pos):get_float("x1") + x2=minetest.env:get_meta(pos):get_float("x2") + y2=minetest.env:get_meta(pos):get_float("y2") + z1=minetest.env:get_meta(pos):get_float("z1") + z2=minetest.env:get_meta(pos):get_float("z2") + meta:set_float("y1",y1) + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos,"technic:hv_cable"..rule) + end + + if minetest.env:get_meta(pos1):get_float("technic_hv_power_machine")==1 then + y1=1 + x1=minetest.env:get_meta(pos):get_float("x1") + x2=minetest.env:get_meta(pos):get_float("x2") + y2=minetest.env:get_meta(pos):get_float("y2") + z1=minetest.env:get_meta(pos):get_float("z1") + z2=minetest.env:get_meta(pos):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos,"technic:hv_cable"..rule) + meta=minetest.env:get_meta(pos) + meta:set_float("y1",y1) + end + + + pos1.y=pos1.y-2 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + y1=1 + x1=minetest.env:get_meta(pos1):get_float("x1") + x2=minetest.env:get_meta(pos1):get_float("x2") + y2=minetest.env:get_meta(pos1):get_float("y2") + z1=minetest.env:get_meta(pos1):get_float("z1") + z2=minetest.env:get_meta(pos1):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos1,"technic:hv_cable"..rule) + meta=minetest.env:get_meta(pos1) + meta:set_float("y1",y1) + meta=minetest.env:get_meta(pos) + y2=1 + x1=minetest.env:get_meta(pos):get_float("x1") + x2=minetest.env:get_meta(pos):get_float("x2") + y1=minetest.env:get_meta(pos):get_float("y1") + z1=minetest.env:get_meta(pos):get_float("z1") + z2=minetest.env:get_meta(pos):get_float("z2") + meta:set_float("y2",y2) + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos,"technic:hv_cable"..rule) + end + pos1.y=pos1.y+1 + + pos1.z=pos1.z+1 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + z2=1 + x1=minetest.env:get_meta(pos1):get_float("x1") + x2=minetest.env:get_meta(pos1):get_float("x2") + y1=minetest.env:get_meta(pos1):get_float("y1") + y2=minetest.env:get_meta(pos1):get_float("y2") + z1=minetest.env:get_meta(pos1):get_float("z1") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos1,"technic:hv_cable"..rule) + meta=minetest.env:get_meta(pos1) + meta:set_float("z2",z2) + meta=minetest.env:get_meta(pos) + z1=1 + x1=minetest.env:get_meta(pos):get_float("x1") + x2=minetest.env:get_meta(pos):get_float("x2") + y1=minetest.env:get_meta(pos):get_float("y1") + y2=minetest.env:get_meta(pos):get_float("y2") + z2=minetest.env:get_meta(pos):get_float("z2") + meta:set_float("z1",z1) + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos,"technic:hv_cable"..rule) + end + pos1.z=pos1.z-2 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + z1=1 + x1=minetest.env:get_meta(pos1):get_float("x1") + x2=minetest.env:get_meta(pos1):get_float("x2") + y1=minetest.env:get_meta(pos1):get_float("y1") + y2=minetest.env:get_meta(pos1):get_float("y2") + z2=minetest.env:get_meta(pos1):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos1,"technic:hv_cable"..rule) + meta=minetest.env:get_meta(pos1) + meta:set_float("z1",z1) + meta=minetest.env:get_meta(pos) + z2=1 + x1=minetest.env:get_meta(pos):get_float("x1") + x2=minetest.env:get_meta(pos):get_float("x2") + y1=minetest.env:get_meta(pos):get_float("y1") + y2=minetest.env:get_meta(pos):get_float("y2") + z1=minetest.env:get_meta(pos):get_float("z1") + meta:set_float("z2",z2) + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + hacky_swap_node(pos,"technic:hv_cable"..rule) + end + pos1.z=pos1.z+1 +end + + +HV_check_connections_on_destroy = function(pos) + local pos1={} + pos1.x=pos.x + pos1.y=pos.y + pos1.z=pos.z + + pos1.x=pos1.x+1 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + x2=0 + x1=minetest.env:get_meta(pos1):get_float("x1") + y1=minetest.env:get_meta(pos1):get_float("y1") + y2=minetest.env:get_meta(pos1):get_float("y2") + z1=minetest.env:get_meta(pos1):get_float("z1") + z2=minetest.env:get_meta(pos1):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end + if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end + meta=minetest.env:get_meta(pos1) + meta:set_float("x2",x2) + end + + pos1.x=pos1.x-2 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + x1=0 + x2=minetest.env:get_meta(pos1):get_float("x2") + y1=minetest.env:get_meta(pos1):get_float("y1") + y2=minetest.env:get_meta(pos1):get_float("y2") + z1=minetest.env:get_meta(pos1):get_float("z1") + z2=minetest.env:get_meta(pos1):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end + if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end + meta=minetest.env:get_meta(pos1) + meta:set_float("x1",x1) + end + pos1.x=pos1.x+1 + + pos1.y=pos1.y+1 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + y2=0 + x1=minetest.env:get_meta(pos1):get_float("x1") + x2=minetest.env:get_meta(pos1):get_float("x2") + y1=minetest.env:get_meta(pos1):get_float("y1") + z1=minetest.env:get_meta(pos1):get_float("z1") + z2=minetest.env:get_meta(pos1):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end + if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end + meta=minetest.env:get_meta(pos1) + meta:set_float("y2",y2) + end + + pos1.y=pos1.y-2 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + y1=0 + x1=minetest.env:get_meta(pos1):get_float("x1") + x2=minetest.env:get_meta(pos1):get_float("x2") + y2=minetest.env:get_meta(pos1):get_float("y2") + z1=minetest.env:get_meta(pos1):get_float("z1") + z2=minetest.env:get_meta(pos1):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end + if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end + meta=minetest.env:get_meta(pos1) + meta:set_float("y1",y1) + end + pos1.y=pos1.y+1 + + pos1.z=pos1.z+1 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + z2=0 + x1=minetest.env:get_meta(pos1):get_float("x1") + x2=minetest.env:get_meta(pos1):get_float("x2") + y1=minetest.env:get_meta(pos1):get_float("y1") + y2=minetest.env:get_meta(pos1):get_float("y2") + z1=minetest.env:get_meta(pos1):get_float("z1") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end + if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end + meta=minetest.env:get_meta(pos1) + meta:set_float("z2",z2) + end + + pos1.z=pos1.z-2 + if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then + z1=0 + x1=minetest.env:get_meta(pos1):get_float("x1") + x2=minetest.env:get_meta(pos1):get_float("x2") + y1=minetest.env:get_meta(pos1):get_float("y1") + y2=minetest.env:get_meta(pos1):get_float("y2") + z2=minetest.env:get_meta(pos1):get_float("z2") + rule=make_rule_number(x1,x2,y1,y2,z1,z2) + if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end + if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end + meta=minetest.env:get_meta(pos1) + meta:set_float("z1",z1) + end + pos1.y=pos1.y+1 + +end + -- cgit v1.2.3 From 00328622d9cc38a7768a7bf449f5c52ddba666f7 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Thu, 25 Apr 2013 21:39:08 -0400 Subject: Store configuration in the world directory. --- item_drop/depends.txt | 1 + item_drop/init.lua | 104 +++++++++++++++++++++++-------------------- technic/config.lua | 49 +++++++++++++++++--- technic/depends.txt | 2 - technic/init.lua | 8 ++-- technic/rubber.lua | 26 ++++++----- technic_worldgen/depends.txt | 1 + technic_worldgen/oregen.lua | 4 ++ 8 files changed, 122 insertions(+), 73 deletions(-) create mode 100644 item_drop/depends.txt diff --git a/item_drop/depends.txt b/item_drop/depends.txt new file mode 100644 index 0000000..b88d3ff --- /dev/null +++ b/item_drop/depends.txt @@ -0,0 +1 @@ +technic diff --git a/item_drop/init.lua b/item_drop/init.lua index a25a3b5..db1f2a3 100644 --- a/item_drop/init.lua +++ b/item_drop/init.lua @@ -1,66 +1,72 @@ dofile(minetest.get_modpath("item_drop").."/item_entity.lua") time_pick = 3 -minetest.register_globalstep(function(dtime) - for _,player in ipairs(minetest.get_connected_players()) do - local pos = player:getpos() - pos.y = pos.y+0.5 - local inv = player:get_inventory() - for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do - if not object:is_player() and object:get_luaentity() then - local obj=object:get_luaentity() - if obj.name == "__builtin:item" then - if inv:room_for_item("main", ItemStack(obj.itemstring)) then - if obj.timer > time_pick then - inv:add_item("main", ItemStack(obj.itemstring)) - if obj.itemstring ~= "" then - minetest.sound_play("item_drop_pickup",{pos = pos, gain = 1.0, max_hear_distance = 10}) - end - if object:get_luaentity() then - object:get_luaentity().itemstring = "" - object:remove() + +if technic.config:getBool("enable_item_pickup") then + minetest.register_globalstep(function(dtime) + for _,player in ipairs(minetest.get_connected_players()) do + local pos = player:getpos() + pos.y = pos.y+0.5 + local inv = player:get_inventory() + for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do + if not object:is_player() and object:get_luaentity() then + local obj=object:get_luaentity() + if obj.name == "__builtin:item" then + if inv:room_for_item("main", ItemStack(obj.itemstring)) then + if obj.timer > time_pick then + inv:add_item("main", ItemStack(obj.itemstring)) + if obj.itemstring ~= "" then + minetest.sound_play("item_drop_pickup",{pos = pos, gain = 1.0, max_hear_distance = 10}) + end + if object:get_luaentity() then + object:get_luaentity().itemstring = "" + object:remove() + end end end end end end end - end -end) + end) +end -function minetest.handle_node_drops(pos, drops, digger) - for _,item in ipairs(drops) do - local count, name - if type(item) == "string" then - count = 1 - name = item - else - count = item:get_count() - name = item:get_name() - end - for i=1,count do - local obj = minetest.env:add_item(pos, name) - if obj ~= nil then - obj:get_luaentity().collect = true - local x = math.random(1, 5) - if math.random(1,2) == 1 then - x = -x - end - local z = math.random(1, 5) - if math.random(1,2) == 1 then - z = -z - end - obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) - obj:get_luaentity().timer = time_pick - -- FIXME this doesnt work for deactiveted objects - if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then - minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj) - obj:remove() - end, obj) +if technic.config:getBool("enable_item_drop") then + function minetest.handle_node_drops(pos, drops, digger) + for _,item in ipairs(drops) do + local count, name + if type(item) == "string" then + count = 1 + name = item + else + count = item:get_count() + name = item:get_name() + end + for i=1,count do + local obj = minetest.env:add_item(pos, name) + if obj ~= nil then + obj:get_luaentity().collect = true + local x = math.random(1, 5) + if math.random(1,2) == 1 then + x = -x + end + local z = math.random(1, 5) + if math.random(1,2) == 1 then + z = -z + end + obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) + obj:get_luaentity().timer = time_pick + -- FIXME this doesnt work for deactiveted objects + if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then + minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj) + obj:remove() + end, obj) + end end end end end end + --[[ minetest.register_on_dieplayer(function(name, pos) local inv = name:get_inventory() diff --git a/technic/config.lua b/technic/config.lua index f237968..f546cf6 100644 --- a/technic/config.lua +++ b/technic/config.lua @@ -1,7 +1,42 @@ -enable_technic_inventory=true -enable_mining_drill=true -enable_mining_laser=true -enable_flashlight=true -enable_rubber_tree_generation=true -enable_marble_generation=true -enable_granite_generation=true +technic.config = {} + +technic.config.loaded = {} + +technic.config.default = { + enable_mining_drill = "true", + enable_mining_laser = "true", + enable_flashlight = "true", + enable_item_drop = "true", + enable_item_pickup = "true", + enable_rubber_tree_generation = "true", + enable_marble_generation = "true", + enable_granite_generation = "true" +} + +function technic.config:load(filename) + file, error = io.open(filename, "r") + if error then return end + local line = file:read("*l") + while line do + local found, _, setting, value = line:find("^([^#%s=]+)%s?=%s?([^%s#]+)") + if found then + self.loaded[setting] = value + end + line = file:read("*l") + end + file:close() +end + +technic.config:load(minetest.get_worldpath().."/technic.conf") + +function technic.config:get(setting) + if self.loaded[setting] then + return self.loaded[setting] + else + return self.default[setting] + end +end + +function technic.config:getBool(setting) + return string.lower(self:get(setting)) == "true" +end diff --git a/technic/depends.txt b/technic/depends.txt index f034c60..3859f8a 100644 --- a/technic/depends.txt +++ b/technic/depends.txt @@ -2,5 +2,3 @@ default moreores pipeworks mesecons -technic_worldgen - diff --git a/technic/init.lua b/technic/init.lua index 2b85d26..7f303c1 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -2,6 +2,8 @@ -- namespace: technic -- (c) 2012-2013 by RealBadAngel +technic = {} + modpath=minetest.get_modpath("technic") --Read technic config file @@ -38,9 +40,9 @@ dofile(modpath.."/forcefield.lua") dofile(modpath.."/wires_hv.lua") --Tools -if enable_mining_drill==true then dofile(modpath.."/mining_drill.lua") end -if enable_mining_laser==true then dofile(modpath.."/mining_laser_mk1.lua") end -if enable_flashlight==true then dofile(modpath.."/flashlight.lua") end +if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end +if technic.config:getBool("enable_mining_laser") then dofile(modpath.."/mining_laser_mk1.lua") end +if technic.config:getBool("enable_flashlight") then dofile(modpath.."/flashlight.lua") end dofile(modpath.."/cans.lua") dofile(modpath.."/chainsaw.lua") dofile(modpath.."/tree_tap.lua") diff --git a/technic/rubber.lua b/technic/rubber.lua index 0e530ff..6ec9731 100644 --- a/technic/rubber.lua +++ b/technic/rubber.lua @@ -88,14 +88,12 @@ minetest.register_abm({ end }) -minetest.register_on_generated(function(minp, maxp, blockseed) - if math.random(1, 100) > 5 then - return - end - local tmp = {x=(maxp.x-minp.x)/2+minp.x, y=(maxp.y-minp.y)/2+minp.y, z=(maxp.z-minp.z)/2+minp.z} - local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"}) - if pos ~= nil then - rubber_tree={ +if technic.config:getBool("enable_rubber_tree_generation") then + minetest.register_on_generated(function(minp, maxp, blockseed) + if math.random(1, 100) > 5 then + return + end + local rubber_tree={ axiom="FFFFA", rules_a="[&FFBFA]////[&BFFFA]////[&FBFFA]", rules_b="[&FFA]////[&FFA]////[&FFA]", @@ -107,10 +105,14 @@ minetest.register_on_generated(function(minp, maxp, blockseed) thin_trunks=false; fruit_tree=false, fruit="" - } - minetest.env:spawn_tree({x=pos.x, y=pos.y+1, z=pos.z},rubber_tree) - end -end) + } + local tmp = {x=(maxp.x-minp.x)/2+minp.x, y=(maxp.y-minp.y)/2+minp.y, z=(maxp.z-minp.z)/2+minp.z} + local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"}) + if pos ~= nil then + minetest.env:spawn_tree({x=pos.x, y=pos.y+1, z=pos.z}, rubber_tree) + end + end) +end -- ========= FUEL ========= diff --git a/technic_worldgen/depends.txt b/technic_worldgen/depends.txt index 4ad96d5..d684218 100644 --- a/technic_worldgen/depends.txt +++ b/technic_worldgen/depends.txt @@ -1 +1,2 @@ default +technic diff --git a/technic_worldgen/oregen.lua b/technic_worldgen/oregen.lua index b17e438..50f5415 100644 --- a/technic_worldgen/oregen.lua +++ b/technic_worldgen/oregen.lua @@ -28,6 +28,7 @@ minetest.register_ore({ height_min = -31000, height_max = 2, }) +if technic.config:getBool("enable_marble_generation") then minetest.register_ore({ ore_type = "sheet", ore = "technic:marble", @@ -40,6 +41,8 @@ minetest.register_ore({ noise_threshhold = 0.4, noise_params = {offset=0, scale=15, spread={x=150, y=150, z=150}, seed=23, octaves=3, persist=0.70} }) +end +if technic.config:getBool("enable_granite_generation") then minetest.register_ore({ ore_type = "sheet", ore = "technic:granite", @@ -52,4 +55,5 @@ minetest.register_ore({ noise_threshhold = 0.4, noise_params = {offset=0, scale=15, spread={x=130, y=130, z=130}, seed=24, octaves=3, persist=0.70} }) +end -- cgit v1.2.3 From 6463b77e60639f4012b702fef344cc7e201d3e3a Mon Sep 17 00:00:00 2001 From: kpoppel Date: Mon, 6 May 2013 20:00:00 +0200 Subject: Add milling machine from non cubic to technic mod. Next step is to make sure it only works if powered. --- technic/chainsaw.lua | 296 +++++-- technic/cnc.lua | 208 +++++ technic/cnc_api.lua | 970 +++++++++++++++++++++ technic/cnc_nodes.lua | 354 ++++++++ technic/init.lua | 14 +- technic/textures/technic_cnc_bottom.png | Bin 0 -> 2006 bytes technic/textures/technic_cnc_cylinder.png | Bin 0 -> 456 bytes .../textures/technic_cnc_cylinder_horizontal.png | Bin 0 -> 463 bytes technic/textures/technic_cnc_element_cross.png | Bin 0 -> 415 bytes technic/textures/technic_cnc_element_edge.png | Bin 0 -> 409 bytes technic/textures/technic_cnc_element_end.png | Bin 0 -> 391 bytes technic/textures/technic_cnc_element_straight.png | Bin 0 -> 412 bytes technic/textures/technic_cnc_element_t.png | Bin 0 -> 389 bytes technic/textures/technic_cnc_front.png | Bin 0 -> 2000 bytes technic/textures/technic_cnc_full.png | Bin 0 -> 372 bytes technic/textures/technic_cnc_half.png | Bin 0 -> 460 bytes .../textures/technic_cnc_milling_background.png | Bin 0 -> 78748 bytes technic/textures/technic_cnc_onecurvededge.png | Bin 0 -> 507 bytes technic/textures/technic_cnc_pyramid.png | Bin 0 -> 480 bytes technic/textures/technic_cnc_side.png | Bin 0 -> 1922 bytes technic/textures/technic_cnc_slope.png | Bin 0 -> 437 bytes technic/textures/technic_cnc_slope_edge.png | Bin 0 -> 419 bytes technic/textures/technic_cnc_slope_edge_upsdwn.png | Bin 0 -> 486 bytes technic/textures/technic_cnc_slope_inner_edge.png | Bin 0 -> 497 bytes .../technic_cnc_slope_inner_edge_upsdwn.png | Bin 0 -> 605 bytes technic/textures/technic_cnc_slope_lying.png | Bin 0 -> 548 bytes technic/textures/technic_cnc_slope_upsdwn.png | Bin 0 -> 440 bytes technic/textures/technic_cnc_sphere.png | Bin 0 -> 532 bytes technic/textures/technic_cnc_spike.png | Bin 0 -> 556 bytes technic/textures/technic_cnc_stick.png | Bin 0 -> 320 bytes technic/textures/technic_cnc_top.png | Bin 0 -> 2137 bytes technic/textures/technic_cnc_twocurvededge.png | Bin 0 -> 768 bytes 32 files changed, 1790 insertions(+), 52 deletions(-) create mode 100644 technic/cnc.lua create mode 100644 technic/cnc_api.lua create mode 100644 technic/cnc_nodes.lua create mode 100644 technic/textures/technic_cnc_bottom.png create mode 100644 technic/textures/technic_cnc_cylinder.png create mode 100644 technic/textures/technic_cnc_cylinder_horizontal.png create mode 100644 technic/textures/technic_cnc_element_cross.png create mode 100644 technic/textures/technic_cnc_element_edge.png create mode 100644 technic/textures/technic_cnc_element_end.png create mode 100644 technic/textures/technic_cnc_element_straight.png create mode 100644 technic/textures/technic_cnc_element_t.png create mode 100644 technic/textures/technic_cnc_front.png create mode 100644 technic/textures/technic_cnc_full.png create mode 100644 technic/textures/technic_cnc_half.png create mode 100644 technic/textures/technic_cnc_milling_background.png create mode 100644 technic/textures/technic_cnc_onecurvededge.png create mode 100644 technic/textures/technic_cnc_pyramid.png create mode 100644 technic/textures/technic_cnc_side.png create mode 100644 technic/textures/technic_cnc_slope.png create mode 100644 technic/textures/technic_cnc_slope_edge.png create mode 100644 technic/textures/technic_cnc_slope_edge_upsdwn.png create mode 100644 technic/textures/technic_cnc_slope_inner_edge.png create mode 100644 technic/textures/technic_cnc_slope_inner_edge_upsdwn.png create mode 100644 technic/textures/technic_cnc_slope_lying.png create mode 100644 technic/textures/technic_cnc_slope_upsdwn.png create mode 100644 technic/textures/technic_cnc_sphere.png create mode 100644 technic/textures/technic_cnc_spike.png create mode 100644 technic/textures/technic_cnc_stick.png create mode 100644 technic/textures/technic_cnc_top.png create mode 100644 technic/textures/technic_cnc_twocurvededge.png diff --git a/technic/chainsaw.lua b/technic/chainsaw.lua index 2c3fbf5..c31d9a8 100644 --- a/technic/chainsaw.lua +++ b/technic/chainsaw.lua @@ -1,63 +1,261 @@ -chainsaw_max_charge=30000 +-- Configuration +local chainsaw_max_charge = 30000 -- 30000 - Maximum charge of the saw +local chainsaw_charge_per_node = 12 -- 12 - Gives 2500 nodes on a single charge (about 50 complete normal trees) +local chainsaw_leaves = true -- true - Cut down entire trees, leaves and all + register_power_tool ("technic:chainsaw",chainsaw_max_charge) minetest.register_tool("technic:chainsaw", { - description = "Chainsaw", - inventory_image = "technic_chainsaw.png", - stack_max = 1, - on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type=="node" then - item=itemstack:to_table() - local meta=get_item_meta(item["metadata"]) - if meta==nil then return end --tool not charghed - if meta["charge"]==nil then return end - charge=meta["charge"] - charge_to_take=600; - if charge-charge_to_take>0 then - charge_to_take=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge_to_take) - charge=charge-charge_to_take; - set_RE_wear(item,charge,chainsaw_max_charge) - meta["charge"]=charge - item["metadata"]=set_item_meta(meta) - itemstack:replace(item) - return itemstack - end - end - end, + description = "Chainsaw", + inventory_image = "technic_chainsaw.png", + stack_max = 1, + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type=="node" then + item=itemstack:to_table() + local meta=get_item_meta(item["metadata"]) + if meta==nil then return end --tool not charged + if meta["charge"]==nil then return end + -- Send current charge to digging function so that the chainsaw will stop after digging a number of nodes. + local charge=meta["charge"] + if charge < chainsaw_charge_per_node then return end -- only cut if charged + + charge=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge) + set_RE_wear(item,charge,chainsaw_max_charge) + meta["charge"]=charge + item["metadata"]=set_item_meta(meta) + itemstack:replace(item) + return itemstack + end + end, }) minetest.register_craft({ - output = 'technic:chainsaw', - recipe = { - {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:battery'}, - {'technic:stainless_steel_ingot', 'technic:motor', 'technic:battery'}, - {'','','moreores:copper_ingot'}, - } + output = 'technic:chainsaw', + recipe = { + {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:battery'}, + {'technic:stainless_steel_ingot', 'technic:motor', 'technic:battery'}, + {'','','moreores:copper_ingot'}, + } }) +-- The default stuff +local timber_nodenames={["default:jungletree"] = true, + ["default:papyrus"] = true, + ["default:cactus"] = true, + ["default:tree"] = true, + ["default:apple"] = true +} + +if chainsaw_leaves == true then + timber_nodenames["default:leaves"] = true +end + +-- Support moretrees if it is there +if( minetest.get_modpath("moretrees") ~= nil ) then + timber_nodenames["moretrees:apple_tree_trunk"] = true + timber_nodenames["moretrees:apple_tree_trunk_sideways"] = true + timber_nodenames["moretrees:beech_trunk"] = true + timber_nodenames["moretrees:beech_trunk_sideways"] = true + timber_nodenames["moretrees:birch_trunk"] = true + timber_nodenames["moretrees:birch_trunk_sideways"] = true + timber_nodenames["moretrees:fir_trunk"] = true + timber_nodenames["moretrees:fir_trunk_sideways"] = true + timber_nodenames["moretrees:oak_trunk"] = true + timber_nodenames["moretrees:oak_trunk_sideways"] = true + timber_nodenames["moretrees:palm_trunk"] = true + timber_nodenames["moretrees:palm_trunk_sideways"] = true + timber_nodenames["moretrees:pine_trunk"] = true + timber_nodenames["moretrees:pine_trunk_sideways"] = true + timber_nodenames["moretrees:rubber_tree_trunk"] = true + timber_nodenames["moretrees:rubber_tree_trunk_sideways"] = true + timber_nodenames["moretrees:rubber_tree_trunk_empty"] = true + timber_nodenames["moretrees:rubber_tree_trunk_sideways_empty"] = true + timber_nodenames["moretrees:sequoia_trunk"] = true + timber_nodenames["moretrees:sequoia_trunk_sideways"] = true + timber_nodenames["moretrees:spruce_trunk"] = true + timber_nodenames["moretrees:spruce_trunk_sideways"] = true + timber_nodenames["moretrees:willow_trunk"] = true + timber_nodenames["moretrees:willow_trunk_sideways"] = true + timber_nodenames["moretrees:jungletree_trunk"] = true + timber_nodenames["moretrees:jungletree_trunk_sideways"] = true + + if chainsaw_leaves == true then + timber_nodenames["moretrees:apple_tree_leaves"] = true + timber_nodenames["moretrees:oak_leaves"] = true + timber_nodenames["moretrees:sequoia_leaves"] = true + timber_nodenames["moretrees:birch_leaves"] = true + timber_nodenames["moretrees:birch_leaves"] = true + timber_nodenames["moretrees:palm_leaves"] = true + timber_nodenames["moretrees:spruce_leaves"] = true + timber_nodenames["moretrees:spruce_leaves"] = true + timber_nodenames["moretrees:pine_leaves"] = true + timber_nodenames["moretrees:willow_leaves"] = true + timber_nodenames["moretrees:rubber_tree_leaves"] = true + timber_nodenames["moretrees:jungletree_leaves_green"] = true + timber_nodenames["moretrees:jungletree_leaves_yellow"] = true + timber_nodenames["moretrees:jungletree_leaves_red"] = true + end +end + +-- Support growing_trees if it is there +if( minetest.get_modpath("growing_trees") ~= nil ) then + timber_nodenames["growing_trees:trunk"] = true + timber_nodenames["growing_trees:medium_trunk"] = true + timber_nodenames["growing_trees:big_trunk"] = true + timber_nodenames["growing_trees:trunk_top"] = true + timber_nodenames["growing_trees:trunk_sprout"] = true + timber_nodenames["growing_trees:branch_sprout"] = true + timber_nodenames["growing_trees:branch"] = true + timber_nodenames["growing_trees:branch_xmzm"] = true + timber_nodenames["growing_trees:branch_xpzm"] = true + timber_nodenames["growing_trees:branch_xmzp"] = true + timber_nodenames["growing_trees:branch_xpzp"] = true + timber_nodenames["growing_trees:branch_zz"] = true + timber_nodenames["growing_trees:branch_xx"] = true + + if chainsaw_leaves == true then + timber_nodenames["growing_trees:leaves"] = true + end +end + +-- Support growing_cactus if it is there +if( minetest.get_modpath("growing_cactus") ~= nil ) then + timber_nodenames["growing_cactus:sprout"] = true + timber_nodenames["growing_cactus:branch_sprout_vertical"] = true + timber_nodenames["growing_cactus:branch_sprout_vertical_fixed"] = true + timber_nodenames["growing_cactus:branch_sprout_xp"] = true + timber_nodenames["growing_cactus:branch_sprout_xm"] = true + timber_nodenames["growing_cactus:branch_sprout_zp"] = true + timber_nodenames["growing_cactus:branch_sprout_zm"] = true + timber_nodenames["growing_cactus:trunk"] = true + timber_nodenames["growing_cactus:branch_trunk"] = true + timber_nodenames["growing_cactus:branch"] = true + timber_nodenames["growing_cactus:branch_xp"] = true + timber_nodenames["growing_cactus:branch_xm"] = true + timber_nodenames["growing_cactus:branch_zp"] = true + timber_nodenames["growing_cactus:branch_zm"] = true + timber_nodenames["growing_cactus:branch_zz"] = true + timber_nodenames["growing_cactus:branch_xx"] = true +end + +-- Table for saving what was sawed down +local produced + +-- Saw down trees entry point +chainsaw_dig_it = function(pos, player,current_charge) + local remaining_charge=current_charge + + -- A bit of trickery here: use a different node drop callback + -- and restore the original afterwards. + minetest.handle_node_drops = chainsaw_handle_node_drops + + -- clear result and start sawing things down + produced = {} + remaining_charge = recursive_dig(pos, remaining_charge, player) + minetest.sound_play("chainsaw", {pos = pos, gain = 1.0, max_hear_distance = 10,}) + + -- Restore the original noder drop handler + minetest.handle_node_drops = original_handle_node_drops + + -- Now drop items for the player + local number, produced_item, p + for produced_item,number in pairs(produced) do + --print("ADDING ITEM: " .. produced_item .. " " .. number) + -- Drop stacks of 99 or less + p = { + x = pos.x + math.random()*4, + y = pos.y, + z = pos.z + math.random()*4 + } + while number > 99 do + minetest.env:add_item(p, produced_item .. " 99") + p = { + x = pos.x + math.random()*4, + y = pos.y, + z = pos.z + math.random()*4 + } + number = number - 99 + end + minetest.env:add_item(p, produced_item .. " " .. number) + end + return remaining_charge +end + +-- Override the default handling routine to be able to count up the +-- items sawed down so that we can drop them i an nice single stack +chainsaw_handle_node_drops = function(pos, drops, digger) + -- Add dropped items to list of collected nodes + local _, dropped_item + for _, dropped_item in ipairs(drops) do + if produced[dropped_item] == nil then + produced[dropped_item] = 1 + else + produced[dropped_item] = produced[dropped_item] + 1 + end + end +end + +-- Save the currently installed dropping mechanism so we can restore it. +local original_handle_node_drops = minetest.handle_node_drops +-- This function does all the hard work. Recursively we dig the node at hand +-- if it is in the table and then search the surroundings for more stuff to dig. +recursive_dig = function(pos, remaining_charge, player) + local node=minetest.env:get_node(pos) + local i=1 + -- Lookup node name in timber table: + if timber_nodenames[node.name] ~= nil then + -- Return if we are out of power + if remaining_charge < chainsaw_charge_per_node then + return 0 + end + local np + -- wood found - cut it. + minetest.env:dig_node(pos) + remaining_charge=remaining_charge-chainsaw_charge_per_node + -- check surroundings and run recursively if any charge left + np={x=pos.x+1, y=pos.y, z=pos.z} + if timber_nodenames[minetest.env:get_node(np).name] ~= nil then + remaining_charge = recursive_dig(np, remaining_charge) + end + np={x=pos.x+1, y=pos.y, z=pos.z+1} + if timber_nodenames[minetest.env:get_node(np).name] ~= nil then + remaining_charge = recursive_dig(np, remaining_charge) + end + np={x=pos.x+1, y=pos.y, z=pos.z-1} + if timber_nodenames[minetest.env:get_node(np).name] ~= nil then + remaining_charge = recursive_dig(np, remaining_charge) + end -timber_nodenames={"default:jungletree", "default:papyrus", "default:cactus", "default:tree"} + np={x=pos.x-1, y=pos.y, z=pos.z} + if timber_nodenames[minetest.env:get_node(np).name] ~= nil then + remaining_charge = recursive_dig(np, remaining_charge) + end + np={x=pos.x-1, y=pos.y, z=pos.z+1} + if timber_nodenames[minetest.env:get_node(np).name] ~= nil then + remaining_charge = recursive_dig(np, remaining_charge) + end + np={x=pos.x-1, y=pos.y, z=pos.z-1} + if timber_nodenames[minetest.env:get_node(np).name] ~= nil then + remaining_charge = recursive_dig(np, remaining_charge) + end -function chainsaw_dig_it (pos, player,charge_to_take) - charge_to_take=0 - local node=minetest.env:get_node(pos) - local i=1 - while timber_nodenames[i]~=nil do - if node.name==timber_nodenames[i] then - charge_to_take=600 - np={x=pos.x, y=pos.y, z=pos.z} - while minetest.env:get_node(np).name==timber_nodenames[i] do - minetest.env:remove_node(np) - minetest.env:add_item(np, timber_nodenames[i]) - np={x=np.x, y=np.y+1, z=np.z} - end - minetest.sound_play("chainsaw", {pos = pos, gain = 1.0, max_hear_distance = 10,}) - return charge_to_take - end - i=i+1 - end + np={x=pos.x, y=pos.y+1, z=pos.z} + if timber_nodenames[minetest.env:get_node(np).name] ~= nil then + remaining_charge = recursive_dig(np, remaining_charge) + end -return charge_to_take + np={x=pos.x, y=pos.y, z=pos.z+1} + if timber_nodenames[minetest.env:get_node(np).name] ~= nil then + remaining_charge = recursive_dig(np, remaining_charge) + end + np={x=pos.x, y=pos.y, z=pos.z-1} + if timber_nodenames[minetest.env:get_node(np).name] ~= nil then + remaining_charge = recursive_dig(np, remaining_charge) + end + return remaining_charge + end + -- Nothing sawed down + return remaining_charge end diff --git a/technic/cnc.lua b/technic/cnc.lua new file mode 100644 index 0000000..6e763ef --- /dev/null +++ b/technic/cnc.lua @@ -0,0 +1,208 @@ +-- Technic CNC v1.0 by kpo +-- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck +local shape = {} +local size = 0 +local onesize_products = { + slope = 2, + slope_edge = 1, + slope_inner_edge = 1, + pyramid = 2, + spike = 1, + cylinder = 2, + sphere = 1, + stick = 8, + slope_upsdwn = 2, + slope_edge_upsdwn = 1, + slope_inner_edge_upsdwn = 1, + cylinder_hor = 2, + slope_lying = 2, + onecurvededge = 1, + twocurvededge = 1, +} +local twosize_products = { + element_straight = 4, + element_end = 2, + element_cross = 1, + element_t = 1, + element_edge = 2, +} + +local showbackground = "--" +local max_cncruns = 99 +local max_products = 99 + +--showlabelin = "" +--showlabelout = "label[4.5,5.5;Out:]" + +-- I want the CNC machine to be a two block thing +minetest.register_node("technic:cnc", { + description = "CNC Milling Machine", + tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png", + "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front.png"}, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + + }, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + groups = {oddly_breakable_by_hand=2, cracky=3, dig_immediate=1}, + + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("input") or not inv:is_empty("output") then + minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty"); + return false + end + return true + end, + + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + if technic_cnc_api.allow_menu_background == true or technic_cnc_api.allow_menu_background == 1 then + showbackground = "background[-0.15,-0.25;8.40,11.75;technic_cnc_background.png]" + end + + meta:set_string("formspec", "invsize[8,11;]".. + "label[0,0;Choose Milling Program:]".. + "image_button[0,0.5;1,1;technic_cnc_slope.png;slope; ]".. + "image_button[1,0.5;1,1;technic_cnc_slope_edge.png;slope_edge; ]".. + "image_button[2,0.5;1,1;technic_cnc_slope_inner_edge.png;slope_inner_edge; ]".. + "image_button[3,0.5;1,1;technic_cnc_pyramid.png;pyramid; ]".. + "image_button[4,0.5;1,1;technic_cnc_spike.png;spike; ]".. + "image_button[5,0.5;1,1;technic_cnc_cylinder.png;cylinder; ]".. + "image_button[6,0.5;1,1;technic_cnc_sphere.png;sphere; ]".. + "image_button[7,0.5;1,1;technic_cnc_stick.png;stick; ]".. + + "image_button[0,1.5;1,1;technic_cnc_slope_upsdwn.png;slope_upsdwn; ]".. + "image_button[1,1.5;1,1;technic_cnc_slope_edge_upsdwn.png;slope_upsdwn_edge; ]".. + "image_button[2,1.5;1,1;technic_cnc_slope_inner_edge_upsdwn.png;slope_upddown_inner_edge; ]".. + "image_button[5,1.5;1,1;technic_cnc_cylinder_horizontal.png;cylinder_horizontal; ]".. + + "image_button[0,2.5;1,1;technic_cnc_slope_lying.png;slope_lying; ]".. + "image_button[1,2.5;1,1;technic_cnc_onecurvededge.png;onecurvededge; ]".. + "image_button[2,2.5;1,1;technic_cnc_twocurvededge.png;twocurvededge; ]".. + + "label[0,3.5;Slim Elements half / normal height:]".. + + "image_button[0,4;1,0.5;technic_cnc_full.png;full; ]".. + "image_button[0,4.5;1,0.5;technic_cnc_half.png;half; ]".. + "image_button[1,4;1,1;technic_cnc_element_straight.png;element_straight; ]".. + "image_button[2,4;1,1;technic_cnc_element_end.png;element_end; ]".. + "image_button[3,4;1,1;technic_cnc_element_cross.png;element_cross; ]".. + "image_button[4,4;1,1;technic_cnc_element_t.png;element_t; ]".. + "image_button[5,4;1,1;technic_cnc_element_edge.png;element_edge; ]".. + + "label[0, 5.5;In:]".. -- showlabelin.. + "list[current_name;input;0.5,5.5;1,1;]".. + "field[3, 6;1,1;num_cncruns;Repeat program:;${num_cncruns}]".. -- Fill default with meta data num_cncruns + "label[4, 5.5;Out:]".. -- showlabelout.. + "list[current_name;output;4.5,5.5;1,1;]".. + + "list[current_player;main;0,7;8,4;]".. + showbackground) + meta:set_string("infotext", "CNC Milling Machine") + meta:set_string("num_cncruns", 1 ); + + local inv = meta:get_inventory() + inv:set_size("input", 1) + inv:set_size("output", 1) + end, + + on_receive_fields = function(pos, formname, fields, sender) + -- REGISTER MILLING PROGRAMMS AND OUTPUTS: + ------------------------------------------ + -- Program for half/full size + if fields["full"] then + size = 1 + return + end + + if fields["half"] then + size = 2 + return + end + + local meta = minetest.env:get_meta(pos) + local inv = meta:get_inventory() + + -- Limit the number entered + if( fields.num_cncruns and tonumber( fields.num_cncruns) > 0 and tonumber(fields.num_cncruns) < 100 ) then + meta:set_string( "num_cncruns", fields.num_cncruns ); + else + minetest.chat_send_player(sender:get_player_name(), "CNC machine runs set to a bad value. Machine resets."); + meta:set_string( "num_cncruns", 1 ); + fields.num_cncruns = 1 + end + + -- Do nothing if the machine is empty + if inv:is_empty("input") then + return + end + + -- Do nothing if the output is not empty and the product used is not the same as what is already there + + -- Resolve the node name and the number of items to make and the number of items to take + local product = "" + local produces = 1 + local input_used = 1 + local inputstack = inv:get_stack("input", 1) + local inputname = inputstack:get_name() + local multiplier = 1 + for k, _ in pairs(fields) do + -- Set a multipier for the half/full size capable blocks + if twosize_products[k] ~= nil then + multiplier = size*twosize_products[k] + else + multiplier = onesize_products[k] + end + + if onesize_products[k] ~= nil or twosize_products[k] ~= nil then + product = inputname .. "_technic_cnc_" .. k + produces = math.min( fields.num_cncruns*multiplier, max_products) -- produce at most max_products + input_used = math.min( math.floor(produces/multiplier), inputstack:get_count()) -- use at most what we got + produces = input_used*multiplier -- final production + print(size) + print(fields.num_cncruns) + print(product) + print(produces) + print(input_used) + print("------------------") + break + end + end + + -- CNC does the transformation + ------------------------------ + if minetest.registered_nodes[product] ~= nil then + inv:add_item("output",product .. " " .. produces) + inputstack:take_item(input_used) + inv:set_stack("input",1,inputstack) + else + minetest.chat_send_player(sender:get_player_name(), "CNC machine does not know how to mill this material. Please remove it."); + end + return; + end, -- callback function + }) +---------- + + +-- Milling Machine Recipe +------------------------- +minetest.register_craft({ + output = 'technic:cnc', + recipe = { + {'default:glass', 'technic:diamond_drill_head', 'default:glass'}, + {'technic:control_logic_unit', 'technic:motor', 'default:steel_ingot'}, + {'default:steel_ingot', 'default:copper_ingot', 'default:steel_ingot'}, + }, + }) +------------------------- \ No newline at end of file diff --git a/technic/cnc_api.lua b/technic/cnc_api.lua new file mode 100644 index 0000000..390a996 --- /dev/null +++ b/technic/cnc_api.lua @@ -0,0 +1,970 @@ +-- API for the technic CNC machine +-- Again code is adapted from the NonCubic Blocks MOD v1.4 by yves_de_beck +technic_cnc_api = {} + +-- HERE YOU CAN CHANGE THE DETAIL-LEVEL: +---------------------------------------- +technic_cnc_api.detail_level = 16 -- 16; 1-32 + +-- HERE YOU CAN DE/ACTIVATE BACKGROUND FOR CNC MENU: +-------------------------------------------------------- +technic_cnc_api.allow_menu_background = false + +-- REGISTER NONCUBIC FORMS, CREATE MODELS AND RECIPES: +------------------------------------------------------ + +-- SLOPE +-------- +function technic_cnc_api.register_slope(recipeitem, groups, images, description) + +local slopebox = {} +local detail = technic_cnc_api.detail_level +for i = 0, detail-1 do + slopebox[i+1]={-0.5, (i/detail)-0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} +end + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = slopebox, + }, + groups = groups, + }) +end + + +-- SLOPE Lying +---------------- +function technic_cnc_api.register_slope_lying(recipeitem, groups, images, description) + +local slopeboxlying = {} +local detail = technic_cnc_api.detail_level +for i = 0, detail-1 do + slopeboxlying[i+1]={(i/detail)-0.5, -0.5, (i/detail)-0.5, (i/detail)-0.5+(1/detail), 0.5 , 0.5} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_lying", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = slopeboxlying, + }, + groups = groups, + }) + minetest.register_craft({ + output = recipeitem .. "_technic_cnc_slope_lying 1", + recipe = { + {"", "", ""}, + {"", recipeitem .. "_technic_cnc_slope", ""}, + {"", "", ""}, + }, + }) + +end + + +-- SLOPE UPSIDE DOWN +-------------------- +function technic_cnc_api.register_slope_upsdown(recipeitem, groups, images, description) + +if subname == "dirt" then +return +end + +local slopeupdwnbox = {} +local detail = technic_cnc_api.detail_level +for i = 0, detail-1 do + slopeupdwnbox[i+1]={-0.5, (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_upsdown", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = slopeupdwnbox, + }, + groups = groups, + }) +end + + +-- SLOPE EDGE +------------- +function technic_cnc_api.register_slope_edge(recipeitem, groups, images, description) + +local slopeboxedge = {} +local detail = technic_cnc_api.detail_level +for i = 0, detail-1 do + slopeboxedge[i+1]={(i/detail)-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_edge", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = slopeboxedge, + }, + groups = groups, + }) +end + + +-- SLOPE INNER EDGE +------------------- +function technic_cnc_api.register_slope_inner_edge(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_inner_edge", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = { + -- PART 1 + {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5}, + {-0.45, -0.5, -0.5, 0.5, -0.4, 0.5}, + {-0.4, -0.5, -0.5, 0.5, -0.35, 0.5}, + {-0.35, -0.5, -0.5, 0.5, -0.3, 0.5}, + {-0.3, -0.5, -0.5, 0.5, -0.25, 0.5}, + {-0.25, -0.5, -0.5, 0.5, -0.2, 0.5}, + {-0.2, -0.5, -0.5, 0.5, -0.15, 0.5}, + {-0.15, -0.5, -0.5, 0.5, -0.1, 0.5}, + {-0.1, -0.5, -0.5, 0.5, -0.05, 0.5}, + {-0.05, -0.5, -0.5, 0.5, 0, 0.5}, + {0, -0.5, -0.5, 0.5, 0.05, 0.5}, + {0.05, -0.5, -0.5, 0.5, 0.1, 0.5}, + {0.1, -0.5, -0.5, 0.5, 0.15, 0.5}, + {0.15, -0.5, -0.5, 0.5, 0.2, 0.5}, + {0.2, -0.5, -0.5, 0.5, 0.25, 0.5}, + {0.25, -0.5, -0.5, 0.5, 0.3, 0.5}, + {0.3, -0.5, -0.5, 0.5, 0.35, 0.5}, + {0.35, -0.5, -0.5, 0.5, 0.4, 0.5}, + {0.4, -0.5, -0.5, 0.5, 0.45, 0.5}, + {0.45, -0.5, -0.5, 0.5, 0.5, 0.5}, + -- PART 2 + {-0.5, -0.5, -0.45, 0.5, -0.45, 0.5}, + {-0.5, -0.5, -0.4, 0.5, -0.4, 0.5}, + {-0.5, -0.5, -0.35, 0.5, -0.35, 0.5}, + {-0.5, -0.5, -0.3, 0.5, -0.3, 0.5}, + {-0.5, -0.5, -0.25, 0.5, -0.25, 0.5}, + {-0.5, -0.5, -0.2, 0.5, -0.2, 0.5}, + {-0.5, -0.5, -0.15, 0.5, -0.15, 0.5}, + {-0.5, -0.5, -0.1, 0.5, -0.1, 0.5}, + {-0.5, -0.5, -0.05, 0.5, -0.05, 0.5}, + {-0.5, -0.5, 0, 0.5, 0, 0.5}, + {-0.5, -0.5, 0.05, 0.5, 0.05, 0.5}, + {-0.5, -0.5, 0.1, 0.5, 0.1, 0.5}, + {-0.5, -0.5, 0.15, 0.5, 0.15, 0.5}, + {-0.5, -0.5, 0.2, 0.5, 0.2, 0.5}, + {-0.5, -0.5, .25, 0.5, 0.25, 0.5}, + {-0.5, -0.5, 0.3, 0.5, 0.3, 0.5}, + {-0.5, -0.5, 0.35, 0.5, 0.35, 0.5}, + {-0.5, -0.5, 0.4, 0.5, 0.4, 0.5}, + {-0.5, -0.5, 0.45, 0.5, 0.45, 0.5}, + {-0.5, -0.5, 0.5, 0.5, 0.5, 0.5}, + }, + }, + groups = groups, + }) +end + + +-- SLOPE EDGE UPSIDE DOWN +------------------------- +function technic_cnc_api.register_slope_upsdown_edge(recipeitem, groups, images, description) + +if recipeitem == "default:dirt" then + return +end + +local slopeupdwnboxedge = {} +local detail = technic_cnc_api.detail_level +for i = 0, detail-1 do + slopeupdwnboxedge[i+1]={(-1*(i/detail))+0.5-(1/detail), (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_upsdown_edge", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = slopeupdwnboxedge, + }, + groups = groups, + }) +end + + +-- SLOPE INNER EDGE UPSIDE DOWN +------------------------------- +function technic_cnc_api.register_slope_upsdown_inner_edge(recipeitem, groups, images, description) + +if recipename == "default:dirt" then +return +end + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_upsdown_inner_edge", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = { + {0.45, -0.5, -0.5, 0.5, -0.45, 0.5}, + {0.4, -0.45, -0.5, 0.5, -0.4, 0.5}, + {0.35, -0.4, -0.5, 0.5, -0.35, 0.5}, + {0.3, -0.35, -0.5, 0.5, -0.3, 0.5}, + {0.25, -0.3, -0.5, 0.5, -0.25, 0.5}, + {0.2, -0.25, -0.5, 0.5, -0.2, 0.5}, + {0.15, -0.2, -0.5, 0.5, -0.15, 0.5}, + {0.1, -0.15, -0.5, 0.5, -0.1, 0.5}, + {0.05, -0.1, -0.5, 0.5, -0.05, 0.5}, + {0, -0.05, -0.5, 0.5, 0, 0.5}, + {-0.05, 0, -0.5, 0.5, 0.05, 0.5}, + {-0.1, 0.05, -0.5, 0.5, 0.1, 0.5}, + {-0.15, 0.1, -0.5, 0.5, 0.15, 0.5}, + {-0.2, 0.15, -0.5, 0.5, 0.2, 0.5}, + {-0.25, 0.2, -0.5, 0.5, 0.25, 0.5}, + {-0.3, 0.25, -0.5, 0.5, 0.3, 0.5}, + {-0.35, 0.3, -0.5, 0.5, 0.35, 0.5}, + {-0.4, 0.35, -0.5, 0.5, 0.4, 0.5}, + {-0.45, 0.4, -0.5, 0.5, 0.45, 0.5}, + {-0.5, 0.45, -0.5, 0.5, 0.5, 0.5}, + + {-0.5, -0.5, 0.45, 0.5, -0.45, 0.5}, + {-0.5, -0.45, 0.4, 0.5, -0.4, 0.5}, + {-0.5, -0.4, 0.35, 0.5, -0.35, 0.5}, + {-0.5, -0.35, 0.3, 0.5, -0.3, 0.5}, + {-0.5, -0.3, 0.25, 0.5, -0.25, 0.5}, + {-0.5, -0.25, 0.2, 0.5, -0.2, 0.5}, + {-0.5, -0.2, 0.15, 0.5, -0.15, 0.5}, + {-0.5, -0.15, 0.1, 0.5, -0.1, 0.5}, + {-0.5, -0.1, 0.05, 0.5, -0.05, 0.5}, + {-0.5, -0.05, 0, 0.5, 0, 0.5}, + {-0.5, 0, -0.05, 0.5, 0.05, 0.5}, + {-0.5, 0.05, -0.1, 0.5, 0.1, 0.5}, + {-0.5, 0.1, -0.15, 0.5, 0.15, 0.5}, + {-0.5, 0.15, -0.2, 0.5, 0.2, 0.5}, + {-0.5, 0.2, -0.25, 0.5, 0.25, 0.5}, + {-0.5, 0.25, -0.3, 0.5, 0.3, 0.5}, + {-0.5, 0.3, -0.35, 0.5, 0.35, 0.5}, + {-0.5, 0.35, -0.4, 0.5, 0.4, 0.5}, + {-0.5, 0.4, -0.45, 0.5, 0.45, 0.5}, + {-0.5, 0.45, -0.5, 0.5, 0.5, 0.5}, + + }, + }, + groups = groups, + }) +end + + +-- PYRAMID +---------- +function technic_cnc_api.register_pyramid(recipeitem, groups, images, description) + +local pyrabox = {} +local detail = technic_cnc_api.detail_level/2 +for i = 0, detail-1 do + pyrabox[i+1]={(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail/2)-0.5+(1/detail), 0.5-(i/detail/2)} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_pyramid", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + node_box = { + type = "fixed", + fixed = pyrabox, + }, + groups = groups, + }) +end + + +-- SPIKE +-------- +function technic_cnc_api.register_spike(recipeitem, groups, images, description) + +if recipename == "default:dirt" then + return +end + +local spikebox = {} +local detail = technic_cnc_api.detail_level +for i = 0, detail-1 do + spikebox[i+1]={(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail)-0.5+(1/detail), 0.5-(i/detail/2)} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_spike", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = spikebox, + }, + groups = groups, + }) +end + + +-- Block one curved edge +------------------------ +function technic_cnc_api.register_onecurvededge(recipeitem, groups, images, description) + +local quartercyclebox = {} +local detail = technic_cnc_api.detail_level*2 +local sehne +for i = (detail/2)-1, detail-1 do + sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) + quartercyclebox[i]={-0.5, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_onecurvededge", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = quartercyclebox, + }, + groups = groups, + }) +end + + +-- Block two curved edges +------------------------- +function technic_cnc_api.register_twocurvededge(recipeitem, groups, images, description) + +local quartercyclebox2 = {} +local detail = technic_cnc_api.detail_level*2 +local sehne +for i = (detail/2)-1, detail-1 do + sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) + quartercyclebox2[i]={-sehne, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_twocurvededge", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = quartercyclebox2, + }, + groups = groups, + }) + minetest.register_craft({ + output = recipeitem .. "_technic_cnc_twocurvededge 3", + recipe = { + {"", "", ""}, + {recipeitem .. "_technic_cnc_onecurvededge", "", ""}, + {recipeitem .. "_technic_cnc_onecurvededge", recipeitem .. "_technic_cnc_onecurvededge", ""}, + }, + }) + +end + +-- Cylinder +----------- +function technic_cnc_api.register_cylinder(recipeitem, groups, images, description) + +if recipename == "default:dirt" then +return +end + +local cylbox = {} +local detail = technic_cnc_api.detail_level +local sehne +for i = 1, detail-1 do + sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) + cylbox[i]={(i/detail)-0.5, -0.5, -sehne, (i/detail)+(1/detail)-0.5, 0.5, sehne} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_cylinder", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = cylbox, + }, + groups = groups, + }) + minetest.register_craft({ + output = recipeitem .. "_technic_cnc_cylinder 1", + recipe = { + {"", "", ""}, + {"", recipeitem .. "_technic_cnc_cylinder_horizontal", ""}, + {"", "", ""}, + }, + }) + +end + + +-- Cylinder Horizontal +---------------------- +function technic_cnc_api.register_cylinder_horizontal(recipeitem, groups, images, description) + +if recipename == "default:dirt" then + return +end + +local cylbox_horizontal = {} +local detail = technic_cnc_api.detail_level +local sehne +for i = 1, detail-1 do + sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) + cylbox_horizontal[i]={-0.5, (i/detail)-0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, sehne} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_cylinder_horizontal", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = cylbox_horizontal, + }, + groups = groups, + }) + minetest.register_craft({ + output = recipeitem .. "_technic_cnc_cylinder_horizontal 1", + recipe = { + {"", "", ""}, + {"", recipeitem .. "_technic_cnc_cylinder", ""}, + {"", "", ""}, + }, + }) +end + + +-- Sphere +--------- +function technic_cnc_api.register_sphere(recipeitem, groups, images, description) + +if recipename == "default:dirt" then + return +end + +local spherebox = {} +local detail = technic_cnc_api.detail_level +local sehne +for i = 1, detail-1 do + sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) + spherebox[i]={-sehne, (i/detail)-0.5, -sehne, sehne, (i/detail)+(1/detail)-0.5, sehne} +end +minetest.register_node(":" .. recipeitem .. "_technic_cnc_cylinder_sphere", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = spherebox, + }, + groups = groups, + }) +end + + +-- Element straight +------------------- +function technic_cnc_api.register_element_straight(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_straight", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.3, -0.5, -0.5, 0.3, 0, 0.5}, + }, + node_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.5, 0.3, 0, 0.5}, + }, + }, + groups = groups, + }) +end + + +-- Element Edge +--------------- +function technic_cnc_api.register_element_edge(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_edge", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.5, 0.3, 0, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, + }, + }, + node_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.5, 0.3, 0, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, + }, + }, + groups = groups, + }) +end + + +-- Element T +------------ +function technic_cnc_api.register_element_t(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_t", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.5, 0.3, 0, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, + {0.3, -0.5, -0.3, 0.5, 0, 0.3}, + }, + }, + node_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.5, 0.3, 0, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, + {0.3, -0.5, -0.3, 0.5, 0, 0.3}, + }, + }, + groups = groups, + }) +end + + +-- Element Cross +---------------- +function technic_cnc_api.register_element_cross(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_cross", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = { + {0.3, -0.5, -0.3, 0.5, 0, 0.3}, + {-0.3, -0.5, -0.5, 0.3, 0, 0.5}, + {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, + }, + }, + node_box = { + type = "fixed", + fixed = { + {0.3, -0.5, -0.3, 0.5, 0, 0.3}, + {-0.3, -0.5, -0.5, 0.3, 0, 0.5}, + {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, + }, + }, + groups = groups, + }) +end + + +-- Element End +-------------- +function technic_cnc_api.register_element_end(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_end", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.3, -0.5, -0.3, 0.3, 0, 0.5}, + }, + node_box = { + type = "fixed", + fixed = {-0.3, -0.5, -0.3, 0.3, 0, 0.5}, + }, + groups = groups, + }) +end + + +-- Element straight DOUBLE +-------------------------- +function technic_cnc_api.register_element_straight_double(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_straight_double", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5}, + }, + }, + groups = groups, + }) + minetest.register_craft({ + output = recipeitem .. "_technic_cnc_element_straight_double 1", + recipe = { + {"", "", ""}, + {"", recipeitem .. "_technic_cnc_element_straight", ""}, + {"", recipeitem .. "_technic_cnc_element_straight", ""}, + }, + }) +end + + +-- Element Edge DOUBLE +---------------------- +function technic_cnc_api.register_element_edge_double(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_edge_double", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, + }, + }, + node_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, + }, + }, + groups = groups, + }) + minetest.register_craft({ + output = recipeitem .. "_technic_cnc_element_edge_double 1", + recipe = { + {"", "", ""}, + {"", recipeitem .. "_technic_cnc_element_edge", ""}, + {"", recipeitem .. "_technic_cnc_element_edge", ""}, + }, + }) +end + + +-- Element T DOUBLE +------------------- +function technic_cnc_api.register_element_t_double(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_t_double", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, + {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}, + }, + }, + node_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, + {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}, + }, + }, + groups = groups, + }) + minetest.register_craft({ + output = recipeitem .. "_technic_cnc_element_t_double 1", + recipe = { + {"", "", ""}, + {"", recipeitem .. "_technic_cnc_element_t", ""}, + {"", recipeitem .. "_technic_cnc_element_t", ""}, + }, + }) +end + + +-- Element Cross Double +----------------------- +function technic_cnc_api.register_element_cross_double(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_cross_double", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = { + {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}, + {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5}, + {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, + }, + }, + node_box = { + type = "fixed", + fixed = { + {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}, + {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5}, + {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, + }, + }, + groups = groups, + }) + minetest.register_craft({ + output = recipeitem .. "_technic_cnc_element_cross_double 1", + recipe = { + {"", "", ""}, + {"", recipeitem .. "_technic_cnc_element_cross", ""}, + {"", recipeitem .. "_technic_cnc_element_cross", ""}, + }, + }) + +end + + +-- Element End Double +--------------------- +function technic_cnc_api.register_element_end_double(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_end_double", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.5}, + }, + node_box = { + type = "fixed", + fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.5}, + }, + groups = groups, + }) + minetest.register_craft({ + output = recipeitem .. "_technic_cnc_element_end_double 1", + recipe = { + {"", "", ""}, + {"", recipeitem .. "_technic_cnc_element_end", ""}, + {"", recipeitem .. "_technic_cnc_element_end", ""}, + }, + }) +end + + +-- STICK +-------- +function technic_cnc_api.register_stick(recipeitem, groups, images, description) + +minetest.register_node(":" .. recipeitem .. "_technic_cnc_stick", { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15}, + }, + node_box = { + type = "fixed", + fixed = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15}, + }, + groups = groups, + }) + minetest.register_craft({ + output = recipeitem .. "_technic_cnc_stick 8", + recipe = { + {'default:stick', "", ""}, + {"", "", ""}, + {recipeitem, "", ""}, + }, + }) +end + + + +-- REGISTER NEW TECHNIC_CNC_API's PART 2: technic_cnc_api.register_element_end(subname, recipeitem, groups, images, desc_element_xyz) +----------------------------------------------------------------------------------------------------------------------- +function technic_cnc_api.register_slope_edge_etc(recipeitem, groups, images, desc_slope, desc_slope_lying, desc_slope_upsdown, desc_slope_edge, desc_slope_inner_edge, desc_slope_upsdwn_edge, desc_slope_upsdwn_inner_edge, desc_pyramid, desc_spike, desc_onecurvededge, desc_twocurvededge, desc_cylinder, desc_cylinder_horizontal, desc_sphere, desc_element_straight, desc_element_edge, desc_element_t, desc_element_cross, desc_element_end) + + technic_cnc_api.register_slope(recipeitem, groups, images, desc_slope) + technic_cnc_api.register_slope_lying(recipeitem, groups, images, desc_slope_lying) + technic_cnc_api.register_slope_upsdown(recipeitem, groups, images, desc_slope_upsdown) + technic_cnc_api.register_slope_edge(recipeitem, groups, images, desc_slope_edge) + technic_cnc_api.register_slope_inner_edge(recipeitem, groups, images, desc_slope_inner_edge) + technic_cnc_api.register_slope_upsdown_edge(recipeitem, groups, images, desc_slope_upsdwn_edge) + technic_cnc_api.register_slope_upsdown_inner_edge(recipeitem, groups, images, desc_slope_upsdwn_inner_edge) + technic_cnc_api.register_pyramid(recipeitem, groups, images, desc_pyramid) + technic_cnc_api.register_spike(recipeitem, groups, images, desc_spike) + technic_cnc_api.register_onecurvededge(recipeitem, groups, images, desc_onecurvededge) + technic_cnc_api.register_twocurvededge(recipeitem, groups, images, desc_twocurvededge) + technic_cnc_api.register_cylinder(recipeitem, groups, images, desc_cylinder) + technic_cnc_api.register_cylinder_horizontal(recipeitem, groups, images, desc_cylinder_horizontal) + technic_cnc_api.register_sphere(recipeitem, groups, images, desc_sphere) + technic_cnc_api.register_element_straight(recipeitem, groups, images, desc_element_straight) + technic_cnc_api.register_element_edge(recipeitem, groups, images, desc_element_edge) + technic_cnc_api.register_element_t(recipeitem, groups, images, desc_element_t) + technic_cnc_api.register_element_cross(recipeitem, groups, images, desc_element_cross) + technic_cnc_api.register_element_end(recipeitem, groups, images, desc_element_end) +end + +-- REGISTER STICKS: noncubic.register_xyz(recipeitem, groups, images, desc_element_xyz) +------------------------------------------------------------------------------------------------------------ +function technic_cnc_api.register_stick_etc(recipeitem, groups, images, desc_stick) + technic_cnc_api.register_stick(recipeitem, groups, images, desc_stick) +end + +function technic_cnc_api.register_elements(recipeitem, groups, images, desc_element_straight_double, desc_element_edge_double, desc_element_t_double, desc_element_cross_double, desc_element_end_double) + technic_cnc_api.register_element_straight_double(recipeitem, groups, images, desc_element_straight_double) + technic_cnc_api.register_element_edge_double(recipeitem, groups, images, desc_element_edge_double) + technic_cnc_api.register_element_t_double(recipeitem, groups, images, desc_element_t_double) + technic_cnc_api.register_element_cross_double(recipeitem, groups, images, desc_element_cross_double) + technic_cnc_api.register_element_end_double(recipeitem, groups, images, desc_element_end_double) +end diff --git a/technic/cnc_nodes.lua b/technic/cnc_nodes.lua new file mode 100644 index 0000000..2f375a5 --- /dev/null +++ b/technic/cnc_nodes.lua @@ -0,0 +1,354 @@ +-- REGISTER MATERIALS AND PROPERTIES FOR NONCUBIC ELEMENTS: +----------------------------------------------------------- + +-- WOOD +------- +technic_cnc_api.register_slope_edge_etc("default:wood", + {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + {"default_wood.png"}, + "Wooden Slope", + "Wooden Slope Lying", + "Wooden Slope Upside Down", + "Wooden Slope Edge", + "Wooden Slope Inner Edge", + "Wooden Slope Upside Down Edge", + "Wooden Slope Upside Down Inner Edge", + "Wooden Pyramid", + "Wooden Spike", + "Wooden One Curved Edge Block", + "Wooden Two Curved Edge Block", + "Wooden Cylinder", + "Wooden Cylinder Horizontal", + "Wooden Sphere", + "Wooden Element Straight", + "Wooden Element Edge", + "Wooden Element T", + "Wooden Element Cross", + "Wooden Element End") +-- STONE +-------- +technic_cnc_api.register_slope_edge_etc("default:stone", + {cracky=3,not_in_creative_inventory=1}, + {"default_stone.png"}, + "Stone Slope", + "Stone Slope Lying", + "Stone Slope Upside Down", + "Stone Slope Edge", + "Stone Slope Inner Edge", + "Stone Slope Upside Down Edge", + "Stone Slope Upside Down Inner Edge", + "Stone Pyramid", + "Stone Spike", + "Stone One Curved Edge Block", + "Stone Two Curved Edge Block", + "Stone Cylinder", + "Stote Cylinder Horizontal", + "Stone Sphere", + "Stone Element Straight", + "Stone Element Edge", + "Stone Element T", + "Stone Element Cross", + "Stone Element End") +-- COBBLE +--------- +technic_cnc_api.register_slope_edge_etc("default:cobble", + {cracky=3,not_in_creative_inventory=1}, + {"default_cobble.png"}, + "Cobble Slope", + "Cobble Slope Lying", + "Cobble Slope Upside Down", + "Cobble Slope Edge", + "Cobble Slope Inner Edge", + "Cobble Slope Upside Down Edge", + "Cobble Slope Upside Down Inner Edge", + "Cobble Pyramid", + "Cobble Spike", + "Cobble One Curved Edge Block", + "Cobble Two Curved Edge Block", + "Cobble Cylinder", + "Cobble Cylinder Horizontal", + "Cobble Sphere", + "Cobble Element Straight", + "Cobble Element Edge", + "Cobble Element T", + "Cobble Element Cross", + "Cobble Element End") +-- BRICK +-------- +technic_cnc_api.register_slope_edge_etc("default:brick", + {cracky=3,not_in_creative_inventory=1}, + {"default_brick.png"}, + "Brick Slope", + "Brick Slope Upside Down", + "Brick Slope Edge", + "Brick Slope Inner Edge", + "Brick Slope Upside Down Edge", + "Brick Slope Upside Down Inner Edge", + "Brick Pyramid", + "Brick Spike", + "Brick One Curved Edge Block", + "Brick Two Curved Edge Block", + "Brick Cylinder", + "Brick Cylinder Horizontal", + "Brick Sphere", + "Brick Element Straight", + "Brick Element Edge", + "Brick Element T", + "Brick Element Cross", + "Brick Element End") +-- SANDSTONE +------------ +technic_cnc_api.register_slope_edge_etc("default:sandstone", + {crumbly=2,cracky=2,not_in_creative_inventory=1}, + {"default_sandstone.png"}, + "Sandstone Slope", + "Sandstone Slope Lying", + "Sandstone Slope Upside Down", + "Sandstone Slope Edge", + "Sandstone Slope Inner Edge", + "Sandstone Slope Upside Down Edge", + "Sandstone Slope Upside Down Inner Edge", + "Sandstone Pyramid", + "Sandstone Spike", + "Sandstone One Curved Edge Block", + "Sandstone Two Curved Edge Block", + "Sandstone Cylinder", + "Sandstone Cylinder Horizontal", + "Sandstone Sphere", + "Sandstone Element Straight", + "Sandstone Element Edge", + "Sandstone Element T", + "Sandstone Element Cross", + "Sandstone Element End") +-- LEAVES +--------- +technic_cnc_api.register_slope_edge_etc("default:leaves", + {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, + {"bucharest_tree.png"}, + "Leaves Slope", + "Leaves Slope Lying", + "Leaves Slope Upside Down", + "Leaves Slope Edge", + "Leaves Slope Inner Edge", + "Leaves Slope Upside Down Edge", + "Leaves Slope Upside Down Inner Edge", + "Leaves Pyramid", + "Leaves Spike", + "Leaves One Curved Edge Block", + "Leaves Two Curved Edge Block", + "Leaves Cylinder", + "Leaves Cylinder Horizontal", + "Leaves Sphere", + "Leaves Element Straight", + "Leaves Element Edge", + "Leaves Element T", + "Leaves Element Cross", + "Leaves Element End") +-- DIRT +------- +technic_cnc_api.register_slope_edge_etc("default:dirt", + {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, + {"default_grass.png", "default_dirt.png", "default_grass.png"}, + "Dirt Slope", + "Dirt Slope Lying", + "Dirt Slope Upside Down", + "Dirt Slope Edge", + "Dirt Slope Inner Edge", + "Dirt Slope Upside Down Edge", + "Dirt Slope Upside Down Inner Edge", + "Dirt Pyramid", + "Dirt Spike", + "Dirt One Curved Edge Block", + "Dirt Two Curved Edge Block", + "Dirt Cylinder", + "Dirt Cylinder Horizontal", + "Dirt Sphere", + "Dirt Element Straight", + "Dirt Element Edge", + "Dirt Element T", + "Dirt Element Cross", + "Dirt Element End") +-- TREE +------- +technic_cnc_api.register_slope_edge_etc("default:tree", + {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,not_in_creative_inventory=1}, + {"default_tree.png"}, + "Tree Slope", + "Tree Slope Lying", + "Tree Slope Upside Down", + "Tree Slope Edge", + "Tree Slope Inner Edge", + "Tree Slope Upside Down Edge", + "Tree Slope Upside Down Inner Edge", + "Tree Pyramid", + "Tree Spike", + "Tree One Curved Edge Block", + "Tree Two Curved Edge Block", + "Tree Cylinder", + "Tree Cylinder Horizontal", + "Tree Sphere", + "Tree Element Straight", + "Tree Element Edge", + "Tree Element T", + "Tree Element Cross", + "Tree Element End") +-- STEEL +-------- +technic_cnc_api.register_slope_edge_etc("default:steelblock", + {snappy=1,bendy=2,cracky=1,melty=2,level=2,not_in_creative_inventory=1}, + {"default_steel_block.png"}, + "Steel Slope", + "Steel Slope Lying", + "Steel Slope Upside Down", + "Steel Slope Edge", + "Steel Slope Inner Edge", + "Steel Slope Upside Down Edge", + "Steel Slope Upside Down Inner Edge", + "Steel Pyramid", + "Steel Spike", + "Steel One Curved Edge Block", + "Steel Two Curved Edge Block", + "Steel Cylinder", + "Steel Cylinder Horizontal", + "Steel Sphere", + "Steel Element Straight", + "Steel Element Edge", + "Steel Element T", + "Steel Element Cross", + "Steel Element End") + +-- REGISTER MATERIALS AND PROPERTIES FOR STICKS: +------------------------------------------------ + +-- WOOD +------- +technic_cnc_api.register_stick_etc("default:wood", + {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + {"default_wood.png"}, + "Wooden Stick") +-- STONE +-------- +technic_cnc_api.register_stick_etc("default:stone", + {cracky=3,not_in_creative_inventory=1}, + {"default_stone.png"}, + "Stone Stick") +-- COBBLE +--------- +technic_cnc_api.register_stick_etc("default:cobble", + {cracky=3,not_in_creative_inventory=1}, + {"default_cobble.png"}, + "Cobble Stick") +-- BRICK +-------- +technic_cnc_api.register_stick_etc("default:brick", + {cracky=3,not_in_creative_inventory=1}, + {"default_brick.png"}, + "Brick Stick") +-- SANDSTONE +------------ +technic_cnc_api.register_stick_etc("default:sandstone", + {crumbly=2,cracky=2,not_in_creative_inventory=1}, + {"default_sandstone.png"}, + "Sandstone Stick") +-- LEAVES +--------- +technic_cnc_api.register_stick_etc("default:leaves", + {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, + {"bucharest_tree.png"}, + "Leaves Stick") +-- TREE +------- +technic_cnc_api.register_stick_etc("default:tree", + {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1,not_in_creative_inventory=1}, + {"default_tree.png"}, + "Tree Stick") +-- STEEL +-------- +technic_cnc_api.register_stick_etc("default:steelblock", + {snappy=1,bendy=2,cracky=1,melty=2,level=2,not_in_creative_inventory=1}, + {"default_steel_block.png"}, + "Steel Stick") + +-- REGISTER MATERIALS AND PROPERTIES FOR HALF AND NORMAL HEIGHT ELEMENTS: +------------------------------------------------------------------------- + +-- WOOD +------- +technic_cnc_api.register_elements("default:wood", + {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + {"default_wood.png"}, + "Wooden Element Straight Double", + "Wooden Element Edge Double", + "Wooden Element T Double", + "Wooden Element Cross Double", + "Wooden Element End Double") +-- STONE +-------- +technic_cnc_api.register_elements("default:stone", + {cracky=3,not_in_creative_inventory=1}, + {"default_stone.png"}, + "Stone Element Straight Double", + "Stone Element Edge Double", + "Stone Element T Double", + "Stone Element Cross Double", + "Stone Element End Double") +-- COBBLE +--------- +technic_cnc_api.register_elements("default:cobble", + {cracky=3,not_in_creative_inventory=1}, + {"default_cobble.png"}, + "Cobble Element Straight Double", + "Cobble Element Edge Double", + "Cobble Element T Double", + "Cobble Element Cross Double", + "Cobble Element End Double") +-- BRICK +-------- +technic_cnc_api.register_elements("default:brick", + {cracky=3,not_in_creative_inventory=1}, + {"default_brick.png"}, + "Brick Element Straight Double", + "Brick Element Edge Double", + "Brick Element T Double", + "Brick Element Cross Double", + "Brick Element End Double") +-- SANDSTONE +------------ +technic_cnc_api.register_elements("default:sandstone", + {crumbly=2,cracky=2,not_in_creative_inventory=1}, + {"default_sandstone.png"}, + "Sandstone Element Straight Double", + "Sandstone Element Edge Double", + "Sandstone Element T Double", + "Sandstone Element Cross Double", + "Sandstone Element End Double") +-- LEAVES +--------- +technic_cnc_api.register_elements("default:leaves", + {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, + {"bucharest_tree.png"}, + "Leaves Element Straight Double", + "Leaves Element Edge Double", + "Leaves Element T Double", + "Leaves Element Cross Double", + "Leaves Element End Double") +-- TREE +------- +technic_cnc_api.register_elements("default:tree", + {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1,not_in_creative_inventory=1}, + {"default_tree.png"}, + "Tree Element Straight Double", + "Tree Element Edge Double", + "Tree Element T Double", + "Tree Element Cross Double", + "Tree Element End Double") +-- STEEL +-------- +technic_cnc_api.register_elements("default:steel", + {snappy=1,bendy=2,cracky=1,melty=2,level=2,not_in_creative_inventory=1}, + {"default_steel_block.png"}, + "Steel Element Straight Double", + "Steel Element Edge Double", + "Steel Element T Double", + "Steel Element Cross Double", + "Steel Element End Double") diff --git a/technic/init.lua b/technic/init.lua index 58e0488..ff904e2 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -2,6 +2,8 @@ -- namespace: technic -- (c) 2012-2013 by RealBadAngel +technic = {} + modpath=minetest.get_modpath("technic") --Read technic config file @@ -25,6 +27,9 @@ dofile(modpath.."/tool_workshop.lua") dofile(modpath.."/music_player.lua") dofile(modpath.."/generator.lua") dofile(modpath.."/grinder.lua") +dofile(modpath.."/cnc.lua") +dofile(modpath.."/cnc_api.lua") +dofile(modpath.."/cnc_nodes.lua") --MV machines dofile(modpath.."/wires_mv.lua") @@ -34,10 +39,13 @@ dofile(modpath.."/electric_furnace_mv.lua") dofile(modpath.."/alloy_furnace_mv.lua") dofile(modpath.."/forcefield.lua") +--HV machines +dofile(modpath.."/wires_hv.lua") + --Tools -if enable_mining_drill==true then dofile(modpath.."/mining_drill.lua") end -if enable_mining_laser==true then dofile(modpath.."/mining_laser_mk1.lua") end -if enable_flashlight==true then dofile(modpath.."/flashlight.lua") end +if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end +if technic.config:getBool("enable_mining_laser") then dofile(modpath.."/mining_laser_mk1.lua") end +if technic.config:getBool("enable_flashlight") then dofile(modpath.."/flashlight.lua") end dofile(modpath.."/cans.lua") dofile(modpath.."/chainsaw.lua") dofile(modpath.."/tree_tap.lua") diff --git a/technic/textures/technic_cnc_bottom.png b/technic/textures/technic_cnc_bottom.png new file mode 100644 index 0000000..e600cb1 Binary files /dev/null and b/technic/textures/technic_cnc_bottom.png differ diff --git a/technic/textures/technic_cnc_cylinder.png b/technic/textures/technic_cnc_cylinder.png new file mode 100644 index 0000000..06da024 Binary files /dev/null and b/technic/textures/technic_cnc_cylinder.png differ diff --git a/technic/textures/technic_cnc_cylinder_horizontal.png b/technic/textures/technic_cnc_cylinder_horizontal.png new file mode 100644 index 0000000..670ecf2 Binary files /dev/null and b/technic/textures/technic_cnc_cylinder_horizontal.png differ diff --git a/technic/textures/technic_cnc_element_cross.png b/technic/textures/technic_cnc_element_cross.png new file mode 100644 index 0000000..f2ad0b7 Binary files /dev/null and b/technic/textures/technic_cnc_element_cross.png differ diff --git a/technic/textures/technic_cnc_element_edge.png b/technic/textures/technic_cnc_element_edge.png new file mode 100644 index 0000000..e6104cf Binary files /dev/null and b/technic/textures/technic_cnc_element_edge.png differ diff --git a/technic/textures/technic_cnc_element_end.png b/technic/textures/technic_cnc_element_end.png new file mode 100644 index 0000000..6bc6837 Binary files /dev/null and b/technic/textures/technic_cnc_element_end.png differ diff --git a/technic/textures/technic_cnc_element_straight.png b/technic/textures/technic_cnc_element_straight.png new file mode 100644 index 0000000..1648b7b Binary files /dev/null and b/technic/textures/technic_cnc_element_straight.png differ diff --git a/technic/textures/technic_cnc_element_t.png b/technic/textures/technic_cnc_element_t.png new file mode 100644 index 0000000..0d49cd8 Binary files /dev/null and b/technic/textures/technic_cnc_element_t.png differ diff --git a/technic/textures/technic_cnc_front.png b/technic/textures/technic_cnc_front.png new file mode 100644 index 0000000..6cc0490 Binary files /dev/null and b/technic/textures/technic_cnc_front.png differ diff --git a/technic/textures/technic_cnc_full.png b/technic/textures/technic_cnc_full.png new file mode 100644 index 0000000..d551a45 Binary files /dev/null and b/technic/textures/technic_cnc_full.png differ diff --git a/technic/textures/technic_cnc_half.png b/technic/textures/technic_cnc_half.png new file mode 100644 index 0000000..51ebcd7 Binary files /dev/null and b/technic/textures/technic_cnc_half.png differ diff --git a/technic/textures/technic_cnc_milling_background.png b/technic/textures/technic_cnc_milling_background.png new file mode 100644 index 0000000..6a9c2f4 Binary files /dev/null and b/technic/textures/technic_cnc_milling_background.png differ diff --git a/technic/textures/technic_cnc_onecurvededge.png b/technic/textures/technic_cnc_onecurvededge.png new file mode 100644 index 0000000..46779fd Binary files /dev/null and b/technic/textures/technic_cnc_onecurvededge.png differ diff --git a/technic/textures/technic_cnc_pyramid.png b/technic/textures/technic_cnc_pyramid.png new file mode 100644 index 0000000..5dc3322 Binary files /dev/null and b/technic/textures/technic_cnc_pyramid.png differ diff --git a/technic/textures/technic_cnc_side.png b/technic/textures/technic_cnc_side.png new file mode 100644 index 0000000..1ecbbac Binary files /dev/null and b/technic/textures/technic_cnc_side.png differ diff --git a/technic/textures/technic_cnc_slope.png b/technic/textures/technic_cnc_slope.png new file mode 100644 index 0000000..083ae18 Binary files /dev/null and b/technic/textures/technic_cnc_slope.png differ diff --git a/technic/textures/technic_cnc_slope_edge.png b/technic/textures/technic_cnc_slope_edge.png new file mode 100644 index 0000000..785adf6 Binary files /dev/null and b/technic/textures/technic_cnc_slope_edge.png differ diff --git a/technic/textures/technic_cnc_slope_edge_upsdwn.png b/technic/textures/technic_cnc_slope_edge_upsdwn.png new file mode 100644 index 0000000..5adb788 Binary files /dev/null and b/technic/textures/technic_cnc_slope_edge_upsdwn.png differ diff --git a/technic/textures/technic_cnc_slope_inner_edge.png b/technic/textures/technic_cnc_slope_inner_edge.png new file mode 100644 index 0000000..906dd25 Binary files /dev/null and b/technic/textures/technic_cnc_slope_inner_edge.png differ diff --git a/technic/textures/technic_cnc_slope_inner_edge_upsdwn.png b/technic/textures/technic_cnc_slope_inner_edge_upsdwn.png new file mode 100644 index 0000000..0ae0e14 Binary files /dev/null and b/technic/textures/technic_cnc_slope_inner_edge_upsdwn.png differ diff --git a/technic/textures/technic_cnc_slope_lying.png b/technic/textures/technic_cnc_slope_lying.png new file mode 100644 index 0000000..377769a Binary files /dev/null and b/technic/textures/technic_cnc_slope_lying.png differ diff --git a/technic/textures/technic_cnc_slope_upsdwn.png b/technic/textures/technic_cnc_slope_upsdwn.png new file mode 100644 index 0000000..b802b60 Binary files /dev/null and b/technic/textures/technic_cnc_slope_upsdwn.png differ diff --git a/technic/textures/technic_cnc_sphere.png b/technic/textures/technic_cnc_sphere.png new file mode 100644 index 0000000..69ada47 Binary files /dev/null and b/technic/textures/technic_cnc_sphere.png differ diff --git a/technic/textures/technic_cnc_spike.png b/technic/textures/technic_cnc_spike.png new file mode 100644 index 0000000..92e6e58 Binary files /dev/null and b/technic/textures/technic_cnc_spike.png differ diff --git a/technic/textures/technic_cnc_stick.png b/technic/textures/technic_cnc_stick.png new file mode 100644 index 0000000..8dfe408 Binary files /dev/null and b/technic/textures/technic_cnc_stick.png differ diff --git a/technic/textures/technic_cnc_top.png b/technic/textures/technic_cnc_top.png new file mode 100644 index 0000000..5123334 Binary files /dev/null and b/technic/textures/technic_cnc_top.png differ diff --git a/technic/textures/technic_cnc_twocurvededge.png b/technic/textures/technic_cnc_twocurvededge.png new file mode 100644 index 0000000..3219a90 Binary files /dev/null and b/technic/textures/technic_cnc_twocurvededge.png differ -- cgit v1.2.3 From c1df318e855beb4a23f134820c81a071ffec2b03 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Mon, 6 May 2013 23:14:27 +0200 Subject: Fixes to te machine level of service. --- technic/cnc.lua | 350 +++++++++++++++++++++++++++++++++------------------- technic/cnc_api.lua | 14 +-- 2 files changed, 228 insertions(+), 136 deletions(-) diff --git a/technic/cnc.lua b/technic/cnc.lua index 6e763ef..71b78b0 100644 --- a/technic/cnc.lua +++ b/technic/cnc.lua @@ -1,40 +1,94 @@ -- Technic CNC v1.0 by kpo -- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck local shape = {} -local size = 0 local onesize_products = { - slope = 2, - slope_edge = 1, - slope_inner_edge = 1, - pyramid = 2, - spike = 1, - cylinder = 2, - sphere = 1, - stick = 8, - slope_upsdwn = 2, - slope_edge_upsdwn = 1, - slope_inner_edge_upsdwn = 1, - cylinder_hor = 2, - slope_lying = 2, - onecurvededge = 1, - twocurvededge = 1, + slope = 2, + slope_edge = 1, + slope_inner_edge = 1, + pyramid = 2, + spike = 1, + cylinder = 2, + sphere = 1, + stick = 8, + slope_upsdown = 2, + slope_edge_upsdown = 1, + slope_inner_edge_upsdown = 1, + cylinder_horizontal = 2, + slope_lying = 2, + onecurvededge = 1, + twocurvededge = 1, } local twosize_products = { - element_straight = 4, - element_end = 2, - element_cross = 1, - element_t = 1, - element_edge = 2, + element_straight = 4, + element_end = 2, + element_cross = 1, + element_t = 1, + element_edge = 2, } -local showbackground = "--" -local max_cncruns = 99 -local max_products = 99 +--cnc_recipes ={} +--registered_cnc_recipes_count=1 +-- +--function register_cnc_recipe (string1,string2) +-- cnc_recipes[registered_cnc_recipes_count]={} +-- cnc_recipes[registered_cnc_recipes_count].src_name=string1 +-- cnc_recipes[registered_cnc_recipes_count].dst_name=string2 +-- registered_cnc_recipes_count=registered_cnc_recipes_count+1 +-- if unified_inventory then +-- unified_inventory.register_craft({ +-- type = "cnc milling", +-- output = string2, +-- items = {string1}, +-- width = 0, +-- }) +-- end +--end ---showlabelin = "" ---showlabelout = "label[4.5,5.5;Out:]" +local cnc_formspec = + "invsize[9,11;]".. + "label[1,0;Choose Milling Program:]".. + "image_button[1,0.5;1,1;technic_cnc_slope.png;slope; ]".. + "image_button[2,0.5;1,1;technic_cnc_slope_edge.png;slope_edge; ]".. + "image_button[3,0.5;1,1;technic_cnc_slope_inner_edge.png;slope_inner_edge; ]".. + "image_button[4,0.5;1,1;technic_cnc_pyramid.png;pyramid; ]".. + "image_button[5,0.5;1,1;technic_cnc_spike.png;spike; ]".. + "image_button[6,0.5;1,1;technic_cnc_cylinder.png;cylinder; ]".. + "image_button[7,0.5;1,1;technic_cnc_sphere.png;sphere; ]".. + "image_button[8,0.5;1,1;technic_cnc_stick.png;stick; ]".. + + "image_button[1,1.5;1,1;technic_cnc_slope_upsdwn.png;slope_upsdown; ]".. + "image_button[2,1.5;1,1;technic_cnc_slope_edge_upsdwn.png;slope_edge_upsdown; ]".. + "image_button[3,1.5;1,1;technic_cnc_slope_inner_edge_upsdwn.png;slope_inner_edge_upsdown; ]".. + "image_button[4,1.5;1,1;technic_cnc_cylinder_horizontal.png;cylinder_horizontal; ]".. + + "image_button[1,2.5;1,1;technic_cnc_slope_lying.png;slope_lying; ]".. + "image_button[2,2.5;1,1;technic_cnc_onecurvededge.png;onecurvededge; ]".. + "image_button[3,2.5;1,1;technic_cnc_twocurvededge.png;twocurvededge; ]".. + + "label[1,3.5;Slim Elements half / normal height:]".. + + "image_button[1,4;1,0.5;technic_cnc_full.png;full; ]".. + "image_button[1,4.5;1,0.5;technic_cnc_half.png;half; ]".. + "image_button[2,4;1,1;technic_cnc_element_straight.png;element_straight; ]".. + "image_button[3,4;1,1;technic_cnc_element_end.png;element_end; ]".. + "image_button[4,4;1,1;technic_cnc_element_cross.png;element_cross; ]".. + "image_button[5,4;1,1;technic_cnc_element_t.png;element_t; ]".. + "image_button[6,4;1,1;technic_cnc_element_edge.png;element_edge; ]".. + + "label[0, 5.5;In:]".. + "list[current_name;src;0.5,5.5;1,1;]".. + "label[4, 5.5;Out:]".. + "list[current_name;dst;5,5.5;4,1;]".. + + "list[current_player;main;0,7;8,4;]" + + +local cnc_power_formspec= + "label[0,3;Power]".. + "image[0,1;1,2;technic_power_meter_bg.png]" + +local size = 1; --- I want the CNC machine to be a two block thing minetest.register_node("technic:cnc", { description = "CNC Milling Machine", tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png", @@ -53,72 +107,44 @@ minetest.register_node("technic:cnc", { type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, }, - groups = {oddly_breakable_by_hand=2, cracky=3, dig_immediate=1}, + groups = {cracky=2}, + legacy_facedir_simple = true, + technic_power_machine=1, + internal_EU_buffer=0; + internal_EU_buffer_size=5000; + cnc_time = 0; + src_time = 0; -- fixme + + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "CNC machine") + meta:set_float("technic_power_machine", 1) + meta:set_float("internal_EU_buffer", 0) + meta:set_float("internal_EU_buffer_size", 5000) + meta:set_string("formspec", cnc_formspec..cnc_power_formspec) + meta:set_float("cnc_time", 0) + + local inv = meta:get_inventory() + inv:set_size("src", 1) + inv:set_size("dst", 4) + + meta:set_string("formspec", cnc_formspec) + meta:set_string("infotext", "CNC Milling Machine") + end, can_dig = function(pos,player) local meta = minetest.env:get_meta(pos); local inv = meta:get_inventory() - if not inv:is_empty("input") or not inv:is_empty("output") then + if not inv:is_empty("src") or not inv:is_empty("dst") then minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty"); return false end return true end, - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - if technic_cnc_api.allow_menu_background == true or technic_cnc_api.allow_menu_background == 1 then - showbackground = "background[-0.15,-0.25;8.40,11.75;technic_cnc_background.png]" - end - - meta:set_string("formspec", "invsize[8,11;]".. - "label[0,0;Choose Milling Program:]".. - "image_button[0,0.5;1,1;technic_cnc_slope.png;slope; ]".. - "image_button[1,0.5;1,1;technic_cnc_slope_edge.png;slope_edge; ]".. - "image_button[2,0.5;1,1;technic_cnc_slope_inner_edge.png;slope_inner_edge; ]".. - "image_button[3,0.5;1,1;technic_cnc_pyramid.png;pyramid; ]".. - "image_button[4,0.5;1,1;technic_cnc_spike.png;spike; ]".. - "image_button[5,0.5;1,1;technic_cnc_cylinder.png;cylinder; ]".. - "image_button[6,0.5;1,1;technic_cnc_sphere.png;sphere; ]".. - "image_button[7,0.5;1,1;technic_cnc_stick.png;stick; ]".. - - "image_button[0,1.5;1,1;technic_cnc_slope_upsdwn.png;slope_upsdwn; ]".. - "image_button[1,1.5;1,1;technic_cnc_slope_edge_upsdwn.png;slope_upsdwn_edge; ]".. - "image_button[2,1.5;1,1;technic_cnc_slope_inner_edge_upsdwn.png;slope_upddown_inner_edge; ]".. - "image_button[5,1.5;1,1;technic_cnc_cylinder_horizontal.png;cylinder_horizontal; ]".. - - "image_button[0,2.5;1,1;technic_cnc_slope_lying.png;slope_lying; ]".. - "image_button[1,2.5;1,1;technic_cnc_onecurvededge.png;onecurvededge; ]".. - "image_button[2,2.5;1,1;technic_cnc_twocurvededge.png;twocurvededge; ]".. - - "label[0,3.5;Slim Elements half / normal height:]".. - - "image_button[0,4;1,0.5;technic_cnc_full.png;full; ]".. - "image_button[0,4.5;1,0.5;technic_cnc_half.png;half; ]".. - "image_button[1,4;1,1;technic_cnc_element_straight.png;element_straight; ]".. - "image_button[2,4;1,1;technic_cnc_element_end.png;element_end; ]".. - "image_button[3,4;1,1;technic_cnc_element_cross.png;element_cross; ]".. - "image_button[4,4;1,1;technic_cnc_element_t.png;element_t; ]".. - "image_button[5,4;1,1;technic_cnc_element_edge.png;element_edge; ]".. - - "label[0, 5.5;In:]".. -- showlabelin.. - "list[current_name;input;0.5,5.5;1,1;]".. - "field[3, 6;1,1;num_cncruns;Repeat program:;${num_cncruns}]".. -- Fill default with meta data num_cncruns - "label[4, 5.5;Out:]".. -- showlabelout.. - "list[current_name;output;4.5,5.5;1,1;]".. - - "list[current_player;main;0,7;8,4;]".. - showbackground) - meta:set_string("infotext", "CNC Milling Machine") - meta:set_string("num_cncruns", 1 ); - local inv = meta:get_inventory() - inv:set_size("input", 1) - inv:set_size("output", 1) - end, - on_receive_fields = function(pos, formname, fields, sender) - -- REGISTER MILLING PROGRAMMS AND OUTPUTS: + -- REGISTER MILLING PROGRAMS AND OUTPUTS: ------------------------------------------ -- Program for half/full size if fields["full"] then @@ -131,32 +157,12 @@ minetest.register_node("technic:cnc", { return end - local meta = minetest.env:get_meta(pos) - local inv = meta:get_inventory() - - -- Limit the number entered - if( fields.num_cncruns and tonumber( fields.num_cncruns) > 0 and tonumber(fields.num_cncruns) < 100 ) then - meta:set_string( "num_cncruns", fields.num_cncruns ); - else - minetest.chat_send_player(sender:get_player_name(), "CNC machine runs set to a bad value. Machine resets."); - meta:set_string( "num_cncruns", 1 ); - fields.num_cncruns = 1 - end - - -- Do nothing if the machine is empty - if inv:is_empty("input") then - return - end - - -- Do nothing if the output is not empty and the product used is not the same as what is already there - - -- Resolve the node name and the number of items to make and the number of items to take - local product = "" - local produces = 1 - local input_used = 1 - local inputstack = inv:get_stack("input", 1) + -- Resolve the node name and the number of items to make + local meta = minetest.env:get_meta(pos) + local inv = meta:get_inventory() + local inputstack = inv:get_stack("src", 1) local inputname = inputstack:get_name() - local multiplier = 1 + local multiplier = 0 for k, _ in pairs(fields) do -- Set a multipier for the half/full size capable blocks if twosize_products[k] ~= nil then @@ -164,38 +170,124 @@ minetest.register_node("technic:cnc", { else multiplier = onesize_products[k] end - + if onesize_products[k] ~= nil or twosize_products[k] ~= nil then - product = inputname .. "_technic_cnc_" .. k - produces = math.min( fields.num_cncruns*multiplier, max_products) -- produce at most max_products - input_used = math.min( math.floor(produces/multiplier), inputstack:get_count()) -- use at most what we got - produces = input_used*multiplier -- final production - print(size) - print(fields.num_cncruns) - print(product) - print(produces) - print(input_used) - print("------------------") + meta:set_float( "cnc_multiplier", multiplier) + meta:set_string("cnc_user", sender:get_player_name()) + end + + if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then + meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k) break end - end - -- CNC does the transformation - ------------------------------ - if minetest.registered_nodes[product] ~= nil then - inv:add_item("output",product .. " " .. produces) - inputstack:take_item(input_used) - inv:set_stack("input",1,inputstack) - else - minetest.chat_send_player(sender:get_player_name(), "CNC machine does not know how to mill this material. Please remove it."); + if twosize_products[k] ~= nil and size==1 then + meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double") + break + end end - return; + return end, -- callback function }) ----------- +minetest.register_node("technic:cnc_active", { + description = "CNC Machine", + tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png", + "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"}, + paramtype2 = "facedir", + groups = {cracky=2,not_in_creative_inventory=1}, + legacy_facedir_simple = true, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty"); + return false + end + return true + end, +}) + +minetest.register_abm( + { + nodenames = {"technic:cnc","technic:cnc_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local charge= meta:get_float("internal_EU_buffer") + local max_charge= meta:get_float("internal_EU_buffer_size") + local cnc_cost=350 + + local load = math.floor((charge/max_charge)*100) + meta:set_string("formspec", cnc_formspec.. + "image[0,1;1,2;technic_power_meter_bg.png^[lowpart:".. + (load)..":technic_power_meter_fg.png]" + ) + + local inv = meta:get_inventory() + local srclist = inv:get_list("src") + if inv:is_empty("src") then + meta:set_float("cnc_on",0) + meta:set_string("cnc_product", "") -- Reset the program + end + + if (meta:get_float("cnc_on") == 1) then + if charge>=cnc_cost then + charge=charge-cnc_cost; + meta:set_float("internal_EU_buffer",charge) + meta:set_float("src_time", meta:get_float("src_time") + 1) + if meta:get_float("src_time") >= meta:get_float("cnc_time") then + local product = meta:get_string("cnc_product") + if inv:room_for_item("dst",product) then + -- CNC does the transformation + ------------------------------ + if minetest.registered_nodes[product] ~= nil then + inv:add_item("dst",product .. " " .. meta:get_float("cnc_multiplier")) + srcstack = inv:get_stack("src", 1) + srcstack:take_item() + inv:set_stack("src",1,srcstack) + if inv:is_empty("src") then + meta:set_float("cnc_on",0) + meta:set_string("cnc_product", "") -- Reset the program +-- print("cnc product reset") + end + else + minetest.chat_send_player(meta:get_string("cnc_user"), "CNC machine does not know how to handle this material. Please remove it."); + end + else + minetest.chat_send_player(meta:get_string("cnc_user"), "CNC inventory full!") + end + meta:set_float("src_time", 0) + end + end + end + + if (meta:get_float("cnc_on")==0) then + if not inv:is_empty("src") then + local product = meta:get_string("cnc_product") + if minetest.registered_nodes[product] ~= nil then + meta:set_float("cnc_on",1) + hacky_swap_node(pos,"technic:cnc_active") + meta:set_string("infotext", "CNC Machine Active") + cnc_time=3 + meta:set_float("cnc_time",cnc_time) + meta:set_float("src_time", 0) + return + end + else + hacky_swap_node(pos,"technic:cnc") + meta:set_string("infotext", "CNC Machine Inactive") + end + end + end + }) + +register_LV_machine ("technic:cnc","RE") +register_LV_machine ("technic:cnc_active","RE") +------------------------- --- Milling Machine Recipe +-- CNC Machine Recipe ------------------------- minetest.register_craft({ output = 'technic:cnc', diff --git a/technic/cnc_api.lua b/technic/cnc_api.lua index 390a996..2d5dcfe 100644 --- a/technic/cnc_api.lua +++ b/technic/cnc_api.lua @@ -212,7 +212,7 @@ end -- SLOPE EDGE UPSIDE DOWN ------------------------- -function technic_cnc_api.register_slope_upsdown_edge(recipeitem, groups, images, description) +function technic_cnc_api.register_slope_edge_upsdown(recipeitem, groups, images, description) if recipeitem == "default:dirt" then return @@ -223,7 +223,7 @@ local detail = technic_cnc_api.detail_level for i = 0, detail-1 do slopeupdwnboxedge[i+1]={(-1*(i/detail))+0.5-(1/detail), (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5} end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_upsdown_edge", { +minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_edge_upsdown", { description = description, drawtype = "nodebox", tiles = images, @@ -245,13 +245,13 @@ end -- SLOPE INNER EDGE UPSIDE DOWN ------------------------------- -function technic_cnc_api.register_slope_upsdown_inner_edge(recipeitem, groups, images, description) +function technic_cnc_api.register_slope_inner_edge_upsdown(recipeitem, groups, images, description) if recipename == "default:dirt" then return end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_upsdown_inner_edge", { +minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_inner_edge_upsdown", { description = description, drawtype = "nodebox", tiles = images, @@ -548,7 +548,7 @@ for i = 1, detail-1 do sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) spherebox[i]={-sehne, (i/detail)-0.5, -sehne, sehne, (i/detail)+(1/detail)-0.5, sehne} end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_cylinder_sphere", { +minetest.register_node(":" .. recipeitem .. "_technic_cnc_sphere", { description = description, drawtype = "nodebox", tiles = images, @@ -939,8 +939,8 @@ function technic_cnc_api.register_slope_edge_etc(recipeitem, groups, images, des technic_cnc_api.register_slope_upsdown(recipeitem, groups, images, desc_slope_upsdown) technic_cnc_api.register_slope_edge(recipeitem, groups, images, desc_slope_edge) technic_cnc_api.register_slope_inner_edge(recipeitem, groups, images, desc_slope_inner_edge) - technic_cnc_api.register_slope_upsdown_edge(recipeitem, groups, images, desc_slope_upsdwn_edge) - technic_cnc_api.register_slope_upsdown_inner_edge(recipeitem, groups, images, desc_slope_upsdwn_inner_edge) + technic_cnc_api.register_slope_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_edge) + technic_cnc_api.register_slope_inner_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_inner_edge) technic_cnc_api.register_pyramid(recipeitem, groups, images, desc_pyramid) technic_cnc_api.register_spike(recipeitem, groups, images, desc_spike) technic_cnc_api.register_onecurvededge(recipeitem, groups, images, desc_onecurvededge) -- cgit v1.2.3 From 7f2be244f2f7f2497cba33ba1e2bd5a599f23bfb Mon Sep 17 00:00:00 2001 From: kpoppel Date: Tue, 7 May 2013 22:34:06 +0200 Subject: Add textures for active mode of CNC. Correct two typing bug in battery_box.lua --- technic/textures/technic_cnc_front_active.png | Bin 0 -> 2216 bytes technic/textures/technic_cnc_top_active.png | Bin 0 -> 2214 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 technic/textures/technic_cnc_front_active.png create mode 100644 technic/textures/technic_cnc_top_active.png diff --git a/technic/textures/technic_cnc_front_active.png b/technic/textures/technic_cnc_front_active.png new file mode 100644 index 0000000..f7a3c7f Binary files /dev/null and b/technic/textures/technic_cnc_front_active.png differ diff --git a/technic/textures/technic_cnc_top_active.png b/technic/textures/technic_cnc_top_active.png new file mode 100644 index 0000000..2bc9d81 Binary files /dev/null and b/technic/textures/technic_cnc_top_active.png differ -- cgit v1.2.3 From fef948c5ac919082fa30d441ec62d6d1d0d2c98b Mon Sep 17 00:00:00 2001 From: kpoppel Date: Tue, 7 May 2013 22:51:03 +0200 Subject: CNC can now change programs while it is working. --- technic/battery_box.lua | 4 +- technic/cnc.lua | 116 ++++++++++++++++++++++++++---------------------- 2 files changed, 66 insertions(+), 54 deletions(-) diff --git a/technic/battery_box.lua b/technic/battery_box.lua index 0e08d74..9c91821 100644 --- a/technic/battery_box.lua +++ b/technic/battery_box.lua @@ -218,7 +218,7 @@ minetest.register_abm({ end end --- dischargin registered power tools +-- discharging registered power tools if inv:is_empty("dst") == false then srcstack = inv:get_stack("dst", 1) src_item=srcstack:to_table() @@ -297,7 +297,7 @@ table_index=1 local pos1={} i=1 repeat - if PR_nodes[i]==nil then break end -- gettin power from all connected producers + if PR_nodes[i]==nil then break end -- getting power from all connected producers pos1.x=PR_nodes[i].x pos1.y=PR_nodes[i].y pos1.z=PR_nodes[i].z diff --git a/technic/cnc.lua b/technic/cnc.lua index 71b78b0..4976502 100644 --- a/technic/cnc.lua +++ b/technic/cnc.lua @@ -1,5 +1,11 @@ -- Technic CNC v1.0 by kpo -- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck + +-- Idea: +-- Somehw have a tabbed/paged panel if the number of shapes should expand +-- beyond what is available in the panel today. +-- I could imagine some form of API allowing modders to come with their own node +-- box definitions and easily stuff it in the this machine for production. local shape = {} local onesize_products = { slope = 2, @@ -89,6 +95,57 @@ local cnc_power_formspec= local size = 1; +-- The form handler is declared here because we need it in both the inactive and active modes +-- in order to be able to change programs wile it is running. +local form_handler = function(pos, formname, fields, sender) + -- REGISTER MILLING PROGRAMS AND OUTPUTS: + ------------------------------------------ + -- Program for half/full size + if fields["full"] then + size = 1 + return + end + + if fields["half"] then + size = 2 + return + end + + -- Resolve the node name and the number of items to make + local meta = minetest.env:get_meta(pos) + local inv = meta:get_inventory() + local inputstack = inv:get_stack("src", 1) + local inputname = inputstack:get_name() + local multiplier = 0 + for k, _ in pairs(fields) do + -- Set a multipier for the half/full size capable blocks + if twosize_products[k] ~= nil then + multiplier = size*twosize_products[k] + else + multiplier = onesize_products[k] + end + + if onesize_products[k] ~= nil or twosize_products[k] ~= nil then + meta:set_float( "cnc_multiplier", multiplier) + meta:set_string("cnc_user", sender:get_player_name()) + end + + if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then + meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k) + print(inputname .. "_technic_cnc_" .. k) + break + end + + if twosize_products[k] ~= nil and size==1 then + meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double") + print(inputname .. "_technic_cnc_" .. k .. "_double") + break + end + end + return + end -- callback function + +-- The actual block inactive state minetest.register_node("technic:cnc", { description = "CNC Milling Machine", tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png", @@ -117,7 +174,7 @@ minetest.register_node("technic:cnc", { on_construct = function(pos) local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "CNC machine") + meta:set_string("infotext", "CNC Machine Inactive") meta:set_float("technic_power_machine", 1) meta:set_float("internal_EU_buffer", 0) meta:set_float("internal_EU_buffer_size", 5000) @@ -127,9 +184,6 @@ minetest.register_node("technic:cnc", { local inv = meta:get_inventory() inv:set_size("src", 1) inv:set_size("dst", 4) - - meta:set_string("formspec", cnc_formspec) - meta:set_string("infotext", "CNC Milling Machine") end, can_dig = function(pos,player) @@ -142,58 +196,14 @@ minetest.register_node("technic:cnc", { return true end, - - on_receive_fields = function(pos, formname, fields, sender) - -- REGISTER MILLING PROGRAMS AND OUTPUTS: - ------------------------------------------ - -- Program for half/full size - if fields["full"] then - size = 1 - return - end - - if fields["half"] then - size = 2 - return - end - - -- Resolve the node name and the number of items to make - local meta = minetest.env:get_meta(pos) - local inv = meta:get_inventory() - local inputstack = inv:get_stack("src", 1) - local inputname = inputstack:get_name() - local multiplier = 0 - for k, _ in pairs(fields) do - -- Set a multipier for the half/full size capable blocks - if twosize_products[k] ~= nil then - multiplier = size*twosize_products[k] - else - multiplier = onesize_products[k] - end - - if onesize_products[k] ~= nil or twosize_products[k] ~= nil then - meta:set_float( "cnc_multiplier", multiplier) - meta:set_string("cnc_user", sender:get_player_name()) - end - - if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then - meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k) - break - end - - if twosize_products[k] ~= nil and size==1 then - meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double") - break - end - end - return - end, -- callback function + on_receive_fields = form_handler, }) +-- Active state block minetest.register_node("technic:cnc_active", { description = "CNC Machine", - tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png", - "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"}, + tiles = {"technic_cnc_top_active.png", "technic_cnc_bottom.png", "technic_cnc_side.png", + "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"}, paramtype2 = "facedir", groups = {cracky=2,not_in_creative_inventory=1}, legacy_facedir_simple = true, @@ -206,8 +216,10 @@ minetest.register_node("technic:cnc_active", { end return true end, + on_receive_fields = form_handler, }) +-- Action code performing the transformation minetest.register_abm( { nodenames = {"technic:cnc","technic:cnc_active"}, -- cgit v1.2.3 From 5940f5bda421add111a881b4df82b793121738a9 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Wed, 8 May 2013 00:06:54 +0200 Subject: Slope box fixes. From Bas080. --- technic/cnc_api.lua | 109 ++++++++-------------------------------------------- 1 file changed, 16 insertions(+), 93 deletions(-) diff --git a/technic/cnc_api.lua b/technic/cnc_api.lua index 2d5dcfe..aecfadb 100644 --- a/technic/cnc_api.lua +++ b/technic/cnc_api.lua @@ -6,10 +6,6 @@ technic_cnc_api = {} ---------------------------------------- technic_cnc_api.detail_level = 16 -- 16; 1-32 --- HERE YOU CAN DE/ACTIVATE BACKGROUND FOR CNC MENU: --------------------------------------------------------- -technic_cnc_api.allow_menu_background = false - -- REGISTER NONCUBIC FORMS, CREATE MODELS AND RECIPES: ------------------------------------------------------ @@ -146,6 +142,12 @@ end -- SLOPE INNER EDGE ------------------- function technic_cnc_api.register_slope_inner_edge(recipeitem, groups, images, description) + local slopeboxedge = {} + local detail = technic_cnc_api.detail_level + for i = 0, detail-1 do + slopeboxedge[i+1]={(i/detail)-0.5, -0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} + slopeboxedge[i+detail+1]={-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} + end minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_inner_edge", { description = description, @@ -159,51 +161,8 @@ minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_inner_edge", { fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, }, node_box = { - type = "fixed", - fixed = { - -- PART 1 - {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5}, - {-0.45, -0.5, -0.5, 0.5, -0.4, 0.5}, - {-0.4, -0.5, -0.5, 0.5, -0.35, 0.5}, - {-0.35, -0.5, -0.5, 0.5, -0.3, 0.5}, - {-0.3, -0.5, -0.5, 0.5, -0.25, 0.5}, - {-0.25, -0.5, -0.5, 0.5, -0.2, 0.5}, - {-0.2, -0.5, -0.5, 0.5, -0.15, 0.5}, - {-0.15, -0.5, -0.5, 0.5, -0.1, 0.5}, - {-0.1, -0.5, -0.5, 0.5, -0.05, 0.5}, - {-0.05, -0.5, -0.5, 0.5, 0, 0.5}, - {0, -0.5, -0.5, 0.5, 0.05, 0.5}, - {0.05, -0.5, -0.5, 0.5, 0.1, 0.5}, - {0.1, -0.5, -0.5, 0.5, 0.15, 0.5}, - {0.15, -0.5, -0.5, 0.5, 0.2, 0.5}, - {0.2, -0.5, -0.5, 0.5, 0.25, 0.5}, - {0.25, -0.5, -0.5, 0.5, 0.3, 0.5}, - {0.3, -0.5, -0.5, 0.5, 0.35, 0.5}, - {0.35, -0.5, -0.5, 0.5, 0.4, 0.5}, - {0.4, -0.5, -0.5, 0.5, 0.45, 0.5}, - {0.45, -0.5, -0.5, 0.5, 0.5, 0.5}, - -- PART 2 - {-0.5, -0.5, -0.45, 0.5, -0.45, 0.5}, - {-0.5, -0.5, -0.4, 0.5, -0.4, 0.5}, - {-0.5, -0.5, -0.35, 0.5, -0.35, 0.5}, - {-0.5, -0.5, -0.3, 0.5, -0.3, 0.5}, - {-0.5, -0.5, -0.25, 0.5, -0.25, 0.5}, - {-0.5, -0.5, -0.2, 0.5, -0.2, 0.5}, - {-0.5, -0.5, -0.15, 0.5, -0.15, 0.5}, - {-0.5, -0.5, -0.1, 0.5, -0.1, 0.5}, - {-0.5, -0.5, -0.05, 0.5, -0.05, 0.5}, - {-0.5, -0.5, 0, 0.5, 0, 0.5}, - {-0.5, -0.5, 0.05, 0.5, 0.05, 0.5}, - {-0.5, -0.5, 0.1, 0.5, 0.1, 0.5}, - {-0.5, -0.5, 0.15, 0.5, 0.15, 0.5}, - {-0.5, -0.5, 0.2, 0.5, 0.2, 0.5}, - {-0.5, -0.5, .25, 0.5, 0.25, 0.5}, - {-0.5, -0.5, 0.3, 0.5, 0.3, 0.5}, - {-0.5, -0.5, 0.35, 0.5, 0.35, 0.5}, - {-0.5, -0.5, 0.4, 0.5, 0.4, 0.5}, - {-0.5, -0.5, 0.45, 0.5, 0.45, 0.5}, - {-0.5, -0.5, 0.5, 0.5, 0.5, 0.5}, - }, + type = "fixed", + fixed = slopeboxedge, }, groups = groups, }) @@ -251,6 +210,13 @@ if recipename == "default:dirt" then return end +local slopeboxedge = {} +local detail = technic_cnc_api.detail_level +for i = 0, detail-1 do + slopeboxedge[i+1]={0.5-(i/detail)-(1/detail), (i/detail)-0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} + slopeboxedge[i+detail+1]={-0.5, (i/detail)-0.5, 0.5-(i/detail)-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5} +end + minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_inner_edge_upsdown", { description = description, drawtype = "nodebox", @@ -264,50 +230,7 @@ minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_inner_edge_upsdo }, node_box = { type = "fixed", - fixed = { - {0.45, -0.5, -0.5, 0.5, -0.45, 0.5}, - {0.4, -0.45, -0.5, 0.5, -0.4, 0.5}, - {0.35, -0.4, -0.5, 0.5, -0.35, 0.5}, - {0.3, -0.35, -0.5, 0.5, -0.3, 0.5}, - {0.25, -0.3, -0.5, 0.5, -0.25, 0.5}, - {0.2, -0.25, -0.5, 0.5, -0.2, 0.5}, - {0.15, -0.2, -0.5, 0.5, -0.15, 0.5}, - {0.1, -0.15, -0.5, 0.5, -0.1, 0.5}, - {0.05, -0.1, -0.5, 0.5, -0.05, 0.5}, - {0, -0.05, -0.5, 0.5, 0, 0.5}, - {-0.05, 0, -0.5, 0.5, 0.05, 0.5}, - {-0.1, 0.05, -0.5, 0.5, 0.1, 0.5}, - {-0.15, 0.1, -0.5, 0.5, 0.15, 0.5}, - {-0.2, 0.15, -0.5, 0.5, 0.2, 0.5}, - {-0.25, 0.2, -0.5, 0.5, 0.25, 0.5}, - {-0.3, 0.25, -0.5, 0.5, 0.3, 0.5}, - {-0.35, 0.3, -0.5, 0.5, 0.35, 0.5}, - {-0.4, 0.35, -0.5, 0.5, 0.4, 0.5}, - {-0.45, 0.4, -0.5, 0.5, 0.45, 0.5}, - {-0.5, 0.45, -0.5, 0.5, 0.5, 0.5}, - - {-0.5, -0.5, 0.45, 0.5, -0.45, 0.5}, - {-0.5, -0.45, 0.4, 0.5, -0.4, 0.5}, - {-0.5, -0.4, 0.35, 0.5, -0.35, 0.5}, - {-0.5, -0.35, 0.3, 0.5, -0.3, 0.5}, - {-0.5, -0.3, 0.25, 0.5, -0.25, 0.5}, - {-0.5, -0.25, 0.2, 0.5, -0.2, 0.5}, - {-0.5, -0.2, 0.15, 0.5, -0.15, 0.5}, - {-0.5, -0.15, 0.1, 0.5, -0.1, 0.5}, - {-0.5, -0.1, 0.05, 0.5, -0.05, 0.5}, - {-0.5, -0.05, 0, 0.5, 0, 0.5}, - {-0.5, 0, -0.05, 0.5, 0.05, 0.5}, - {-0.5, 0.05, -0.1, 0.5, 0.1, 0.5}, - {-0.5, 0.1, -0.15, 0.5, 0.15, 0.5}, - {-0.5, 0.15, -0.2, 0.5, 0.2, 0.5}, - {-0.5, 0.2, -0.25, 0.5, 0.25, 0.5}, - {-0.5, 0.25, -0.3, 0.5, 0.3, 0.5}, - {-0.5, 0.3, -0.35, 0.5, 0.35, 0.5}, - {-0.5, 0.35, -0.4, 0.5, 0.4, 0.5}, - {-0.5, 0.4, -0.45, 0.5, 0.45, 0.5}, - {-0.5, 0.45, -0.5, 0.5, 0.5, 0.5}, - - }, + fixed = slopeboxedge, }, groups = groups, }) -- cgit v1.2.3 From 2d68498dc10bc74a35a5cc0ff4e81b6640807511 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Wed, 8 May 2013 01:42:22 +0200 Subject: Massive change to the way CNC programs are registered. Now the API is open for adding new nodes and inhibiting some nodes for some materials. No more recipes outside of the CNC machine. Code length also greatly reduced. --- technic/cnc_api.lua | 1131 +++++++++++++------------------------------------ technic/cnc_nodes.lua | 338 ++------------- 2 files changed, 332 insertions(+), 1137 deletions(-) diff --git a/technic/cnc_api.lua b/technic/cnc_api.lua index aecfadb..2d5e305 100644 --- a/technic/cnc_api.lua +++ b/technic/cnc_api.lua @@ -8,851 +8,330 @@ technic_cnc_api.detail_level = 16 -- 16; 1-32 -- REGISTER NONCUBIC FORMS, CREATE MODELS AND RECIPES: ------------------------------------------------------ - --- SLOPE --------- -function technic_cnc_api.register_slope(recipeitem, groups, images, description) - -local slopebox = {} -local detail = technic_cnc_api.detail_level -for i = 0, detail-1 do - slopebox[i+1]={-0.5, (i/detail)-0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} -end - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = slopebox, - }, - groups = groups, - }) -end - - --- SLOPE Lying ----------------- -function technic_cnc_api.register_slope_lying(recipeitem, groups, images, description) - -local slopeboxlying = {} -local detail = technic_cnc_api.detail_level -for i = 0, detail-1 do - slopeboxlying[i+1]={(i/detail)-0.5, -0.5, (i/detail)-0.5, (i/detail)-0.5+(1/detail), 0.5 , 0.5} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_lying", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = slopeboxlying, - }, - groups = groups, - }) - minetest.register_craft({ - output = recipeitem .. "_technic_cnc_slope_lying 1", - recipe = { - {"", "", ""}, - {"", recipeitem .. "_technic_cnc_slope", ""}, - {"", "", ""}, - }, - }) - -end - - --- SLOPE UPSIDE DOWN --------------------- -function technic_cnc_api.register_slope_upsdown(recipeitem, groups, images, description) - -if subname == "dirt" then -return -end - -local slopeupdwnbox = {} -local detail = technic_cnc_api.detail_level -for i = 0, detail-1 do - slopeupdwnbox[i+1]={-0.5, (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_upsdown", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = slopeupdwnbox, - }, - groups = groups, - }) -end - - --- SLOPE EDGE -------------- -function technic_cnc_api.register_slope_edge(recipeitem, groups, images, description) - -local slopeboxedge = {} -local detail = technic_cnc_api.detail_level -for i = 0, detail-1 do - slopeboxedge[i+1]={(i/detail)-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_edge", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = slopeboxedge, - }, - groups = groups, - }) -end - - --- SLOPE INNER EDGE -------------------- -function technic_cnc_api.register_slope_inner_edge(recipeitem, groups, images, description) - local slopeboxedge = {} - local detail = technic_cnc_api.detail_level - for i = 0, detail-1 do - slopeboxedge[i+1]={(i/detail)-0.5, -0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} - slopeboxedge[i+detail+1]={-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} +local cnc_sphere = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + local sehne + for i = 1, detail-1 do + sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) + nodebox[i]={-sehne, (i/detail)-0.5, -sehne, sehne, (i/detail)+(1/detail)-0.5, sehne} + end + return nodebox end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_inner_edge", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = slopeboxedge, - }, - groups = groups, - }) -end - - --- SLOPE EDGE UPSIDE DOWN -------------------------- -function technic_cnc_api.register_slope_edge_upsdown(recipeitem, groups, images, description) - -if recipeitem == "default:dirt" then - return -end - -local slopeupdwnboxedge = {} -local detail = technic_cnc_api.detail_level -for i = 0, detail-1 do - slopeupdwnboxedge[i+1]={(-1*(i/detail))+0.5-(1/detail), (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_edge_upsdown", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = slopeupdwnboxedge, - }, - groups = groups, - }) -end - - --- SLOPE INNER EDGE UPSIDE DOWN -------------------------------- -function technic_cnc_api.register_slope_inner_edge_upsdown(recipeitem, groups, images, description) - -if recipename == "default:dirt" then -return -end - -local slopeboxedge = {} -local detail = technic_cnc_api.detail_level -for i = 0, detail-1 do - slopeboxedge[i+1]={0.5-(i/detail)-(1/detail), (i/detail)-0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} - slopeboxedge[i+detail+1]={-0.5, (i/detail)-0.5, 0.5-(i/detail)-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5} -end - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_slope_inner_edge_upsdown", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = slopeboxedge, - }, - groups = groups, - }) -end - - --- PYRAMID ----------- -function technic_cnc_api.register_pyramid(recipeitem, groups, images, description) - -local pyrabox = {} -local detail = technic_cnc_api.detail_level/2 -for i = 0, detail-1 do - pyrabox[i+1]={(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail/2)-0.5+(1/detail), 0.5-(i/detail/2)} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_pyramid", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, - }, - node_box = { - type = "fixed", - fixed = pyrabox, - }, - groups = groups, - }) -end - - --- SPIKE --------- -function technic_cnc_api.register_spike(recipeitem, groups, images, description) - -if recipename == "default:dirt" then - return -end - -local spikebox = {} -local detail = technic_cnc_api.detail_level -for i = 0, detail-1 do - spikebox[i+1]={(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail)-0.5+(1/detail), 0.5-(i/detail/2)} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_spike", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = spikebox, - }, - groups = groups, - }) -end - - --- Block one curved edge ------------------------- -function technic_cnc_api.register_onecurvededge(recipeitem, groups, images, description) - -local quartercyclebox = {} -local detail = technic_cnc_api.detail_level*2 -local sehne -for i = (detail/2)-1, detail-1 do - sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) - quartercyclebox[i]={-0.5, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_onecurvededge", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = quartercyclebox, - }, - groups = groups, - }) -end - - --- Block two curved edges -------------------------- -function technic_cnc_api.register_twocurvededge(recipeitem, groups, images, description) - -local quartercyclebox2 = {} -local detail = technic_cnc_api.detail_level*2 -local sehne -for i = (detail/2)-1, detail-1 do - sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) - quartercyclebox2[i]={-sehne, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_twocurvededge", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = quartercyclebox2, - }, - groups = groups, - }) - minetest.register_craft({ - output = recipeitem .. "_technic_cnc_twocurvededge 3", - recipe = { - {"", "", ""}, - {recipeitem .. "_technic_cnc_onecurvededge", "", ""}, - {recipeitem .. "_technic_cnc_onecurvededge", recipeitem .. "_technic_cnc_onecurvededge", ""}, - }, - }) - -end - --- Cylinder ------------ -function technic_cnc_api.register_cylinder(recipeitem, groups, images, description) - -if recipename == "default:dirt" then -return -end - -local cylbox = {} -local detail = technic_cnc_api.detail_level -local sehne -for i = 1, detail-1 do - sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) - cylbox[i]={(i/detail)-0.5, -0.5, -sehne, (i/detail)+(1/detail)-0.5, 0.5, sehne} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_cylinder", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = cylbox, - }, - groups = groups, - }) - minetest.register_craft({ - output = recipeitem .. "_technic_cnc_cylinder 1", - recipe = { - {"", "", ""}, - {"", recipeitem .. "_technic_cnc_cylinder_horizontal", ""}, - {"", "", ""}, - }, - }) - -end - - --- Cylinder Horizontal ----------------------- -function technic_cnc_api.register_cylinder_horizontal(recipeitem, groups, images, description) - -if recipename == "default:dirt" then - return -end - -local cylbox_horizontal = {} -local detail = technic_cnc_api.detail_level -local sehne -for i = 1, detail-1 do - sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) - cylbox_horizontal[i]={-0.5, (i/detail)-0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, sehne} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_cylinder_horizontal", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = cylbox_horizontal, - }, - groups = groups, - }) - minetest.register_craft({ - output = recipeitem .. "_technic_cnc_cylinder_horizontal 1", - recipe = { - {"", "", ""}, - {"", recipeitem .. "_technic_cnc_cylinder", ""}, - {"", "", ""}, - }, - }) -end - - --- Sphere ---------- -function technic_cnc_api.register_sphere(recipeitem, groups, images, description) - -if recipename == "default:dirt" then - return -end - -local spherebox = {} -local detail = technic_cnc_api.detail_level -local sehne -for i = 1, detail-1 do - sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) - spherebox[i]={-sehne, (i/detail)-0.5, -sehne, sehne, (i/detail)+(1/detail)-0.5, sehne} -end -minetest.register_node(":" .. recipeitem .. "_technic_cnc_sphere", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = spherebox, - }, - groups = groups, - }) -end - - --- Element straight -------------------- -function technic_cnc_api.register_element_straight(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_straight", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.3, -0.5, -0.5, 0.3, 0, 0.5}, - }, - node_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.5, 0.3, 0, 0.5}, - }, - }, - groups = groups, - }) -end - - --- Element Edge ---------------- -function technic_cnc_api.register_element_edge(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_edge", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.5, 0.3, 0, 0.3}, - {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, - }, - }, - node_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.5, 0.3, 0, 0.3}, - {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, - }, - }, - groups = groups, - }) -end - - --- Element T ------------- -function technic_cnc_api.register_element_t(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_t", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.5, 0.3, 0, 0.3}, - {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, - {0.3, -0.5, -0.3, 0.5, 0, 0.3}, - }, - }, - node_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.5, 0.3, 0, 0.3}, - {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, - {0.3, -0.5, -0.3, 0.5, 0, 0.3}, - }, - }, - groups = groups, - }) -end - - --- Element Cross ----------------- -function technic_cnc_api.register_element_cross(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_cross", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = { - {0.3, -0.5, -0.3, 0.5, 0, 0.3}, - {-0.3, -0.5, -0.5, 0.3, 0, 0.5}, - {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, - }, - }, - node_box = { - type = "fixed", - fixed = { - {0.3, -0.5, -0.3, 0.5, 0, 0.3}, - {-0.3, -0.5, -0.5, 0.3, 0, 0.5}, - {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, - }, - }, - groups = groups, - }) -end - - --- Element End --------------- -function technic_cnc_api.register_element_end(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_end", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.3, -0.5, -0.3, 0.3, 0, 0.5}, - }, - node_box = { - type = "fixed", - fixed = {-0.3, -0.5, -0.3, 0.3, 0, 0.5}, - }, - groups = groups, - }) -end +local cnc_cylinder_horizontal = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + local sehne + for i = 1, detail-1 do + sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) + nodebox[i]={-0.5, (i/detail)-0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, sehne} + end + return nodebox + end +local cnc_cylinder = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + local sehne + for i = 1, detail-1 do + sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) + nodebox[i]={(i/detail)-0.5, -0.5, -sehne, (i/detail)+(1/detail)-0.5, 0.5, sehne} + end + return nodebox + end --- Element straight DOUBLE --------------------------- -function technic_cnc_api.register_element_straight_double(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_straight_double", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5}, - }, - }, - groups = groups, - }) - minetest.register_craft({ - output = recipeitem .. "_technic_cnc_element_straight_double 1", - recipe = { - {"", "", ""}, - {"", recipeitem .. "_technic_cnc_element_straight", ""}, - {"", recipeitem .. "_technic_cnc_element_straight", ""}, - }, - }) -end +local cnc_twocurvededge = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level*2 + local sehne + for i = (detail/2)-1, detail-1 do + sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) + nodebox[i]={-sehne, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5} + end + return nodebox + end +local cnc_onecurvededge = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level*2 + local sehne + for i = (detail/2)-1, detail-1 do + sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2)) + nodebox[i]={-0.5, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5} + end + return nodebox + end --- Element Edge DOUBLE ----------------------- -function technic_cnc_api.register_element_edge_double(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_edge_double", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3}, - {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, - }, - }, - node_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3}, - {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, - }, - }, - groups = groups, - }) - minetest.register_craft({ - output = recipeitem .. "_technic_cnc_element_edge_double 1", - recipe = { - {"", "", ""}, - {"", recipeitem .. "_technic_cnc_element_edge", ""}, - {"", recipeitem .. "_technic_cnc_element_edge", ""}, - }, - }) +local cnc_spike = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + for i = 0, detail-1 do + nodebox[i+1]={(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail)-0.5+(1/detail), 0.5-(i/detail/2)} end + return nodebox + end +local cnc_pyramid = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level/2 + for i = 0, detail-1 do + nodebox[i+1]={(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail/2)-0.5+(1/detail), 0.5-(i/detail/2)} + end + return nodebox + end --- Element T DOUBLE -------------------- -function technic_cnc_api.register_element_t_double(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_t_double", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3}, - {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, - {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}, - }, - }, - node_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3}, - {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, - {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}, - }, - }, - groups = groups, - }) - minetest.register_craft({ - output = recipeitem .. "_technic_cnc_element_t_double 1", - recipe = { - {"", "", ""}, - {"", recipeitem .. "_technic_cnc_element_t", ""}, - {"", recipeitem .. "_technic_cnc_element_t", ""}, - }, - }) -end +local cnc_slope_inner_edge_upsdown = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + for i = 0, detail-1 do + nodebox[i+1]={0.5-(i/detail)-(1/detail), (i/detail)-0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} + nodebox[i+detail+1]={-0.5, (i/detail)-0.5, 0.5-(i/detail)-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5} + end + return nodebox + end +local cnc_slope_edge_upsdown = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + for i = 0, detail-1 do + nodebox[i+1]={(-1*(i/detail))+0.5-(1/detail), (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5} + end + return nodebox + end --- Element Cross Double ------------------------ -function technic_cnc_api.register_element_cross_double(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_cross_double", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = { - {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}, - {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5}, - {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, - }, - }, - node_box = { - type = "fixed", - fixed = { - {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}, - {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5}, - {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, - }, - }, - groups = groups, - }) - minetest.register_craft({ - output = recipeitem .. "_technic_cnc_element_cross_double 1", - recipe = { - {"", "", ""}, - {"", recipeitem .. "_technic_cnc_element_cross", ""}, - {"", recipeitem .. "_technic_cnc_element_cross", ""}, - }, - }) +local cnc_slope_inner_edge = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + for i = 0, detail-1 do + nodebox[i+1]={(i/detail)-0.5, -0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} + nodebox[i+detail+1]={-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} + end + return nodebox + end -end +local cnc_slope_edge = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + for i = 0, detail-1 do + nodebox[i+1]={(i/detail)-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} + end + return nodebox + end +local cnc_slope_upsdown = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + for i = 0, detail-1 do + nodebox[i+1]={-0.5, (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5} + end + return nodebox + end --- Element End Double ---------------------- -function technic_cnc_api.register_element_end_double(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_element_end_double", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.5}, - }, - node_box = { - type = "fixed", - fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.5}, - }, - groups = groups, - }) - minetest.register_craft({ - output = recipeitem .. "_technic_cnc_element_end_double 1", - recipe = { - {"", "", ""}, - {"", recipeitem .. "_technic_cnc_element_end", ""}, - {"", recipeitem .. "_technic_cnc_element_end", ""}, - }, - }) -end +local cnc_slope_lying = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + for i = 0, detail-1 do + nodebox[i+1]={(i/detail)-0.5, -0.5, (i/detail)-0.5, (i/detail)-0.5+(1/detail), 0.5 , 0.5} + end + return nodebox + end +local cnc_slope = + function() + local nodebox = {} + local detail = technic_cnc_api.detail_level + for i = 0, detail-1 do + nodebox[i+1]={-0.5, (i/detail)-0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5} + end + return nodebox + end --- STICK --------- -function technic_cnc_api.register_stick(recipeitem, groups, images, description) - -minetest.register_node(":" .. recipeitem .. "_technic_cnc_stick", { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - walkable = true, - selection_box = { - type = "fixed", - fixed = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15}, - }, - node_box = { - type = "fixed", - fixed = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15}, - }, - groups = groups, - }) - minetest.register_craft({ - output = recipeitem .. "_technic_cnc_stick 8", - recipe = { - {'default:stick', "", ""}, - {"", "", ""}, - {recipeitem, "", ""}, - }, - }) +-- Define slope boxes for the various nodes +------------------------------------------- +technic_cnc_api.cnc_programs = { + {suffix = "technic_cnc_stick", + nodebox = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15}, + desc = "Stick"}, + + {suffix = "technic_cnc_element_end_double", + nodebox = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.5}, + desc = "Element End Double"}, + + {suffix = "technic_cnc_element_cross_double", + nodebox = { + {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}, + {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5}, + {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}}, + desc = "Element Cross Double"}, + + {suffix = "technic_cnc_element_t_double", + nodebox = { + {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}, + {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}}, + desc = "Element T Double"}, + + {suffix = "technic_cnc_element_edge_double", + nodebox = { + {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}}, + desc = "Element Edge Double"}, + + {suffix = "technic_cnc_element_straight_double", + nodebox = {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5}, + desc = "Element Straight Double"}, + + {suffix = "technic_cnc_element_end", + nodebox = {-0.3, -0.5, -0.3, 0.3, 0, 0.5}, + desc = "Element End"}, + + {suffix = "technic_cnc_element_cross", + nodebox = { + {0.3, -0.5, -0.3, 0.5, 0, 0.3}, + {-0.3, -0.5, -0.5, 0.3, 0, 0.5}, + {-0.5, -0.5, -0.3, -0.3, 0, 0.3}}, + desc = "Element Cross"}, + + {suffix = "technic_cnc_element_t", + nodebox = { + {-0.3, -0.5, -0.5, 0.3, 0, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0, 0.3}, + {0.3, -0.5, -0.3, 0.5, 0, 0.3}}, + desc = "Element T"}, + + {suffix = "technic_cnc_element_edge", + nodebox = { + {-0.3, -0.5, -0.5, 0.3, 0, 0.3}, + {-0.5, -0.5, -0.3, -0.3, 0, 0.3}}, + desc = "Element Edge"}, + + {suffix = "technic_cnc_element_straight", + nodebox = {-0.3, -0.5, -0.5, 0.3, 0, 0.5}, + desc = "Element Straight"}, + + {suffix = "technic_cnc_sphere", + nodebox = cnc_sphere(), + desc = "Sphere"}, + + {suffix = "technic_cnc_cylinder_horizontal", + nodebox = cnc_cylinder_horizontal(), + desc = "Cylinder Horizontal"}, + + {suffix = "technic_cnc_cylinder", + nodebox = cnc_cylinder(), + desc = ""}, + + {suffix = "technic_cnc_twocurvededge", + nodebox = cnc_twocurvededge(), + desc = "One Curved Edge Block"}, + + {suffix = "technic_cnc_onecurvededge", + nodebox = cnc_onecurvededge(), + desc = "Two Curved Edge Block"}, + + {suffix = "technic_cnc_spike", + nodebox = cnc_spike(), + desc = "Spike"}, + + {suffix = "technic_cnc_pyramid", + nodebox = cnc_pyramid(), + desc = "Pyramid"}, + + {suffix = "technic_cnc_slope_inner_edge_upsdown", + nodebox = cnc_slope_inner_edge_upsdown(), + desc = "Slope Upside Down Inner Edge"}, + + {suffix = "technic_cnc_slope_edge_upsdown", + nodebox = cnc_slope_edge_upsdown(), + desc = "Slope Upside Down Edge"}, + + {suffix = "technic_cnc_slope_inner_edge", + nodebox = cnc_slope_inner_edge(), + desc = "Slope Inner Edge"}, + + {suffix = "technic_cnc_slope_edge", + nodebox = cnc_slope_edge(), + desc = "Slope Edge"}, + + {suffix = "technic_cnc_slope_upsdown", + nodebox = cnc_slope_upsdown(), + desc = "Slope Upside Down"}, + + {suffix = "technic_cnc_slope_lying", + nodebox = cnc_slope_lying(), + desc = "Slope Lying"}, + + {suffix = "technic_cnc_slope", + nodebox = cnc_slope(), + desc = "Slope"}, +-- {suffix = "", +-- nodebox =}, +} + +-- Allow disabling certain programs for some node. Default is allowing all types for all nodes +technic_cnc_api.cnc_programs_disable = { + -- ["default:brick"] = {"technic_cnc_stick"}, -- Example: Disallow the stick for brick + -- ... + ["default:dirt"] = {"technic_cnc_sphere", "technic_cnc_slope_upsdown", "technic_cnc_edge", + "technic_cnc_inner_edge", "technic_cnc_slope_edge_upsdown", "technic_cnc_slope_inner_edge_upsdown", + "technic_cnc_stick", "technic_cnc_cylinder_horizontal"} +} + +-- Generic function for registering all the different node types +function technic_cnc_api.register_cnc_program(recipeitem, suffix, nodebox, groups, images, description) + minetest.register_node(":" .. recipeitem .. "_" .. suffix, { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + selection_box = { + type = "fixed", + fixed = nodebox + }, + node_box = { + type = "fixed", + fixed = nodebox + }, + groups = groups, + }) +end + +-- function to iterate over all the programs the CNC machine knows +function technic_cnc_api.register_all(recipeitem, groups, images, description) + for _, data in ipairs(technic_cnc_api.cnc_programs) do + -- Disable node creation for disabled node types for some material + local do_register = true + if technic_cnc_api.cnc_programs_disable[recipeitem] ~= nil then + for __, disable in ipairs(technic_cnc_api.cnc_programs_disable[recipeitem]) do + if disable == data.suffix then + do_register = false + end + end + end + -- Create the node if it passes the test + if do_register then + technic_cnc_api.register_cnc_program(recipeitem, data.suffix, data.nodebox, groups, images, description.." "..data.desc) + end + end end - -- REGISTER NEW TECHNIC_CNC_API's PART 2: technic_cnc_api.register_element_end(subname, recipeitem, groups, images, desc_element_xyz) ----------------------------------------------------------------------------------------------------------------------- function technic_cnc_api.register_slope_edge_etc(recipeitem, groups, images, desc_slope, desc_slope_lying, desc_slope_upsdown, desc_slope_edge, desc_slope_inner_edge, desc_slope_upsdwn_edge, desc_slope_upsdwn_inner_edge, desc_pyramid, desc_spike, desc_onecurvededge, desc_twocurvededge, desc_cylinder, desc_cylinder_horizontal, desc_sphere, desc_element_straight, desc_element_edge, desc_element_t, desc_element_cross, desc_element_end) diff --git a/technic/cnc_nodes.lua b/technic/cnc_nodes.lua index 2f375a5..df82385 100644 --- a/technic/cnc_nodes.lua +++ b/technic/cnc_nodes.lua @@ -1,354 +1,70 @@ -- REGISTER MATERIALS AND PROPERTIES FOR NONCUBIC ELEMENTS: ----------------------------------------------------------- - --- WOOD -------- -technic_cnc_api.register_slope_edge_etc("default:wood", - {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, - {"default_wood.png"}, - "Wooden Slope", - "Wooden Slope Lying", - "Wooden Slope Upside Down", - "Wooden Slope Edge", - "Wooden Slope Inner Edge", - "Wooden Slope Upside Down Edge", - "Wooden Slope Upside Down Inner Edge", - "Wooden Pyramid", - "Wooden Spike", - "Wooden One Curved Edge Block", - "Wooden Two Curved Edge Block", - "Wooden Cylinder", - "Wooden Cylinder Horizontal", - "Wooden Sphere", - "Wooden Element Straight", - "Wooden Element Edge", - "Wooden Element T", - "Wooden Element Cross", - "Wooden Element End") --- STONE --------- -technic_cnc_api.register_slope_edge_etc("default:stone", - {cracky=3,not_in_creative_inventory=1}, - {"default_stone.png"}, - "Stone Slope", - "Stone Slope Lying", - "Stone Slope Upside Down", - "Stone Slope Edge", - "Stone Slope Inner Edge", - "Stone Slope Upside Down Edge", - "Stone Slope Upside Down Inner Edge", - "Stone Pyramid", - "Stone Spike", - "Stone One Curved Edge Block", - "Stone Two Curved Edge Block", - "Stone Cylinder", - "Stote Cylinder Horizontal", - "Stone Sphere", - "Stone Element Straight", - "Stone Element Edge", - "Stone Element T", - "Stone Element Cross", - "Stone Element End") --- COBBLE ---------- -technic_cnc_api.register_slope_edge_etc("default:cobble", - {cracky=3,not_in_creative_inventory=1}, - {"default_cobble.png"}, - "Cobble Slope", - "Cobble Slope Lying", - "Cobble Slope Upside Down", - "Cobble Slope Edge", - "Cobble Slope Inner Edge", - "Cobble Slope Upside Down Edge", - "Cobble Slope Upside Down Inner Edge", - "Cobble Pyramid", - "Cobble Spike", - "Cobble One Curved Edge Block", - "Cobble Two Curved Edge Block", - "Cobble Cylinder", - "Cobble Cylinder Horizontal", - "Cobble Sphere", - "Cobble Element Straight", - "Cobble Element Edge", - "Cobble Element T", - "Cobble Element Cross", - "Cobble Element End") --- BRICK --------- -technic_cnc_api.register_slope_edge_etc("default:brick", - {cracky=3,not_in_creative_inventory=1}, - {"default_brick.png"}, - "Brick Slope", - "Brick Slope Upside Down", - "Brick Slope Edge", - "Brick Slope Inner Edge", - "Brick Slope Upside Down Edge", - "Brick Slope Upside Down Inner Edge", - "Brick Pyramid", - "Brick Spike", - "Brick One Curved Edge Block", - "Brick Two Curved Edge Block", - "Brick Cylinder", - "Brick Cylinder Horizontal", - "Brick Sphere", - "Brick Element Straight", - "Brick Element Edge", - "Brick Element T", - "Brick Element Cross", - "Brick Element End") --- SANDSTONE ------------- -technic_cnc_api.register_slope_edge_etc("default:sandstone", - {crumbly=2,cracky=2,not_in_creative_inventory=1}, - {"default_sandstone.png"}, - "Sandstone Slope", - "Sandstone Slope Lying", - "Sandstone Slope Upside Down", - "Sandstone Slope Edge", - "Sandstone Slope Inner Edge", - "Sandstone Slope Upside Down Edge", - "Sandstone Slope Upside Down Inner Edge", - "Sandstone Pyramid", - "Sandstone Spike", - "Sandstone One Curved Edge Block", - "Sandstone Two Curved Edge Block", - "Sandstone Cylinder", - "Sandstone Cylinder Horizontal", - "Sandstone Sphere", - "Sandstone Element Straight", - "Sandstone Element Edge", - "Sandstone Element T", - "Sandstone Element Cross", - "Sandstone Element End") --- LEAVES ---------- -technic_cnc_api.register_slope_edge_etc("default:leaves", - {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, - {"bucharest_tree.png"}, - "Leaves Slope", - "Leaves Slope Lying", - "Leaves Slope Upside Down", - "Leaves Slope Edge", - "Leaves Slope Inner Edge", - "Leaves Slope Upside Down Edge", - "Leaves Slope Upside Down Inner Edge", - "Leaves Pyramid", - "Leaves Spike", - "Leaves One Curved Edge Block", - "Leaves Two Curved Edge Block", - "Leaves Cylinder", - "Leaves Cylinder Horizontal", - "Leaves Sphere", - "Leaves Element Straight", - "Leaves Element Edge", - "Leaves Element T", - "Leaves Element Cross", - "Leaves Element End") -- DIRT ------- -technic_cnc_api.register_slope_edge_etc("default:dirt", +technic_cnc_api.register_all("default:dirt", {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, {"default_grass.png", "default_dirt.png", "default_grass.png"}, - "Dirt Slope", - "Dirt Slope Lying", - "Dirt Slope Upside Down", - "Dirt Slope Edge", - "Dirt Slope Inner Edge", - "Dirt Slope Upside Down Edge", - "Dirt Slope Upside Down Inner Edge", - "Dirt Pyramid", - "Dirt Spike", - "Dirt One Curved Edge Block", - "Dirt Two Curved Edge Block", - "Dirt Cylinder", - "Dirt Cylinder Horizontal", - "Dirt Sphere", - "Dirt Element Straight", - "Dirt Element Edge", - "Dirt Element T", - "Dirt Element Cross", - "Dirt Element End") --- TREE -------- -technic_cnc_api.register_slope_edge_etc("default:tree", - {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,not_in_creative_inventory=1}, - {"default_tree.png"}, - "Tree Slope", - "Tree Slope Lying", - "Tree Slope Upside Down", - "Tree Slope Edge", - "Tree Slope Inner Edge", - "Tree Slope Upside Down Edge", - "Tree Slope Upside Down Inner Edge", - "Tree Pyramid", - "Tree Spike", - "Tree One Curved Edge Block", - "Tree Two Curved Edge Block", - "Tree Cylinder", - "Tree Cylinder Horizontal", - "Tree Sphere", - "Tree Element Straight", - "Tree Element Edge", - "Tree Element T", - "Tree Element Cross", - "Tree Element End") --- STEEL --------- -technic_cnc_api.register_slope_edge_etc("default:steelblock", - {snappy=1,bendy=2,cracky=1,melty=2,level=2,not_in_creative_inventory=1}, - {"default_steel_block.png"}, - "Steel Slope", - "Steel Slope Lying", - "Steel Slope Upside Down", - "Steel Slope Edge", - "Steel Slope Inner Edge", - "Steel Slope Upside Down Edge", - "Steel Slope Upside Down Inner Edge", - "Steel Pyramid", - "Steel Spike", - "Steel One Curved Edge Block", - "Steel Two Curved Edge Block", - "Steel Cylinder", - "Steel Cylinder Horizontal", - "Steel Sphere", - "Steel Element Straight", - "Steel Element Edge", - "Steel Element T", - "Steel Element Cross", - "Steel Element End") - --- REGISTER MATERIALS AND PROPERTIES FOR STICKS: ------------------------------------------------- + "Dirt") +technic_cnc_api.cnc_programs_disable["default:dirt"] = {"technic_cnc_sphere", "technic_cnc_slope_upsdown", + "technic_cnc_edge", "technic_cnc_inner_edge", + "technic_cnc_slope_edge_upsdown", "technic_cnc_slope_inner_edge_upsdown", + "technic_cnc_stick", "technic_cnc_cylinder_horizontal"} --- WOOD -------- -technic_cnc_api.register_stick_etc("default:wood", - {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, - {"default_wood.png"}, - "Wooden Stick") --- STONE --------- -technic_cnc_api.register_stick_etc("default:stone", - {cracky=3,not_in_creative_inventory=1}, - {"default_stone.png"}, - "Stone Stick") --- COBBLE ---------- -technic_cnc_api.register_stick_etc("default:cobble", - {cracky=3,not_in_creative_inventory=1}, - {"default_cobble.png"}, - "Cobble Stick") --- BRICK --------- -technic_cnc_api.register_stick_etc("default:brick", - {cracky=3,not_in_creative_inventory=1}, - {"default_brick.png"}, - "Brick Stick") --- SANDSTONE ------------- -technic_cnc_api.register_stick_etc("default:sandstone", - {crumbly=2,cracky=2,not_in_creative_inventory=1}, - {"default_sandstone.png"}, - "Sandstone Stick") --- LEAVES ---------- -technic_cnc_api.register_stick_etc("default:leaves", - {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, - {"bucharest_tree.png"}, - "Leaves Stick") -- TREE ------- -technic_cnc_api.register_stick_etc("default:tree", - {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1,not_in_creative_inventory=1}, +technic_cnc_api.register_all("default:tree", + {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, {"default_tree.png"}, - "Tree Stick") --- STEEL --------- -technic_cnc_api.register_stick_etc("default:steelblock", - {snappy=1,bendy=2,cracky=1,melty=2,level=2,not_in_creative_inventory=1}, - {"default_steel_block.png"}, - "Steel Stick") - --- REGISTER MATERIALS AND PROPERTIES FOR HALF AND NORMAL HEIGHT ELEMENTS: -------------------------------------------------------------------------- + "Wooden") -- WOOD ------- -technic_cnc_api.register_elements("default:wood", +technic_cnc_api.register_all("default:wood", {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, {"default_wood.png"}, - "Wooden Element Straight Double", - "Wooden Element Edge Double", - "Wooden Element T Double", - "Wooden Element Cross Double", - "Wooden Element End Double") + "Wooden") -- STONE -------- -technic_cnc_api.register_elements("default:stone", +technic_cnc_api.register_all("default:stone", {cracky=3,not_in_creative_inventory=1}, {"default_stone.png"}, - "Stone Element Straight Double", - "Stone Element Edge Double", - "Stone Element T Double", - "Stone Element Cross Double", - "Stone Element End Double") + "Stone") -- COBBLE --------- -technic_cnc_api.register_elements("default:cobble", +technic_cnc_api.register_all("default:cobble", {cracky=3,not_in_creative_inventory=1}, {"default_cobble.png"}, - "Cobble Element Straight Double", - "Cobble Element Edge Double", - "Cobble Element T Double", - "Cobble Element Cross Double", - "Cobble Element End Double") + "Cobble") -- BRICK -------- -technic_cnc_api.register_elements("default:brick", +technic_cnc_api.register_all("default:brick", {cracky=3,not_in_creative_inventory=1}, {"default_brick.png"}, - "Brick Element Straight Double", - "Brick Element Edge Double", - "Brick Element T Double", - "Brick Element Cross Double", - "Brick Element End Double") + "Brick") + -- SANDSTONE ------------ -technic_cnc_api.register_elements("default:sandstone", +technic_cnc_api.register_all("default:sandstone", {crumbly=2,cracky=2,not_in_creative_inventory=1}, {"default_sandstone.png"}, - "Sandstone Element Straight Double", - "Sandstone Element Edge Double", - "Sandstone Element T Double", - "Sandstone Element Cross Double", - "Sandstone Element End Double") + "Sandstone") + -- LEAVES --------- -technic_cnc_api.register_elements("default:leaves", +technic_cnc_api.register_all("default:leaves", {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1}, {"bucharest_tree.png"}, - "Leaves Element Straight Double", - "Leaves Element Edge Double", - "Leaves Element T Double", - "Leaves Element Cross Double", - "Leaves Element End Double") + "Leaves") -- TREE ------- -technic_cnc_api.register_elements("default:tree", +technic_cnc_api.register_all("default:tree", {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1,not_in_creative_inventory=1}, {"default_tree.png"}, - "Tree Element Straight Double", - "Tree Element Edge Double", - "Tree Element T Double", - "Tree Element Cross Double", - "Tree Element End Double") + "Tree") -- STEEL -------- -technic_cnc_api.register_elements("default:steel", +technic_cnc_api.register_all("default:steel", {snappy=1,bendy=2,cracky=1,melty=2,level=2,not_in_creative_inventory=1}, {"default_steel_block.png"}, - "Steel Element Straight Double", - "Steel Element Edge Double", - "Steel Element T Double", - "Steel Element Cross Double", - "Steel Element End Double") + "Steel") -- cgit v1.2.3 From ad8c6e3731dd70ad6d11fe720249eb0df8772586 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Thu, 9 May 2013 16:00:43 +0200 Subject: Add stained glass textures --- framedglass/textures/framedglass_blackglass.png | Bin 0 -> 346 bytes framedglass/textures/framedglass_blueglass.png | Bin 0 -> 432 bytes framedglass/textures/framedglass_brownglass.png | Bin 0 -> 403 bytes framedglass/textures/framedglass_cyanglass.png | Bin 0 -> 442 bytes framedglass/textures/framedglass_darkgreenglass.png | Bin 0 -> 414 bytes framedglass/textures/framedglass_darkgreyglass.png | Bin 0 -> 436 bytes framedglass/textures/framedglass_greenglass.png | Bin 0 -> 445 bytes framedglass/textures/framedglass_greyglass.png | Bin 0 -> 349 bytes framedglass/textures/framedglass_orangeglass.png | Bin 0 -> 410 bytes framedglass/textures/framedglass_pinkglass.png | Bin 0 -> 412 bytes framedglass/textures/framedglass_redglass.png | Bin 0 -> 444 bytes framedglass/textures/framedglass_violetglass.png | Bin 0 -> 418 bytes framedglass/textures/framedglass_whiteglass.png | Bin 0 -> 348 bytes framedglass/textures/framedglass_yellowglass.png | Bin 0 -> 400 bytes framedglass/textures/stained_glass_lime.png | Bin 0 -> 444 bytes framedglass/textures/stained_glass_magenta.png | Bin 0 -> 313 bytes 16 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 framedglass/textures/framedglass_blackglass.png create mode 100644 framedglass/textures/framedglass_blueglass.png create mode 100644 framedglass/textures/framedglass_brownglass.png create mode 100644 framedglass/textures/framedglass_cyanglass.png create mode 100644 framedglass/textures/framedglass_darkgreenglass.png create mode 100644 framedglass/textures/framedglass_darkgreyglass.png create mode 100644 framedglass/textures/framedglass_greenglass.png create mode 100644 framedglass/textures/framedglass_greyglass.png create mode 100644 framedglass/textures/framedglass_orangeglass.png create mode 100644 framedglass/textures/framedglass_pinkglass.png create mode 100644 framedglass/textures/framedglass_redglass.png create mode 100644 framedglass/textures/framedglass_violetglass.png create mode 100644 framedglass/textures/framedglass_whiteglass.png create mode 100644 framedglass/textures/framedglass_yellowglass.png create mode 100644 framedglass/textures/stained_glass_lime.png create mode 100644 framedglass/textures/stained_glass_magenta.png diff --git a/framedglass/textures/framedglass_blackglass.png b/framedglass/textures/framedglass_blackglass.png new file mode 100644 index 0000000..4e82027 Binary files /dev/null and b/framedglass/textures/framedglass_blackglass.png differ diff --git a/framedglass/textures/framedglass_blueglass.png b/framedglass/textures/framedglass_blueglass.png new file mode 100644 index 0000000..2768017 Binary files /dev/null and b/framedglass/textures/framedglass_blueglass.png differ diff --git a/framedglass/textures/framedglass_brownglass.png b/framedglass/textures/framedglass_brownglass.png new file mode 100644 index 0000000..b61bdbf Binary files /dev/null and b/framedglass/textures/framedglass_brownglass.png differ diff --git a/framedglass/textures/framedglass_cyanglass.png b/framedglass/textures/framedglass_cyanglass.png new file mode 100644 index 0000000..31edcc6 Binary files /dev/null and b/framedglass/textures/framedglass_cyanglass.png differ diff --git a/framedglass/textures/framedglass_darkgreenglass.png b/framedglass/textures/framedglass_darkgreenglass.png new file mode 100644 index 0000000..c90a027 Binary files /dev/null and b/framedglass/textures/framedglass_darkgreenglass.png differ diff --git a/framedglass/textures/framedglass_darkgreyglass.png b/framedglass/textures/framedglass_darkgreyglass.png new file mode 100644 index 0000000..78c394b Binary files /dev/null and b/framedglass/textures/framedglass_darkgreyglass.png differ diff --git a/framedglass/textures/framedglass_greenglass.png b/framedglass/textures/framedglass_greenglass.png new file mode 100644 index 0000000..0886c74 Binary files /dev/null and b/framedglass/textures/framedglass_greenglass.png differ diff --git a/framedglass/textures/framedglass_greyglass.png b/framedglass/textures/framedglass_greyglass.png new file mode 100644 index 0000000..bb1927d Binary files /dev/null and b/framedglass/textures/framedglass_greyglass.png differ diff --git a/framedglass/textures/framedglass_orangeglass.png b/framedglass/textures/framedglass_orangeglass.png new file mode 100644 index 0000000..4ac3eb7 Binary files /dev/null and b/framedglass/textures/framedglass_orangeglass.png differ diff --git a/framedglass/textures/framedglass_pinkglass.png b/framedglass/textures/framedglass_pinkglass.png new file mode 100644 index 0000000..68185c7 Binary files /dev/null and b/framedglass/textures/framedglass_pinkglass.png differ diff --git a/framedglass/textures/framedglass_redglass.png b/framedglass/textures/framedglass_redglass.png new file mode 100644 index 0000000..1d20920 Binary files /dev/null and b/framedglass/textures/framedglass_redglass.png differ diff --git a/framedglass/textures/framedglass_violetglass.png b/framedglass/textures/framedglass_violetglass.png new file mode 100644 index 0000000..aec8ce0 Binary files /dev/null and b/framedglass/textures/framedglass_violetglass.png differ diff --git a/framedglass/textures/framedglass_whiteglass.png b/framedglass/textures/framedglass_whiteglass.png new file mode 100644 index 0000000..0f2a170 Binary files /dev/null and b/framedglass/textures/framedglass_whiteglass.png differ diff --git a/framedglass/textures/framedglass_yellowglass.png b/framedglass/textures/framedglass_yellowglass.png new file mode 100644 index 0000000..521198c Binary files /dev/null and b/framedglass/textures/framedglass_yellowglass.png differ diff --git a/framedglass/textures/stained_glass_lime.png b/framedglass/textures/stained_glass_lime.png new file mode 100644 index 0000000..782edc9 Binary files /dev/null and b/framedglass/textures/stained_glass_lime.png differ diff --git a/framedglass/textures/stained_glass_magenta.png b/framedglass/textures/stained_glass_magenta.png new file mode 100644 index 0000000..43e28b7 Binary files /dev/null and b/framedglass/textures/stained_glass_magenta.png differ -- cgit v1.2.3 From 4a22282699d76eee4733f2f94ec3e8b03f535411 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Thu, 9 May 2013 16:01:18 +0200 Subject: Add stained glass code --- framedglass/init.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/framedglass/init.lua b/framedglass/init.lua index ebe88ea..6bb92ae 100644 --- a/framedglass/init.lua +++ b/framedglass/init.lua @@ -75,3 +75,33 @@ minetest.register_node("framedglass:steel_framed_obsidian_glass", { groups = {cracky=3,oddly_breakable_by_hand=3}, sounds = default.node_sound_glass_defaults(), }) + +function add_coloured_framedglass(name, desc, dye, texture) +minetest.register_node( "framedglass:steel_framed_obsidian_glass"..name, { + description = "Steel-framed "..desc.." Obsidian Glass", + tiles = {"framedglass_steel_frame.png",texture}, + drawtype = "glasslike_framed", + paramtype = "light", + sunlight_propagates = true, + is_ground_content = true, + use_texture_alpha = true, + groups = {cracky=3}, + sounds = default.node_sound_glass_defaults(), +}) +end + +add_coloured_framedglass ("red","Red","","framedglass_redglass.png") +add_coloured_framedglass ("green","Green","","framedglass_greenglass.png") +add_coloured_framedglass ("blue","Blue","","framedglass_blueglass.png") +add_coloured_framedglass ("cyan","Cyan","","framedglass_cyanglass.png") +add_coloured_framedglass ("darkgreen","Dark Green","","framedglass_darkgreenglass.png") +add_coloured_framedglass ("violet","Violet","","framedglass_violetglass.png") +add_coloured_framedglass ("pink","Pink","","framedglass_pinkglass.png") +add_coloured_framedglass ("yellow","Yellow","","framedglass_yellowglass.png") +add_coloured_framedglass ("orange","Orange","","framedglass_orangeglass.png") +add_coloured_framedglass ("brown","Brown","","framedglass_brownglass.png") +add_coloured_framedglass ("white","White","","framedglass_whiteglass.png") +add_coloured_framedglass ("grey","Grey","","framedglass_greyglass.png") +add_coloured_framedglass ("darkgrey","Dark Grey","","framedglass_darkgreyglass.png") +add_coloured_framedglass ("black","Black","","framedglass_blackglass.png") + -- cgit v1.2.3 From 64207baa4563db90fa80ed23f3b8f41f96f0260d Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Thu, 9 May 2013 16:02:02 +0200 Subject: Add HV battery box --- technic/battery_box_hv.lua | 357 +++++++++++++++++++++++++++++++++++++++++++++ technic/init.lua | 1 + 2 files changed, 358 insertions(+) create mode 100644 technic/battery_box_hv.lua diff --git a/technic/battery_box_hv.lua b/technic/battery_box_hv.lua new file mode 100644 index 0000000..05166eb --- /dev/null +++ b/technic/battery_box_hv.lua @@ -0,0 +1,357 @@ +HV_machines = {} + +registered_HV_machines_count=0 + +function register_HV_machine (string1,string2) +registered_HV_machines_count=registered_HV_machines_count+1 +HV_machines[registered_HV_machines_count]={} +HV_machines[registered_HV_machines_count].machine_name=string1 +HV_machines[registered_HV_machines_count].machine_type=string2 +end + +minetest.register_craft({ + output = 'technic:hv_battery_box 1', + recipe = { + {'technic:mv_battery_box', 'technic:mv_battery_box', 'mv_technic:battery_box'}, + {'technic:mv_battery_box', 'technic:transformer', 'mv_technic:battery_box'}, + {'', 'technic:hv_cable', ''}, + } +}) + +hv_battery_box_formspec = + "invsize[8,9;]".. + "image[1,1;1,2;technic_power_meter_bg.png]".. + "list[current_name;src;3,1;1,1;]".. + "image[4,1;1,1;technic_battery_reload.png]".. + "list[current_name;dst;5,1;1,1;]".. + "label[0,0;HV Battery Box]".. + "label[3,0;Charge]".. + "label[5,0;Discharge]".. + "label[1,3;Power level]".. + "list[current_player;main;0,5;8,4;]" + +minetest.register_node("technic:hv_battery_box", { + description = "HV Battery Box", + tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png", + "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + technic_mv_power_machine=1, + last_side_shown=0, + drop="technic:hv_battery_box", + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "HV Battery Box") + meta:set_float("technic_hv_power_machine", 1) + meta:set_string("formspec", battery_box_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) + inv:set_size("dst", 1) + battery_charge = 0 + max_charge = 1500000 + last_side_shown=0 + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, +}) + + +for i=1,8,1 do +minetest.register_node("technic:hv_battery_box"..i, { + description = "HV Battery Box", + tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", + "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + sounds = default.node_sound_wood_defaults(), + paramtype="light", + light_source=9, + technic_power_machine=1, + last_side_shown=0, + drop="technic:hv_battery_box", + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "hv Battery box") + meta:set_float("technic_hv_power_machine", 1) + meta:set_string("formspec", battery_box_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) + inv:set_size("dst", 1) + battery_charge = 0 + max_charge = 1500000 + last_side_shown=0 + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, +}) +end + + +HV_nodes_visited = {} + + +minetest.register_abm({ + nodenames = {"technic:hv_battery_box","technic:hv_battery_box1","technic:hv_battery_box2","technic:hv_battery_box3","technic:hv_battery_box4", + "technic:hv_battery_box5","technic:hv_battery_box6","technic:hv_battery_box7","technic:hv_battery_box8" + }, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + charge= meta:get_int("battery_charge") + max_charge= 1500000 + local i=math.ceil((charge/max_charge)*8) + if i>8 then i=8 end + j=meta:get_float("last_side_shown") + if i~=j then + if i>0 then hacky_swap_node(pos,"technic:hv_battery_box"..i) + elseif i==0 then hacky_swap_node(pos,"technic:hv_battery_box") end + meta:set_float("last_side_shown",i) + end + +--loading registered power tools + local inv = meta:get_inventory() + if inv:is_empty("src")==false then + local srcstack = inv:get_stack("src", 1) + local src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + + local item_max_charge=nil + for i=1,registered_power_tools_count,1 do + if power_tools[i].tool_name==src_item["name"] then + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_power_tool"]==nil then + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + end + end + item_max_charge=power_tools[i].max_charge + end + end + + if item_max_charge then + load1=src_meta["charge"] + load_step=16000 + if load10 then + if charge-load_step<0 then load_step=charge end + if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end + load1=load1+load_step + charge=charge-load_step + set_RE_wear(src_item,load1,item_max_charge) + src_meta["charge"]=load1 + src_item["metadata"]=set_item_meta(src_meta) + inv:set_stack("src", 1, src_item) + end + meta:set_int("battery_charge",charge) + end + end + +-- dischargin registered power tools + if inv:is_empty("dst") == false then + srcstack = inv:get_stack("dst", 1) + src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + local item_max_charge=nil + for i=1,registered_power_tools_count,1 do + if power_tools[i].tool_name==src_item["name"] then + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_power_tool"]==nil then + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + end + end + item_max_charge=power_tools[i].max_charge + end + end + + if item_max_charge then + local load1=src_meta["charge"] + load_step=16000 + if load1>0 and chargemax_charge then load_step=max_charge-charge end + if load1-load_step<0 then load_step=load1 end + load1=load1-load_step + charge=charge+load_step + set_RE_wear(src_item,load1,item_max_charge) + src_meta["charge"]=load1 + src_item["metadata"]=set_item_meta(src_meta) + inv:set_stack("dst", 1, src_item) + end + end + end + + meta:set_int("battery_charge",charge) + + local load = math.floor((charge/1500000) * 100) + meta:set_string("formspec", + hv_battery_box_formspec.. + "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. + (load)..":technic_power_meter_fg.png]" + ) + + local pos1={} + + pos1.y=pos.y-1 + pos1.x=pos.x + pos1.z=pos.z + + + meta1 = minetest.env:get_meta(pos1) + if meta1:get_float("hv_cablelike")~=1 then return end + + local HV_nodes = {} + local PR_nodes = {} + local RE_nodes = {} + + HV_nodes[1]={} + HV_nodes[1].x=pos1.x + HV_nodes[1].y=pos1.y + HV_nodes[1].z=pos1.z + HV_nodes[1].visited=false + +table_index=1 + repeat + check_HV_node (PR_nodes,RE_nodes,HV_nodes,table_index) + table_index=table_index+1 + if HV_nodes[table_index]==nil then break end + until false + + +local pos1={} +i=1 + repeat + if PR_nodes[i]==nil then break end -- gettin power from all connected producers + pos1.x=PR_nodes[i].x + pos1.y=PR_nodes[i].y + pos1.z=PR_nodes[i].z + local meta1 = minetest.env:get_meta(pos1) + local internal_EU_buffer=meta1:get_float("internal_EU_buffer") + if charge0 then + charge=charge+charge_to_take + internal_EU_buffer=internal_EU_buffer-charge_to_take + meta1:set_float("internal_EU_buffer",internal_EU_buffer) + end + end + i=i+1 + until false + +if charge>max_charge then charge=max_charge end + +i=1 + repeat + if RE_nodes[i]==nil then break end + pos1.x=RE_nodes[i].x -- loading all conected machines buffers + pos1.y=RE_nodes[i].y + pos1.z=RE_nodes[i].z + local meta1 = minetest.env:get_meta(pos1) + local internal_EU_buffer=meta1:get_float("internal_EU_buffer") + local internal_EU_buffer_size=meta1:get_float("internal_EU_buffer_size") + + local charge_to_give=4000 + if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then + charge_to_give=internal_EU_buffer_size-internal_EU_buffer + end + if charge-charge_to_give<0 then charge_to_give=charge end + + internal_EU_buffer=internal_EU_buffer+charge_to_give + meta1:set_float("internal_EU_buffer",internal_EU_buffer) + charge=charge-charge_to_give; + + i=i+1 + until false + charge=math.floor(charge) + charge_string=tostring(charge) + meta:set_string("infotext", "HV Battery Box: \n"..charge_string.."/"..max_charge); + meta:set_int("battery_charge",charge) + +end +}) + +function add_new_HVcable_node (HV_nodes,pos1) +local i=1 + repeat + if HV_nodes[i]==nil then break end + if pos1.x==HV_nodes[i].x and pos1.y==HV_nodes[i].y and pos1.z==HV_nodes[i].z then return false end + i=i+1 + until false +HV_nodes[i]={} +HV_nodes[i].x=pos1.x +HV_nodes[i].y=pos1.y +HV_nodes[i].z=pos1.z +HV_nodes[i].visited=false +return true +end + +function check_HV_node (PR_nodes,RE_nodes,HV_nodes,i) + local pos1={} + pos1.x=HV_nodes[i].x + pos1.y=HV_nodes[i].y + pos1.z=HV_nodes[i].z + HV_nodes[i].visited=true + new_node_added=false + + pos1.x=pos1.x+1 + check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) + pos1.x=pos1.x-2 + check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) + pos1.x=pos1.x+1 + + pos1.y=pos1.y+1 + check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) + pos1.y=pos1.y-2 + check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) + pos1.y=pos1.y+1 + + pos1.z=pos1.z+1 + check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) + pos1.z=pos1.z-2 + check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) + pos1.z=pos1.z+1 +return new_node_added +end + +function check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) +meta = minetest.env:get_meta(pos1) +if meta:get_float("HV_cablelike")==1 then new_node_added=add_new_HVcable_node(HV_nodes,pos1) end +for i in ipairs(HV_machines) do + if minetest.env:get_node(pos1).name == HV_machines[i].machine_name then + if HV_machines[i].machine_type == "PR" then + new_node_added=add_new_HVcable_node(PR_nodes,pos1) + end + if HV_machines[i].machine_type == "RE" then + new_node_added=add_new_HVcable_node(RE_nodes,pos1) + end + end +end +end + diff --git a/technic/init.lua b/technic/init.lua index ff904e2..eabf48e 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -41,6 +41,7 @@ dofile(modpath.."/forcefield.lua") --HV machines dofile(modpath.."/wires_hv.lua") +dofile(modpath.."/battery_box_hv.lua") --Tools if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end -- cgit v1.2.3 From 630db84ad13682eadc0035c251febfa07353a969 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 25 May 2013 22:39:25 +0200 Subject: bugfix --- unified_inventory/api.lua | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/unified_inventory/api.lua b/unified_inventory/api.lua index ab55903..02c08e9 100644 --- a/unified_inventory/api.lua +++ b/unified_inventory/api.lua @@ -58,7 +58,7 @@ minetest.register_on_joinplayer(function(player) unified_inventory.alternate[player_name] = 1 unified_inventory.current_item[player_name] =nil unified_inventory.set_inventory_formspec(player,unified_inventory.get_formspec(player, unified_inventory.default)) - + --crafting guide inventories local inv = minetest.create_detached_inventory(player:get_player_name().."craftrecipe",{ allow_put = function(inv, listname, index, stack, player) @@ -75,8 +75,8 @@ local inv = minetest.create_detached_inventory(player:get_player_name().."craftr return 0 end, }) - inv:set_size("output", 1) - inv:set_size("build", 3*3) +inv:set_size("output", 1) +inv:set_size("build", 3*3) -- refill slot unified_inventory.refill = minetest.create_detached_inventory(player_name.."refill", { @@ -93,7 +93,6 @@ unified_inventory.refill = minetest.create_detached_inventory(player_name.."refi end, }) unified_inventory.refill:set_size("main", 1) -end) -- trash slot unified_inventory.trash = minetest.create_detached_inventory("trash", { @@ -111,24 +110,18 @@ unified_inventory.trash = minetest.create_detached_inventory("trash", { end, }) unified_inventory.trash:set_size("main", 1) +end) -- set_inventory_formspec unified_inventory.set_inventory_formspec = function(player,formspec) if player then - if minetest.setting_getbool("creative_mode") then - -- if creative mode is on then wait a bit - minetest.after(0.01,function() - player:set_inventory_formspec(formspec) - end) - else player:set_inventory_formspec(formspec) - end end end -- get_formspec unified_inventory.get_formspec = function(player,page) - if player==nil then return "" end + if player==nil then return "" end local player_name = player:get_player_name() unified_inventory.current_page[player_name]=page -- cgit v1.2.3 From 0d81a3f42a96378ab0fa4d34737ad99de19b2f66 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Sat, 25 May 2013 23:00:12 +0200 Subject: Bugfix --- item_drop/init.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/item_drop/init.lua b/item_drop/init.lua index db1f2a3..54b617f 100644 --- a/item_drop/init.lua +++ b/item_drop/init.lua @@ -4,6 +4,7 @@ time_pick = 3 if technic.config:getBool("enable_item_pickup") then minetest.register_globalstep(function(dtime) for _,player in ipairs(minetest.get_connected_players()) do + if player and player:get_hp() > 0 then local pos = player:getpos() pos.y = pos.y+0.5 local inv = player:get_inventory() @@ -26,6 +27,7 @@ if technic.config:getBool("enable_item_pickup") then end end end + end end end) end -- cgit v1.2.3 From 77254735e4a533bcce90e579f56fbae2c3c34359 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Wed, 29 May 2013 03:59:25 +0200 Subject: Make treetap work with moretrees rubber tree. Add moretrees as dependency --- technic/depends.txt | 1 + technic/tree_tap.lua | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/technic/depends.txt b/technic/depends.txt index 3859f8a..7d2e8c3 100644 --- a/technic/depends.txt +++ b/technic/depends.txt @@ -2,3 +2,4 @@ default moreores pipeworks mesecons +moretrees diff --git a/technic/tree_tap.lua b/technic/tree_tap.lua index 107faed..9d805d5 100644 --- a/technic/tree_tap.lua +++ b/technic/tree_tap.lua @@ -7,7 +7,8 @@ local pos=minetest.get_pointed_thing_position(pointed_thing,above) local node=minetest.env:get_node(pos) local node_name=node.name - if node_name == "farming_plus:rubber_tree_full" or node_name == "farming:rubber_tree_full" or node_name == "technic:rubber_tree_full" then + if node_name == "moretrees:rubber_tree_trunk" then + node.name = "moretrees:rubber_tree_trunk_empty" user:get_inventory():add_item("main",ItemStack("technic:raw_latex")) minetest.env:set_node(pos,node) local item=itemstack:to_table() @@ -47,3 +48,13 @@ description = "Rubber Fiber", inventory_image = "technic_rubber.png", }) + +minetest.register_abm({ + nodenames = {"moretrees:rubber_tree_trunk_empty"}, + interval = 60, + chance = 15, + action = function(pos, node) + node.name = "moretrees:rubber_tree_trunk" + minetest.env:set_node(pos, node) + end +}) -- cgit v1.2.3 From 7d890428f547758ffd907252b2effb1d743c02e4 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Thu, 30 May 2013 06:01:01 +0200 Subject: HV Battery Box textures added --- technic/textures/technic_hv_battery_box_bottom.png | Bin 0 -> 653 bytes technic/textures/technic_hv_battery_box_side0.png | Bin 0 -> 777 bytes technic/textures/technic_hv_battery_box_top.png | Bin 0 -> 792 bytes 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 technic/textures/technic_hv_battery_box_bottom.png create mode 100644 technic/textures/technic_hv_battery_box_side0.png create mode 100644 technic/textures/technic_hv_battery_box_top.png diff --git a/technic/textures/technic_hv_battery_box_bottom.png b/technic/textures/technic_hv_battery_box_bottom.png new file mode 100644 index 0000000..996b2d4 Binary files /dev/null and b/technic/textures/technic_hv_battery_box_bottom.png differ diff --git a/technic/textures/technic_hv_battery_box_side0.png b/technic/textures/technic_hv_battery_box_side0.png new file mode 100644 index 0000000..fffd8ea Binary files /dev/null and b/technic/textures/technic_hv_battery_box_side0.png differ diff --git a/technic/textures/technic_hv_battery_box_top.png b/technic/textures/technic_hv_battery_box_top.png new file mode 100644 index 0000000..49dee71 Binary files /dev/null and b/technic/textures/technic_hv_battery_box_top.png differ -- cgit v1.2.3 From ede3978965790f9683b96d12fc0bf80ba30824cd Mon Sep 17 00:00:00 2001 From: kpoppel Date: Mon, 3 Jun 2013 23:37:04 +0200 Subject: Added solar arrays for all voltage tiers. Added transformers for all voltage tiers. I changed the recipes for solar panels to make them less expensive. I also changed the output of the individual panel and made the arrays provie the real "oomph" :-) Solar panels and arrays are dependent on light level, time of day and height abive ground (0) for output and cheating with torches and stuff. Textures added. Fixed bugs in the hv battery box. It was not working at all. I don't understand the hv box top texture though??? I have a sense that all machines connected to the battery boxes are taking the same amount of juice from the box. A method of taking a little or a lot would be nice. --- technic/alloy_furnaces_commons.lua | 2 +- technic/battery_box_hv.lua | 6 +- technic/init.lua | 4 +- technic/items.lua | 30 +++++++ technic/solar_array_hv.lua | 93 ++++++++++++++++++++ technic/solar_array_lv.lua | 94 +++++++++++++++++++++ technic/solar_array_mv.lua | 94 +++++++++++++++++++++ technic/solar_panel.lua | 37 +++++--- technic/textures/technic_hv_solar_array_bottom.png | Bin 0 -> 574 bytes technic/textures/technic_hv_solar_array_side.png | Bin 0 -> 709 bytes technic/textures/technic_hv_solar_array_top.png | Bin 0 -> 777 bytes technic/textures/technic_hv_transformer.png | Bin 0 -> 1801 bytes technic/textures/technic_lv_solar_array_bottom.png | Bin 0 -> 579 bytes technic/textures/technic_lv_solar_array_side.png | Bin 0 -> 465 bytes technic/textures/technic_lv_solar_array_top.png | Bin 0 -> 743 bytes technic/textures/technic_lv_transformer.png | Bin 0 -> 1821 bytes technic/textures/technic_mv_solar_array_bottom.png | Bin 0 -> 574 bytes technic/textures/technic_mv_solar_array_side.png | Bin 0 -> 628 bytes technic/textures/technic_mv_solar_array_top.png | Bin 0 -> 728 bytes .../technicx32/technic_hv_solar_array_bottom.png | Bin 0 -> 2019 bytes .../technicx32/technic_hv_solar_array_side.png | Bin 0 -> 1772 bytes .../technicx32/technic_hv_solar_array_top.png | Bin 0 -> 2855 bytes .../textures/technicx32/technic_hv_transformer.png | Bin 0 -> 1789 bytes .../technicx32/technic_lv_solar_array_bottom.png | Bin 0 -> 2019 bytes .../technicx32/technic_lv_solar_array_side.png | Bin 0 -> 1772 bytes .../technicx32/technic_lv_solar_array_top.png | Bin 0 -> 2728 bytes .../textures/technicx32/technic_lv_transformer.png | Bin 0 -> 1809 bytes .../technicx32/technic_mv_solar_array_bottom.png | Bin 0 -> 2019 bytes .../technicx32/technic_mv_solar_array_side.png | Bin 0 -> 1772 bytes .../technicx32/technic_mv_solar_array_top.png | Bin 0 -> 2784 bytes 30 files changed, 343 insertions(+), 17 deletions(-) create mode 100644 technic/solar_array_hv.lua create mode 100644 technic/solar_array_lv.lua create mode 100644 technic/solar_array_mv.lua create mode 100644 technic/textures/technic_hv_solar_array_bottom.png create mode 100644 technic/textures/technic_hv_solar_array_side.png create mode 100644 technic/textures/technic_hv_solar_array_top.png create mode 100644 technic/textures/technic_hv_transformer.png create mode 100644 technic/textures/technic_lv_solar_array_bottom.png create mode 100644 technic/textures/technic_lv_solar_array_side.png create mode 100644 technic/textures/technic_lv_solar_array_top.png create mode 100644 technic/textures/technic_lv_transformer.png create mode 100644 technic/textures/technic_mv_solar_array_bottom.png create mode 100644 technic/textures/technic_mv_solar_array_side.png create mode 100644 technic/textures/technic_mv_solar_array_top.png create mode 100644 technic/textures/technicx32/technic_hv_solar_array_bottom.png create mode 100644 technic/textures/technicx32/technic_hv_solar_array_side.png create mode 100644 technic/textures/technicx32/technic_hv_solar_array_top.png create mode 100644 technic/textures/technicx32/technic_hv_transformer.png create mode 100644 technic/textures/technicx32/technic_lv_solar_array_bottom.png create mode 100644 technic/textures/technicx32/technic_lv_solar_array_side.png create mode 100644 technic/textures/technicx32/technic_lv_solar_array_top.png create mode 100644 technic/textures/technicx32/technic_lv_transformer.png create mode 100644 technic/textures/technicx32/technic_mv_solar_array_bottom.png create mode 100644 technic/textures/technicx32/technic_mv_solar_array_side.png create mode 100644 technic/textures/technicx32/technic_mv_solar_array_top.png diff --git a/technic/alloy_furnaces_commons.lua b/technic/alloy_furnaces_commons.lua index 559d002..9c9c42a 100644 --- a/technic/alloy_furnaces_commons.lua +++ b/technic/alloy_furnaces_commons.lua @@ -36,4 +36,4 @@ register_alloy_recipe ("default:steel_ingot",3, "technic:chromium_ingot",1, "tec register_alloy_recipe ("technic:copper_dust",2, "technic:zinc_dust",1, "technic:brass_dust",3) register_alloy_recipe ("moreores:copper_ingot",2, "technic:zinc_ingot",1, "technic:brass_ingot",3) register_alloy_recipe ("default:sand",2, "technic:coal_dust",2, "technic:silicon_wafer",1) -register_alloy_recipe ("technic:silicon_wafer",1, "technic:mithril_dust",1, "technic:doped_silicon_wafer",1) +register_alloy_recipe ("technic:silicon_wafer",1, "technic:gold_dust",1, "technic:doped_silicon_wafer",1) diff --git a/technic/battery_box_hv.lua b/technic/battery_box_hv.lua index 05166eb..e565d4c 100644 --- a/technic/battery_box_hv.lua +++ b/technic/battery_box_hv.lua @@ -13,7 +13,7 @@ minetest.register_craft({ output = 'technic:hv_battery_box 1', recipe = { {'technic:mv_battery_box', 'technic:mv_battery_box', 'mv_technic:battery_box'}, - {'technic:mv_battery_box', 'technic:transformer', 'mv_technic:battery_box'}, + {'technic:mv_battery_box', 'technic:hv_transformer', 'mv_technic:battery_box'}, {'', 'technic:hv_cable', ''}, } }) @@ -78,7 +78,7 @@ minetest.register_node("technic:hv_battery_box"..i, { drop="technic:hv_battery_box", on_construct = function(pos) local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "hv Battery box") + meta:set_string("infotext", "HV Battery box") meta:set_float("technic_hv_power_machine", 1) meta:set_string("formspec", battery_box_formspec) local inv = meta:get_inventory() @@ -342,7 +342,7 @@ end function check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) meta = minetest.env:get_meta(pos1) -if meta:get_float("HV_cablelike")==1 then new_node_added=add_new_HVcable_node(HV_nodes,pos1) end +if meta:get_float("hv_cablelike")==1 then new_node_added=add_new_HVcable_node(HV_nodes,pos1) end for i in ipairs(HV_machines) do if minetest.env:get_node(pos1).name == HV_machines[i].machine_name then if HV_machines[i].machine_type == "PR" then diff --git a/technic/init.lua b/technic/init.lua index eabf48e..3cc73be 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -20,6 +20,7 @@ dofile(modpath.."/battery_box.lua") dofile(modpath.."/alloy_furnaces_commons.lua") dofile(modpath.."/alloy_furnace.lua") dofile(modpath.."/solar_panel.lua") +dofile(modpath.."/solar_array_lv.lua") dofile(modpath.."/geothermal.lua") dofile(modpath.."/water_mill.lua") dofile(modpath.."/electric_furnace.lua") @@ -34,7 +35,7 @@ dofile(modpath.."/cnc_nodes.lua") --MV machines dofile(modpath.."/wires_mv.lua") dofile(modpath.."/battery_box_mv.lua") -dofile(modpath.."/solar_panel_mv.lua") +dofile(modpath.."/solar_array_mv.lua") dofile(modpath.."/electric_furnace_mv.lua") dofile(modpath.."/alloy_furnace_mv.lua") dofile(modpath.."/forcefield.lua") @@ -42,6 +43,7 @@ dofile(modpath.."/forcefield.lua") --HV machines dofile(modpath.."/wires_hv.lua") dofile(modpath.."/battery_box_hv.lua") +dofile(modpath.."/solar_array_hv.lua") --Tools if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end diff --git a/technic/items.lua b/technic/items.lua index 7d18570..66c5c85 100644 --- a/technic/items.lua +++ b/technic/items.lua @@ -160,6 +160,21 @@ minetest.register_craft({ } }) +minetest.register_craftitem( "technic:lv_transformer", { + description = "Low Voltage Transformer", + inventory_image = "technic_lv_transformer.png", + on_place_on_ground = minetest.craftitem_place_item, +}) + +minetest.register_craft({ + output = 'technic:lv_transformer', + recipe = { + {'default:iron_lump', 'default:iron_lump', 'default:iron_lump'}, + {'technic:copper_coil', 'default:iron_lump', 'technic:copper_coil'}, + {'default:iron_lump', 'default:iron_lump', 'default:iron_lump'}, + } +}) + minetest.register_craftitem( "technic:mv_transformer", { description = "Medium Voltage Transformer", inventory_image = "technic_mv_transformer.png", @@ -175,6 +190,21 @@ minetest.register_craft({ } }) +minetest.register_craftitem( "technic:hv_transformer", { + description = "High Voltage Transformer", + inventory_image = "technic_hv_transformer.png", + on_place_on_ground = minetest.craftitem_place_item, +}) + +minetest.register_craft({ + output = 'technic:hv_transformer', + recipe = { + {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'}, + {'technic:copper_coil', 'technic:stainless_steel_ingot', 'technic:copper_coil'}, + {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'}, + } +}) + minetest.register_craftitem( "technic:control_logic_unit", { description = "Control Logic Unit", inventory_image = "technic_control_logic_unit.png", diff --git a/technic/solar_array_hv.lua b/technic/solar_array_hv.lua new file mode 100644 index 0000000..89f5d1b --- /dev/null +++ b/technic/solar_array_hv.lua @@ -0,0 +1,93 @@ +-- The high voltage solar array is an assembly of medium voltage arrays. +-- The assembly can deliver high voltage levels and is a 20% less efficient +-- compared to 5 individual medium voltage arrays due to losses in the transformer. +-- However high voltage is supplied. +-- Solar arrays are not able to store large amounts of energy. +minetest.register_node("technic:solar_array_hv", { + tiles = {"technic_hv_solar_array_top.png", "technic_hv_solar_array_bottom.png", "technic_hv_solar_array_side.png", + "technic_hv_solar_array_side.png", "technic_hv_solar_array_side.png", "technic_hv_solar_array_side.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + description="HV Solar Array", + active = false, + technic_hv_power_machine=1, + internal_EU_buffer=0; + internal_EU_buffer_size=3000; + drawtype = "nodebox", + paramtype = "light", + is_ground_content = true, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_float("technic_hv_power_machine", 1) + meta:set_float("internal_EU_buffer", 0) + meta:set_float("internal_EU_buffer_size", 3000) + + meta:set_string("infotext", "HV Solar Array") + meta:set_float("active", false) + end, +}) + +minetest.register_craft({ + output = 'technic:solar_array_hv 1', + recipe = { + {'technic:solar_array_mv', 'technic:solar_array_mv','technic:solar_array_mv'}, + {'technic:solar_array_mv', 'technic:hv_transformer','technic:solar_array_mv'}, + {'', 'technic:hv_cable',''}, + + } +}) + +minetest.register_abm( + {nodenames = {"technic:solar_array_hv"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + -- The action here is to make the solar array produce power + -- Power is dependent on the light level and the height above ground + -- 130m and above is optimal as it would be above cloud level. + -- Height gives 1/4 of the effect, light 3/4. Max. effect is 2880EU for the array. + -- There are many ways to cheat by using other light sources like lamps. + -- As there is no way to determine if light is sunlight that is just a shame. + -- To take care of some of it solar panels do not work outside daylight hours or if + -- built below -10m + local pos1={} + pos1.y=pos.y+1 + pos1.x=pos.x + pos1.z=pos.z + + local light = minetest.env:get_node_light(pos1, nil) + local time_of_day = minetest.env:get_timeofday() + local meta = minetest.env:get_meta(pos) + if light == nil then light = 0 end + -- turn on array only during day time and if sufficient light + -- I know this is counter intuitive when cheating by using other light sources. + if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then + local internal_EU_buffer = meta:get_float("internal_EU_buffer") + local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size") + local charge_to_give = math.floor(light*(light*9.6+pos1.y/130*48)) + if charge_to_give<0 then charge_to_give=0 end + if charge_to_give>2880 then charge_to_give=2880 end + if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then + charge_to_give=internal_EU_buffer_size-internal_EU_buffer + end + meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)") + meta:set_float("active",1) + internal_EU_buffer=internal_EU_buffer+charge_to_give + meta:set_float("internal_EU_buffer",internal_EU_buffer) + + else + meta:set_string("infotext", "Solar Array is inactive"); + meta:set_float("active",0) + end + end, +}) + +register_HV_machine ("technic:solar_array_hv","PR") diff --git a/technic/solar_array_lv.lua b/technic/solar_array_lv.lua new file mode 100644 index 0000000..f657814 --- /dev/null +++ b/technic/solar_array_lv.lua @@ -0,0 +1,94 @@ +-- The solar array is an assembly of panels into a powerful array +-- The assembly can deliver more energy than the individual panel because +-- of the transformer unit which converts the panel output variations into +-- a stable supply. +-- Solar arrays are not able to store large amounts of energy. +-- The LV arrays are used to make medium voltage arrays. +minetest.register_node("technic:solar_array_lv", { + tiles = {"technic_lv_solar_array_top.png", "technic_lv_solar_array_bottom.png", "technic_lv_solar_array_side.png", + "technic_lv_solar_array_side.png", "technic_lv_solar_array_side.png", "technic_lv_solar_array_side.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + description="LV Solar Array", + active = false, + technic_power_machine=1, + internal_EU_buffer=0; + internal_EU_buffer_size=1000; + drawtype = "nodebox", + paramtype = "light", + is_ground_content = true, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_float("technic_power_machine", 1) + meta:set_float("internal_EU_buffer", 0) + meta:set_float("internal_EU_buffer_size", 1000) + + meta:set_string("infotext", "LV Solar Array") + meta:set_float("active", false) + end, +}) + +minetest.register_craft({ + output = 'technic:solar_array_lv 1', + recipe = { + {'technic:solar_panel', 'technic:solar_panel', 'technic:solar_panel'}, + {'technic:solar_panel', 'technic:lv_transformer', 'technic:solar_panel'}, + {'default:steel_ingot', 'technic:lv_cable', 'default:steel_ingot'}, + + } +}) + +minetest.register_abm( + {nodenames = {"technic:solar_array_lv"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + -- The action here is to make the solar array produce power + -- Power is dependent on the light level and the height above ground + -- 130m and above is optimal as it would be above cloud level. + -- Height gives 1/4 of the effect, light 3/4. Max. effect is 160EU for the array. + -- There are many ways to cheat by using other light sources like lamps. + -- As there is no way to determine if light is sunlight that is just a shame. + -- To take care of some of it solar arrays do not work outside daylight hours or if + -- built below -10m + local pos1={} + pos1.y=pos.y+1 + pos1.x=pos.x + pos1.z=pos.z + + local light = minetest.env:get_node_light(pos1, nil) + local time_of_day = minetest.env:get_timeofday() + local meta = minetest.env:get_meta(pos) + if light == nil then light = 0 end + -- turn on array only during day time and if sufficient light + -- I know this is counter intuitive when cheating by using other light sources. + if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then + local internal_EU_buffer = meta:get_float("internal_EU_buffer") + local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size") + local charge_to_give = math.floor(light*(light*0.5333+pos1.y/130*2.6667)) + if charge_to_give<0 then charge_to_give=0 end + if charge_to_give>160 then charge_to_give=160 end + if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then + charge_to_give=internal_EU_buffer_size-internal_EU_buffer + end + meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)") + meta:set_float("active",1) + internal_EU_buffer=internal_EU_buffer+charge_to_give + meta:set_float("internal_EU_buffer",internal_EU_buffer) + + else + meta:set_string("infotext", "Solar Array is inactive"); + meta:set_float("active",0) + end + end, +}) + +register_LV_machine ("technic:solar_array_lv","PR") diff --git a/technic/solar_array_mv.lua b/technic/solar_array_mv.lua new file mode 100644 index 0000000..73fe85a --- /dev/null +++ b/technic/solar_array_mv.lua @@ -0,0 +1,94 @@ +-- The medium voltage solar array is an assembly of low voltage arrays. +-- The assembly can deliver medium voltage levels and is a 10% less efficient +-- compared to 5 individual low voltage arrays due to losses in the transformer. +-- However medium voltage is supplied. +-- Solar arrays are not able to store large amounts of energy. +-- The MV arrays are used to make high voltage arrays. +minetest.register_node("technic:solar_array_mv", { + tiles = {"technic_mv_solar_array_top.png", "technic_mv_solar_array_bottom.png", "technic_mv_solar_array_side.png", + "technic_mv_solar_array_side.png", "technic_mv_solar_array_side.png", "technic_mv_solar_array_side.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + description="MV Solar Array", + active = false, + technic_mv_power_machine=1, + internal_EU_buffer=0; + internal_EU_buffer_size=1000; + drawtype = "nodebox", + paramtype = "light", + is_ground_content = true, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_float("technic_mv_power_machine", 1) + meta:set_float("internal_EU_buffer", 0) + meta:set_float("internal_EU_buffer_size", 1000) + + meta:set_string("infotext", "MV Solar Array") + meta:set_float("active", false) + end, +}) + +minetest.register_craft({ + output = 'technic:solar_array_mv 1', + recipe = { + {'technic:solar_array_lv', 'technic:solar_array_lv','technic:solar_array_lv'}, + {'technic:solar_array_lv', 'technic:mv_transformer','technic:solar_array_lv'}, + {'', 'technic:mv_cable',''}, + + } +}) + +minetest.register_abm( + {nodenames = {"technic:solar_array_mv"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + -- The action here is to make the solar array produce power + -- Power is dependent on the light level and the height above ground + -- 130m and above is optimal as it would be above cloud level. + -- Height gives 1/4 of the effect, light 3/4. Max. effect is 720EU for the array. + -- There are many ways to cheat by using other light sources like lamps. + -- As there is no way to determine if light is sunlight that is just a shame. + -- To take care of some of it solar panels do not work outside daylight hours or if + -- built below -10m + local pos1={} + pos1.y=pos.y+1 + pos1.x=pos.x + pos1.z=pos.z + + local light = minetest.env:get_node_light(pos1, nil) + local time_of_day = minetest.env:get_timeofday() + local meta = minetest.env:get_meta(pos) + if light == nil then light = 0 end + -- turn on array only during day time and if sufficient light + -- I know this is counter intuitive when cheating by using other light sources. + if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then + local internal_EU_buffer = meta:get_float("internal_EU_buffer") + local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size") + local charge_to_give = math.floor(light*(light*2.4+pos1.y/130*12)) + if charge_to_give<0 then charge_to_give=0 end + if charge_to_give>720 then charge_to_give=720 end + if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then + charge_to_give=internal_EU_buffer_size-internal_EU_buffer + end + meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)") + meta:set_float("active",1) + internal_EU_buffer=internal_EU_buffer+charge_to_give + meta:set_float("internal_EU_buffer",internal_EU_buffer) + + else + meta:set_string("infotext", "Solar Array is inactive"); + meta:set_float("active",0) + end + end, +}) + +register_MV_machine ("technic:solar_array_mv","PR") diff --git a/technic/solar_panel.lua b/technic/solar_panel.lua index 93f2b63..5b53f5f 100644 --- a/technic/solar_panel.lua +++ b/technic/solar_panel.lua @@ -1,3 +1,6 @@ +-- Solar panels are the building blocks of LV solar arrays +-- They can however also be used separately but with reduced efficiency due to the missing transformer. +-- Individual panels are 20% less efficient than when the panels are combined into full arrays. minetest.register_node("technic:solar_panel", { tiles = {"technic_solar_panel_top.png", "technic_solar_panel_bottom.png", "technic_solar_panel_side.png", "technic_solar_panel_side.png", "technic_solar_panel_side.png", "technic_solar_panel_side.png"}, @@ -7,7 +10,7 @@ minetest.register_node("technic:solar_panel", { active = false, technic_power_machine=1, internal_EU_buffer=0; - internal_EU_buffer_size=1000; + internal_EU_buffer_size=160; drawtype = "nodebox", paramtype = "light", is_ground_content = true, @@ -23,7 +26,7 @@ minetest.register_node("technic:solar_panel", { local meta = minetest.env:get_meta(pos) meta:set_float("technic_power_machine", 1) meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 1000) + meta:set_float("internal_EU_buffer_size", 160) meta:set_string("infotext", "Solar Panel") meta:set_float("active", false) @@ -34,7 +37,7 @@ minetest.register_craft({ output = 'technic:solar_panel 1', recipe = { {'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'}, - {'technic:doped_silicon_wafer', 'moreores:copper_ingot','technic:doped_silicon_wafer'}, + {'technic:doped_silicon_wafer', 'technic:lv_cable', 'technic:doped_silicon_wafer'}, {'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'}, } @@ -42,29 +45,39 @@ minetest.register_craft({ minetest.register_abm( {nodenames = {"technic:solar_panel"}, - interval = 1, - chance = 1, + interval = 1, + chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - + -- The action here is to make the solar panel prodice power + -- Power is dependent on the light level and the height above ground + -- 130m and above is optimal as it would be above cloud level. + -- Height gives 1/4 of the effect, light 3/4. Max. effect is 26EU. + -- There are many ways to cheat by using other light sources like lamps. + -- As there is no way to determine if light is sunlight that is just a shame. + -- To take care of some of it solar panels do not work outside daylight hours or if + -- built below -10m local pos1={} pos1.y=pos.y+1 pos1.x=pos.x pos1.z=pos.z local light = minetest.env:get_node_light(pos1, nil) + local time_of_day = minetest.env:get_timeofday() local meta = minetest.env:get_meta(pos) if light == nil then light = 0 end - if light >= 12 then - meta:set_string("infotext", "Solar Panel is active ") - meta:set_float("active",1) + -- turn on panel only during day time and if sufficient light + -- I know this is counter intuitive when cheating by using other light sources underground. + if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then local internal_EU_buffer=meta:get_float("internal_EU_buffer") local internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size") - local charge_to_give=40+(pos1.y/250*40) -- make solar energy depending on height + local charge_to_give=math.floor(light*(light*0.0867+pos1.y/130*0.4333)) if charge_to_give<0 then charge_to_give=0 end - if charge_to_give>160 then charge_to_give=160 end + if charge_to_give>26 then charge_to_give=26 end if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer + charge_to_give=internal_EU_buffer_size-internal_EU_buffer end + meta:set_string("infotext", "Solar Panel is active ("..charge_to_give.."EU)") + meta:set_float("active",1) internal_EU_buffer=internal_EU_buffer+charge_to_give meta:set_float("internal_EU_buffer",internal_EU_buffer) diff --git a/technic/textures/technic_hv_solar_array_bottom.png b/technic/textures/technic_hv_solar_array_bottom.png new file mode 100644 index 0000000..596e79a Binary files /dev/null and b/technic/textures/technic_hv_solar_array_bottom.png differ diff --git a/technic/textures/technic_hv_solar_array_side.png b/technic/textures/technic_hv_solar_array_side.png new file mode 100644 index 0000000..a3aa8c7 Binary files /dev/null and b/technic/textures/technic_hv_solar_array_side.png differ diff --git a/technic/textures/technic_hv_solar_array_top.png b/technic/textures/technic_hv_solar_array_top.png new file mode 100644 index 0000000..b7f0b43 Binary files /dev/null and b/technic/textures/technic_hv_solar_array_top.png differ diff --git a/technic/textures/technic_hv_transformer.png b/technic/textures/technic_hv_transformer.png new file mode 100644 index 0000000..e1d4c98 Binary files /dev/null and b/technic/textures/technic_hv_transformer.png differ diff --git a/technic/textures/technic_lv_solar_array_bottom.png b/technic/textures/technic_lv_solar_array_bottom.png new file mode 100644 index 0000000..9e888e3 Binary files /dev/null and b/technic/textures/technic_lv_solar_array_bottom.png differ diff --git a/technic/textures/technic_lv_solar_array_side.png b/technic/textures/technic_lv_solar_array_side.png new file mode 100644 index 0000000..b22447e Binary files /dev/null and b/technic/textures/technic_lv_solar_array_side.png differ diff --git a/technic/textures/technic_lv_solar_array_top.png b/technic/textures/technic_lv_solar_array_top.png new file mode 100644 index 0000000..cabd315 Binary files /dev/null and b/technic/textures/technic_lv_solar_array_top.png differ diff --git a/technic/textures/technic_lv_transformer.png b/technic/textures/technic_lv_transformer.png new file mode 100644 index 0000000..613b196 Binary files /dev/null and b/technic/textures/technic_lv_transformer.png differ diff --git a/technic/textures/technic_mv_solar_array_bottom.png b/technic/textures/technic_mv_solar_array_bottom.png new file mode 100644 index 0000000..596e79a Binary files /dev/null and b/technic/textures/technic_mv_solar_array_bottom.png differ diff --git a/technic/textures/technic_mv_solar_array_side.png b/technic/textures/technic_mv_solar_array_side.png new file mode 100644 index 0000000..917b9ed Binary files /dev/null and b/technic/textures/technic_mv_solar_array_side.png differ diff --git a/technic/textures/technic_mv_solar_array_top.png b/technic/textures/technic_mv_solar_array_top.png new file mode 100644 index 0000000..cdb7cf7 Binary files /dev/null and b/technic/textures/technic_mv_solar_array_top.png differ diff --git a/technic/textures/technicx32/technic_hv_solar_array_bottom.png b/technic/textures/technicx32/technic_hv_solar_array_bottom.png new file mode 100644 index 0000000..94c8222 Binary files /dev/null and b/technic/textures/technicx32/technic_hv_solar_array_bottom.png differ diff --git a/technic/textures/technicx32/technic_hv_solar_array_side.png b/technic/textures/technicx32/technic_hv_solar_array_side.png new file mode 100644 index 0000000..d39d3d8 Binary files /dev/null and b/technic/textures/technicx32/technic_hv_solar_array_side.png differ diff --git a/technic/textures/technicx32/technic_hv_solar_array_top.png b/technic/textures/technicx32/technic_hv_solar_array_top.png new file mode 100644 index 0000000..3e1b9e0 Binary files /dev/null and b/technic/textures/technicx32/technic_hv_solar_array_top.png differ diff --git a/technic/textures/technicx32/technic_hv_transformer.png b/technic/textures/technicx32/technic_hv_transformer.png new file mode 100644 index 0000000..7794644 Binary files /dev/null and b/technic/textures/technicx32/technic_hv_transformer.png differ diff --git a/technic/textures/technicx32/technic_lv_solar_array_bottom.png b/technic/textures/technicx32/technic_lv_solar_array_bottom.png new file mode 100644 index 0000000..94c8222 Binary files /dev/null and b/technic/textures/technicx32/technic_lv_solar_array_bottom.png differ diff --git a/technic/textures/technicx32/technic_lv_solar_array_side.png b/technic/textures/technicx32/technic_lv_solar_array_side.png new file mode 100644 index 0000000..d39d3d8 Binary files /dev/null and b/technic/textures/technicx32/technic_lv_solar_array_side.png differ diff --git a/technic/textures/technicx32/technic_lv_solar_array_top.png b/technic/textures/technicx32/technic_lv_solar_array_top.png new file mode 100644 index 0000000..3d8c7ab Binary files /dev/null and b/technic/textures/technicx32/technic_lv_solar_array_top.png differ diff --git a/technic/textures/technicx32/technic_lv_transformer.png b/technic/textures/technicx32/technic_lv_transformer.png new file mode 100644 index 0000000..99ac927 Binary files /dev/null and b/technic/textures/technicx32/technic_lv_transformer.png differ diff --git a/technic/textures/technicx32/technic_mv_solar_array_bottom.png b/technic/textures/technicx32/technic_mv_solar_array_bottom.png new file mode 100644 index 0000000..94c8222 Binary files /dev/null and b/technic/textures/technicx32/technic_mv_solar_array_bottom.png differ diff --git a/technic/textures/technicx32/technic_mv_solar_array_side.png b/technic/textures/technicx32/technic_mv_solar_array_side.png new file mode 100644 index 0000000..d39d3d8 Binary files /dev/null and b/technic/textures/technicx32/technic_mv_solar_array_side.png differ diff --git a/technic/textures/technicx32/technic_mv_solar_array_top.png b/technic/textures/technicx32/technic_mv_solar_array_top.png new file mode 100644 index 0000000..e4999d5 Binary files /dev/null and b/technic/textures/technicx32/technic_mv_solar_array_top.png differ -- cgit v1.2.3 From 4f1a44a80b5522db60125f3018c0ce80fbb9e3b4 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Mon, 3 Jun 2013 23:42:44 +0200 Subject: Removing ununsed textures. Added more safety to item_drop to get around a fatal server halt issue. --- item_drop/item_entity.lua | 2 +- technic/solar_panel_mv.lua | 78 --------------------- technic/textures/technic_mv_solar_panel_bottom.png | Bin 574 -> 0 bytes technic/textures/technic_mv_solar_panel_side.png | Bin 628 -> 0 bytes technic/textures/technic_mv_solar_panel_top.png | Bin 728 -> 0 bytes technic/textures/technic_mv_solarpanel_bottom.png | Bin 574 -> 0 bytes technic/textures/technic_mv_solarpanel_side.png | Bin 628 -> 0 bytes technic/textures/technic_mv_solarpanel_top.png | Bin 728 -> 0 bytes .../technicx32/technic_mv_solar_panel_bottom.png | Bin 2019 -> 0 bytes .../technicx32/technic_mv_solar_panel_side.png | Bin 1772 -> 0 bytes .../technicx32/technic_mv_solar_panel_top.png | Bin 2728 -> 0 bytes 11 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 technic/solar_panel_mv.lua delete mode 100644 technic/textures/technic_mv_solar_panel_bottom.png delete mode 100644 technic/textures/technic_mv_solar_panel_side.png delete mode 100644 technic/textures/technic_mv_solar_panel_top.png delete mode 100644 technic/textures/technic_mv_solarpanel_bottom.png delete mode 100644 technic/textures/technic_mv_solarpanel_side.png delete mode 100644 technic/textures/technic_mv_solarpanel_top.png delete mode 100644 technic/textures/technicx32/technic_mv_solar_panel_bottom.png delete mode 100644 technic/textures/technicx32/technic_mv_solar_panel_side.png delete mode 100644 technic/textures/technicx32/technic_mv_solar_panel_top.png diff --git a/item_drop/item_entity.lua b/item_drop/item_entity.lua index 3d1a83b..5da8285 100644 --- a/item_drop/item_entity.lua +++ b/item_drop/item_entity.lua @@ -109,7 +109,7 @@ minetest.register_entity(":__builtin:item", { return end - if minetest.registered_nodes[name].liquidtype == "flowing" then + if minetest.registered_nodes[name] and minetest.registered_nodes[name].liquidtype == "flowing" then get_flowing_dir = function(self) local pos = self.object:getpos() local param2 = minetest.env:get_node(pos).param2 diff --git a/technic/solar_panel_mv.lua b/technic/solar_panel_mv.lua deleted file mode 100644 index 4deb42e..0000000 --- a/technic/solar_panel_mv.lua +++ /dev/null @@ -1,78 +0,0 @@ -minetest.register_node("technic:solar_panel_mv", { - tiles = {"technic_mv_solar_panel_top.png", "technic_mv_solar_panel_bottom.png", "technic_mv_solar_panel_side.png", - "technic_mv_solar_panel_side.png", "technic_mv_solar_panel_side.png", "technic_mv_solar_panel_side.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - sounds = default.node_sound_wood_defaults(), - description="MV Solar Panel", - active = false, - technic_mv_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=10000; - drawtype = "nodebox", - paramtype = "light", - is_ground_content = true, - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, - }, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, - }, - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_float("technic_mv_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 10000) - - meta:set_string("infotext", "MV Solar Panel") - meta:set_float("active", false) - end, -}) - -minetest.register_craft({ - output = 'technic:solar_panel_mv 1', - recipe = { - {'technic:solar_panel', 'technic:solar_panel','technic:solar_panel'}, - {'technic:solar_panel', 'technic:mv_transformer','technic:solar_panel'}, - {'', 'technic:mv_cable',''}, - - } -}) - -minetest.register_abm( - {nodenames = {"technic:solar_panel_mv"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - - local pos1={} - pos1.y=pos.y+1 - pos1.x=pos.x - pos1.z=pos.z - - local light = minetest.env:get_node_light(pos1, nil) - local meta = minetest.env:get_meta(pos) - if light == nil then light = 0 end - if light >= 14 then - meta:set_string("infotext", "Solar Panel is active ") - meta:set_float("active",1) - local internal_EU_buffer=meta:get_float("internal_EU_buffer") - local internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size") - local charge_to_give=300+(pos1.y/250*300) -- make solar energy depending on height - if charge_to_give<0 then charge_to_give=0 end - if charge_to_give>600 then charge_to_give=600 end - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta:set_float("internal_EU_buffer",internal_EU_buffer) - - else - meta:set_string("infotext", "Solar Panel is inactive"); - meta:set_float("active",0) - end - end, -}) - -register_MV_machine ("technic:solar_panel_mv","PR") diff --git a/technic/textures/technic_mv_solar_panel_bottom.png b/technic/textures/technic_mv_solar_panel_bottom.png deleted file mode 100644 index 596e79a..0000000 Binary files a/technic/textures/technic_mv_solar_panel_bottom.png and /dev/null differ diff --git a/technic/textures/technic_mv_solar_panel_side.png b/technic/textures/technic_mv_solar_panel_side.png deleted file mode 100644 index 917b9ed..0000000 Binary files a/technic/textures/technic_mv_solar_panel_side.png and /dev/null differ diff --git a/technic/textures/technic_mv_solar_panel_top.png b/technic/textures/technic_mv_solar_panel_top.png deleted file mode 100644 index cdb7cf7..0000000 Binary files a/technic/textures/technic_mv_solar_panel_top.png and /dev/null differ diff --git a/technic/textures/technic_mv_solarpanel_bottom.png b/technic/textures/technic_mv_solarpanel_bottom.png deleted file mode 100644 index 596e79a..0000000 Binary files a/technic/textures/technic_mv_solarpanel_bottom.png and /dev/null differ diff --git a/technic/textures/technic_mv_solarpanel_side.png b/technic/textures/technic_mv_solarpanel_side.png deleted file mode 100644 index 917b9ed..0000000 Binary files a/technic/textures/technic_mv_solarpanel_side.png and /dev/null differ diff --git a/technic/textures/technic_mv_solarpanel_top.png b/technic/textures/technic_mv_solarpanel_top.png deleted file mode 100644 index cdb7cf7..0000000 Binary files a/technic/textures/technic_mv_solarpanel_top.png and /dev/null differ diff --git a/technic/textures/technicx32/technic_mv_solar_panel_bottom.png b/technic/textures/technicx32/technic_mv_solar_panel_bottom.png deleted file mode 100644 index 94c8222..0000000 Binary files a/technic/textures/technicx32/technic_mv_solar_panel_bottom.png and /dev/null differ diff --git a/technic/textures/technicx32/technic_mv_solar_panel_side.png b/technic/textures/technicx32/technic_mv_solar_panel_side.png deleted file mode 100644 index d39d3d8..0000000 Binary files a/technic/textures/technicx32/technic_mv_solar_panel_side.png and /dev/null differ diff --git a/technic/textures/technicx32/technic_mv_solar_panel_top.png b/technic/textures/technicx32/technic_mv_solar_panel_top.png deleted file mode 100644 index 3d8c7ab..0000000 Binary files a/technic/textures/technicx32/technic_mv_solar_panel_top.png and /dev/null differ -- cgit v1.2.3 From be774436c14c781d6c5482d8b4436f7687ba4d2f Mon Sep 17 00:00:00 2001 From: kpoppel Date: Tue, 4 Jun 2013 00:05:07 +0200 Subject: Fix solr array recipes for hv and mv to match that of the lv array. --- technic/solar_array_hv.lua | 2 +- technic/solar_array_mv.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/technic/solar_array_hv.lua b/technic/solar_array_hv.lua index 89f5d1b..e159248 100644 --- a/technic/solar_array_hv.lua +++ b/technic/solar_array_hv.lua @@ -40,7 +40,7 @@ minetest.register_craft({ recipe = { {'technic:solar_array_mv', 'technic:solar_array_mv','technic:solar_array_mv'}, {'technic:solar_array_mv', 'technic:hv_transformer','technic:solar_array_mv'}, - {'', 'technic:hv_cable',''}, + {'default:steel_ingot', 'technic:hv_cable', 'default:steel_ingot'}, } }) diff --git a/technic/solar_array_mv.lua b/technic/solar_array_mv.lua index 73fe85a..de75301 100644 --- a/technic/solar_array_mv.lua +++ b/technic/solar_array_mv.lua @@ -41,7 +41,7 @@ minetest.register_craft({ recipe = { {'technic:solar_array_lv', 'technic:solar_array_lv','technic:solar_array_lv'}, {'technic:solar_array_lv', 'technic:mv_transformer','technic:solar_array_lv'}, - {'', 'technic:mv_cable',''}, + {'default:steel_ingot', 'technic:mv_cable', 'default:steel_ingot'}, } }) -- cgit v1.2.3 From 26c0bba1f2a31a1fc3f6148fc09fdc42d717ddf7 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Tue, 4 Jun 2013 23:36:07 +0200 Subject: Added ingot grinding for the type which already have a <>_dust in place. The default bronze_ingot does not have a dust item. --- technic/grinder.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/technic/grinder.lua b/technic/grinder.lua index b4dbd90..e89cb4c 100644 --- a/technic/grinder.lua +++ b/technic/grinder.lua @@ -22,14 +22,26 @@ register_grinder_recipe("default:cobble","default:gravel") register_grinder_recipe("default:gravel","default:dirt") register_grinder_recipe("default:desert_stone","default:desert_sand") register_grinder_recipe("default:iron_lump","technic:iron_dust 2") +register_grinder_recipe("default:steel_ingot","technic:iron_dust 2") register_grinder_recipe("default:coal_lump","technic:coal_dust 2") register_grinder_recipe("default:copper_lump","technic:copper_dust 2") +register_grinder_recipe("default:copper_ingot","technic:copper_dust 2") +register_grinder_recipe("default:gold_lump","technic:gold_dust 2") +register_grinder_recipe("default:gold_ingot","technic:gold_dust 2") +--register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 2") -- Dust does not exist yet +--register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 2") -- needs check for the mod register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2") +register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 2") register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2") -register_grinder_recipe("default:gold_lump","technic:gold_dust 2") +register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 2") register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2") +register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 2") register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2") +register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 2") +register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 2") +register_grinder_recipe("technic:brass_ingot","technic:brass_dust 2") register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2") +register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 2") register_grinder_recipe("technic:coal_dust","dye:black 2") register_grinder_recipe("default:cactus","dye:green 2") register_grinder_recipe("default:dry_shrub","dye:brown 2") -- cgit v1.2.3 From e62a0fd0c1fc92125b168dc08ff33298d04860b5 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Thu, 6 Jun 2013 22:46:40 +0200 Subject: Changed grinding of ingots to give 1 dust. This is to avoid duplication exploit. --- technic/grinder.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/technic/grinder.lua b/technic/grinder.lua index e89cb4c..b676bed 100644 --- a/technic/grinder.lua +++ b/technic/grinder.lua @@ -22,26 +22,26 @@ register_grinder_recipe("default:cobble","default:gravel") register_grinder_recipe("default:gravel","default:dirt") register_grinder_recipe("default:desert_stone","default:desert_sand") register_grinder_recipe("default:iron_lump","technic:iron_dust 2") -register_grinder_recipe("default:steel_ingot","technic:iron_dust 2") +register_grinder_recipe("default:steel_ingot","technic:iron_dust 1") register_grinder_recipe("default:coal_lump","technic:coal_dust 2") register_grinder_recipe("default:copper_lump","technic:copper_dust 2") -register_grinder_recipe("default:copper_ingot","technic:copper_dust 2") +register_grinder_recipe("default:copper_ingot","technic:copper_dust 1") register_grinder_recipe("default:gold_lump","technic:gold_dust 2") -register_grinder_recipe("default:gold_ingot","technic:gold_dust 2") ---register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 2") -- Dust does not exist yet ---register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 2") -- needs check for the mod +register_grinder_recipe("default:gold_ingot","technic:gold_dust 1") +--register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 1") -- Dust does not exist yet +--register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 1") -- needs check for the mod register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2") -register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 2") +register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 1") register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2") -register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 2") +register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 1") register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2") -register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 2") -register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2") -register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 2") -register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 2") -register_grinder_recipe("technic:brass_ingot","technic:brass_dust 2") +register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 1") +register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2") +register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 1") +register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 1") +register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1") register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2") -register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 2") +register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1") register_grinder_recipe("technic:coal_dust","dye:black 2") register_grinder_recipe("default:cactus","dye:green 2") register_grinder_recipe("default:dry_shrub","dye:brown 2") -- cgit v1.2.3 From 802db28dc397e5ceb9f543c8adbb4e451a65ec0e Mon Sep 17 00:00:00 2001 From: kpoppel Date: Thu, 6 Jun 2013 22:49:08 +0200 Subject: Whitespace cleanup --- technic/grinder.lua | 80 ++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/technic/grinder.lua b/technic/grinder.lua index b676bed..07baa05 100644 --- a/technic/grinder.lua +++ b/technic/grinder.lua @@ -21,36 +21,36 @@ register_grinder_recipe("default:stone","default:sand") register_grinder_recipe("default:cobble","default:gravel") register_grinder_recipe("default:gravel","default:dirt") register_grinder_recipe("default:desert_stone","default:desert_sand") -register_grinder_recipe("default:iron_lump","technic:iron_dust 2") -register_grinder_recipe("default:steel_ingot","technic:iron_dust 1") -register_grinder_recipe("default:coal_lump","technic:coal_dust 2") +register_grinder_recipe("default:iron_lump","technic:iron_dust 2") +register_grinder_recipe("default:steel_ingot","technic:iron_dust 1") +register_grinder_recipe("default:coal_lump","technic:coal_dust 2") register_grinder_recipe("default:copper_lump","technic:copper_dust 2") register_grinder_recipe("default:copper_ingot","technic:copper_dust 1") -register_grinder_recipe("default:gold_lump","technic:gold_dust 2") -register_grinder_recipe("default:gold_ingot","technic:gold_dust 1") +register_grinder_recipe("default:gold_lump","technic:gold_dust 2") +register_grinder_recipe("default:gold_ingot","technic:gold_dust 1") --register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 1") -- Dust does not exist yet --register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 1") -- needs check for the mod -register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2") -register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 1") +register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2") +register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 1") register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2") register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 1") -register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2") +register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2") register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 1") register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2") register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 1") -register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 1") -register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1") -register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2") -register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1") -register_grinder_recipe("technic:coal_dust","dye:black 2") -register_grinder_recipe("default:cactus","dye:green 2") -register_grinder_recipe("default:dry_shrub","dye:brown 2") -register_grinder_recipe("flowers:flower_geranium","dye:blue 2") -register_grinder_recipe("flowers:flower_dandelion_white","dye:white 2") -register_grinder_recipe("flowers:flower_dandelion_yellow","dye:yellow 2") -register_grinder_recipe("flowers:flower_tulip","dye:orange 2") -register_grinder_recipe("flowers:flower_rose","dye:red 2") -register_grinder_recipe("flowers:flower_viola","dye:violet 2") +register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 1") +register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1") +register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2") +register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1") +register_grinder_recipe("technic:coal_dust","dye:black 2") +register_grinder_recipe("default:cactus","dye:green 2") +register_grinder_recipe("default:dry_shrub","dye:brown 2") +register_grinder_recipe("flowers:flower_geranium","dye:blue 2") +register_grinder_recipe("flowers:flower_dandelion_white","dye:white 2") +register_grinder_recipe("flowers:flower_dandelion_yellow","dye:yellow 2") +register_grinder_recipe("flowers:flower_tulip","dye:orange 2") +register_grinder_recipe("flowers:flower_rose","dye:red 2") +register_grinder_recipe("flowers:flower_viola","dye:violet 2") minetest.register_craftitem( "technic:coal_dust", { description = "Coal Dust", @@ -68,7 +68,7 @@ minetest.register_craft({ type = "cooking", output = "default:steel_ingot", recipe = "technic:iron_dust", -}) +}) minetest.register_craftitem( "technic:copper_dust", { description = "Copper Dust", @@ -79,7 +79,7 @@ minetest.register_craft({ type = "cooking", output = "moreores:copper_ingot", recipe = "technic:copper_dust", -}) +}) minetest.register_craftitem( "technic:tin_dust", { description = "Tin Dust", @@ -90,7 +90,7 @@ minetest.register_craft({ type = "cooking", output = "moreores:tin_ingot", recipe = "technic:tin_dust", -}) +}) minetest.register_craftitem( "technic:silver_dust", { description = "Silver Dust", @@ -101,7 +101,7 @@ minetest.register_craft({ type = "cooking", output = "moreores:silver_ingot", recipe = "technic:silver_dust", -}) +}) minetest.register_craftitem( "technic:gold_dust", { description = "Gold Dust", @@ -112,7 +112,7 @@ minetest.register_craft({ type = "cooking", output = "moreores:gold_ingot", recipe = "technic:gold_dust", -}) +}) minetest.register_craftitem( "technic:mithril_dust", { description = "Mithril Dust", @@ -123,7 +123,7 @@ minetest.register_craft({ type = "cooking", output = "moreores:mithril_ingot", recipe = "technic:mithril_dust", -}) +}) minetest.register_craftitem( "technic:chromium_dust", { description = "Chromium Dust", @@ -134,7 +134,7 @@ minetest.register_craft({ type = "cooking", output = "technic:chromium_ingot", recipe = "technic:chromium_dust", -}) +}) minetest.register_craftitem( "technic:bronze_dust", { description = "Bronze Dust", @@ -145,7 +145,7 @@ minetest.register_craft({ type = "cooking", output = "moreores:bronze_ingot", recipe = "technic:bronze_dust", -}) +}) minetest.register_craftitem( "technic:brass_dust", { description = "Brass Dust", @@ -156,7 +156,7 @@ minetest.register_craft({ type = "cooking", output = "technic:brass_ingot", recipe = "technic:brass_dust", -}) +}) minetest.register_craftitem( "technic:stainless_steel_dust", { description = "Stainless Steel Dust", @@ -167,7 +167,7 @@ minetest.register_craft({ type = "cooking", output = "technic:stainless_steel_ingot", recipe = "technic:stainless_steel_dust", -}) +}) minetest.register_craftitem( "technic:zinc_dust", { description = "Zinc Dust", @@ -178,7 +178,7 @@ minetest.register_craft({ type = "cooking", output = "technic:zinc_ingot", recipe = "technic:zinc_dust", -}) +}) minetest.register_alias("grinder", "technic:grinder") minetest.register_craft({ @@ -193,7 +193,7 @@ minetest.register_craft({ minetest.register_craftitem("technic:grinder", { description = "Grinder", stack_max = 99, -}) +}) grinder_formspec = "invsize[8,9;]".. @@ -290,7 +290,7 @@ minetest.register_abm({ local inv = meta:get_inventory() local srclist = inv:get_list("src") - if inv:is_empty("src") then meta:set_float("grinder_on",0) end + if inv:is_empty("src") then meta:set_float("grinder_on",0) end if (meta:get_float("grinder_on") == 1) then if charge>=grind_cost then @@ -299,7 +299,7 @@ minetest.register_abm({ meta:set_float("src_time", meta:get_float("src_time") + 1) if meta:get_float("src_time") >= meta:get_float("grind_time") then -- check if there's room for output in "dst" list - grinded = get_grinded_item (inv:get_stack("src", 1)) + grinded = get_grinded_item (inv:get_stack("src", 1)) if inv:room_for_item("dst",grinded) then -- Put result in "dst" list inv:add_item("dst", grinded) @@ -307,7 +307,7 @@ minetest.register_abm({ srcstack = inv:get_stack("src", 1) srcstack:take_item() inv:set_stack("src", 1, srcstack) - if inv:is_empty("src") then meta:set_float("grinder_on",0) end + if inv:is_empty("src") then meta:set_float("grinder_on",0) end else print("Grinder inventory full!") end @@ -316,10 +316,10 @@ minetest.register_abm({ end end if (meta:get_float("grinder_on")==0) then - local grinded=nil + local grinded=nil if not inv:is_empty("src") then grinded = get_grinded_item (inv:get_stack("src", 1)) - if grinded then + if grinded then meta:set_float("grinder_on",1) hacky_swap_node(pos,"technic:grinder_active") meta:set_string("infotext", "Grinder Active") @@ -328,13 +328,13 @@ minetest.register_abm({ meta:set_float("src_time", 0) return end - else + else hacky_swap_node(pos,"technic:grinder") meta:set_string("infotext", "Grinder Inactive") end end end -}) +}) function get_grinded_item (items) new_item =nil -- cgit v1.2.3 From a27b59dde52eec754db6930b420e1493e16980b8 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Wed, 12 Jun 2013 22:08:23 +0200 Subject: Fix to the chainsaw. handle_node drops should no longer become nil. --- technic/chainsaw.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/technic/chainsaw.lua b/technic/chainsaw.lua index c31d9a8..5b3b05b 100644 --- a/technic/chainsaw.lua +++ b/technic/chainsaw.lua @@ -138,6 +138,13 @@ if( minetest.get_modpath("growing_cactus") ~= nil ) then timber_nodenames["growing_cactus:branch_xx"] = true end +-- Support farming_plus if it is there +if( minetest.get_modpath("farming_plus") ~= nil ) then + if chainsaw_leaves == true then + timber_nodenames["farming_plus:cocoa_leaves"] = true + end +end + -- Table for saving what was sawed down local produced @@ -145,6 +152,9 @@ local produced chainsaw_dig_it = function(pos, player,current_charge) local remaining_charge=current_charge + -- Save the currently installed dropping mechanism so we can restore it. + local original_handle_node_drops = minetest.handle_node_drops + -- A bit of trickery here: use a different node drop callback -- and restore the original afterwards. minetest.handle_node_drops = chainsaw_handle_node_drops @@ -195,9 +205,6 @@ chainsaw_handle_node_drops = function(pos, drops, digger) end end --- Save the currently installed dropping mechanism so we can restore it. -local original_handle_node_drops = minetest.handle_node_drops - -- This function does all the hard work. Recursively we dig the node at hand -- if it is in the table and then search the surroundings for more stuff to dig. recursive_dig = function(pos, remaining_charge, player) -- cgit v1.2.3 From cfb5bd190c8188d0a0ffd43701864cb1de48bd5d Mon Sep 17 00:00:00 2001 From: kpoppel Date: Wed, 12 Jun 2013 23:30:37 +0200 Subject: Added the Mv and HV down converters. Doing that required some changes to the batteries in that they have new meta data aligned with the other machines. I also added a BA type machine in addition to the existing PR and RE types. This way it is easy to find he batteries on the network. --- technic/battery_box.lua | 693 ++++++++++----------- technic/battery_box_hv.lua | 614 +++++++++--------- technic/battery_box_mv.lua | 631 +++++++++---------- technic/down_converter_hv.lua | 225 +++++++ technic/down_converter_mv.lua | 226 +++++++ technic/init.lua | 2 + technic/solar_array_mv.lua | 3 +- .../textures/technic_hv_down_converter_bottom.png | Bin 0 -> 653 bytes .../textures/technic_hv_down_converter_side.png | Bin 0 -> 609 bytes technic/textures/technic_hv_down_converter_top.png | Bin 0 -> 653 bytes .../textures/technic_mv_down_converter_bottom.png | Bin 0 -> 738 bytes .../textures/technic_mv_down_converter_side.png | Bin 0 -> 670 bytes technic/textures/technic_mv_down_converter_top.png | Bin 0 -> 738 bytes 13 files changed, 1395 insertions(+), 999 deletions(-) create mode 100644 technic/down_converter_hv.lua create mode 100644 technic/down_converter_mv.lua create mode 100644 technic/textures/technic_hv_down_converter_bottom.png create mode 100644 technic/textures/technic_hv_down_converter_side.png create mode 100644 technic/textures/technic_hv_down_converter_top.png create mode 100644 technic/textures/technic_mv_down_converter_bottom.png create mode 100644 technic/textures/technic_mv_down_converter_side.png create mode 100644 technic/textures/technic_mv_down_converter_top.png diff --git a/technic/battery_box.lua b/technic/battery_box.lua index 9c91821..5726053 100644 --- a/technic/battery_box.lua +++ b/technic/battery_box.lua @@ -1,408 +1,393 @@ -LV_machines = {} -registered_LV_machines_count=0 - -function register_LV_machine (string1,string2) -registered_LV_machines_count=registered_LV_machines_count+1 -LV_machines[registered_LV_machines_count]={} -LV_machines[registered_LV_machines_count].machine_name=string1 -LV_machines[registered_LV_machines_count].machine_type=string2 +-- register LV machines here +local LV_machines = {} +function register_LV_machine(string1,string2) + LV_machines[string1] = string2 end power_tools ={} registered_power_tools_count=0 function register_power_tool (string1,max_charge) -registered_power_tools_count=registered_power_tools_count+1 -power_tools[registered_power_tools_count]={} -power_tools[registered_power_tools_count].tool_name=string1 -power_tools[registered_power_tools_count].max_charge=max_charge + registered_power_tools_count=registered_power_tools_count+1 + power_tools[registered_power_tools_count]={} + power_tools[registered_power_tools_count].tool_name=string1 + power_tools[registered_power_tools_count].max_charge=max_charge end - register_power_tool ("technic:battery",10000) register_power_tool ("technic:red_energy_crystal",100000) register_power_tool ("technic:green_energy_crystal",250000) register_power_tool ("technic:blue_energy_crystal",500000) minetest.register_craft({ - output = 'technic:battery 1', - recipe = { - {'default:wood', 'moreores:copper_ingot', 'default:wood'}, - {'default:wood', 'moreores:tin_ingot', 'default:wood'}, - {'default:wood', 'moreores:copper_ingot', 'default:wood'}, - } -}) + output = 'technic:battery 1', + recipe = { + {'default:wood', 'moreores:copper_ingot', 'default:wood'}, + {'default:wood', 'moreores:tin_ingot', 'default:wood'}, + {'default:wood', 'moreores:copper_ingot', 'default:wood'}, + } + }) minetest.register_craft({ - output = 'technic:battery_box 1', - recipe = { - {'technic:battery', 'default:wood', 'technic:battery'}, - {'technic:battery', 'moreores:copper_ingot', 'technic:battery'}, - {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}, - } -}) + output = 'technic:battery_box 1', + recipe = { + {'technic:battery', 'default:wood', 'technic:battery'}, + {'technic:battery', 'moreores:copper_ingot', 'technic:battery'}, + {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}, + } + }) minetest.register_tool("technic:battery", -{description = "RE Battery", -inventory_image = "technic_battery.png", -tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=10000, maxlevel=0}}}}) + {description = "RE Battery", + inventory_image = "technic_battery.png", + tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=10000, maxlevel=0}}}}) minetest.register_craftitem("technic:battery_box", { - description = "Battery box", - stack_max = 99, -}) + description = "Battery box", + stack_max = 99, + }) battery_box_formspec = - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "list[current_name;src;3,1;1,1;]".. - "image[4,1;1,1;technic_battery_reload.png]".. - "list[current_name;dst;5,1;1,1;]".. - "label[0,0;Battery box]".. - "label[3,0;Charge]".. - "label[5,0;Discharge]".. - "label[1,3;Power level]".. - "list[current_player;main;0,5;8,4;]" - -minetest.register_node("technic:battery_box", { - description = "Battery box", - tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png", "technic_battery_box_side0.png", - "technic_battery_box_side0.png", "technic_battery_box_side0.png", "technic_battery_box_side0.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - sounds = default.node_sound_wood_defaults(), - technic_power_machine=1, - last_side_shown=0, - drop="technic:battery_box", - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "Battery box") - meta:set_float("technic_power_machine", 1) - meta:set_string("formspec", battery_box_formspec) - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 1) - battery_charge = 0 - max_charge = 60000 - last_side_shown=0 - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, -}) + "invsize[8,9;]".. + "image[1,1;1,2;technic_power_meter_bg.png]".. + "list[current_name;src;3,1;1,1;]".. + "image[4,1;1,1;technic_battery_reload.png]".. + "list[current_name;dst;5,1;1,1;]".. + "label[0,0;Battery box]".. + "label[3,0;Charge]".. + "label[5,0;Discharge]".. + "label[1,3;Power level]".. + "list[current_player;main;0,5;8,4;]" + +minetest.register_node( + "technic:battery_box", { + description = "LV Battery Box", + tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png", "technic_battery_box_side0.png", + "technic_battery_box_side0.png", "technic_battery_box_side0.png", "technic_battery_box_side0.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + drop="technic:battery_box", + on_construct = function(pos) + if pos == nil then return end + local meta = minetest.env:get_meta(pos) + local inv = meta:get_inventory() + meta:set_string("infotext", "Battery box") + meta:set_float("technic_power_machine", 1) + meta:set_string("formspec", battery_box_formspec) + meta:set_float("internal_EU_buffer", 0) + meta:set_float("internal_EU_buffer_size", 60000) + inv:set_size("src", 1) + inv:set_size("dst", 1) + end, + can_dig = function(pos,player) + if pos == nil then return end + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, + }) for i=1,8,1 do -minetest.register_node("technic:battery_box"..i, { - description = "Battery box", - tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png", "technic_battery_box_side0.png^technic_power_meter"..i..".png", - "technic_battery_box_side0.png^technic_power_meter"..i..".png", "technic_battery_box_side0.png^technic_power_meter"..i..".png", "technic_battery_box_side0.png^technic_power_meter"..i..".png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, - sounds = default.node_sound_wood_defaults(), - technic_power_machine=1, - last_side_shown=0, - drop="technic:battery_box", - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "Battery box") - meta:set_float("technic_power_machine", 1) - meta:set_string("formspec", battery_box_formspec) - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 1) - battery_charge = 0 - max_charge = 60000 - last_side_shown=0 - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, -}) + minetest.register_node( + "technic:battery_box"..i, { + description = "LV Battery Box", + tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png", "technic_battery_box_side0.png^technic_power_meter"..i..".png", + "technic_battery_box_side0.png^technic_power_meter"..i..".png", "technic_battery_box_side0.png^technic_power_meter"..i..".png", "technic_battery_box_side0.png^technic_power_meter"..i..".png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + sounds = default.node_sound_wood_defaults(), + drop="technic:battery_box", + on_construct = function(pos) + if pos == nil then return end + local meta = minetest.env:get_meta(pos) + local inv = meta:get_inventory() + meta:set_string("infotext", "Battery box") + meta:set_float("technic_power_machine", 1) + meta:set_string("formspec", battery_box_formspec) + meta:set_float("internal_EU_buffer", 0) + meta:set_float("internal_EU_buffer_size", 60000) + inv:set_size("src", 1) + inv:set_size("dst", 1) + end, + can_dig = function(pos,player) + if pos == nil then return end + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, + }) end -LV_nodes_visited = {} - function get_RE_item_load (load1,max_load) -if load1==0 then load1=65535 end -local temp = 65536-load1 -temp= temp/65535*max_load -return math.floor(temp + 0.5) + if load1==0 then load1=65535 end + local temp = 65536-load1 + temp= temp/65535*max_load + return math.floor(temp + 0.5) end function set_RE_item_load (load1,max_load) -if load1 == 0 then return 65535 end -local temp=load1/max_load*65535 -temp=65536-temp -return math.floor(temp) + if load1 == 0 then return 65535 end + local temp=load1/max_load*65535 + temp=65536-temp + return math.floor(temp) end function set_RE_wear (item_stack,load1,max_load) -local temp=65536-math.floor(load1/max_load*65535) -item_stack["wear"]=tostring(temp) -return item_stack + local temp=65536-math.floor(load1/max_load*65535) + item_stack["wear"]=tostring(temp) + return item_stack end -minetest.register_abm({ - nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4", - "technic:battery_box5","technic:battery_box6","technic:battery_box7","technic:battery_box8"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - charge= meta:get_int("battery_charge") - max_charge= 60000 - local i=math.ceil((charge/max_charge)*8) - if i>8 then i=8 end - j=meta:get_float("last_side_shown") - if i~=j then - if i>0 then hacky_swap_node(pos,"technic:battery_box"..i) - elseif i==0 then hacky_swap_node(pos,"technic:battery_box") end - meta:set_float("last_side_shown",i) - end - ---loading registered power tools - local inv = meta:get_inventory() - if inv:is_empty("src")==false then - local srcstack = inv:get_stack("src", 1) - local src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - - local item_max_charge=nil - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - item_max_charge=power_tools[i].max_charge - end +minetest.register_abm( + {nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4", + "technic:battery_box5","technic:battery_box6","technic:battery_box7","technic:battery_box8"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local max_charge = 60000 -- Set maximum charge for the device here + local charge = meta:get_int("internal_EU_buffer") + + -- Select node textures + local i=math.ceil((charge/max_charge)*8) + if i > 8 then i = 8 end + local j = meta:get_float("last_side_shown") + if i~=j then + if i>0 then hacky_swap_node(pos,"technic:battery_box"..i) + elseif i==0 then hacky_swap_node(pos,"technic:battery_box") end + meta:set_float("last_side_shown",i) end - if item_max_charge then - load1=src_meta["charge"] - load_step=1000 - if load10 then - if charge-load_step<0 then load_step=charge end - if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end - load1=load1+load_step - charge=charge-load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("src", 1, src_item) - end - meta:set_int("battery_charge",charge) - end - end - --- discharging registered power tools - if inv:is_empty("dst") == false then - srcstack = inv:get_stack("dst", 1) - src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - local item_max_charge=nil - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - item_max_charge=power_tools[i].max_charge - end - end - - if item_max_charge then - local load1=src_meta["charge"] - load_step=1000 - if load1>0 and chargemax_charge then load_step=max_charge-charge end - if load1-load_step<0 then load_step=load1 end - load1=load1-load_step - charge=charge+load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("dst", 1, src_item) - end - end + --charge registered power tools + local inv = meta:get_inventory() + if inv:is_empty("src")==false then + local srcstack = inv:get_stack("src", 1) + local src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + + local item_max_charge=nil + for i=1,registered_power_tools_count,1 do + if power_tools[i].tool_name==src_item["name"] then + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_power_tool"]==nil then + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + end + end + -- Do the charging + local item_max_charge = power_tools[i].max_charge + local load1 = src_meta["charge"] + local load_step = 1000 -- how much to charge per tick + if load10 then + if charge-load_step<0 then load_step=charge end + if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end + load1=load1+load_step + charge=charge-load_step + set_RE_wear(src_item,load1,item_max_charge) + src_meta["charge"]=load1 + src_item["metadata"]=set_item_meta(src_meta) + inv:set_stack("src", 1, src_item) + end + meta:set_int("internal_EU_buffer",charge) + break + end + end end - meta:set_int("battery_charge",charge) + -- discharging registered power tools + if inv:is_empty("dst") == false then + srcstack = inv:get_stack("dst", 1) + src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + local item_max_charge=nil + for i=1,registered_power_tools_count,1 do + if power_tools[i].tool_name==src_item["name"] then + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_power_tool"]==nil then + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + end + end + local item_max_charge = power_tools[i].max_charge + local load1 = src_meta["charge"] + local load_step = 4000 -- how much to discharge per tick + if load1>0 and chargemax_charge then load_step=max_charge-charge end + if load1-load_step<0 then load_step=load1 end + load1=load1-load_step + charge=charge+load_step + set_RE_wear(src_item,load1,item_max_charge) + src_meta["charge"]=load1 + src_item["metadata"]=set_item_meta(src_meta) + inv:set_stack("dst", 1, src_item) + end + meta:set_int("internal_EU_buffer",charge) + break + end + end + end - local load = math.floor(charge/60000 * 100) - meta:set_string("formspec", + local load = math.floor(charge/60000 * 100) + meta:set_string("formspec", battery_box_formspec.. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]") - - local pos1={} - - pos1.y=pos.y-1 - pos1.x=pos.x - pos1.z=pos.z - - - meta1 = minetest.env:get_meta(pos1) - if meta1:get_float("cablelike")~=1 then return end - - local LV_nodes = {} - local PR_nodes = {} - local RE_nodes = {} - - LV_nodes[1]={} - LV_nodes[1].x=pos1.x - LV_nodes[1].y=pos1.y - LV_nodes[1].z=pos1.z - LV_nodes[1].visited=false - - -table_index=1 - repeat - check_LV_node (PR_nodes,RE_nodes,LV_nodes,table_index) - table_index=table_index+1 - if LV_nodes[table_index]==nil then break end - until false - - -local pos1={} -i=1 - repeat - if PR_nodes[i]==nil then break end -- getting power from all connected producers - pos1.x=PR_nodes[i].x - pos1.y=PR_nodes[i].y - pos1.z=PR_nodes[i].z - local meta1 = minetest.env:get_meta(pos1) - local internal_EU_buffer=meta1:get_float("internal_EU_buffer") - if charge0 then - charge=charge+charge_to_take - internal_EU_buffer=internal_EU_buffer-charge_to_take - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - end - end - i=i+1 - until false - -if charge>max_charge then charge=max_charge end - -i=1 - repeat - if RE_nodes[i]==nil then break end - pos1.x=RE_nodes[i].x -- loading all conected machines buffers - pos1.y=RE_nodes[i].y - pos1.z=RE_nodes[i].z - local meta1 = minetest.env:get_meta(pos1) - local internal_EU_buffer=meta1:get_float("internal_EU_buffer") - local internal_EU_buffer_size=meta1:get_float("internal_EU_buffer_size") - - local charge_to_give=200 - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - if charge-charge_to_give<0 then charge_to_give=charge end - - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - charge=charge-charge_to_give; - - i=i+1 - until false - charge=math.floor(charge) - charge_string=tostring(charge) - meta:set_string("infotext", "Battery box: "..charge_string.."/"..max_charge); - meta:set_int("battery_charge",charge) + "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. + (load)..":technic_power_meter_fg.png]" + ) + + -- Next index the surrounding network the get the producers and receivers on the power grid + local pos1={} + pos1.y=pos.y-1 + pos1.x=pos.x + pos1.z=pos.z + + meta1 = minetest.env:get_meta(pos1) + if meta1:get_float("cablelike")~=1 then return end + + local LV_nodes = {} + local PR_nodes = {} + local RE_nodes = {} + local BA_nodes = {} + + LV_nodes[1]={} + LV_nodes[1].x=pos1.x + LV_nodes[1].y=pos1.y + LV_nodes[1].z=pos1.z + LV_nodes[1].visited=false + + local table_index=1 + repeat + check_LV_node(PR_nodes,RE_nodes,BA_nodes,LV_nodes,table_index) + table_index=table_index+1 + if LV_nodes[table_index]==nil then break end + until false + + + -- Get power from all connected producers + local pr_pos + for _,pr_pos in ipairs(PR_nodes) do + local meta1 = minetest.env:get_meta(pr_pos) + local internal_EU_buffer = meta1:get_float("internal_EU_buffer") + local charge_to_take = 200 + if charge0 then + charge=charge+charge_to_take + internal_EU_buffer=internal_EU_buffer-charge_to_take + meta1:set_float("internal_EU_buffer",internal_EU_buffer) + end + end + end + if charge>max_charge then charge=max_charge end + + -- Provide power to all connected receivers + local re_pos + for _,re_pos in ipairs(RE_nodes) do + local meta1 = minetest.env:get_meta(re_pos) + local internal_EU_buffer = meta1:get_float("internal_EU_buffer") + local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size") + local charge_to_give = math.min(200, charge/table.getn(RE_nodes)) + if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then + charge_to_give=internal_EU_buffer_size-internal_EU_buffer + end + if charge-charge_to_give<0 then charge_to_give=charge end + + internal_EU_buffer=internal_EU_buffer+charge_to_give + meta1:set_float("internal_EU_buffer",internal_EU_buffer) + charge=charge-charge_to_give; + end + charge=math.floor(charge) + meta:set_string("infotext", "LV Battery box: "..charge.."/"..max_charge); + meta:set_int("internal_EU_buffer",charge) + end + }) + +-- Register as a battery type +-- Battery type machines function as power reservoirs and can both receive and give back power +register_LV_machine("technic:battery_box","BA") +for i=1,8,1 do + register_LV_machine("technic:battery_box"..i,"BA") end -}) function add_new_cable_node (LV_nodes,pos1) - local i=1 - repeat - if LV_nodes[i]==nil then break end - if pos1.x==LV_nodes[i].x and pos1.y==LV_nodes[i].y and pos1.z==LV_nodes[i].z then return false end - i=i+1 - until false - LV_nodes[i]={} - LV_nodes[i].x=pos1.x - LV_nodes[i].y=pos1.y - LV_nodes[i].z=pos1.z - LV_nodes[i].visited=false - return true + if LV_nodes == nil then return true end + local i=1 + repeat + if LV_nodes[i]==nil then break end + if pos1.x==LV_nodes[i].x and pos1.y==LV_nodes[i].y and pos1.z==LV_nodes[i].z then return false end + i=i+1 + until false + LV_nodes[i]={} + LV_nodes[i].x=pos1.x + LV_nodes[i].y=pos1.y + LV_nodes[i].z=pos1.z + return true end -function check_LV_node (PR_nodes,RE_nodes,LV_nodes,i) - local pos1={} - pos1.x=LV_nodes[i].x - pos1.y=LV_nodes[i].y - pos1.z=LV_nodes[i].z - LV_nodes[i].visited=true - new_node_added=false - - pos1.x=pos1.x+1 - check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1) - pos1.x=pos1.x-2 - check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1) - pos1.x=pos1.x+1 - - pos1.y=pos1.y+1 - check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1) - pos1.y=pos1.y-2 - check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1) - pos1.y=pos1.y+1 - - pos1.z=pos1.z+1 - check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1) - pos1.z=pos1.z-2 - check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1) - pos1.z=pos1.z+1 -return new_node_added +function check_LV_node(PR_nodes,RE_nodes,BA_nodes,LV_nodes,i) + local pos1={} + pos1.x=LV_nodes[i].x + pos1.y=LV_nodes[i].y + pos1.z=LV_nodes[i].z + + pos1.x=pos1.x+1 + check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) + pos1.x=pos1.x-2 + check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) + pos1.x=pos1.x+1 + + pos1.y=pos1.y+1 + check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) + pos1.y=pos1.y-2 + check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) + pos1.y=pos1.y+1 + + pos1.z=pos1.z+1 + check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) + pos1.z=pos1.z-2 + check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) + pos1.z=pos1.z+1 + return new_node_added end -function check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1) -meta = minetest.env:get_meta(pos1) -if meta:get_float("cablelike")==1 then new_node_added=add_new_cable_node(LV_nodes,pos1) end -for i in ipairs(LV_machines) do - if minetest.env:get_node(pos1).name == LV_machines[i].machine_name then - if LV_machines[i].machine_type == "PR" then - new_node_added=add_new_cable_node(PR_nodes,pos1) - end - if LV_machines[i].machine_type == "RE" then - new_node_added=add_new_cable_node(RE_nodes,pos1) - end - end -end +function check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) + local meta = minetest.env:get_meta(pos1) + local name = minetest.env:get_node(pos1).name + if meta:get_float("cablelike")==1 then + add_new_cable_node(LV_nodes,pos1) + elseif LV_machines[name] then + --print(name.." is a "..LV_machines[name]) + if LV_machines[name] == "PR" then + add_new_cable_node(PR_nodes,pos1) + elseif LV_machines[name] == "RE" then + add_new_cable_node(RE_nodes,pos1) + elseif LV_machines[name] == "BA" then + add_new_cable_node(BA_nodes,pos1) + end + end end diff --git a/technic/battery_box_hv.lua b/technic/battery_box_hv.lua index e565d4c..16aead9 100644 --- a/technic/battery_box_hv.lua +++ b/technic/battery_box_hv.lua @@ -1,357 +1,331 @@ -HV_machines = {} - -registered_HV_machines_count=0 - -function register_HV_machine (string1,string2) -registered_HV_machines_count=registered_HV_machines_count+1 -HV_machines[registered_HV_machines_count]={} -HV_machines[registered_HV_machines_count].machine_name=string1 -HV_machines[registered_HV_machines_count].machine_type=string2 +-- register MV machines here +technic.HV_machines = {} +local HV_machines = technic.HV_machines +function register_HV_machine(string1,string2) + technic.HV_machines[string1] = string2 end minetest.register_craft({ - output = 'technic:hv_battery_box 1', - recipe = { - {'technic:mv_battery_box', 'technic:mv_battery_box', 'mv_technic:battery_box'}, - {'technic:mv_battery_box', 'technic:hv_transformer', 'mv_technic:battery_box'}, - {'', 'technic:hv_cable', ''}, - } -}) + output = 'technic:hv_battery_box 1', + recipe = { + {'technic:mv_battery_box', 'technic:mv_battery_box', 'mv_technic:battery_box'}, + {'technic:mv_battery_box', 'technic:hv_transformer', 'mv_technic:battery_box'}, + {'', 'technic:hv_cable', ''}, + } + }) hv_battery_box_formspec = - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "list[current_name;src;3,1;1,1;]".. - "image[4,1;1,1;technic_battery_reload.png]".. - "list[current_name;dst;5,1;1,1;]".. - "label[0,0;HV Battery Box]".. - "label[3,0;Charge]".. - "label[5,0;Discharge]".. - "label[1,3;Power level]".. - "list[current_player;main;0,5;8,4;]" - -minetest.register_node("technic:hv_battery_box", { - description = "HV Battery Box", - tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png", - "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - sounds = default.node_sound_wood_defaults(), - technic_mv_power_machine=1, - last_side_shown=0, - drop="technic:hv_battery_box", - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "HV Battery Box") - meta:set_float("technic_hv_power_machine", 1) - meta:set_string("formspec", battery_box_formspec) - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 1) - battery_charge = 0 - max_charge = 1500000 - last_side_shown=0 - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, -}) - + "invsize[8,9;]".. + "image[1,1;1,2;technic_power_meter_bg.png]".. + "list[current_name;src;3,1;1,1;]".. + "image[4,1;1,1;technic_battery_reload.png]".. + "list[current_name;dst;5,1;1,1;]".. + "label[0,0;HV Battery Box]".. + "label[3,0;Charge]".. + "label[5,0;Discharge]".. + "label[1,3;Power level]".. + "list[current_player;main;0,5;8,4;]" + +minetest.register_node( + "technic:hv_battery_box", { + description = "HV Battery Box", + tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png", + "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + drop="technic:hv_battery_box", + on_construct = function(pos) + if pos==nil then return end + local meta = minetest.env:get_meta(pos) + local inv = meta:get_inventory() + meta:set_string("infotext", "HV Battery Box") + meta:set_float("technic_hv_power_machine", 1) + meta:set_string("formspec", battery_box_formspec) + inv:set_size("src", 1) + inv:set_size("dst", 1) + end, + can_dig = function(pos,player) + if pos==nil then return end + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, + }) for i=1,8,1 do -minetest.register_node("technic:hv_battery_box"..i, { - description = "HV Battery Box", - tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", - "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, - sounds = default.node_sound_wood_defaults(), - paramtype="light", - light_source=9, - technic_power_machine=1, - last_side_shown=0, - drop="technic:hv_battery_box", - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "HV Battery box") - meta:set_float("technic_hv_power_machine", 1) - meta:set_string("formspec", battery_box_formspec) - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 1) - battery_charge = 0 - max_charge = 1500000 - last_side_shown=0 - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, -}) + minetest.register_node( + "technic:hv_battery_box"..i, { + description = "HV Battery Box", + tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", + "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + sounds = default.node_sound_wood_defaults(), + paramtype="light", + light_source=9, + drop="technic:hv_battery_box", + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + local inv = meta:get_inventory() + meta:set_string("infotext", "HV Battery box") + meta:set_float("technic_hv_power_machine", 1) + meta:set_string("formspec", battery_box_formspec) + inv:set_size("src", 1) + inv:set_size("dst", 1) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end, + }) end - -HV_nodes_visited = {} - - -minetest.register_abm({ - nodenames = {"technic:hv_battery_box","technic:hv_battery_box1","technic:hv_battery_box2","technic:hv_battery_box3","technic:hv_battery_box4", - "technic:hv_battery_box5","technic:hv_battery_box6","technic:hv_battery_box7","technic:hv_battery_box8" - }, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - charge= meta:get_int("battery_charge") - max_charge= 1500000 - local i=math.ceil((charge/max_charge)*8) - if i>8 then i=8 end - j=meta:get_float("last_side_shown") - if i~=j then - if i>0 then hacky_swap_node(pos,"technic:hv_battery_box"..i) - elseif i==0 then hacky_swap_node(pos,"technic:hv_battery_box") end - meta:set_float("last_side_shown",i) - end - ---loading registered power tools - local inv = meta:get_inventory() - if inv:is_empty("src")==false then - local srcstack = inv:get_stack("src", 1) - local src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - - local item_max_charge=nil - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - item_max_charge=power_tools[i].max_charge - end - end - - if item_max_charge then - load1=src_meta["charge"] - load_step=16000 - if load10 then - if charge-load_step<0 then load_step=charge end - if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end - load1=load1+load_step - charge=charge-load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("src", 1, src_item) - end - meta:set_int("battery_charge",charge) - end - end - --- dischargin registered power tools - if inv:is_empty("dst") == false then - srcstack = inv:get_stack("dst", 1) - src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - local item_max_charge=nil - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - item_max_charge=power_tools[i].max_charge - end +minetest.register_abm( + {nodenames = {"technic:hv_battery_box","technic:hv_battery_box1","technic:hv_battery_box2","technic:hv_battery_box3","technic:hv_battery_box4", + "technic:hv_battery_box5","technic:hv_battery_box6","technic:hv_battery_box7","technic:hv_battery_box8" + }, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local max_charge = 1500000 + local charge = meta:get_int("internal_EU_buffer") + + -- Select node textures + local i = math.ceil((charge/max_charge)*8) + if i > 8 then i = 8 end + local j = meta:get_float("last_side_shown") + if i~=j then + if i>0 then hacky_swap_node(pos,"technic:hv_battery_box"..i) + elseif i==0 then hacky_swap_node(pos,"technic:hv_battery_box") end + meta:set_float("last_side_shown",i) end - if item_max_charge then - local load1=src_meta["charge"] - load_step=16000 - if load1>0 and chargemax_charge then load_step=max_charge-charge end - if load1-load_step<0 then load_step=load1 end - load1=load1-load_step - charge=charge+load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("dst", 1, src_item) - end + --charge registered power tools + local inv = meta:get_inventory() + if inv:is_empty("src")==false then + local srcstack = inv:get_stack("src", 1) + local src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + + for i=1,registered_power_tools_count,1 do + if power_tools[i].tool_name==src_item["name"] then + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_power_tool"]==nil then + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + end + end + -- Do the charging + local item_max_charge = power_tools[i].max_charge + local load1 = src_meta["charge"] + local load_step = 16000 -- how much to charge per tick + if load10 then + if charge-load_step<0 then load_step=charge end + if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end + load1=load1+load_step + charge=charge-load_step + set_RE_wear(src_item,load1,item_max_charge) + src_meta["charge"]=load1 + src_item["metadata"]=set_item_meta(src_meta) + inv:set_stack("src", 1, src_item) + end + meta:set_int("internal_EU_buffer",charge) + break + end + end end + + -- discharging registered power tools + if inv:is_empty("dst") == false then + srcstack = inv:get_stack("dst", 1) + src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + local item_max_charge=nil + for i=1,registered_power_tools_count,1 do + if power_tools[i].tool_name==src_item["name"] then + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_power_tool"]==nil then + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + end + end + local item_max_charge = power_tools[i].max_charge + local load1 = src_meta["charge"] + local load_step = 16000 -- how much to discharge per tick + if load1>0 and chargemax_charge then load_step=max_charge-charge end + if load1-load_step<0 then load_step=load1 end + load1=load1-load_step + charge=charge+load_step + set_RE_wear(src_item,load1,item_max_charge) + src_meta["charge"]=load1 + src_item["metadata"]=set_item_meta(src_meta) + inv:set_stack("dst", 1, src_item) + end + meta:set_int("internal_EU_buffer",charge) + break + end + end end - - meta:set_int("battery_charge",charge) - local load = math.floor((charge/1500000) * 100) - meta:set_string("formspec", - hv_battery_box_formspec.. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]" - ) - - local pos1={} - pos1.y=pos.y-1 - pos1.x=pos.x - pos1.z=pos.z + local load = math.floor((charge/1500000) * 100) + meta:set_string("formspec", + hv_battery_box_formspec.. + "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. + (load)..":technic_power_meter_fg.png]" + ) + -- Next index the surrounding network the get the producers and receivers on the + local pos1={} + pos1.y=pos.y-1 + pos1.x=pos.x + pos1.z=pos.z - meta1 = minetest.env:get_meta(pos1) - if meta1:get_float("hv_cablelike")~=1 then return end + meta1 = minetest.env:get_meta(pos1) + if meta1:get_float("hv_cablelike")~=1 then return end local HV_nodes = {} local PR_nodes = {} local RE_nodes = {} + local BA_nodes = {} HV_nodes[1]={} HV_nodes[1].x=pos1.x HV_nodes[1].y=pos1.y HV_nodes[1].z=pos1.z HV_nodes[1].visited=false - -table_index=1 - repeat - check_HV_node (PR_nodes,RE_nodes,HV_nodes,table_index) - table_index=table_index+1 - if HV_nodes[table_index]==nil then break end - until false - - -local pos1={} -i=1 - repeat - if PR_nodes[i]==nil then break end -- gettin power from all connected producers - pos1.x=PR_nodes[i].x - pos1.y=PR_nodes[i].y - pos1.z=PR_nodes[i].z - local meta1 = minetest.env:get_meta(pos1) - local internal_EU_buffer=meta1:get_float("internal_EU_buffer") - if charge0 then - charge=charge+charge_to_take - internal_EU_buffer=internal_EU_buffer-charge_to_take - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - end - end - i=i+1 - until false - -if charge>max_charge then charge=max_charge end - -i=1 - repeat - if RE_nodes[i]==nil then break end - pos1.x=RE_nodes[i].x -- loading all conected machines buffers - pos1.y=RE_nodes[i].y - pos1.z=RE_nodes[i].z - local meta1 = minetest.env:get_meta(pos1) - local internal_EU_buffer=meta1:get_float("internal_EU_buffer") - local internal_EU_buffer_size=meta1:get_float("internal_EU_buffer_size") - local charge_to_give=4000 - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - if charge-charge_to_give<0 then charge_to_give=charge end - - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - charge=charge-charge_to_give; - - i=i+1 - until false - charge=math.floor(charge) - charge_string=tostring(charge) - meta:set_string("infotext", "HV Battery Box: \n"..charge_string.."/"..max_charge); - meta:set_int("battery_charge",charge) + local table_index=1 + repeat + check_HV_node (PR_nodes,RE_nodes,BA_nodes,HV_nodes,table_index) + table_index=table_index+1 + if HV_nodes[table_index]==nil then break end + until false + + -- Get power from all connected producers + local pr_pos + for _,pr_pos in ipairs(PR_nodes) do + local meta1 = minetest.env:get_meta(pr_pos) + local internal_EU_buffer = meta1:get_float("internal_EU_buffer") + local charge_to_take = 4000 + if charge0 then + charge=charge+charge_to_take + internal_EU_buffer=internal_EU_buffer-charge_to_take + meta1:set_float("internal_EU_buffer",internal_EU_buffer) + end + end + end + if charge>max_charge then charge=max_charge end + + -- Provide power to all connected receivers + local re_pos + for _,re_pos in ipairs(RE_nodes) do + local meta1 = minetest.env:get_meta(re_pos) + local internal_EU_buffer = meta1:get_float("internal_EU_buffer") + local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size") + local charge_to_give = math.min(4000, charge/table.getn(RE_nodes)) + if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then + charge_to_give=internal_EU_buffer_size-internal_EU_buffer + end + if charge-charge_to_give<0 then charge_to_give=charge end + + internal_EU_buffer=internal_EU_buffer+charge_to_give + meta1:set_float("internal_EU_buffer",internal_EU_buffer) + charge=charge-charge_to_give; + end + charge=math.floor(charge) + meta:set_string("infotext", "MV Battery box: "..charge.."/"..max_charge); + meta:set_int("internal_EU_buffer",charge) + end + }) + +-- Register as a battery type +-- Battery type machines function as power reservoirs and can both receive and give back power +register_HV_machine("technic:hv_battery_box","BA") +for i=1,8,1 do + register_HV_machine("technic:hv_battery_box"..i,"BA") end -}) function add_new_HVcable_node (HV_nodes,pos1) -local i=1 - repeat - if HV_nodes[i]==nil then break end - if pos1.x==HV_nodes[i].x and pos1.y==HV_nodes[i].y and pos1.z==HV_nodes[i].z then return false end - i=i+1 - until false -HV_nodes[i]={} -HV_nodes[i].x=pos1.x -HV_nodes[i].y=pos1.y -HV_nodes[i].z=pos1.z -HV_nodes[i].visited=false -return true + if HV_nodes == nil then return true end + local i=1 + repeat + if HV_nodes[i]==nil then break end + if pos1.x==HV_nodes[i].x and pos1.y==HV_nodes[i].y and pos1.z==HV_nodes[i].z then return false end + i=i+1 + until false + HV_nodes[i]={} + HV_nodes[i].x=pos1.x + HV_nodes[i].y=pos1.y + HV_nodes[i].z=pos1.z + return true end -function check_HV_node (PR_nodes,RE_nodes,HV_nodes,i) - local pos1={} - pos1.x=HV_nodes[i].x - pos1.y=HV_nodes[i].y - pos1.z=HV_nodes[i].z - HV_nodes[i].visited=true - new_node_added=false - - pos1.x=pos1.x+1 - check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) - pos1.x=pos1.x-2 - check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) - pos1.x=pos1.x+1 - - pos1.y=pos1.y+1 - check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) - pos1.y=pos1.y-2 - check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) - pos1.y=pos1.y+1 - - pos1.z=pos1.z+1 - check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) - pos1.z=pos1.z-2 - check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) - pos1.z=pos1.z+1 -return new_node_added +function check_HV_node(PR_nodes,RE_nodes,BA_nodes,HV_nodes,i) + local pos1={} + pos1.x=HV_nodes[i].x + pos1.y=HV_nodes[i].y + pos1.z=HV_nodes[i].z + + pos1.x=pos1.x+1 + check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) + pos1.x=pos1.x-2 + check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) + pos1.x=pos1.x+1 + + pos1.y=pos1.y+1 + check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) + pos1.y=pos1.y-2 + check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) + pos1.y=pos1.y+1 + + pos1.z=pos1.z+1 + check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) + pos1.z=pos1.z-2 + check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) + pos1.z=pos1.z+1 end -function check_HV_node_subp (PR_nodes,RE_nodes,HV_nodes,pos1) -meta = minetest.env:get_meta(pos1) -if meta:get_float("hv_cablelike")==1 then new_node_added=add_new_HVcable_node(HV_nodes,pos1) end -for i in ipairs(HV_machines) do - if minetest.env:get_node(pos1).name == HV_machines[i].machine_name then - if HV_machines[i].machine_type == "PR" then - new_node_added=add_new_HVcable_node(PR_nodes,pos1) - end - if HV_machines[i].machine_type == "RE" then - new_node_added=add_new_HVcable_node(RE_nodes,pos1) - end - end +function check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) + local meta = minetest.env:get_meta(pos1) + local name = minetest.env:get_node(pos1).name + if meta:get_float("hv_cablelike")==1 then + add_new_HVcable_node(HV_nodes,pos1) + elseif HV_machines[name] then + --print(name.." is a "..HV_machines[name]) + if HV_machines[name] == "PR" then + add_new_HVcable_node(PR_nodes,pos1) + elseif HV_machines[name] == "RE" then + add_new_HVcable_node(RE_nodes,pos1) + elseif HV_machines[name] == "BA" then + add_new_HVcable_node(BA_nodes,pos1) + end + end end -end - diff --git a/technic/battery_box_mv.lua b/technic/battery_box_mv.lua index 8fc6dc7..86c445c 100644 --- a/technic/battery_box_mv.lua +++ b/technic/battery_box_mv.lua @@ -1,355 +1,338 @@ -MV_machines = {} - -registered_MV_machines_count=0 - -function register_MV_machine (string1,string2) -registered_MV_machines_count=registered_MV_machines_count+1 -MV_machines[registered_MV_machines_count]={} -MV_machines[registered_MV_machines_count].machine_name=string1 -MV_machines[registered_MV_machines_count].machine_type=string2 +-- register MV machines here +technic.MV_machines = {} +--local MV_machines = {} +local MV_machines = technic.MV_machines +function register_MV_machine(string1,string2) + technic.MV_machines[string1] = string2 end -minetest.register_craft({ - output = 'technic:mv_battery_box 1', - recipe = { - {'technic:battery_box', 'technic:battery_box', 'technic:battery_box'}, - {'technic:battery_box', 'technic:mv_transformer', 'technic:battery_box'}, - {'', 'technic:mv_cable', ''}, - } -}) +minetest.register_craft( + { + output = 'technic:mv_battery_box 1', + recipe = { + {'technic:battery_box', 'technic:battery_box', 'technic:battery_box'}, + {'technic:battery_box', 'technic:mv_transformer', 'technic:battery_box'}, + {'', 'technic:mv_cable', ''}, + } + }) mv_battery_box_formspec = - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "list[current_name;src;3,1;1,1;]".. - "image[4,1;1,1;technic_battery_reload.png]".. - "list[current_name;dst;5,1;1,1;]".. - "label[0,0;MV_Battery box]".. - "label[3,0;Charge]".. - "label[5,0;Discharge]".. - "label[1,3;Power level]".. - "list[current_player;main;0,5;8,4;]" - -minetest.register_node("technic:mv_battery_box", { - description = "MV Battery Box", - tiles = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png", - "technic_mv_battery_box_side0.png", "technic_mv_battery_box_side0.png", "technic_mv_battery_box_side0.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - sounds = default.node_sound_wood_defaults(), - technic_mv_power_machine=1, - last_side_shown=0, - drop="technic:mv_battery_box", - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "MV Battery box") - meta:set_float("technic_mv_power_machine", 1) - meta:set_string("formspec", battery_box_formspec) - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 1) - battery_charge = 0 - max_charge = 300000 - last_side_shown=0 - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false + "invsize[8,9;]".. + "image[1,1;1,2;technic_power_meter_bg.png]".. + "list[current_name;src;3,1;1,1;]".. + "image[4,1;1,1;technic_battery_reload.png]".. + "list[current_name;dst;5,1;1,1;]".. + "label[0,0;MV_Battery box]".. + "label[3,0;Charge]".. + "label[5,0;Discharge]".. + "label[1,3;Power level]".. + "list[current_player;main;0,5;8,4;]" + +minetest.register_node( + "technic:mv_battery_box", { + description = "MV Battery Box", + tiles = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png", + "technic_mv_battery_box_side0.png", "technic_mv_battery_box_side0.png", "technic_mv_battery_box_side0.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + drop = "technic:mv_battery_box", + on_construct = function(pos) + if pos==nil then return end + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + meta:set_string("infotext", "MV Battery box") + meta:set_float("technic_mv_power_machine", 1) + meta:set_string("formspec", battery_box_formspec) + meta:set_float("internal_EU_buffer", 0) + meta:set_float("internal_EU_buffer_size", 300000) + inv:set_size("src", 1) + inv:set_size("dst", 1) + end, + can_dig = function(pos,player) + if pos==nil then return end + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true end - return true - end, -}) + }) for i=1,8,1 do -minetest.register_node("technic:mv_battery_box"..i, { - description = "MV Battery Box", - tiles = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", - "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, - sounds = default.node_sound_wood_defaults(), - technic_power_machine=1, - last_side_shown=0, - drop="technic:mv_battery_box", - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "MV Battery box") - meta:set_float("technic_mv_power_machine", 1) - meta:set_string("formspec", battery_box_formspec) - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 1) - battery_charge = 0 - max_charge = 300000 - last_side_shown=0 - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, -}) + minetest.register_node( + "technic:mv_battery_box"..i, { + description = "MV Battery Box", + tiles = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", + "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + sounds = default.node_sound_wood_defaults(), + drop = "technic:mv_battery_box", + on_construct = function(pos) + if pos==nil then return end + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + meta:set_string("infotext", "MV Battery box") + meta:set_float("technic_mv_power_machine", 1) + meta:set_string("formspec", battery_box_formspec) + meta:set_float("internal_EU_buffer", 0) + meta:set_float("internal_EU_buffer_size", 300000) + inv:set_size("src", 1) + inv:set_size("dst", 1) + end, + can_dig = function(pos,player) + if pos==nil then return end + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("dst") then + return false + elseif not inv:is_empty("src") then + return false + end + return true + end + }) end - -MV_nodes_visited = {} - - -minetest.register_abm({ - nodenames = {"technic:mv_battery_box","technic:mv_battery_box1","technic:mv_battery_box2","technic:mv_battery_box3","technic:mv_battery_box4", - "technic:mv_battery_box5","technic:mv_battery_box6","technic:mv_battery_box7","technic:mv_battery_box8" - }, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - charge= meta:get_int("battery_charge") - max_charge= 300000 - local i=math.ceil((charge/max_charge)*8) - if i>8 then i=8 end - j=meta:get_float("last_side_shown") - if i~=j then - if i>0 then hacky_swap_node(pos,"technic:mv_battery_box"..i) - elseif i==0 then hacky_swap_node(pos,"technic:mv_battery_box") end - meta:set_float("last_side_shown",i) - end - ---loading registered power tools - local inv = meta:get_inventory() - if inv:is_empty("src")==false then - local srcstack = inv:get_stack("src", 1) - local src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - - local item_max_charge=nil - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - item_max_charge=power_tools[i].max_charge - end - end - - if item_max_charge then - load1=src_meta["charge"] - load_step=4000 - if load10 then - if charge-load_step<0 then load_step=charge end - if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end - load1=load1+load_step - charge=charge-load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("src", 1, src_item) - end - meta:set_int("battery_charge",charge) - end - end - --- dischargin registered power tools - if inv:is_empty("dst") == false then - srcstack = inv:get_stack("dst", 1) - src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - local item_max_charge=nil - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - item_max_charge=power_tools[i].max_charge - end +minetest.register_abm( + {nodenames = {"technic:mv_battery_box","technic:mv_battery_box1","technic:mv_battery_box2","technic:mv_battery_box3","technic:mv_battery_box4", + "technic:mv_battery_box5","technic:mv_battery_box6","technic:mv_battery_box7","technic:mv_battery_box8" + }, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local max_charge = 300000 -- Set maximum charge for the device here + local charge = meta:get_int("internal_EU_buffer") + + -- Select node textures + local i = math.ceil((charge/max_charge)*8) + if i > 8 then i = 8 end + local j = meta:get_float("last_side_shown") + if i~=j then + if i>0 then hacky_swap_node(pos,"technic:mv_battery_box"..i) + elseif i==0 then hacky_swap_node(pos,"technic:mv_battery_box") end + meta:set_float("last_side_shown",i) end - if item_max_charge then - local load1=src_meta["charge"] - load_step=4000 - if load1>0 and chargemax_charge then load_step=max_charge-charge end - if load1-load_step<0 then load_step=load1 end - load1=load1-load_step - charge=charge+load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("dst", 1, src_item) - end + --charge registered power tools + local inv = meta:get_inventory() + if inv:is_empty("src")==false then + local srcstack = inv:get_stack("src", 1) + local src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + + -- Power tools should really be made into a hash table to avoid linear search. But the list is short so okay... + for i=1,registered_power_tools_count,1 do + if power_tools[i].tool_name==src_item["name"] then + -- What is this code doing? Setting tool properties if not set already???? + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_power_tool"]==nil then + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + end + end + -- Do the charging + local item_max_charge = power_tools[i].max_charge + local load1 = src_meta["charge"] + local load_step = 4000 -- how much to charge per tick + if load10 then + if charge-load_step<0 then load_step=charge end + if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end + load1=load1+load_step + charge=charge-load_step + set_RE_wear(src_item,load1,item_max_charge) + src_meta["charge"] = load1 + src_item["metadata"] = set_item_meta(src_meta) + inv:set_stack("src", 1, src_item) + end + meta:set_int("internal_EU_buffer",charge) + break + end + end end + + -- discharging registered power tools + if inv:is_empty("dst") == false then + srcstack = inv:get_stack("dst", 1) + src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + local item_max_charge=nil + for i=1,registered_power_tools_count,1 do + if power_tools[i].tool_name==src_item["name"] then + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_power_tool"]==nil then + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + end + end + local item_max_charge = power_tools[i].max_charge + local load1 = src_meta["charge"] + local load_step = 4000 -- how much to discharge per tick + if load1>0 and chargemax_charge then load_step=max_charge-charge end + if load1-load_step<0 then load_step=load1 end + load1=load1-load_step + charge=charge+load_step + set_RE_wear(src_item,load1,item_max_charge) + src_meta["charge"]=load1 + src_item["metadata"]=set_item_meta(src_meta) + inv:set_stack("dst", 1, src_item) + end + meta:set_int("internal_EU_buffer",charge) + break + end + end end - - meta:set_int("battery_charge",charge) - local load = math.floor((charge/300000) * 100) - meta:set_string("formspec", + local load = math.floor((charge/300000) * 100) + meta:set_string("formspec", mv_battery_box_formspec.. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]" - ) - - local pos1={} - - pos1.y=pos.y-1 - pos1.x=pos.x - pos1.z=pos.z + "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. + (load)..":technic_power_meter_fg.png]" + ) + -- Next index the surrounding network the get the producers and receivers on the power grid + local pos1 = {} + pos1.y = pos.y-1 + pos1.x = pos.x + pos1.z = pos.z - meta1 = minetest.env:get_meta(pos1) - if meta1:get_float("mv_cablelike")~=1 then return end + meta1 = minetest.env:get_meta(pos1) + if meta1:get_float("mv_cablelike")~=1 then return end local MV_nodes = {} local PR_nodes = {} local RE_nodes = {} + local BA_nodes = {} + + MV_nodes[1] = {} + MV_nodes[1].x = pos1.x + MV_nodes[1].y = pos1.y + MV_nodes[1].z = pos1.z + + local table_index=1 + repeat + check_MV_node(PR_nodes,RE_nodes,BA_nodes,MV_nodes,table_index) + table_index=table_index+1 + if MV_nodes[table_index]==nil then break end + until false + + -- Get power from all connected producers + local pr_pos + for _,pr_pos in ipairs(PR_nodes) do + local meta1 = minetest.env:get_meta(pr_pos) + local internal_EU_buffer = meta1:get_float("internal_EU_buffer") + local charge_to_take = 1000 + if charge0 then + charge=charge+charge_to_take + internal_EU_buffer=internal_EU_buffer-charge_to_take + meta1:set_float("internal_EU_buffer",internal_EU_buffer) + end + end + end - MV_nodes[1]={} - MV_nodes[1].x=pos1.x - MV_nodes[1].y=pos1.y - MV_nodes[1].z=pos1.z - MV_nodes[1].visited=false - -table_index=1 - repeat - check_MV_node (PR_nodes,RE_nodes,MV_nodes,table_index) - table_index=table_index+1 - if MV_nodes[table_index]==nil then break end - until false - - -local pos1={} -i=1 - repeat - if PR_nodes[i]==nil then break end -- gettin power from all connected producers - pos1.x=PR_nodes[i].x - pos1.y=PR_nodes[i].y - pos1.z=PR_nodes[i].z - local meta1 = minetest.env:get_meta(pos1) - local internal_EU_buffer=meta1:get_float("internal_EU_buffer") - if charge0 then - charge=charge+charge_to_take - internal_EU_buffer=internal_EU_buffer-charge_to_take - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - end - end - i=i+1 - until false - -if charge>max_charge then charge=max_charge end - -i=1 - repeat - if RE_nodes[i]==nil then break end - pos1.x=RE_nodes[i].x -- loading all conected machines buffers - pos1.y=RE_nodes[i].y - pos1.z=RE_nodes[i].z - local meta1 = minetest.env:get_meta(pos1) - local internal_EU_buffer=meta1:get_float("internal_EU_buffer") - local internal_EU_buffer_size=meta1:get_float("internal_EU_buffer_size") - - local charge_to_give=1000 - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - if charge-charge_to_give<0 then charge_to_give=charge end - - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - charge=charge-charge_to_give; - - i=i+1 - until false - charge=math.floor(charge) - charge_string=tostring(charge) - meta:set_string("infotext", "Battery box: "..charge_string.."/"..max_charge); - meta:set_int("battery_charge",charge) - + if charge>max_charge then charge=max_charge end + + -- Provide power to all connected receivers + local re_pos + for _,re_pos in ipairs(RE_nodes) do + local meta1 = minetest.env:get_meta(re_pos) + local internal_EU_buffer = meta1:get_float("internal_EU_buffer") + local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size") + local charge_to_give = math.min(1000, charge/table.getn(RE_nodes)) + if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then + charge_to_give=internal_EU_buffer_size-internal_EU_buffer + end + if charge-charge_to_give<0 then charge_to_give=charge end + + internal_EU_buffer=internal_EU_buffer+charge_to_give + meta1:set_float("internal_EU_buffer",internal_EU_buffer) + charge=charge-charge_to_give; + end + charge=math.floor(charge) + meta:set_string("infotext", "MV Battery box: "..charge.."/"..max_charge); + meta:set_int("internal_EU_buffer",charge) + end + }) + +-- Register as a battery type +-- Battery type machines function as power reservoirs and can both receive and give back power +register_MV_machine("technic:mv_battery_box","BA") +for i=1,8,1 do + register_MV_machine("technic:mv_battery_box"..i,"BA") end -}) function add_new_MVcable_node (MV_nodes,pos1) -local i=1 - repeat - if MV_nodes[i]==nil then break end - if pos1.x==MV_nodes[i].x and pos1.y==MV_nodes[i].y and pos1.z==MV_nodes[i].z then return false end - i=i+1 - until false -MV_nodes[i]={} -MV_nodes[i].x=pos1.x -MV_nodes[i].y=pos1.y -MV_nodes[i].z=pos1.z -MV_nodes[i].visited=false -return true + if MV_nodes == nil then return true end + local i=1 + repeat + if MV_nodes[i]==nil then break end + if pos1.x==MV_nodes[i].x and pos1.y==MV_nodes[i].y and pos1.z==MV_nodes[i].z then return false end + i=i+1 + until false + MV_nodes[i]={} + MV_nodes[i].x=pos1.x + MV_nodes[i].y=pos1.y + MV_nodes[i].z=pos1.z + return true end -function check_MV_node (PR_nodes,RE_nodes,MV_nodes,i) - local pos1={} - pos1.x=MV_nodes[i].x - pos1.y=MV_nodes[i].y - pos1.z=MV_nodes[i].z - MV_nodes[i].visited=true - new_node_added=false - - pos1.x=pos1.x+1 - check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1) - pos1.x=pos1.x-2 - check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1) - pos1.x=pos1.x+1 - - pos1.y=pos1.y+1 - check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1) - pos1.y=pos1.y-2 - check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1) - pos1.y=pos1.y+1 - - pos1.z=pos1.z+1 - check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1) - pos1.z=pos1.z-2 - check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1) - pos1.z=pos1.z+1 -return new_node_added +function check_MV_node(PR_nodes,RE_nodes,BA_nodes,MV_nodes,i) + local pos1={} + pos1.x=MV_nodes[i].x + pos1.y=MV_nodes[i].y + pos1.z=MV_nodes[i].z + + pos1.x=pos1.x+1 + check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) + pos1.x=pos1.x-2 + check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) + pos1.x=pos1.x+1 + + pos1.y=pos1.y+1 + check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) + pos1.y=pos1.y-2 + check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) + pos1.y=pos1.y+1 + + pos1.z=pos1.z+1 + check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) + pos1.z=pos1.z-2 + check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) + pos1.z=pos1.z+1 end -function check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1) -meta = minetest.env:get_meta(pos1) -if meta:get_float("mv_cablelike")==1 then new_node_added=add_new_MVcable_node(MV_nodes,pos1) end -for i in ipairs(MV_machines) do - if minetest.env:get_node(pos1).name == MV_machines[i].machine_name then - if MV_machines[i].machine_type == "PR" then - new_node_added=add_new_MVcable_node(PR_nodes,pos1) - end - if MV_machines[i].machine_type == "RE" then - new_node_added=add_new_MVcable_node(RE_nodes,pos1) - end - end -end +function check_MV_node_subp (PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) + local meta = minetest.env:get_meta(pos1) + local name = minetest.env:get_node(pos1).name + if meta:get_float("mv_cablelike")==1 then + add_new_MVcable_node(MV_nodes,pos1) + elseif MV_machines[name] then + --print(name.." is a "..MV_machines[name]) + if MV_machines[name] == "PR" then + add_new_MVcable_node(PR_nodes,pos1) + elseif MV_machines[name] == "RE" then + add_new_MVcable_node(RE_nodes,pos1) + elseif MV_machines[name] == "BA" then + add_new_MVcable_node(BA_nodes,pos1) + end + end end - diff --git a/technic/down_converter_hv.lua b/technic/down_converter_hv.lua new file mode 100644 index 0000000..0e2e16d --- /dev/null +++ b/technic/down_converter_hv.lua @@ -0,0 +1,225 @@ +-- The HV down converter will step down HV EUs to MV EUs +-- If we take the solar panel as calibration then the +-- 1 HVEU = 5 MVEU as we stack 5 MV arrays to get a HV array. +-- The downconverter does of course have a conversion loss. +-- This loses 30% of the power. +-- The converter does not store any energy by itself. +minetest.register_node("technic:down_converter_hv", { + description = "HV Down Converter", + tiles = {"technic_hv_down_converter_top.png", "technic_hv_down_converter_bottom.png", "technic_hv_down_converter_side.png", + "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + drawtype = "nodebox", + paramtype = "light", + is_ground_content = true, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_float("technic_hv_power_machine", 1) + meta:set_float("technic_mv_power_machine", 1) + meta:set_float("internal_EU_buffer",0) + meta:set_float("internal_EU_buffer_size",0) + meta:set_string("infotext", "HV Down Converter") + meta:set_float("active", false) + end, + }) + +minetest.register_craft({ + output = 'technic:down_converter_hv 1', + recipe = { + {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot','technic:stainless_steel_ingot'}, + {'technic:hv_transformer', 'technic:hv_cable', 'technic:mv_transformer'}, + {'technic:hv_cable', 'technic:rubber', 'technic:mv_cable'}, + } +}) + +minetest.register_abm( + {nodenames = {"technic:down_converter_hv"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + -- HV->MV conversion factor + local hv_mv_factor = 5 + -- The maximun charge a single converter can handle. Let's set this to + -- what 5 HV solar arrays can produce - 30% loss (2880*5*0.7) + local max_charge = 10080*hv_mv_factor + + local meta = minetest.env:get_meta(pos) + local meta1 = nil + local pos1 = {} + local available_charge = 0 -- counted in MV units + local used_charge = 0 -- counted in MV units + + -- Index all HV nodes connected to the network + -- HV cable comes in through the bottom + pos1.y = pos.y-1 + pos1.x = pos.x + pos1.z = pos.z + meta1 = minetest.env:get_meta(pos1) + if meta1:get_float("hv_cablelike")~=1 then return end + + local HV_nodes = {} -- HV type + local HV_PR_nodes = {} -- HV type + local HV_BA_nodes = {} -- HV type + + HV_nodes[1] = {} + HV_nodes[1].x = pos1.x + HV_nodes[1].y = pos1.y + HV_nodes[1].z = pos1.z + + local table_index = 1 + repeat + check_HV_node(HV_PR_nodes,nil,HV_BA_nodes,HV_nodes,table_index) + table_index = table_index + 1 + if HV_nodes[table_index] == nil then break end + until false + + --print("HV_nodes: PR="..table.getn(HV_PR_nodes).." BA="..table.getn(HV_BA_nodes)) + + -- Index all MV nodes connected to the network + -- MV cable comes out of the top + pos1.y = pos.y+1 + pos1.x = pos.x + pos1.z = pos.z + meta1 = minetest.env:get_meta(pos1) + if meta1:get_float("mv_cablelike")~=1 then return end + + local MV_nodes = {} -- MV type + local MV_RE_nodes = {} -- MV type + local MV_BA_nodes = {} -- MV type + + MV_nodes[1] = {} + MV_nodes[1].x = pos1.x + MV_nodes[1].y = pos1.y + MV_nodes[1].z = pos1.z + + table_index = 1 + repeat + check_MV_node(nil,MV_RE_nodes,MV_BA_nodes,MV_nodes,table_index) + table_index = table_index + 1 + if MV_nodes[table_index] == nil then break end + until false + + --print("MV_nodes: RE="..table.getn(MV_RE_nodes).." BA="..table.getn(MV_BA_nodes)) + + -- First get available power from all the attached HV suppliers + -- Get the supplier internal EU buffer and read the EUs from it + -- No update yet! + local pos1 +-- FIXME: Until further leave the producers out of it and just let the batteries be the hub +-- for _,pos1 in ipairs(HV_PR_nodes) do +-- meta1 = minetest.env:get_meta(pos1) +-- local internal_EU_buffer = meta1:get_float("internal_EU_buffer") +-- available_charge = available_charge + meta1:get_float("internal_EU_buffer") * hv_mv_factor +-- -- Limit conversion capacity +-- if available_charge > max_charge then +-- available_charge = max_charge +-- break +-- end +-- end +-- --print("Available_charge PR:"..available_charge) + + for _,pos1 in ipairs(HV_BA_nodes) do + meta1 = minetest.env:get_meta(pos1) + local internal_EU_buffer = meta1:get_float("internal_EU_buffer") + available_charge = available_charge + meta1:get_float("internal_EU_buffer") * hv_mv_factor + -- Limit conversion capacity + if available_charge > max_charge then + available_charge = max_charge + break + end + end + --print("Available_charge PR+BA:"..available_charge) + + -- Calculate total number of receivers: + local MV_receivers = table.getn(MV_RE_nodes)+table.getn(MV_BA_nodes) + + -- Next supply power to all connected MV machines + -- Get the power receiver internal EU buffer and give EUs to it + -- Note: for now leave out RE type machines until producers distribute power themselves even without a battery +-- for _,pos1 in ipairs(MV_RE_nodes) do +-- local meta1 = minetest.env:get_meta(pos1) +-- local internal_EU_buffer = meta1:get_float("internal_EU_buffer") +-- local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size") +-- local charge_to_give = math.min(4000, available_charge/MV_receivers) -- power rating limit on the MV wire +-- -- How much can this unit take? +-- if internal_EU_buffer+charge_to_give > internal_EU_buffer_size then +-- charge_to_give=internal_EU_buffer_size-internal_EU_buffer +-- end +-- -- If we are emptying the supply take the remainder +-- if available_charge internal_EU_buffer_size then + charge_to_give=internal_EU_buffer_size-internal_EU_buffer + end + --print("charge_to_give2:"..charge_to_give) + -- If we are emptying the supply take the remainder + if available_charge 0 then + internal_EU_buffer = internal_EU_buffer-charge_to_take + meta1:set_float("internal_EU_buffer",internal_EU_buffer) + end + end + + if used_charge>0 then + meta:set_string("infotext", "HV Down Converter is active (HV:"..available_charge.."/MV:"..used_charge..")"); + meta:set_float("active",1) -- used for setting textures someday maybe + else + meta:set_string("infotext", "HV Down Converter is inactive (HV:"..available_charge.."/MV:"..used_charge..")"); + meta:set_float("active",0) -- used for setting textures someday maybe + return + end + end, +}) + +-- This machine does not store energy it receives energy from the HV side and outputs it on the MV side +register_HV_machine ("technic:down_converter_hv","RE") +register_MV_machine ("technic:down_converter_hv","PR") diff --git a/technic/down_converter_mv.lua b/technic/down_converter_mv.lua new file mode 100644 index 0000000..1d26630 --- /dev/null +++ b/technic/down_converter_mv.lua @@ -0,0 +1,226 @@ +-- The MV down converter will step down MV EUs to LV EUs +-- If we take the solar panel as calibration then the +-- 1 MVEU = 5 LVEU as we stack 5 LV arrays to get an MV array. +-- The downconverter does of course have a conversion loss. +-- This loses 30% of the power. +-- The converter does not store any energy by itself. +minetest.register_node( + "technic:down_converter_mv", { + description = "MV Down Converter", + tiles = {"technic_mv_down_converter_top.png", "technic_mv_down_converter_bottom.png", "technic_mv_down_converter_side.png", + "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + drawtype = "nodebox", + paramtype = "light", + is_ground_content = true, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_float("technic_mv_power_machine", 1) + meta:set_float("technic_power_machine", 1) + meta:set_float("internal_EU_buffer",0) + meta:set_float("internal_EU_buffer_size",0) + meta:set_string("infotext", "MV Down Converter") + meta:set_float("active", false) + end, + }) + +minetest.register_craft({ + output = 'technic:down_converter_mv 1', + recipe = { + {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot','technic:stainless_steel_ingot'}, + {'technic:mv_transformer', 'technic:mv_cable', 'technic:lv_transformer'}, + {'technic:mv_cable', 'technic:rubber', 'technic:lv_cable'}, + } +}) + +minetest.register_abm( + {nodenames = {"technic:down_converter_mv"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + -- MV->LV conversion factor + local mv_lv_factor = 5 + -- The maximun charge a single converter can handle. Let's set this to + -- what 5 MV solar arrays can produce - 30% loss (720*5*0.7) + local max_charge = 2520*mv_lv_factor + + local meta = minetest.env:get_meta(pos) + local meta1 = nil + local pos1 = {} + local available_charge = 0 -- counted in LV units + local used_charge = 0 -- counted in LV units + + -- Index all MV nodes connected to the network + -- MV cable comes in through the bottom + pos1.y = pos.y-1 + pos1.x = pos.x + pos1.z = pos.z + meta1 = minetest.env:get_meta(pos1) + if meta1:get_float("mv_cablelike")~=1 then return end + + local MV_nodes = {} -- MV type + local MV_PR_nodes = {} -- MV type + local MV_BA_nodes = {} -- MV type + + MV_nodes[1] = {} + MV_nodes[1].x = pos1.x + MV_nodes[1].y = pos1.y + MV_nodes[1].z = pos1.z + + local table_index = 1 + repeat + check_MV_node(MV_PR_nodes,nil,MV_BA_nodes,MV_nodes,table_index) + table_index = table_index + 1 + if MV_nodes[table_index] == nil then break end + until false + + --print("MV_nodes: PR="..table.getn(MV_PR_nodes).." BA="..table.getn(MV_BA_nodes)) + + -- Index all LV nodes connected to the network + -- LV cable comes out of the top + pos1.y = pos.y+1 + pos1.x = pos.x + pos1.z = pos.z + meta1 = minetest.env:get_meta(pos1) + if meta1:get_float("cablelike")~=1 then return end + + local LV_nodes = {} -- LV type + local LV_RE_nodes = {} -- LV type + local LV_BA_nodes = {} -- LV type + + LV_nodes[1] = {} + LV_nodes[1].x = pos1.x + LV_nodes[1].y = pos1.y + LV_nodes[1].z = pos1.z + + table_index = 1 + repeat + check_LV_node(nil,LV_RE_nodes,LV_BA_nodes,LV_nodes,table_index) + table_index = table_index + 1 + if LV_nodes[table_index] == nil then break end + until false + + --print("LV_nodes: RE="..table.getn(LV_RE_nodes).." BA="..table.getn(LV_BA_nodes)) + + -- First get available power from all the attached MV suppliers + -- Get the supplier internal EU buffer and read the EUs from it + -- No update yet! + local pos1 +-- FIXME: Until further leave the producers out of it and just let the batteries be the hub +-- for _,pos1 in ipairs(MV_PR_nodes) do +-- meta1 = minetest.env:get_meta(pos1) +-- local internal_EU_buffer = meta1:get_float("internal_EU_buffer") +-- available_charge = available_charge + meta1:get_float("internal_EU_buffer") * mv_lv_factor +-- -- Limit conversion capacity +-- if available_charge > max_charge then +-- available_charge = max_charge +-- break +-- end +-- end +-- print("Available_charge PR:"..available_charge) + + for _,pos1 in ipairs(MV_BA_nodes) do + meta1 = minetest.env:get_meta(pos1) + local internal_EU_buffer = meta1:get_float("internal_EU_buffer") + available_charge = available_charge + meta1:get_float("internal_EU_buffer") * mv_lv_factor + -- Limit conversion capacity + if available_charge > max_charge then + available_charge = max_charge + break + end + end + --print("Available_charge PR+BA:"..available_charge) + + -- Calculate total number of receivers: + local LV_receivers = table.getn(LV_RE_nodes)+table.getn(LV_BA_nodes) + + -- Next supply power to all connected LV machines + -- Get the power receiver internal EU buffer and give EUs to it + -- Note: for now leave out RE type machines until producers distribute power themselves even without a battery +-- for _,pos1 in ipairs(LV_RE_nodes) do +-- local meta1 = minetest.env:get_meta(pos1) +-- local internal_EU_buffer = meta1:get_float("internal_EU_buffer") +-- local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size") +-- local charge_to_give = math.min(1000, available_charge/LV_receivers) -- power rating limit on the LV wire +-- -- How much can this unit take? +-- if internal_EU_buffer+charge_to_give > internal_EU_buffer_size then +-- charge_to_give=internal_EU_buffer_size-internal_EU_buffer +-- end +-- -- If we are emptying the supply take the remainder +-- if available_charge internal_EU_buffer_size then + charge_to_give=internal_EU_buffer_size-internal_EU_buffer + end + --print("charge_to_give2:"..charge_to_give) + -- If we are emptying the supply take the remainder + if available_charge 0 then + internal_EU_buffer = internal_EU_buffer-charge_to_take + meta1:set_float("internal_EU_buffer",internal_EU_buffer) + end + end + + if used_charge>0 then + meta:set_string("infotext", "MV Down Converter is active (MV:"..available_charge.."/LV:"..used_charge..")"); + meta:set_float("active",1) -- used for setting textures someday maybe + else + meta:set_string("infotext", "MV Down Converter is inactive (MV:"..available_charge.."/LV:"..used_charge..")"); + meta:set_float("active",0) -- used for setting textures someday maybe + return + end + end, +}) + +-- This machine does not store energy it receives energy from the MV side and outputs it on the LV side +register_MV_machine ("technic:down_converter_mv","RE") +register_LV_machine ("technic:down_converter_mv","PR") diff --git a/technic/init.lua b/technic/init.lua index 3cc73be..2248295 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -36,6 +36,7 @@ dofile(modpath.."/cnc_nodes.lua") dofile(modpath.."/wires_mv.lua") dofile(modpath.."/battery_box_mv.lua") dofile(modpath.."/solar_array_mv.lua") +dofile(modpath.."/down_converter_mv.lua") dofile(modpath.."/electric_furnace_mv.lua") dofile(modpath.."/alloy_furnace_mv.lua") dofile(modpath.."/forcefield.lua") @@ -44,6 +45,7 @@ dofile(modpath.."/forcefield.lua") dofile(modpath.."/wires_hv.lua") dofile(modpath.."/battery_box_hv.lua") dofile(modpath.."/solar_array_hv.lua") +dofile(modpath.."/down_converter_hv.lua") --Tools if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end diff --git a/technic/solar_array_mv.lua b/technic/solar_array_mv.lua index de75301..abcc027 100644 --- a/technic/solar_array_mv.lua +++ b/technic/solar_array_mv.lua @@ -83,7 +83,8 @@ minetest.register_abm( meta:set_float("active",1) internal_EU_buffer=internal_EU_buffer+charge_to_give meta:set_float("internal_EU_buffer",internal_EU_buffer) - + -- Idea: How about letting solar panels provide power without battery boxes? + -- This could provide an even distribution to all receivers. else meta:set_string("infotext", "Solar Array is inactive"); meta:set_float("active",0) diff --git a/technic/textures/technic_hv_down_converter_bottom.png b/technic/textures/technic_hv_down_converter_bottom.png new file mode 100644 index 0000000..996b2d4 Binary files /dev/null and b/technic/textures/technic_hv_down_converter_bottom.png differ diff --git a/technic/textures/technic_hv_down_converter_side.png b/technic/textures/technic_hv_down_converter_side.png new file mode 100644 index 0000000..ab904f1 Binary files /dev/null and b/technic/textures/technic_hv_down_converter_side.png differ diff --git a/technic/textures/technic_hv_down_converter_top.png b/technic/textures/technic_hv_down_converter_top.png new file mode 100644 index 0000000..996b2d4 Binary files /dev/null and b/technic/textures/technic_hv_down_converter_top.png differ diff --git a/technic/textures/technic_mv_down_converter_bottom.png b/technic/textures/technic_mv_down_converter_bottom.png new file mode 100644 index 0000000..a610660 Binary files /dev/null and b/technic/textures/technic_mv_down_converter_bottom.png differ diff --git a/technic/textures/technic_mv_down_converter_side.png b/technic/textures/technic_mv_down_converter_side.png new file mode 100644 index 0000000..6492d5c Binary files /dev/null and b/technic/textures/technic_mv_down_converter_side.png differ diff --git a/technic/textures/technic_mv_down_converter_top.png b/technic/textures/technic_mv_down_converter_top.png new file mode 100644 index 0000000..a610660 Binary files /dev/null and b/technic/textures/technic_mv_down_converter_top.png differ -- cgit v1.2.3 From 37d9d94c44cbadc7e6550efc22612c7c605a9040 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Wed, 19 Jun 2013 00:24:37 +0200 Subject: Added case study of radiated power through inductive coils. --- technic/init.lua | 4 + technic/lighting.lua | 594 +++++++++++++++++++++ technic/power_radiator.lua | 308 +++++++++++ ...echnic_homedecor_glowlight_cube_white_sides.png | Bin 0 -> 255 bytes ...omedecor_glowlight_cube_white_sides_ceiling.png | Bin 0 -> 258 bytes .../technic_homedecor_glowlight_cube_white_tb.png | Bin 0 -> 261 bytes ...chnic_homedecor_glowlight_cube_yellow_sides.png | Bin 0 -> 350 bytes ...medecor_glowlight_cube_yellow_sides_ceiling.png | Bin 0 -> 353 bytes .../technic_homedecor_glowlight_cube_yellow_tb.png | Bin 0 -> 352 bytes ...chnic_homedecor_glowlight_thick_white_sides.png | Bin 0 -> 264 bytes ..._homedecor_glowlight_thick_white_wall_sides.png | Bin 0 -> 265 bytes ...hnic_homedecor_glowlight_thick_yellow_sides.png | Bin 0 -> 475 bytes ...homedecor_glowlight_thick_yellow_wall_sides.png | Bin 0 -> 478 bytes ...echnic_homedecor_glowlight_thin_white_sides.png | Bin 0 -> 225 bytes ...c_homedecor_glowlight_thin_white_wall_sides.png | Bin 0 -> 232 bytes ...chnic_homedecor_glowlight_thin_yellow_sides.png | Bin 0 -> 335 bytes ..._homedecor_glowlight_thin_yellow_wall_sides.png | Bin 0 -> 355 bytes .../technic_homedecor_glowlight_white_tb.png | Bin 0 -> 330 bytes .../technic_homedecor_glowlight_yellow_tb.png | Bin 0 -> 633 bytes 19 files changed, 906 insertions(+) create mode 100644 technic/lighting.lua create mode 100644 technic/power_radiator.lua create mode 100644 technic/textures/technic_homedecor_glowlight_cube_white_sides.png create mode 100644 technic/textures/technic_homedecor_glowlight_cube_white_sides_ceiling.png create mode 100644 technic/textures/technic_homedecor_glowlight_cube_white_tb.png create mode 100644 technic/textures/technic_homedecor_glowlight_cube_yellow_sides.png create mode 100644 technic/textures/technic_homedecor_glowlight_cube_yellow_sides_ceiling.png create mode 100644 technic/textures/technic_homedecor_glowlight_cube_yellow_tb.png create mode 100644 technic/textures/technic_homedecor_glowlight_thick_white_sides.png create mode 100644 technic/textures/technic_homedecor_glowlight_thick_white_wall_sides.png create mode 100644 technic/textures/technic_homedecor_glowlight_thick_yellow_sides.png create mode 100644 technic/textures/technic_homedecor_glowlight_thick_yellow_wall_sides.png create mode 100644 technic/textures/technic_homedecor_glowlight_thin_white_sides.png create mode 100644 technic/textures/technic_homedecor_glowlight_thin_white_wall_sides.png create mode 100644 technic/textures/technic_homedecor_glowlight_thin_yellow_sides.png create mode 100644 technic/textures/technic_homedecor_glowlight_thin_yellow_wall_sides.png create mode 100644 technic/textures/technic_homedecor_glowlight_white_tb.png create mode 100644 technic/textures/technic_homedecor_glowlight_yellow_tb.png diff --git a/technic/init.lua b/technic/init.lua index 2248295..6dd7eac 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -40,6 +40,10 @@ dofile(modpath.."/down_converter_mv.lua") dofile(modpath.."/electric_furnace_mv.lua") dofile(modpath.."/alloy_furnace_mv.lua") dofile(modpath.."/forcefield.lua") +-- These two are a concept study: Supplying appliances with inductive coupled power: +-- lighting and associated textures is taken directly from VanessaE's homedecor and made electric. +dofile(modpath.."/power_radiator.lua") +dofile(modpath.."/lighting.lua") --HV machines dofile(modpath.."/wires_hv.lua") diff --git a/technic/lighting.lua b/technic/lighting.lua new file mode 100644 index 0000000..5aab4c3 --- /dev/null +++ b/technic/lighting.lua @@ -0,0 +1,594 @@ +-- NOTE: The code is takes directly from VanessaE's homedecor mod. +-- I just made it the lights into indictive appliances for this mod. + +-- This file supplies electric powered glowlights + +-- Boilerplate to support localized strings if intllib mod is installed. +local S +if (minetest.get_modpath("intllib")) then + dofile(minetest.get_modpath("intllib").."/intllib.lua") + S = intllib.Getter(minetest.get_current_modname()) +else + S = function ( s ) return s end +end + +function technic_homedecor_node_is_owned(pos, placer) + local ownername = false + if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod + if HasOwner(pos, placer) then -- returns true if the node is owned + if not IsPlayerNodeOwner(pos, placer:get_player_name()) then + if type(getLastOwner) == "function" then -- ...is an old version + ownername = getLastOwner(pos) + elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version + ownername = GetNodeOwnerName(pos) + else + ownername = S("someone") + end + end + end + + elseif type(isprotect)=="function" then -- glomie's protection mod + if not isprotect(5, pos, placer) then + ownername = S("someone") + end + elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod + if not protector.can_dig(5, pos, placer) then + ownername = S("someone") + end + end + + if ownername ~= false then + minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) ) + return true + else + return false + end +end + +local dirs1 = { 20, 23, 22, 21 } +local dirs2 = { 9, 18, 7, 12 } + +function technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + if not technic_homedecor_node_is_owned(pointed_thing.under, placer) + and not technic_homedecor_node_is_owned(pointed_thing.above, placer) then + local node = minetest.env:get_node(pointed_thing.under) + if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].on_rightclick then + + local above = pointed_thing.above + local under = pointed_thing.under + local pitch = placer:get_look_pitch() + local pname = minetest.env:get_node(under).name + local node = minetest.env:get_node(above) + local fdir = minetest.dir_to_facedir(placer:get_look_dir()) + local wield_name = itemstack:get_name() + + if not minetest.registered_nodes[pname] + or not minetest.registered_nodes[pname].on_rightclick then + + local iswall = (above.x ~= under.x) or (above.z ~= under.z) + local isceiling = (above.x == under.x) and (above.z == under.z) and (pitch > 0) + local pos1 = above + + if minetest.registered_nodes[pname]["buildable_to"] then + pos1 = under + iswall = false + end + + if not minetest.registered_nodes[minetest.env:get_node(pos1).name]["buildable_to"] then return end + + if iswall then + minetest.env:add_node(pos1, {name = wield_name, param2 = dirs2[fdir+1] }) -- place wall variant + elseif isceiling then + minetest.env:add_node(pos1, {name = wield_name, param2 = 20 }) -- place upside down variant + else + minetest.env:add_node(pos1, {name = wield_name, param2 = 0 }) -- place right side up + end + + if not homedecor_expect_infinite_stacks then + itemstack:take_item() + return itemstack + end + end + else + minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) + end + end +end + +-- Yellow -- Half node +minetest.register_node('technic:homedecor_glowlight_half_yellow', { + description = S("Yellow Glowlight (thick)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_yellow_tb.png', + 'technic_homedecor_glowlight_yellow_tb.png', + 'technic_homedecor_glowlight_thick_yellow_sides.png', + 'technic_homedecor_glowlight_thick_yellow_sides.png', + 'technic_homedecor_glowlight_thick_yellow_sides.png', + 'technic_homedecor_glowlight_thick_yellow_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } + }, + node_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3 }, + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + print("Hello") + technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thick)") + print("Hello2") + end, + on_punch = function(pos, node, puncher) + print("Punch") + technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_yellow_active") + print("Punch2") + end +}) + +minetest.register_node('technic:homedecor_glowlight_half_yellow_active', { + description = S("Yellow Glowlight (thick)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_yellow_tb.png', + 'technic_homedecor_glowlight_yellow_tb.png', + 'technic_homedecor_glowlight_thick_yellow_sides.png', + 'technic_homedecor_glowlight_thick_yellow_sides.png', + 'technic_homedecor_glowlight_thick_yellow_sides.png', + 'technic_homedecor_glowlight_thick_yellow_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } + }, + node_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + light_source = LIGHT_MAX, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3, not_in_creative_inventory=1}, + drop="technic:homedecor_glowlight_half_yellow", + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thick)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_yellow") + end +}) + +-- Yellow -- Quarter node +minetest.register_node('technic:homedecor_glowlight_quarter_yellow', { + description = S("Yellow Glowlight (thin)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_yellow_tb.png', + 'technic_homedecor_glowlight_yellow_tb.png', + 'technic_homedecor_glowlight_thin_yellow_sides.png', + 'technic_homedecor_glowlight_thin_yellow_sides.png', + 'technic_homedecor_glowlight_thin_yellow_sides.png', + 'technic_homedecor_glowlight_thin_yellow_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } + }, + node_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3 }, + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thin)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_yellow_active") + end +}) + +minetest.register_node('technic:homedecor_glowlight_quarter_yellow_active', { + description = S("Yellow Glowlight (thin)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_yellow_tb.png', + 'technic_homedecor_glowlight_yellow_tb.png', + 'technic_homedecor_glowlight_thin_yellow_sides.png', + 'technic_homedecor_glowlight_thin_yellow_sides.png', + 'technic_homedecor_glowlight_thin_yellow_sides.png', + 'technic_homedecor_glowlight_thin_yellow_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } + }, + node_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + light_source = LIGHT_MAX-1, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3, not_in_creative_inventory=1}, + drop="technic:homedecor_glowlight_quarter_yellow", + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thin)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_yellow") + end +}) + + +-- White -- half node +minetest.register_node('technic:homedecor_glowlight_half_white', { + description = S("White Glowlight (thick)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_white_tb.png', + 'technic_homedecor_glowlight_white_tb.png', + 'technic_homedecor_glowlight_thick_white_sides.png', + 'technic_homedecor_glowlight_thick_white_sides.png', + 'technic_homedecor_glowlight_thick_white_sides.png', + 'technic_homedecor_glowlight_thick_white_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } + }, + node_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3 }, + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 100, "White Glowlight (thick)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_white_active") + end +}) + +minetest.register_node('technic:homedecor_glowlight_half_white_active', { + description = S("White Glowlight (thick)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_white_tb.png', + 'technic_homedecor_glowlight_white_tb.png', + 'technic_homedecor_glowlight_thick_white_sides.png', + 'technic_homedecor_glowlight_thick_white_sides.png', + 'technic_homedecor_glowlight_thick_white_sides.png', + 'technic_homedecor_glowlight_thick_white_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } + }, + node_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + light_source = LIGHT_MAX, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3, not_in_creative_inventory=1}, + drop="technic:homedecor_glowlight_half_white", + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 100, "White Glowlight (thick)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_white") + end +}) + +-- White -- Quarter node +minetest.register_node('technic:homedecor_glowlight_quarter_white', { + description = S("White Glowlight (thin)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_white_tb.png', + 'technic_homedecor_glowlight_white_tb.png', + 'technic_homedecor_glowlight_thin_white_sides.png', + 'technic_homedecor_glowlight_thin_white_sides.png', + 'technic_homedecor_glowlight_thin_white_sides.png', + 'technic_homedecor_glowlight_thin_white_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } + }, + node_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3 }, + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 100, "White Glowlight (thin)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_white_active") + end +}) + +minetest.register_node('technic:homedecor_glowlight_quarter_white_active', { + description = S("White Glowlight (thin)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_white_tb.png', + 'technic_homedecor_glowlight_white_tb.png', + 'technic_homedecor_glowlight_thin_white_sides.png', + 'technic_homedecor_glowlight_thin_white_sides.png', + 'technic_homedecor_glowlight_thin_white_sides.png', + 'technic_homedecor_glowlight_thin_white_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } + }, + node_box = { + type = "fixed", + fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + light_source = LIGHT_MAX-1, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3, not_in_creative_inventory=1}, + drop="technic:homedecor_glowlight_quarter_white", + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 100, "White Glowlight (thin)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_white") + end +}) + +-- Glowlight "cubes" - yellow +minetest.register_node('technic:homedecor_glowlight_small_cube_yellow', { + description = S("Yellow Glowlight (small cube)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_cube_yellow_tb.png', + 'technic_homedecor_glowlight_cube_yellow_tb.png', + 'technic_homedecor_glowlight_cube_yellow_sides.png', + 'technic_homedecor_glowlight_cube_yellow_sides.png', + 'technic_homedecor_glowlight_cube_yellow_sides.png', + 'technic_homedecor_glowlight_cube_yellow_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } + }, + node_box = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3 }, + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_yellow_active") + end +}) + +minetest.register_node('technic:homedecor_glowlight_small_cube_yellow_active', { + description = S("Yellow Glowlight (small cube)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_cube_yellow_tb.png', + 'technic_homedecor_glowlight_cube_yellow_tb.png', + 'technic_homedecor_glowlight_cube_yellow_sides.png', + 'technic_homedecor_glowlight_cube_yellow_sides.png', + 'technic_homedecor_glowlight_cube_yellow_sides.png', + 'technic_homedecor_glowlight_cube_yellow_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } + }, + node_box = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + light_source = LIGHT_MAX-1, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3, not_in_creative_inventory=1}, + drop="technic:homedecor_glowlight_cube_yellow", + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_yellow") + end +}) + +-- Glowlight "cubes" - white +minetest.register_node('technic:homedecor_glowlight_small_cube_white', { + description = S("White Glowlight (small cube)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_cube_white_tb.png', + 'technic_homedecor_glowlight_cube_white_tb.png', + 'technic_homedecor_glowlight_cube_white_sides.png', + 'technic_homedecor_glowlight_cube_white_sides.png', + 'technic_homedecor_glowlight_cube_white_sides.png', + 'technic_homedecor_glowlight_cube_white_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } + }, + node_box = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3 }, + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 50, "White Glowlight (small cube)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_white_active") + end +}) + +minetest.register_node('technic:homedecor_glowlight_small_cube_white_active', { + description = S("White Glowlight (small cube)"), + drawtype = "nodebox", + tiles = { + 'technic_homedecor_glowlight_cube_white_tb.png', + 'technic_homedecor_glowlight_cube_white_tb.png', + 'technic_homedecor_glowlight_cube_white_sides.png', + 'technic_homedecor_glowlight_cube_white_sides.png', + 'technic_homedecor_glowlight_cube_white_sides.png', + 'technic_homedecor_glowlight_cube_white_sides.png' + }, + selection_box = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } + }, + node_box = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 } + }, + + sunlight_propagates = false, + paramtype = "light", + paramtype2 = "facedir", + walkable = true, + light_source = LIGHT_MAX-1, + sounds = default.node_sound_wood_defaults(), + + groups = { snappy = 3, not_in_creative_inventory=1}, + drop="technic:homedecor_glowlight_cube_white", + on_place = function(itemstack, placer, pointed_thing) + technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) + return itemstack + end, + on_construct = function(pos) + technic_inductive_on_construct(pos, 50, "White Glowlight (small cube)") + end, + on_punch = function(pos, node, puncher) + technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_white") + end +}) + +register_inductive_machine("technic:homedecor_glowlight_half_yellow") +register_inductive_machine("technic:homedecor_glowlight_half_white") +register_inductive_machine("technic:homedecor_glowlight_quarter_yellow") +register_inductive_machine("technic:homedecor_glowlight_quarter_white") +register_inductive_machine("technic:homedecor_glowlight_small_cube_yellow") +register_inductive_machine("technic:homedecor_glowlight_small_cube_white") diff --git a/technic/power_radiator.lua b/technic/power_radiator.lua new file mode 100644 index 0000000..3383d18 --- /dev/null +++ b/technic/power_radiator.lua @@ -0,0 +1,308 @@ +-- The power radiator fuctions like an inductive charger +-- only better in the game setting. +-- The purpose is to allow small appliances to receive power +-- without the overhead of the wiring needed for larger machines. +-- +-- The power radiator will consume power corresponding to the +-- sum(power rating of the attached appliances)/0.6 +-- Using inductive power transfer is very inefficient so this is +-- set to the factor 0.6. + +-- API for inductive powered nodes: +-- Use the functions below to set the corresponding callbacks +-- Also two nodes are needed: The inactive and the active one. The active must be called _active . + +-- Register a new appliance using this function +technic_inductive_nodes = {} +registered_inductive_count=0 + +register_inductive_machine = function(name) + registered_inductive_count=registered_inductive_count+1 + technic_inductive_nodes[registered_inductive_count]=name + registered_inductive_count=registered_inductive_count+1 + technic_inductive_nodes[registered_inductive_count]=name.."_active" + end + + +-- Appliances: +-- has_supply: pos of supply node if the appliance has a power radiator near with sufficient power for the demand else "" +-- EU_demand: The power demand of the device. +-- EU_charge: Actual use. set to EU_demand if active==1 +-- active: set to 1 if the device is on +technic_inductive_on_construct = function(pos, eu_demand, infotext) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", infotext) + meta:set_int("technic_inductive_power_machine", 1) + meta:set_int("EU_demand",eu_demand) -- The power demand of this appliance + meta:set_int("EU_charge",0) -- The actual power draw of this appliance + meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators. + meta:set_int("active", 0) -- If the appliance can be turned on and off by using it use this. + end + +technic_inductive_on_punch_off = function(pos, eu_charge, swapnode) + local meta = minetest.env:get_meta(pos) + if meta:get_string("has_supply") ~= "" then + hacky_swap_node(pos, swapnode) + meta:set_int("active", 1) + meta:set_int("EU_charge",eu_charge) + --print("-----------") + --print("Turn on:") + --print("EUcha:"..meta:get_int("EU_charge")) + --print("has_supply:"..meta:get_string("has_supply")) + --print("<----------->") + end + end + +technic_inductive_on_punch_on = function(pos, eu_charge, swapnode) + local meta = minetest.env:get_meta(pos) + hacky_swap_node(pos, swapnode) + meta:set_int("active", 0) + meta:set_int("EU_charge",eu_charge) + --print("-----------") + --print("Turn off:") + --print("EUcha:"..meta:get_int("EU_charge")) + --print("has_supply:"..meta:get_string("has_supply")) + --print("<---------->") + end + +--minetest.register_node( +-- "technic:test_induc", { +-- description = "Test radiator node", +-- drawtype = "nodebox", +-- tiles = { +-- 'homedecor_glowlight_yellow_tb.png', +-- 'homedecor_glowlight_yellow_tb.png', +-- 'homedecor_glowlight_thick_yellow_sides.png', +-- 'homedecor_glowlight_thick_yellow_sides.png', +-- 'homedecor_glowlight_thick_yellow_sides.png', +-- 'homedecor_glowlight_thick_yellow_sides.png' +-- }, +-- +---- tiles = {"technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png", +---- "technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png"}, +-- selection_box = { +-- type = "fixed", +-- fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } +-- }, +-- node_box = { +-- type = "fixed", +-- fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } +-- }, +-- sunlight_propagates = false, +-- paramtype = "light", +-- paramtype2 = "facedir", +-- walkable = true, +-- groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, +-- on_place = function(itemstack, placer, pointed_thing) +-- homedecor_rotate_and_place(itemstack, placer, pointed_thing) +-- return itemstack +-- end, +-- on_construct = function(pos) +-- local meta = minetest.env:get_meta(pos) +-- meta:set_string("infotext", "Power Radiator Appliance") +-- meta:set_int("technic_inductive_power_machine", 1) +-- meta:set_int("EU_demand",200) -- The power demand of this appliance +-- meta:set_int("EU_charge",0) -- The actual power draw of this appliance +-- meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators. +-- meta:set_int("active", 0) -- If the appliance can be turned on and off by using it use this. +-- end, +-- on_punch = function(pos,node,puncher) +-- local meta = minetest.env:get_meta(pos) +-- if meta:get_string("has_supply") ~= "" then +-- hacky_swap_node(pos, "technic:test_induc_active") +-- meta:set_int("active", 1) +-- meta:set_int("EU_charge",200) +-- print("-----------") +-- print("Turn on:") +-- print("EUcha:"..meta:get_int("EU_charge")) +-- print("<----------->") +-- end +-- end, +-- }) +-- +--minetest.register_node( +-- "technic:test_induc_active", { +-- description = "Test radiator node", +-- drawtype = "nodebox", +-- tiles = { +-- 'homedecor_glowlight_yellow_tb.png', +-- 'homedecor_glowlight_yellow_tb.png', +-- 'homedecor_glowlight_thick_yellow_sides.png', +-- 'homedecor_glowlight_thick_yellow_sides.png', +-- 'homedecor_glowlight_thick_yellow_sides.png', +-- 'homedecor_glowlight_thick_yellow_sides.png' +-- }, +-- +---- tiles = {"technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", +---- "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png"}, +-- selection_box = { +-- type = "fixed", +-- fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } +-- }, +-- node_box = { +-- type = "fixed", +-- fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } +-- }, +-- sunlight_propagates = false, +-- paramtype = "light", +-- paramtype2 = "facedir", +-- walkable = true, +-- light_source=14, +-- groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, +-- drop="technic:test_induc", +-- on_place = function(itemstack, placer, pointed_thing) +-- homedecor_rotate_and_place(itemstack, placer, pointed_thing) +-- return itemstack +-- end, +-- on_construct = function(pos) +-- local meta = minetest.env:get_meta(pos) +-- meta:set_string("infotext", "Power Radiator Appliance Active") +-- meta:set_int("technic_inductive_power_machine", 1) +-- meta:set_int("EU_demand",200) -- The power demand of this appliance +-- meta:set_int("EU_charge",0) -- The actual power draw of this appliance +-- meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators. +-- end, +-- on_punch = function(pos,node,puncher) +-- local meta = minetest.env:get_meta(pos) +-- hacky_swap_node(pos, "technic:test_induc") +-- meta:set_int("active", 0) +-- meta:set_int("EU_charge",0) +-- print("-----------") +-- print("Turn off:") +-- print("EUcha:"..meta:get_int("EU_charge")) +-- print("<---------->") +-- end, +-- }) + +local shutdown_inductive_appliances = function(pos) + -- The supply radius + local rad = 4 + -- If the radiator is removed. turn off all appliances in region + -- If another radiator is near it will turn on the appliances again + local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic_inductive_nodes) + for _,pos1 in ipairs(positions) do + local meta1 = minetest.env:get_meta(pos1) + -- If the appliance is belonging to this node + if meta1:get_string("has_supply") == pos.x..pos.y..pos.z then + local nodename = minetest.env:get_node(pos1).name + -- Swap the node and make sure it is off and unpowered + if string.sub(nodename, -7) == "_active" then + hacky_swap_node(pos1, string.sub(nodename, 1, -8)) + meta1:set_int("active", 0) + meta1:set_int("EU_charge", 0) + end + meta1:set_string("has_supply", "") + end + end + end + + +minetest.register_node( + "technic:power_radiator", { + description = "Power Radiator", + tiles = {"technic_hv_down_converter_top.png", "technic_hv_down_converter_bottom.png", "technic_hv_down_converter_side.png", + "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + drawtype = "nodebox", + paramtype = "light", + is_ground_content = true, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_int("technic_mv_power_machine", 1) -- MV machine + meta:set_int("internal_EU_buffer",0) -- internal buffer value + meta:set_int("internal_EU_buffer_size",1000) -- Size of buffer + meta:set_int("connected_EU_demand",0) -- Potential demand of connected appliances + meta:set_string("infotext", "Power Radiator") +-- meta:set_int("active", 0) + end, + on_dig = function(pos, node, digger) + shutdown_inductive_appliances(pos) + return minetest.node_dig(pos, node, digger) + end, + }) + +minetest.register_craft( + { + output = 'technic:power_radiator 1', + recipe = { + {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'}, + {'technic:copper_coil', 'technic:mv_transformer', 'technic:copper_coil'}, + {'technic:rubber', 'technic:mv_cable', 'technic:rubber'}, + } + }) + +minetest.register_abm( + {nodenames = {"technic:power_radiator"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local my_supply = meta:get_int("internal_EU_buffer") + -- The maximum EU sourcing a single radiator can provide. + local max_charge = 1000 -- == the max EU demand of the radiator + local connected_EU_demand = meta:get_int("connected_EU_demand") + --print("--------------------") + --print("My Supply:"..my_supply) + --print("Connected Demand:"..connected_EU_demand) + if my_supply > 0 then + -- Efficiency factor + local eff_factor = 0.6 + -- The supply radius + local rad = 4 + + local meta1 = nil + local pos1 = {} + local used_charge = 0 + + -- Index all nodes within supply range + local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic_inductive_nodes) + for _,pos1 in ipairs(positions) do + local meta1 = minetest.env:get_meta(pos1) + -- If not supplied see if this node can handle it. + if meta1:get_string("has_supply") == "" then + -- if demand surpasses the capacity of this node, don't bother adding it. + local eu_demand = meta1:get_int("EU_demand")/eff_factor + if connected_EU_demand+eu_demand <= max_charge and connected_EU_demand+eu_demand <= my_supply then + -- We can power the appliance. Register, and spend power if it is on. + connected_EU_demand = connected_EU_demand+eu_demand + + meta1:set_string("has_supply", pos.x..pos.y..pos.z) + used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor) + end + elseif meta1:get_string("has_supply") == pos.x..pos.y..pos.z then + -- The appliance has power from this node. Spend power if it is on. + used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor) + end + end + --If demand surpasses actual supply turn off everything - we are out of power + if used_charge>my_supply then + meta:set_string("infotext", "Power Radiator is overloaded ("..math.floor(used_charge/my_supply*100).."% of available power)"); +-- meta:set_int("active",1) -- used for setting textures someday maybe + shutdown_inductive_appliances(pos) + connected_EU_demand = 0 + else + meta:set_string("infotext", "Power Radiator is powered ("..math.floor(used_charge/my_supply*100).."% of available power)"); + meta:set_int("internal_EU_buffer",my_supply-used_charge) +-- meta:set_int("active",1) -- used for setting textures someday maybe + end + else + meta:set_string("infotext", "Power Radiator is unpowered"); +-- meta:set_int("active",0) -- used for setting textures someday maybe + end + + -- Save state + meta:set_int("connected_EU_demand",connected_EU_demand) + return + end, + }) + +register_MV_machine ("technic:power_radiator","RE") diff --git a/technic/textures/technic_homedecor_glowlight_cube_white_sides.png b/technic/textures/technic_homedecor_glowlight_cube_white_sides.png new file mode 100644 index 0000000..9121999 Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_cube_white_sides.png differ diff --git a/technic/textures/technic_homedecor_glowlight_cube_white_sides_ceiling.png b/technic/textures/technic_homedecor_glowlight_cube_white_sides_ceiling.png new file mode 100644 index 0000000..c8006eb Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_cube_white_sides_ceiling.png differ diff --git a/technic/textures/technic_homedecor_glowlight_cube_white_tb.png b/technic/textures/technic_homedecor_glowlight_cube_white_tb.png new file mode 100644 index 0000000..b2e355a Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_cube_white_tb.png differ diff --git a/technic/textures/technic_homedecor_glowlight_cube_yellow_sides.png b/technic/textures/technic_homedecor_glowlight_cube_yellow_sides.png new file mode 100644 index 0000000..b79be07 Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_cube_yellow_sides.png differ diff --git a/technic/textures/technic_homedecor_glowlight_cube_yellow_sides_ceiling.png b/technic/textures/technic_homedecor_glowlight_cube_yellow_sides_ceiling.png new file mode 100644 index 0000000..a9d397a Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_cube_yellow_sides_ceiling.png differ diff --git a/technic/textures/technic_homedecor_glowlight_cube_yellow_tb.png b/technic/textures/technic_homedecor_glowlight_cube_yellow_tb.png new file mode 100644 index 0000000..daf03ab Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_cube_yellow_tb.png differ diff --git a/technic/textures/technic_homedecor_glowlight_thick_white_sides.png b/technic/textures/technic_homedecor_glowlight_thick_white_sides.png new file mode 100644 index 0000000..44c2b36 Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_thick_white_sides.png differ diff --git a/technic/textures/technic_homedecor_glowlight_thick_white_wall_sides.png b/technic/textures/technic_homedecor_glowlight_thick_white_wall_sides.png new file mode 100644 index 0000000..937999e Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_thick_white_wall_sides.png differ diff --git a/technic/textures/technic_homedecor_glowlight_thick_yellow_sides.png b/technic/textures/technic_homedecor_glowlight_thick_yellow_sides.png new file mode 100644 index 0000000..769b054 Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_thick_yellow_sides.png differ diff --git a/technic/textures/technic_homedecor_glowlight_thick_yellow_wall_sides.png b/technic/textures/technic_homedecor_glowlight_thick_yellow_wall_sides.png new file mode 100644 index 0000000..57820f1 Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_thick_yellow_wall_sides.png differ diff --git a/technic/textures/technic_homedecor_glowlight_thin_white_sides.png b/technic/textures/technic_homedecor_glowlight_thin_white_sides.png new file mode 100644 index 0000000..0a337a5 Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_thin_white_sides.png differ diff --git a/technic/textures/technic_homedecor_glowlight_thin_white_wall_sides.png b/technic/textures/technic_homedecor_glowlight_thin_white_wall_sides.png new file mode 100644 index 0000000..0fd3b1e Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_thin_white_wall_sides.png differ diff --git a/technic/textures/technic_homedecor_glowlight_thin_yellow_sides.png b/technic/textures/technic_homedecor_glowlight_thin_yellow_sides.png new file mode 100644 index 0000000..55bb6c0 Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_thin_yellow_sides.png differ diff --git a/technic/textures/technic_homedecor_glowlight_thin_yellow_wall_sides.png b/technic/textures/technic_homedecor_glowlight_thin_yellow_wall_sides.png new file mode 100644 index 0000000..4b28a27 Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_thin_yellow_wall_sides.png differ diff --git a/technic/textures/technic_homedecor_glowlight_white_tb.png b/technic/textures/technic_homedecor_glowlight_white_tb.png new file mode 100644 index 0000000..fdc8a4d Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_white_tb.png differ diff --git a/technic/textures/technic_homedecor_glowlight_yellow_tb.png b/technic/textures/technic_homedecor_glowlight_yellow_tb.png new file mode 100644 index 0000000..ffd9c58 Binary files /dev/null and b/technic/textures/technic_homedecor_glowlight_yellow_tb.png differ -- cgit v1.2.3 From ee5c6c23fab97f1bd1b217a654b72606938619b6 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Tue, 2 Jul 2013 00:03:36 +0200 Subject: Changed power distribution method and streamlined the various existing machines. An electrical network now requires a switching station to work. This statin is the one resolving the network collecting power and distributing it again. Added up/down converter. It is kind of finished. It can be updated with a slot for an upgrade but so far it works without by resolving the types of wires above and below the box. Tool and machine registering changed to use a table with key+value instead of the iterative method it used to have. The power radiator changed to be able to send up to 3000MV EUs in a radius of 6. This update will most likely require existing networks to be dug up and placed again. Also the switching station must be added. --- technic/alloy_furnace.lua | 519 +++++++++++++-------------- technic/alloy_furnace_mv.lua | 641 ++++++++++++++++++++++------------ technic/alloy_furnaces_commons.lua | 97 +++-- technic/battery_box.lua | 463 +++++++++--------------- technic/battery_box_hv.lua | 405 ++++++++------------- technic/battery_box_mv.lua | 399 ++++++++------------- technic/cans.lua | 16 +- technic/chainsaw.lua | 4 +- technic/cnc.lua | 407 ++++++++++----------- technic/electric_furnace.lua | 310 ++++++++-------- technic/electric_furnace_mv.lua | 543 ++++++++++++++-------------- technic/flashlight.lua | 4 +- technic/forcefield.lua | 15 +- technic/generator.lua | 222 ++++++------ technic/geothermal.lua | 228 ++++++------ technic/grinder.lua | 622 +++++++++++++++++---------------- technic/grinder_gloopores.lua | 10 +- technic/init.lua | 66 ++-- technic/lighting.lua | 66 ++-- technic/mining_drill.lua | 28 +- technic/mining_laser_mk1.lua | 8 +- technic/music_player.lua | 242 +++++++------ technic/power_radiator.lua | 211 +++-------- technic/register_machine_and_tool.lua | 70 ++++ technic/solar_array_hv.lua | 63 ++-- technic/solar_array_lv.lua | 78 ++--- technic/solar_array_mv.lua | 76 ++-- technic/solar_panel.lua | 26 +- technic/sonic_screwdriver.lua | 4 +- technic/supply_converter.lua | 223 ++++++++++++ technic/switching_station.lua | 352 +++++++++++++++++++ technic/tool_workshop.lua | 182 +++++----- technic/water_mill.lua | 187 +++++----- 33 files changed, 3602 insertions(+), 3185 deletions(-) create mode 100644 technic/register_machine_and_tool.lua create mode 100644 technic/supply_converter.lua create mode 100644 technic/switching_station.lua diff --git a/technic/alloy_furnace.lua b/technic/alloy_furnace.lua index 149688e..d36b93c 100644 --- a/technic/alloy_furnace.lua +++ b/technic/alloy_furnace.lua @@ -1,12 +1,14 @@ +-- LV Alloy furnace minetest.register_craft({ output = 'technic:coal_alloy_furnace', recipe = { {'default:brick', 'default:brick', 'default:brick'}, - {'default:brick', '', 'default:brick'}, + {'default:brick', '', 'default:brick'}, {'default:brick', 'default:brick', 'default:brick'}, } }) +-- FIXME: kpoppel: I'd like to introduce an induction heating element here... minetest.register_craft({ output = 'technic:alloy_furnace', recipe = { @@ -16,193 +18,178 @@ minetest.register_craft({ } }) --- LV alloy furnace - -alloy_furnace_formspec = - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "list[current_name;src;3,1;1,1;]".. - "list[current_name;src2;3,2;1,1;]".. - "list[current_name;dst;5,1;2,2;]".. - "list[current_player;main;0,5;8,4;]".. - "label[0,0;Electric Alloy Furnace]".. - "label[1,3;Power level]" - -minetest.register_node("technic:alloy_furnace", { - description = "Electric alloy furnace", - tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png", - "technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front.png"}, - paramtype2 = "facedir", - groups = {cracky=2}, - legacy_facedir_simple = true, - sounds = default.node_sound_stone_defaults(), - technic_power_machine=1, - internal_EU_buffer=0; - interal_EU_buffer_size=2000; - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_float("technic_power_machine", 1) - meta:set_string("formspec", alloy_furnace_formspec) - meta:set_string("infotext", "Electric Alloy furnace") - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("src2", 1) - inv:set_size("dst", 4) - local EU_used = 0 - local furnace_is_cookin = 0 - local cooked = nil - meta:set_float("internal_EU_buffer",0) - meta:set_float("internal_EU_buffer_size",2000) - meta:set_float("tube_time", 0) - end, - - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false end - if not inv:is_empty("src") then - return false end - if not inv:is_empty("src2") then - return false end - return true - end, +local alloy_furnace_formspec = + "invsize[8,9;]".. + "list[current_name;src;3,1;1,1;]".. + "list[current_name;src2;3,2;1,1;]".. + "list[current_name;dst;5,1;2,2;]".. + "list[current_player;main;0,5;8,4;]".. + "label[0,0;Electric Alloy Furnace]" + +minetest.register_node( + "technic:alloy_furnace", + { + description = "Electric alloy furnace", + tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png", + "technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front.png"}, + paramtype2 = "facedir", + groups = {cracky=2}, + legacy_facedir_simple = true, + sounds = default.node_sound_stone_defaults(), + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "Electric Alloy furnace") + meta:set_float("technic_power_machine", 1) + meta:set_string("formspec", alloy_furnace_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) + inv:set_size("src2", 1) + inv:set_size("dst", 4) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("src2") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, }) -minetest.register_node("technic:alloy_furnace_active", { - description = "Alloy Furnace", - tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png", - "technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front_active.png"}, - paramtype2 = "facedir", - light_source = 8, - drop = "technic:alloy_furnace", - groups = {cracky=2,not_in_creative_inventory=1}, - legacy_facedir_simple = true, - sounds = default.node_sound_stone_defaults(), - internal_EU_buffer=0; - interal_EU_buffer_size=2000; - technic_power_machine=1, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, -}) - -minetest.register_abm({ - nodenames = {"technic:alloy_furnace","technic:alloy_furnace_active"}, - interval = 1, - chance = 1, - - action = function(pos, node, active_object_count, active_object_count_wider) - - local meta = minetest.env:get_meta(pos) - internal_EU_buffer=meta:get_float("internal_EU_buffer") - internal_EU_buffer_size=meta:get_float("internal_EU_buffer") - local load = math.floor(internal_EU_buffer/2000 * 100) - meta:set_string("formspec", - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]".. - "list[current_name;src;3,1;1,1;]".. - "list[current_name;src2;3,2;1,1;]".. - "list[current_name;dst;5,1;2,2;]".. - "list[current_player;main;0,5;8,4;]".. - "label[0,0;Electric Alloy Furnace]".. - "label[1,3;Power level]") - - local inv = meta:get_inventory() - - local furnace_is_cookin = meta:get_int("furnace_is_cookin") - - local srclist = inv:get_list("src") - local srclist2 = inv:get_list("src2") - - srcstack = inv:get_stack("src", 1) - if srcstack then src_item1=srcstack:to_table() end - srcstack = inv:get_stack("src2", 1) - if srcstack then src_item2=srcstack:to_table() end - dst_index=nil - - if src_item1 and src_item2 then - dst_index=get_cook_result(src_item1,src_item2) - end - - - if (furnace_is_cookin == 1) then - if internal_EU_buffer>=150 then - internal_EU_buffer=internal_EU_buffer-150; - meta:set_float("internal_EU_buffer",internal_EU_buffer) - meta:set_float("src_time", meta:get_float("src_time") + 1) - if dst_index and meta:get_float("src_time") >= 4 then - -- check if there's room for output in "dst" list - dst_stack={} - dst_stack["name"]=alloy_recipes[dst_index].dst_name - dst_stack["count"]=alloy_recipes[dst_index].dst_count - if inv:room_for_item("dst",dst_stack) then - -- Put result in "dst" list - inv:add_item("dst",dst_stack) - -- take stuff from "src" list - for i=1,alloy_recipes[dst_index].src1_count,1 do - srcstack = inv:get_stack("src", 1) - srcstack:take_item() - inv:set_stack("src", 1, srcstack) - end - for i=1,alloy_recipes[dst_index].src2_count,1 do - srcstack = inv:get_stack("src2", 1) - srcstack:take_item() - inv:set_stack("src2", 1, srcstack) - end - - - else - print("Furnace inventory full!") - end - meta:set_string("src_time", 0) - end - end - end - - if dst_index and meta:get_int("furnace_is_cookin")==0 then - hacky_swap_node(pos,"technic:alloy_furnace_active") - meta:set_string("infotext","Electric Alloy Furnace active") - meta:set_int("furnace_is_cookin",1) - meta:set_string("src_time", 0) - return - end - - if meta:get_int("furnace_is_cookin")==0 or dst_index==nil then - hacky_swap_node(pos,"technic:alloy_furnace") - meta:set_string("infotext","Electric Alloy Furnace inactive") - meta:set_int("furnace_is_cookin",0) - meta:set_string("src_time", 0) - end - -end, -}) - -function get_cook_result(src_item1, src_item2) -local counter=registered_recipes_count-1 -for i=1, counter,1 do -if alloy_recipes[i].src1_name==src_item1["name"] and - alloy_recipes[i].src2_name==src_item2["name"] and - alloy_recipes[i].src1_count<=src_item1["count"] and - alloy_recipes[i].src2_count<=src_item2["count"] - then return i end -end -return nil -end - -register_LV_machine ("technic:alloy_furnace","RE") -register_LV_machine ("technic:alloy_furnace_active","RE") - ---coal driven alloy furnace: - +minetest.register_node( + "technic:alloy_furnace_active", + { + description = "Alloy Furnace", + tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png", + "technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front_active.png"}, + paramtype2 = "facedir", + light_source = 8, + drop = "technic:alloy_furnace", + groups = {cracky=2,not_in_creative_inventory=1}, + legacy_facedir_simple = true, + sounds = default.node_sound_stone_defaults(), + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("src2") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, + }) + +minetest.register_abm( + { nodenames = {"technic:alloy_furnace","technic:alloy_furnace_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local eu_input = meta:get_int("LV_EU_input") + local state = meta:get_int("state") + local next_state = state + + -- Machine information + local machine_name = "Electric Alloy Furnace" + local machine_node = "technic:alloy_furnace" + local machine_state_demand = { 50, 600 } + + -- Setup meta data if it does not exist. state is used as an indicator of this + if state == 0 then + meta:set_int("state", 1) + meta:set_int("LV_EU_demand", machine_state_demand[1]) + meta:set_int("LV_EU_input", 0) + meta:set_int("tube_time", 0) + return + end + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "LV") + + -- State machine + if eu_input == 0 then + -- Unpowered - go idle + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + next_state = 1 + elseif eu_input == machine_state_demand[state] then + -- Powered - do the state specific actions + + -- Execute always if powered logic + local inv = meta:get_inventory() + local empty = 1 + local recipe = nil + local result = nil + + -- Get what to cook if anything + local srcstack = inv:get_stack("src", 1) + local src2stack = inv:get_stack("src2", 1) + local src_item1 = nil + local src_item2 = nil + if srcstack and src2stack then + src_item1 = srcstack:to_table() + src_item2 = src2stack:to_table() + empty = 0 + end + + if src_item1 and src_item2 then + recipe = technic.get_alloy_recipe(src_item1,src_item2) + end + if recipe then + result = { name=recipe.dst_name, count=recipe.dst_count} + end + + if recipe then + print("recipe "..recipe.dst_name.." : result "..result.name.." : empty "..empty.." : src_item1 "..src_item1.name.." : src_item2 "..src_item2.name) + end + + if state == 1 then + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Idle") + + if empty == 0 and recipe and inv:room_for_item("dst", result) then + meta:set_string("infotext", machine_name.." Active") + meta:set_string("src_time", 0) + next_state = 2 + end + + elseif state == 2 then + hacky_swap_node(pos, machine_node.."_active") + meta:set_int("src_time", meta:get_int("src_time") + 1) + if meta:get_int("src_time") == 4 then -- 4 ticks per output + meta:set_string("src_time", 0) + -- check if there's room for output in "dst" list and that we have the materials + if recipe and inv:room_for_item("dst", result) then + -- Take stuff from "src" list + srcstack:take_item(recipe.src1_count) + inv:set_stack("src", 1, srcstack) + src2stack:take_item(recipe.src2_count) + inv:set_stack("src2", 1, src2stack) + -- Put result in "dst" list + inv:add_item("dst",result) + else + next_state = 1 + end + end + end + -- Change state? + if next_state ~= state then + meta:set_int("LV_EU_demand", machine_state_demand[next_state]) + meta:set_int("state", next_state) + end + end + end, + }) + +technic.register_LV_machine ("technic:alloy_furnace","RE") +technic.register_LV_machine ("technic:alloy_furnace_active","RE") + +-------------------------------------------------- +-- coal driven alloy furnace. This uses no EUs: +-------------------------------------------------- coal_alloy_furnace_formspec = "size[8,9]".. "label[0,0;Alloy Furnace]".. @@ -212,7 +199,7 @@ coal_alloy_furnace_formspec = "list[current_name;src2;3,1;1,1;]".. "list[current_name;dst;5,1;2,2;]".. "list[current_player;main;0,5;8,4;]" - + minetest.register_node("technic:coal_alloy_furnace", { description = "Alloy Furnace", tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png", @@ -230,9 +217,6 @@ minetest.register_node("technic:coal_alloy_furnace", { inv:set_size("src", 1) inv:set_size("src2", 1) inv:set_size("dst", 4) - local furnace_is_cookin = 0 - local dst_index = nil - end, can_dig = function(pos,player) local meta = minetest.env:get_meta(pos); @@ -268,10 +252,10 @@ minetest.register_abm({ nodenames = {"technic:coal_alloy_furnace","technic:coal_alloy_furnace_active"}, interval = 1, chance = 1, - + action = function(pos, node, active_object_count, active_object_count_wider) local meta = minetest.env:get_meta(pos) - for i, name in ipairs({ + for i, name in pairs({ "fuel_totaltime", "fuel_time", "src_totaltime", @@ -282,108 +266,101 @@ minetest.register_abm({ end end - local inv = meta:get_inventory() + local inv = meta:get_inventory() + local recipe = nil - srcstack = inv:get_stack("src", 1) + -- Get what to cook if anything + local srcstack = inv:get_stack("src", 1) if srcstack then src_item1=srcstack:to_table() end - srcstack = inv:get_stack("src2", 1) - if srcstack then src_item2=srcstack:to_table() end - dst_index=nil - - if src_item1 and src_item2 then - dst_index=get_cook_result(src_item1,src_item2) - end - local was_active = false + local src2stack = inv:get_stack("src2", 1) + if src2stack then src_item2=src2stack:to_table() end + if src_item1 and src_item2 then + recipe = technic.get_alloy_recipe(src_item1,src_item2) + 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") + 1) - meta:set_float("src_time", meta:get_float("src_time") + 1) - if dst_index and meta:get_float("src_time") >= 5 then - -- check if there's room for output in "dst" list - dst_stack={} - dst_stack["name"]=alloy_recipes[dst_index].dst_name - dst_stack["count"]=alloy_recipes[dst_index].dst_count - if inv:room_for_item("dst",dst_stack) then - -- Put result in "dst" list - inv:add_item("dst", dst_stack) - -- take stuff from "src" list - for i=1,alloy_recipes[dst_index].src1_count,1 do - srcstack = inv:get_stack("src", 1) - srcstack:take_item() - inv:set_stack("src", 1, srcstack) - end - for i=1,alloy_recipes[dst_index].src2_count,1 do - srcstack = inv:get_stack("src2", 1) - srcstack:take_item() - inv:set_stack("src2", 1, srcstack) - end - else - print("Furnace inventory full!") - end - meta:set_string("src_time", 0) - end + was_active = true + meta:set_float("fuel_time", meta:get_float("fuel_time") + 1) + meta:set_float("src_time", meta:get_float("src_time") + 1) + if recipe and meta:get_float("src_time") == 6 then + -- check if there's room for output in "dst" list + local dst_stack = { name=recipe.dst_name, count=recipe.dst_count} + if inv:room_for_item("dst",dst_stack) then + -- Take stuff from "src" list + srcstack:take_item(recipe.src1_count) + inv:set_stack("src", 1, srcstack) + src2stack:take_item(recipe.src2_count) + inv:set_stack("src2", 1, src2stack) + -- Put result in "dst" list + inv:add_item("dst",dst_stack) + else + print("Furnace inventory full!") -- Silly code... + 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","Furnace active: "..percent.."%") - hacky_swap_node(pos,"technic:coal_alloy_furnace_active") - meta:set_string("formspec", - "size[8,9]".. - "label[0,0;Electric Alloy Furnace]".. - "image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:".. - (100-percent)..":default_furnace_fire_fg.png]".. - "list[current_name;fuel;2,3;1,1;]".. - "list[current_name;src;2,1;1,1;]".. - "list[current_name;src2;3,1;1,1;]".. - "list[current_name;dst;5,1;2,2;]".. - "list[current_player;main;0,5;8,4;]") - return + local percent = math.floor(meta:get_float("fuel_time") / + meta:get_float("fuel_totaltime") * 100) + meta:set_string("infotext","Furnace active: "..percent.."%") + hacky_swap_node(pos,"technic:coal_alloy_furnace_active") + meta:set_string("formspec", + "size[8,9]".. + "label[0,0;Electric Alloy Furnace]".. + "image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:".. + (100-percent)..":default_furnace_fire_fg.png]".. + "list[current_name;fuel;2,3;1,1;]".. + "list[current_name;src;2,1;1,1;]".. + "list[current_name;src2;3,1;1,1;]".. + "list[current_name;dst;5,1;2,2;]".. + "list[current_player;main;0,5;8,4;]") + return end - local fuel = nil - local fuellist = inv:get_list("fuel") - + -- FIXME: Make this look more like the electrical version. + -- This code refetches the recipe to see if it can be done again after the iteration srcstack = inv:get_stack("src", 1) if srcstack then src_item1=srcstack:to_table() end srcstack = inv:get_stack("src2", 1) if srcstack then src_item2=srcstack:to_table() end - dst_index=nil + if src_item1 and src_item2 then + recipe = technic.get_alloy_recipe(src_item1,src_item2) + end - if src_item1 and src_item2 then - dst_index=get_cook_result(src_item1,src_item2) - end - - - if fuellist then - fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) + if recipe==nil then + if was_active then + meta:set_string("infotext","Furnace is empty") + hacky_swap_node(pos,"technic:coal_alloy_furnace") + meta:set_string("formspec", coal_alloy_furnace_formspec) + end + return end - if fuel.time <= 0 then - meta:set_string("infotext","Furnace out of fuel") - hacky_swap_node(pos,"technic:coal_alloy_furnace") - meta:set_string("formspec", coal_alloy_furnace_formspec) - return + -- Next take a hard look at the fuel situation + local fuel = nil + local fuellist = inv:get_list("fuel") + + if fuellist then + fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) end - if dst_index==nil then - if was_active then - meta:set_string("infotext","Furnace is empty") - hacky_swap_node(pos,"technic:coal_alloy_furnace") - meta:set_string("formspec", coal_alloy_furnace_formspec) - end - return + if fuel.time <= 0 then + meta:set_string("infotext","Furnace out of fuel") + hacky_swap_node(pos,"technic:coal_alloy_furnace") + meta:set_string("formspec", coal_alloy_furnace_formspec) + return end meta:set_string("fuel_totaltime", fuel.time) meta:set_string("fuel_time", 0) - + local stack = inv:get_stack("fuel", 1) stack:take_item() inv:set_stack("fuel", 1, stack) - -end, -}) + end, + }) diff --git a/technic/alloy_furnace_mv.lua b/technic/alloy_furnace_mv.lua index 1d78f6e..cadcb67 100644 --- a/technic/alloy_furnace_mv.lua +++ b/technic/alloy_furnace_mv.lua @@ -9,262 +9,451 @@ minetest.register_craft({ } }) -MV_alloy_furnace_formspec = +local mv_alloy_furnace_formspec = "invsize[8,10;]".. "label[0,0;MV Alloy Furnace]".. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "label[1,2.8;Power level]".. - "list[current_name;src;3,1;1,2;]".. + "list[current_name;src;3,1;1,2;]".. "list[current_name;dst;5,1;2,2;]".. "list[current_player;main;0,6;8,4;]".. "list[current_name;upgrade1;1,4;1,1;]".. "list[current_name;upgrade2;2,4;1,1;]".. "label[1,5;Upgrade Slots]" -minetest.register_node("technic:mv_alloy_furnace", { - description = "MV Alloy Furnace", - tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png", - "technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front.png"}, - paramtype2 = "facedir", - groups = {cracky=2, tubedevice=1,tubedevice_receiver=1}, - tube={insert_object=function(pos,node,stack,direction) - local meta=minetest.env:get_meta(pos) - local inv=meta:get_inventory() - return inv:add_item("src",stack) - end, - can_insert=function(pos,node,stack,direction) +minetest.register_node( + "technic:mv_alloy_furnace", + {description = "MV Alloy Furnace", + tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png", + "technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front.png"}, + paramtype2 = "facedir", + groups = {cracky=2, tubedevice=1,tubedevice_receiver=1}, + tube={insert_object=function(pos,node,stack,direction) + local meta=minetest.env:get_meta(pos) + local inv=meta:get_inventory() + return inv:add_item("src",stack) + end, + can_insert=function(pos,node,stack,direction) local meta=minetest.env:get_meta(pos) local inv=meta:get_inventory() return inv:room_for_item("src",stack) - end, - }, - legacy_facedir_simple = true, - sounds = default.node_sound_stone_defaults(), - technic_power_machine=1, - internal_EU_buffer=0; - interal_EU_buffer_size=2000; - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_float("technic_power_machine", 1) - meta:set_string("formspec", mv_alloy_furnace_formspec) - meta:set_string("infotext", "MV Electric Alloy furnace") - local inv = meta:get_inventory() - inv:set_size("src", 2) - inv:set_size("dst", 4) - inv:set_size("upgrade1", 1) - inv:set_size("upgrade2", 1) - local EU_used = 0 - local furnace_is_cookin = 0 - local cooked = nil - meta:set_float("internal_EU_buffer",0) - meta:set_float("internal_EU_buffer_size",2000) - - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false end - if not inv:is_empty("src") then - return false end - if not inv:is_empty("upgrade1") then - return false end - if not inv:is_empty("upgrade2") then - return false end - return true - end, + end, + }, + legacy_facedir_simple = true, + sounds = default.node_sound_stone_defaults(), + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "MV Alloy furnace") + meta:set_float("technic_mv_power_machine", 1) + meta:set_int("tube_time", 0) + meta:set_string("formspec", mv_alloy_furnace_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 2) + inv:set_size("dst", 4) + inv:set_size("upgrade1", 1) + inv:set_size("upgrade2", 1) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, }) -minetest.register_node("technic:mv_alloy_furnace_active", { - description = "MV Alloy Furnace", - tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png", - "technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front_active.png"}, - paramtype2 = "facedir", - light_source = 8, - drop = "technic:mv_alloy_furnace", - groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1}, - tube={insert_object=function(pos,node,stack,direction) - local meta=minetest.env:get_meta(pos) - local inv=meta:get_inventory() - return inv:add_item("src",stack) - end, - can_insert=function(pos,node,stack,direction) +minetest.register_node( + "technic:mv_alloy_furnace_active", + {description = "MV Alloy Furnace", + tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png", + "technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front_active.png"}, + paramtype2 = "facedir", + light_source = 8, + drop = "technic:mv_alloy_furnace", + groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1}, + tube={insert_object=function(pos,node,stack,direction) + local meta=minetest.env:get_meta(pos) + local inv=meta:get_inventory() + return inv:add_item("src",stack) + end, + can_insert=function(pos,node,stack,direction) local meta=minetest.env:get_meta(pos) local inv=meta:get_inventory() return inv:room_for_item("src",stack) - end, - }, - legacy_facedir_simple = true, - sounds = default.node_sound_stone_defaults(), - internal_EU_buffer=0; - interal_EU_buffer_size=2000; - technic_power_machine=1, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false end - if not inv:is_empty("src") then - return false end - if not inv:is_empty("upgrade1") then - return false end - if not inv:is_empty("upgrade2") then - return false end - return true - end, + end, + }, + legacy_facedir_simple = true, + sounds = default.node_sound_stone_defaults(), + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, + -- These three makes sure upgrades are not moved in or out while the furnace is active. + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if listname == "src" or listname == "dst" then + return 99 + else + return 0 -- Disallow the move + end + end, + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if listname == "src" or listname == "dst" then + return 99 + else + return 0 -- Disallow the move + end + end, + allow_metadata_inventory_move = function(pos, from_list, to_list, to_list, to_index, count, player) + return 0 + end, }) -minetest.register_abm({ - nodenames = {"technic:mv_alloy_furnace","technic:mv_alloy_furnace_active"}, - interval = 1, - chance = 1, - - action = function(pos, node, active_object_count, active_object_count_wider) - local pos1={} - pos1.x=pos.x - pos1.y=pos.y - pos1.z=pos.z - local x_velocity=0 - local z_velocity=0 - - -- output is on the left side of the furnace - if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end - if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end - if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end - if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end - - local output_tube_connected = false - local meta=minetest.env:get_meta(pos1) - if meta:get_int("tubelike")==1 then output_tube_connected=true end - meta = minetest.env:get_meta(pos) - local inv = meta:get_inventory() - local upg_item1 - local upg_item1_name="" - local upg_item2 - local upg_item2_name="" - local srcstack = inv:get_stack("upgrade1", 1) - if srcstack then upg_item1=srcstack:to_table() end - srcstack = inv:get_stack("upgrade2", 1) - if srcstack then upg_item2=srcstack:to_table() end - if upg_item1 then upg_item1_name=upg_item1.name end - if upg_item2 then upg_item2_name=upg_item2.name end - - local speed=0 - if upg_item1_name=="technic:control_logic_unit" then speed=speed+1 end - if upg_item2_name=="technic:control_logic_unit" then speed=speed+1 end - tube_time=meta:get_float("tube_time") - tube_time=tube_time+speed - if tube_time>3 then - tube_time=0 - if output_tube_connected then send_cooked_alloys(pos,x_velocity,z_velocity) end - end - meta:set_float("tube_time", tube_time) +local send_cooked_items = function(pos,x_velocity,z_velocity) + -- Send items on their way in the pipe system. + local meta=minetest.env:get_meta(pos) + local inv = meta:get_inventory() + local i=0 + for _,stack in ipairs(inv:get_list("dst")) do + i=i+1 + if stack then + local item0=stack:to_table() + if item0 then + item0["count"]="1" + local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},item0) + item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z} + item1:setvelocity({x=x_velocity, y=0, z=z_velocity}) + item1:setacceleration({x=0, y=0, z=0}) + stack:take_item(1); + inv:set_stack("dst", i, stack) + return + end + end + end + end - local extra_buffer_size = 0 - if upg_item1_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end - if upg_item2_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end - local internal_EU_buffer_size=2000+extra_buffer_size - meta:set_float("internal_EU_buffer_size",internal_EU_buffer_size) +local smelt_item = function(pos) + local meta=minetest.env:get_meta(pos) + local inv = meta:get_inventory() + meta:set_int("src_time", meta:get_int("src_time") + 3) -- Cooking time 3x faster + local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")}) + dst_stack={} + dst_stack["name"]=alloy_recipes[dst_index].dst_name + dst_stack["count"]=alloy_recipes[dst_index].dst_count - internal_EU_buffer=meta:get_float("internal_EU_buffer") - if internal_EU_buffer > internal_EU_buffer_size then internal_EU_buffer = internal_EU_buffer_size end - local meta = minetest.env:get_meta(pos) - local load = math.floor(internal_EU_buffer/internal_EU_buffer_size * 100) - meta:set_string("formspec", - MV_alloy_furnace_formspec.. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]") + if result and result.item and meta:get_int("src_time") >= result.time then + meta:set_int("src_time", 0) + -- check if there's room for output in "dst" list + if inv:room_for_item("dst",result) then + -- take stuff from "src" list + srcstack = inv:get_stack("src", 1) + srcstack:take_item() + inv:set_stack("src", 1, srcstack) + -- Put result in "dst" list + inv:add_item("dst", result.item) + return 1 + else + return 0 -- done + end + end + return 0 -- done + end - local inv = meta:get_inventory() +minetest.register_abm( + {nodenames = {"technic:mv_alloy_furnace","technic:mv_alloy_furnace_active"}, + interval = 1, + chance = 1, - local furnace_is_cookin = meta:get_int("furnace_is_cookin") + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local eu_input = meta:get_int("MV_EU_input") + local state = meta:get_int("state") + local next_state = state - local srclist = inv:get_list("src") - local srclist2 = inv:get_list("src2") + -- Machine information + local machine_name = "MV Alloy Furnace" + local machine_node = "technic:mv_alloy_furnace" + local machine_state_demand = { 50, 2000, 1500, 1000 } - srcstack = inv:get_stack("src", 1) - if srcstack then src_item1=srcstack:to_table() end - srcstack = inv:get_stack("src", 2) - if srcstack then src_item2=srcstack:to_table() end - dst_index=nil - - if src_item1 and src_item2 then - dst_index=get_cook_result(src_item1,src_item2) - end + -- Setup meta data if it does not exist. state is used as an indicator of this + if state == 0 then + meta:set_int("state", 1) + meta:set_int("MV_EU_demand", machine_state_demand[1]) + meta:set_int("MV_EU_input", 0) + return + end + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "MV") + + -- Execute always logic + -- CODE HERE -- + -- State machine + if eu_input == 0 then + -- Unpowered - go idle + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + next_state = 1 + elseif eu_input == machine_state_demand[state] then + -- Powered - do the state specific actions + + -- Execute always if powered logic + local meta=minetest.env:get_meta(pos) + + -- Get the names of the upgrades + local meta=minetest.env:get_meta(pos) + local inv = meta:get_inventory() + local upg_item1 + local upg_item1_name="" + local upg_item2 + local upg_item2_name="" + local srcstack = inv:get_stack("upgrade1", 1) + if srcstack then upg_item1=srcstack:to_table() end + srcstack = inv:get_stack("upgrade2", 1) + if srcstack then upg_item2=srcstack:to_table() end + if upg_item1 then upg_item1_name=upg_item1.name end + if upg_item2 then upg_item2_name=upg_item2.name end + + -- Save some power by installing battery upgrades. Fully upgraded makes this + -- furnace use the same amount of power as the LV version + local EU_saving_upgrade = 0 + if upg_item1_name=="technic:battery" then EU_saving_upgrade = EU_saving_upgrade + 1 end + if upg_item2_name=="technic:battery" then EU_saving_upgrade = EU_saving_upgrade + 1 end + + -- Tube loading speed can be upgraded using control logic units + local tube_speed_upgrade = 0 + if upg_item1_name=="technic:control_logic_unit" then tube_speed_upgrade = tube_speed_upgrade + 1 end + if upg_item2_name=="technic:control_logic_unit" then tube_speed_upgrade = tube_speed_upgrade + 1 end + + -- Handle pipeworks (consumes tube_speed_upgrade) + local pos1={x=pos.x, y=pos.y, z=pos.z} + local x_velocity=0 + local z_velocity=0 + + -- Output is on the left side of the furnace + if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end + if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end + if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end + if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end + + local output_tube_connected = false + local meta1 = minetest.env:get_meta(pos1) + if meta1:get_int("tubelike") == 1 then + output_tube_connected=true + end + tube_time = meta:get_int("tube_time") + tube_time = tube_time + tube_speed_upgrade + if tube_time > 3 then + tube_time = 0 + if output_tube_connected then + send_cooked_items(pos,x_velocity,z_velocity) + end + end + meta:set_int("tube_time", tube_time) - if (furnace_is_cookin == 1) then - if internal_EU_buffer>=150 then - internal_EU_buffer=internal_EU_buffer-150; - meta:set_float("internal_EU_buffer",internal_EU_buffer) - meta:set_float("src_time", meta:get_float("src_time") + 1) - if dst_index and meta:get_float("src_time") >= 4 then - -- check if there's room for output in "dst" list - dst_stack={} - dst_stack["name"]=alloy_recipes[dst_index].dst_name - dst_stack["count"]=alloy_recipes[dst_index].dst_count - if inv:room_for_item("dst",dst_stack) then - -- Put result in "dst" list - inv:add_item("dst",dst_stack) - -- take stuff from "src" list - for i=1,alloy_recipes[dst_index].src1_count,1 do - srcstack = inv:get_stack("src", 1) - srcstack:take_item() - inv:set_stack("src", 1, srcstack) - end - for i=1,alloy_recipes[dst_index].src2_count,1 do - srcstack = inv:get_stack("src", 2) - srcstack:take_item() - inv:set_stack("src", 2, srcstack) - end + -- The machine shuts down if we have nothing to smelt and no tube is connected + -- or if we have nothing to send with a tube connected. + if (not output_tube_connected and inv:is_empty("src")) + or ( output_tube_connected and inv:is_empty("dst")) then + next_state = 1 + end + ---------------------- + local empty = 1 + local recipe = nil + local result = nil - else - print("Furnace inventory full!") - end - meta:set_string("src_time", 0) - end - end + -- Get what to cook if anything + local srcstack = inv:get_stack("src", 1) + local src2stack = inv:get_stack("src", 2) + local src_item1 = nil + local src_item2 = nil + if srcstack and src2stack then + src_item1 = srcstack:to_table() + src_item2 = src2stack:to_table() + empty = 0 + end + + if src_item1 and src_item2 then + recipe = technic.get_alloy_recipe(src_item1,src_item2) + end + if recipe then + result = { name=recipe.dst_name, count=recipe.dst_count} + end + + if state == 1 then + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Idle") + + local meta=minetest.env:get_meta(pos) + local inv = meta:get_inventory() + if not inv:is_empty("src") then + if empty == 0 and recipe and inv:room_for_item("dst", result) then + meta:set_string("infotext", machine_name.." Active") + meta:set_int("src_time", 0) + next_state = 2+EU_saving_upgrade -- Next state is decided by the battery upgrade (state 2= 0 batteries, state 3 = 1 battery, 4 = 2 batteries) + end + end + + elseif state == 2 or state == 3 or state == 4 then + hacky_swap_node(pos, machine_node.."_active") + meta:set_int("src_time", meta:get_int("src_time") + 1) + if meta:get_int("src_time") == 4 then -- 4 ticks per output + meta:set_string("src_time", 0) + -- check if there's room for output in "dst" list and that we have the materials + if recipe and inv:room_for_item("dst", result) then + -- Take stuff from "src" list + srcstack:take_item(recipe.src1_count) + inv:set_stack("src", 1, srcstack) + src2stack:take_item(recipe.src2_count) + inv:set_stack("src2", 1, src2stack) + -- Put result in "dst" list + inv:add_item("dst",result) + else + next_state = 1 + end + end + end + end + -- Change state? + if next_state ~= state then + meta:set_int("MV_EU_demand", machine_state_demand[next_state]) + meta:set_int("state", next_state) end - if dst_index and meta:get_int("furnace_is_cookin")==0 then - hacky_swap_node(pos,"technic:mv_alloy_furnace_active") - meta:set_string("infotext","MV Alloy Furnace active") - meta:set_int("furnace_is_cookin",1) - meta:set_string("src_time", 0) - return - end - if meta:get_int("furnace_is_cookin")==0 or dst_index==nil then - hacky_swap_node(pos,"technic:mv_alloy_furnace") - meta:set_string("infotext","MV Alloy Furnace inactive") - meta:set_int("furnace_is_cookin",0) - meta:set_string("src_time", 0) - end -end, -}) + ------------------------------------ -function send_cooked_alloys (pos,x_velocity,z_velocity) - local meta=minetest.env:get_meta(pos) - local inv = meta:get_inventory() - local i=0 - for _,stack in ipairs(inv:get_list("dst")) do - i=i+1 - if stack then - local item0=stack:to_table() - if item0 then - item0["count"]="1" - local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},item0) - item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z} - item1:setvelocity({x=x_velocity, y=0, z=z_velocity}) - item1:setacceleration({x=0, y=0, z=0}) - stack:take_item(1); - inv:set_stack("dst", i, stack) - return - end - end - end -end +-- local pos1={} +-- pos1.x=pos.x +-- pos1.y=pos.y +-- pos1.z=pos.z +-- local x_velocity=0 +-- local z_velocity=0 +-- +-- -- output is on the left side of the furnace +-- if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end +-- if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end +-- if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end +-- if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end +-- +-- local output_tube_connected = false +-- local meta=minetest.env:get_meta(pos1) +-- if meta:get_int("tubelike")==1 then output_tube_connected=true end +-- meta = minetest.env:get_meta(pos) +-- local inv = meta:get_inventory() +-- local upg_item1 +-- local upg_item1_name="" +-- local upg_item2 +-- local upg_item2_name="" +-- local srcstack = inv:get_stack("upgrade1", 1) +-- if srcstack then upg_item1=srcstack:to_table() end +-- srcstack = inv:get_stack("upgrade2", 1) +-- if srcstack then upg_item2=srcstack:to_table() end +-- if upg_item1 then upg_item1_name=upg_item1.name end +-- if upg_item2 then upg_item2_name=upg_item2.name end +-- +-- local speed=0 +-- if upg_item1_name=="technic:control_logic_unit" then speed=speed+1 end +-- if upg_item2_name=="technic:control_logic_unit" then speed=speed+1 end +-- tube_time=meta:get_float("tube_time") +-- tube_time=tube_time+speed +-- if tube_time>3 then +-- tube_time=0 +-- if output_tube_connected then send_cooked_items(pos,x_velocity,z_velocity) end +-- end +-- meta:set_float("tube_time", tube_time) +-- +-- local extra_buffer_size = 0 +-- if upg_item1_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end +-- if upg_item2_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end +-- local internal_EU_buffer_size=2000+extra_buffer_size +-- meta:set_float("internal_EU_buffer_size",internal_EU_buffer_size) +-- +-- internal_EU_buffer=meta:get_float("internal_EU_buffer") +-- if internal_EU_buffer > internal_EU_buffer_size then internal_EU_buffer = internal_EU_buffer_size end +-- local meta = minetest.env:get_meta(pos) +-- local load = math.floor(internal_EU_buffer/internal_EU_buffer_size * 100) +-- meta:set_string("formspec", +-- MV_alloy_furnace_formspec.. +-- "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. +-- (load)..":technic_power_meter_fg.png]") +-- +-- local inv = meta:get_inventory() +-- +-- local furnace_is_cookin = meta:get_int("furnace_is_cookin") +-- +-- local srclist = inv:get_list("src") +-- local srclist2 = inv:get_list("src2") +-- +-- srcstack = inv:get_stack("src", 1) +-- if srcstack then src_item1=srcstack:to_table() end +-- srcstack = inv:get_stack("src", 2) +-- if srcstack then src_item2=srcstack:to_table() end +-- dst_index=nil +-- +-- if src_item1 and src_item2 then +-- dst_index=get_cook_result(src_item1,src_item2) +-- end +-- +-- +-- if (furnace_is_cookin == 1) then +-- if internal_EU_buffer>=150 then +-- internal_EU_buffer=internal_EU_buffer-150; +-- meta:set_float("internal_EU_buffer",internal_EU_buffer) +-- meta:set_float("src_time", meta:get_float("src_time") + 1) +-- if dst_index and meta:get_float("src_time") >= 4 then +-- -- check if there's room for output in "dst" list +-- dst_stack={} +-- dst_stack["name"]=alloy_recipes[dst_index].dst_name +-- dst_stack["count"]=alloy_recipes[dst_index].dst_count +-- if inv:room_for_item("dst",dst_stack) then +-- -- Put result in "dst" list +-- inv:add_item("dst",dst_stack) +-- -- take stuff from "src" list +-- for i=1,alloy_recipes[dst_index].src1_count,1 do +-- srcstack = inv:get_stack("src", 1) +-- srcstack:take_item() +-- inv:set_stack("src", 1, srcstack) +-- end +-- for i=1,alloy_recipes[dst_index].src2_count,1 do +-- srcstack = inv:get_stack("src", 2) +-- srcstack:take_item() +-- inv:set_stack("src", 2, srcstack) +-- end +-- +-- else +-- print("Furnace inventory full!") +-- end +-- meta:set_string("src_time", 0) +-- end +-- end +-- end +-- +-- if dst_index and meta:get_int("furnace_is_cookin")==0 then +-- hacky_swap_node(pos,"technic:mv_alloy_furnace_active") +-- meta:set_string("infotext","MV Alloy Furnace active") +-- meta:set_int("furnace_is_cookin",1) +-- meta:set_string("src_time", 0) +-- return +-- end +-- +-- if meta:get_int("furnace_is_cookin")==0 or dst_index==nil then +-- hacky_swap_node(pos,"technic:mv_alloy_furnace") +-- meta:set_string("infotext","MV Alloy Furnace inactive") +-- meta:set_int("furnace_is_cookin",0) +-- meta:set_string("src_time", 0) +-- end +-- + end, + }) -register_MV_machine ("technic:mv_alloy_furnace","RE") -register_MV_machine ("technic:mv_alloy_furnace_active","RE") +technic.register_MV_machine ("technic:mv_alloy_furnace","RE") +technic.register_MV_machine ("technic:mv_alloy_furnace_active","RE") diff --git a/technic/alloy_furnaces_commons.lua b/technic/alloy_furnaces_commons.lua index 9c9c42a..5a6e65b 100644 --- a/technic/alloy_furnaces_commons.lua +++ b/technic/alloy_furnaces_commons.lua @@ -1,32 +1,77 @@ -alloy_recipes ={} +-- Register alloy recipes +technic.alloy_recipes = {} -registered_recipes_count=1 +-- Register recipe in a table +technic.register_alloy_recipe = function(metal1, count1, metal2, count2, result, count3) + technic.alloy_recipes[metal1..metal2] = { src1_count = count1, src2_count = count2, dst_name = result, dst_count = count3 } + if unified_inventory then + unified_inventory.register_craft( + { + type = "alloy", + output = result.." "..count3, + items = {metal1.." "..count1,metal2.." "..count2}, + width = 2, + }) + end + end + +-- Retrieve a recipe given the input metals. +-- Input parameters are a table from a StackItem +technic.get_alloy_recipe = function(metal1, metal2) + -- Check for both combinations of metals and for the right amount in both + if technic.alloy_recipes[metal1.name..metal2.name] + and metal1.count >= technic.alloy_recipes[metal1.name..metal2.name].src1_count + and metal2.count >= technic.alloy_recipes[metal1.name..metal2.name].src2_count then + return technic.alloy_recipes[metal1.name..metal2.name] + elseif technic.alloy_recipes[metal2.name..metal1.name] + and metal2.count >= technic.alloy_recipes[metal2.name..metal1.name].src1_count + and metal1.count >= technic.alloy_recipes[metal2.name..metal1.name].src2_count then + return technic.alloy_recipes[metal2.name..metal1.name] + else + return nil + end + end + +technic.register_alloy_recipe("technic:copper_dust", 3, "technic:tin_dust", 1, "technic:bronze_dust", 4) +technic.register_alloy_recipe("moreores:copper_ingot",3, "moreores:tin_ingot", 1, "moreores:bronze_ingot", 4) +technic.register_alloy_recipe("technic:iron_dust", 3, "technic:chromium_dust", 1, "technic:stainless_steel_dust", 4) +technic.register_alloy_recipe("default:steel_ingot", 3, "technic:chromium_ingot",1, "technic:stainless_steel_ingot",4) +technic.register_alloy_recipe("technic:copper_dust", 2, "technic:zinc_dust", 1, "technic:brass_dust", 3) +technic.register_alloy_recipe("moreores:copper_ingot",2, "technic:zinc_ingot", 1, "technic:brass_ingot", 3) +technic.register_alloy_recipe("default:sand", 2, "technic:coal_dust", 2, "technic:silicon_wafer", 1) +technic.register_alloy_recipe("technic:silicon_wafer",1, "technic:gold_dust", 1, "technic:doped_silicon_wafer", 1) + +-------------------------------------- +-- LEGACY CODE - some other mods might depend on this - Register the same recipes as above... +-------------------------------------- +alloy_recipes = {} +registered_recipes_count = 1 function register_alloy_recipe (string1,count1, string2,count2, string3,count3) -alloy_recipes[registered_recipes_count]={} -alloy_recipes[registered_recipes_count].src1_name=string1 -alloy_recipes[registered_recipes_count].src1_count=count1 -alloy_recipes[registered_recipes_count].src2_name=string2 -alloy_recipes[registered_recipes_count].src2_count=count2 -alloy_recipes[registered_recipes_count].dst_name=string3 -alloy_recipes[registered_recipes_count].dst_count=count3 -registered_recipes_count=registered_recipes_count+1 -alloy_recipes[registered_recipes_count]={} -alloy_recipes[registered_recipes_count].src1_name=string2 -alloy_recipes[registered_recipes_count].src1_count=count2 -alloy_recipes[registered_recipes_count].src2_name=string1 -alloy_recipes[registered_recipes_count].src2_count=count1 -alloy_recipes[registered_recipes_count].dst_name=string3 -alloy_recipes[registered_recipes_count].dst_count=count3 -registered_recipes_count=registered_recipes_count+1 -if unified_inventory then - unified_inventory.register_craft({ - type = "alloy", - output = string3.." "..count3, - items = {string1.." "..count1,string2.." "..count2}, - width = 2, - }) - end + alloy_recipes[registered_recipes_count]={} + alloy_recipes[registered_recipes_count].src1_name=string1 + alloy_recipes[registered_recipes_count].src1_count=count1 + alloy_recipes[registered_recipes_count].src2_name=string2 + alloy_recipes[registered_recipes_count].src2_count=count2 + alloy_recipes[registered_recipes_count].dst_name=string3 + alloy_recipes[registered_recipes_count].dst_count=count3 + registered_recipes_count=registered_recipes_count+1 + alloy_recipes[registered_recipes_count]={} + alloy_recipes[registered_recipes_count].src1_name=string2 + alloy_recipes[registered_recipes_count].src1_count=count2 + alloy_recipes[registered_recipes_count].src2_name=string1 + alloy_recipes[registered_recipes_count].src2_count=count1 + alloy_recipes[registered_recipes_count].dst_name=string3 + alloy_recipes[registered_recipes_count].dst_count=count3 + registered_recipes_count=registered_recipes_count+1 + if unified_inventory then + unified_inventory.register_craft({ + type = "alloy", + output = string3.." "..count3, + items = {string1.." "..count1,string2.." "..count2}, + width = 2, + }) + end end register_alloy_recipe ("technic:copper_dust",3, "technic:tin_dust",1, "technic:bronze_dust",4) diff --git a/technic/battery_box.lua b/technic/battery_box.lua index 5726053..1f0740d 100644 --- a/technic/battery_box.lua +++ b/technic/battery_box.lua @@ -1,23 +1,8 @@ --- register LV machines here -local LV_machines = {} -function register_LV_machine(string1,string2) - LV_machines[string1] = string2 -end - -power_tools ={} -registered_power_tools_count=0 - -function register_power_tool (string1,max_charge) - registered_power_tools_count=registered_power_tools_count+1 - power_tools[registered_power_tools_count]={} - power_tools[registered_power_tools_count].tool_name=string1 - power_tools[registered_power_tools_count].max_charge=max_charge -end - -register_power_tool ("technic:battery",10000) -register_power_tool ("technic:red_energy_crystal",100000) -register_power_tool ("technic:green_energy_crystal",250000) -register_power_tool ("technic:blue_energy_crystal",500000) +-- LV Battery box and some other nodes... +technic.register_LV_power_tool("technic:battery",10000) +technic.register_MV_power_tool("technic:red_energy_crystal",100000) +technic.register_HV_power_tool("technic:green_energy_crystal",250000) +technic.register_HV_power_tool("technic:blue_energy_crystal",500000) minetest.register_craft({ output = 'technic:battery 1', @@ -28,29 +13,32 @@ minetest.register_craft({ } }) -minetest.register_craft({ - output = 'technic:battery_box 1', - recipe = { - {'technic:battery', 'default:wood', 'technic:battery'}, - {'technic:battery', 'moreores:copper_ingot', 'technic:battery'}, - {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}, - } - }) - - minetest.register_tool("technic:battery", {description = "RE Battery", inventory_image = "technic_battery.png", tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=10000, maxlevel=0}}}}) -minetest.register_craftitem("technic:battery_box", { - description = "Battery box", - stack_max = 99, - }) - +-------------------------------------------- +-- The Battery box +-------------------------------------------- +minetest.register_craftitem( + "technic:battery_box", + { + description = "Battery box", + stack_max = 99, + }) +minetest.register_craft( + { + output = 'technic:battery_box 1', + recipe = { + {'technic:battery', 'default:wood', 'technic:battery'}, + {'technic:battery', 'moreores:copper_ingot', 'technic:battery'}, + {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}, + } + }) -battery_box_formspec = +local battery_box_formspec = "invsize[8,9;]".. "image[1,1;1,2;technic_power_meter_bg.png]".. "list[current_name;src;3,1;1,1;]".. @@ -71,28 +59,28 @@ minetest.register_node( sounds = default.node_sound_wood_defaults(), drop="technic:battery_box", on_construct = function(pos) - if pos == nil then return end local meta = minetest.env:get_meta(pos) local inv = meta:get_inventory() meta:set_string("infotext", "Battery box") meta:set_float("technic_power_machine", 1) meta:set_string("formspec", battery_box_formspec) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 60000) + meta:set_int("LV_EU_demand", 0) -- How much can this node charge + meta:set_int("LV_EU_supply", 0) -- How much can this node discharge + meta:set_int("LV_EU_input", 0) -- How much power is this machine getting. + meta:set_float("internal_EU_charge", 0) inv:set_size("src", 1) inv:set_size("dst", 1) end, can_dig = function(pos,player) - if pos == nil then return end - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, }) @@ -105,51 +93,101 @@ for i=1,8,1 do groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, sounds = default.node_sound_wood_defaults(), drop="technic:battery_box", - on_construct = function(pos) - if pos == nil then return end - local meta = minetest.env:get_meta(pos) - local inv = meta:get_inventory() - meta:set_string("infotext", "Battery box") - meta:set_float("technic_power_machine", 1) - meta:set_string("formspec", battery_box_formspec) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 60000) - inv:set_size("src", 1) - inv:set_size("dst", 1) - end, can_dig = function(pos,player) - if pos == nil then return end - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, }) end -function get_RE_item_load (load1,max_load) - if load1==0 then load1=65535 end - local temp = 65536-load1 - temp= temp/65535*max_load - return math.floor(temp + 0.5) -end - -function set_RE_item_load (load1,max_load) - if load1 == 0 then return 65535 end - local temp=load1/max_load*65535 - temp=65536-temp - return math.floor(temp) -end +local power_tools = technic.LV_power_tools + +local charge_LV_tools = function(meta, charge) + --charge registered power tools + local inv = meta:get_inventory() + if inv:is_empty("src")==false then + local srcstack = inv:get_stack("src", 1) + local src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + + local toolname = src_item["name"] + if power_tools[toolname] ~= nil then + -- Set meta data for the tool if it didn't do it itself :-( + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_power_tool"]==nil then + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + end + end + -- Do the charging + local item_max_charge = power_tools[toolname] + local load = src_meta["charge"] + local load_step = 1000 -- how much to charge per tick + if load0 then + if charge-load_step<0 then load_step=charge end + if load+load_step>item_max_charge then load_step=item_max_charge-load end + load=load+load_step + charge=charge-load_step + technic.set_RE_wear(src_item,load,item_max_charge) + src_meta["charge"] = load + src_item["metadata"] = set_item_meta(src_meta) + inv:set_stack("src", 1, src_item) + end + end + end + return charge -- return the remaining charge in the battery + end -function set_RE_wear (item_stack,load1,max_load) - local temp=65536-math.floor(load1/max_load*65535) - item_stack["wear"]=tostring(temp) - return item_stack -end +local discharge_LV_tools = function(meta, charge, max_charge) + -- discharging registered power tools + local inv = meta:get_inventory() + if inv:is_empty("dst") == false then + srcstack = inv:get_stack("dst", 1) + src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + local toolname = src_item["name"] + if power_tools[toolname] ~= nil then + -- Set meta data for the tool if it didn't do it itself :-( + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_power_tool"]==nil then + src_meta["technic_power_tool"]=true + src_meta["charge"]=0 + end + end + -- Do the discharging + local item_max_charge = power_tools[toolname] + local load = src_meta["charge"] + local load_step = 4000 -- how much to discharge per tick + if load>0 and chargemax_charge then load_step=max_charge-charge end + if load-load_step<0 then load_step=load end + load=load-load_step + charge=charge+load_step + technic.set_RE_wear(src_item,load,item_max_charge) + src_meta["charge"]=load + src_item["metadata"]=set_item_meta(src_meta) + inv:set_stack("dst", 1, src_item) + end + end + end + return charge -- return the remaining charge in the battery + end minetest.register_abm( {nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4", @@ -157,12 +195,39 @@ minetest.register_abm( interval = 1, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - local max_charge = 60000 -- Set maximum charge for the device here - local charge = meta:get_int("internal_EU_buffer") + local meta = minetest.env:get_meta(pos) + local max_charge = 60000 -- Set maximum charge for the device here + local max_charge_rate = 1000 -- Set maximum rate of charging + local max_discharge_rate = 2000 -- Set maximum rate of discharging + local eu_input = meta:get_int("LV_EU_input") + local current_charge = meta:get_int("internal_EU_charge") -- Battery charge right now + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "LV") + + -- Charge/discharge the battery with the input EUs + if eu_input >=0 then + current_charge = math.min(current_charge+eu_input, max_charge) + else + current_charge = math.max(current_charge+eu_input, 0) + end + + -- Charging/discharging tools here + current_charge = charge_LV_tools(meta, current_charge) + current_charge = discharge_LV_tools(meta, current_charge, max_charge) + + -- Set a demand (we allow batteries to charge on less than the demand though) + meta:set_int("LV_EU_demand", math.min(max_charge_rate, max_charge-current_charge)) + --print("BA:"..max_charge_rate.."|"..max_charge-current_charge.."|"..math.min(max_charge_rate, max_charge-current_charge)) + + -- Set how much we can supply + meta:set_int("LV_EU_supply", math.min(max_discharge_rate, current_charge)) + + meta:set_int("internal_EU_charge", current_charge) + --dprint("BA: input:"..eu_input.." supply="..meta:get_int("LV_EU_supply").." demand="..meta:get_int("LV_EU_demand").." current:"..current_charge) -- Select node textures - local i=math.ceil((charge/max_charge)*8) + local i=math.ceil((current_charge/max_charge)*8) if i > 8 then i = 8 end local j = meta:get_float("last_side_shown") if i~=j then @@ -170,224 +235,26 @@ minetest.register_abm( elseif i==0 then hacky_swap_node(pos,"technic:battery_box") end meta:set_float("last_side_shown",i) end - - --charge registered power tools - local inv = meta:get_inventory() - if inv:is_empty("src")==false then - local srcstack = inv:get_stack("src", 1) - local src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - - local item_max_charge=nil - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - -- Do the charging - local item_max_charge = power_tools[i].max_charge - local load1 = src_meta["charge"] - local load_step = 1000 -- how much to charge per tick - if load10 then - if charge-load_step<0 then load_step=charge end - if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end - load1=load1+load_step - charge=charge-load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("src", 1, src_item) - end - meta:set_int("internal_EU_buffer",charge) - break - end - end - end - - -- discharging registered power tools - if inv:is_empty("dst") == false then - srcstack = inv:get_stack("dst", 1) - src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - local item_max_charge=nil - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - local item_max_charge = power_tools[i].max_charge - local load1 = src_meta["charge"] - local load_step = 4000 -- how much to discharge per tick - if load1>0 and chargemax_charge then load_step=max_charge-charge end - if load1-load_step<0 then load_step=load1 end - load1=load1-load_step - charge=charge+load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("dst", 1, src_item) - end - meta:set_int("internal_EU_buffer",charge) - break - end - end - end - local load = math.floor(charge/60000 * 100) + local load = math.floor(current_charge/max_charge * 100) meta:set_string("formspec", battery_box_formspec.. "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. (load)..":technic_power_meter_fg.png]" ) - -- Next index the surrounding network the get the producers and receivers on the power grid - local pos1={} - pos1.y=pos.y-1 - pos1.x=pos.x - pos1.z=pos.z - - meta1 = minetest.env:get_meta(pos1) - if meta1:get_float("cablelike")~=1 then return end - - local LV_nodes = {} - local PR_nodes = {} - local RE_nodes = {} - local BA_nodes = {} - - LV_nodes[1]={} - LV_nodes[1].x=pos1.x - LV_nodes[1].y=pos1.y - LV_nodes[1].z=pos1.z - LV_nodes[1].visited=false - - local table_index=1 - repeat - check_LV_node(PR_nodes,RE_nodes,BA_nodes,LV_nodes,table_index) - table_index=table_index+1 - if LV_nodes[table_index]==nil then break end - until false - - - -- Get power from all connected producers - local pr_pos - for _,pr_pos in ipairs(PR_nodes) do - local meta1 = minetest.env:get_meta(pr_pos) - local internal_EU_buffer = meta1:get_float("internal_EU_buffer") - local charge_to_take = 200 - if charge0 then - charge=charge+charge_to_take - internal_EU_buffer=internal_EU_buffer-charge_to_take - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - end - end + if eu_input == 0 then + meta:set_string("infotext", "LV Battery box: "..current_charge.."/"..max_charge.." (idle)") + else + meta:set_string("infotext", "LV Battery box: "..current_charge.."/"..max_charge) end - if charge>max_charge then charge=max_charge end - - -- Provide power to all connected receivers - local re_pos - for _,re_pos in ipairs(RE_nodes) do - local meta1 = minetest.env:get_meta(re_pos) - local internal_EU_buffer = meta1:get_float("internal_EU_buffer") - local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size") - local charge_to_give = math.min(200, charge/table.getn(RE_nodes)) - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - if charge-charge_to_give<0 then charge_to_give=charge end - - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - charge=charge-charge_to_give; - end - charge=math.floor(charge) - meta:set_string("infotext", "LV Battery box: "..charge.."/"..max_charge); - meta:set_int("internal_EU_buffer",charge) end }) -- Register as a battery type -- Battery type machines function as power reservoirs and can both receive and give back power -register_LV_machine("technic:battery_box","BA") +technic.register_LV_machine("technic:battery_box","BA") for i=1,8,1 do - register_LV_machine("technic:battery_box"..i,"BA") -end - -function add_new_cable_node (LV_nodes,pos1) - if LV_nodes == nil then return true end - local i=1 - repeat - if LV_nodes[i]==nil then break end - if pos1.x==LV_nodes[i].x and pos1.y==LV_nodes[i].y and pos1.z==LV_nodes[i].z then return false end - i=i+1 - until false - LV_nodes[i]={} - LV_nodes[i].x=pos1.x - LV_nodes[i].y=pos1.y - LV_nodes[i].z=pos1.z - return true -end - -function check_LV_node(PR_nodes,RE_nodes,BA_nodes,LV_nodes,i) - local pos1={} - pos1.x=LV_nodes[i].x - pos1.y=LV_nodes[i].y - pos1.z=LV_nodes[i].z - - pos1.x=pos1.x+1 - check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) - pos1.x=pos1.x-2 - check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) - pos1.x=pos1.x+1 - - pos1.y=pos1.y+1 - check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) - pos1.y=pos1.y-2 - check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) - pos1.y=pos1.y+1 - - pos1.z=pos1.z+1 - check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) - pos1.z=pos1.z-2 - check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) - pos1.z=pos1.z+1 - return new_node_added -end - -function check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1) - local meta = minetest.env:get_meta(pos1) - local name = minetest.env:get_node(pos1).name - if meta:get_float("cablelike")==1 then - add_new_cable_node(LV_nodes,pos1) - elseif LV_machines[name] then - --print(name.." is a "..LV_machines[name]) - if LV_machines[name] == "PR" then - add_new_cable_node(PR_nodes,pos1) - elseif LV_machines[name] == "RE" then - add_new_cable_node(RE_nodes,pos1) - elseif LV_machines[name] == "BA" then - add_new_cable_node(BA_nodes,pos1) - end - end + technic.register_LV_machine("technic:battery_box"..i,"BA") end diff --git a/technic/battery_box_hv.lua b/technic/battery_box_hv.lua index 16aead9..8cd0e2f 100644 --- a/technic/battery_box_hv.lua +++ b/technic/battery_box_hv.lua @@ -1,10 +1,4 @@ --- register MV machines here -technic.HV_machines = {} -local HV_machines = technic.HV_machines -function register_HV_machine(string1,string2) - technic.HV_machines[string1] = string2 -end - +-- HV battery box minetest.register_craft({ output = 'technic:hv_battery_box 1', recipe = { @@ -14,7 +8,7 @@ minetest.register_craft({ } }) -hv_battery_box_formspec = +local battery_box_formspec = "invsize[8,9;]".. "image[1,1;1,2;technic_power_meter_bg.png]".. "list[current_name;src;3,1;1,1;]".. @@ -35,74 +29,176 @@ minetest.register_node( sounds = default.node_sound_wood_defaults(), drop="technic:hv_battery_box", on_construct = function(pos) - if pos==nil then return end local meta = minetest.env:get_meta(pos) local inv = meta:get_inventory() meta:set_string("infotext", "HV Battery Box") meta:set_float("technic_hv_power_machine", 1) meta:set_string("formspec", battery_box_formspec) + meta:set_int("HV_EU_demand", 0) -- How much can this node charge + meta:set_int("HV_EU_supply", 0) -- How much can this node discharge + meta:set_int("HV_EU_input", 0) -- How much power is this machine getting. + meta:set_float("internal_EU_charge", 0) inv:set_size("src", 1) inv:set_size("dst", 1) end, can_dig = function(pos,player) - if pos==nil then return end local meta = minetest.env:get_meta(pos); local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); return false + else + return true end - return true end, }) for i=1,8,1 do minetest.register_node( - "technic:hv_battery_box"..i, { - description = "HV Battery Box", - tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", - "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, - sounds = default.node_sound_wood_defaults(), - paramtype="light", - light_source=9, - drop="technic:hv_battery_box", - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - local inv = meta:get_inventory() - meta:set_string("infotext", "HV Battery box") - meta:set_float("technic_hv_power_machine", 1) - meta:set_string("formspec", battery_box_formspec) - inv:set_size("src", 1) - inv:set_size("dst", 1) - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, - }) + "technic:hv_battery_box"..i, + {description = "HV Battery Box", + tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", + "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + sounds = default.node_sound_wood_defaults(), + paramtype="light", + light_source=9, + drop="technic:hv_battery_box", + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, + }) end +local power_tools = technic.HV_power_tools + +local charge_HV_tools = function(meta, charge) + --charge registered power tools + local inv = meta:get_inventory() + if inv:is_empty("src")==false then + local srcstack = inv:get_stack("src", 1) + local src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + + local toolname = src_item["name"] + if power_tools[toolname] ~= nil then + -- Set meta data for the tool if it didn't do it itself :-( + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_hv_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_hv_power_tool"]==nil then + src_meta["technic_hv_power_tool"]=true + src_meta["charge"]=0 + end + end + -- Do the charging + local item_max_charge = power_tools[toolname] + local load = src_meta["charge"] + local load_step = 1000 -- how much to charge per tick + if load0 then + if charge-load_step<0 then load_step=charge end + if load+load_step>item_max_charge then load_step=item_max_charge-load end + load=load+load_step + charge=charge-load_step + technic.set_RE_wear(src_item,load,item_max_charge) + src_meta["charge"] = load + src_item["metadata"] = set_item_meta(src_meta) + inv:set_stack("src", 1, src_item) + end + end + end + return charge -- return the remaining charge in the battery + end + +local discharge_HV_tools = function(meta, charge, max_charge) + -- discharging registered power tools + local inv = meta:get_inventory() + if inv:is_empty("dst") == false then + srcstack = inv:get_stack("dst", 1) + src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + local toolname = src_item["name"] + if power_tools[toolname] ~= nil then + -- Set meta data for the tool if it didn't do it itself :-( + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_hv_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_hv_power_tool"]==nil then + src_meta["technic_hv_power_tool"]=true + src_meta["charge"]=0 + end + end + -- Do the discharging + local item_max_charge = power_tools[toolname] + local load = src_meta["charge"] + local load_step = 4000 -- how much to discharge per tick + if load>0 and chargemax_charge then load_step=max_charge-charge end + if load-load_step<0 then load_step=load end + load=load-load_step + charge=charge+load_step + technic.set_RE_wear(src_item,load,item_max_charge) + src_meta["charge"]=load + src_item["metadata"]=set_item_meta(src_meta) + inv:set_stack("dst", 1, src_item) + end + end + end + return charge -- return the remaining charge in the battery + end + minetest.register_abm( {nodenames = {"technic:hv_battery_box","technic:hv_battery_box1","technic:hv_battery_box2","technic:hv_battery_box3","technic:hv_battery_box4", "technic:hv_battery_box5","technic:hv_battery_box6","technic:hv_battery_box7","technic:hv_battery_box8" }, interval = 1, - chance = 1, + chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - local max_charge = 1500000 - local charge = meta:get_int("internal_EU_buffer") + local meta = minetest.env:get_meta(pos) + local max_charge = 1500000 -- Set maximum charge for the device here + local max_charge_rate = 3000 -- Set maximum rate of charging + local max_discharge_rate = 5000 -- Set maximum rate of discharging (16000) + local eu_input = meta:get_int("HV_EU_input") + local current_charge = meta:get_int("internal_EU_charge") -- Battery charge right now + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "HV") + + -- Charge/discharge the battery with the input EUs + if eu_input >=0 then + current_charge = math.min(current_charge+eu_input, max_charge) + else + current_charge = math.max(current_charge+eu_input, 0) + end + + -- Charging/discharging tools here + current_charge = charge_HV_tools(meta, current_charge) + current_charge = discharge_HV_tools(meta, current_charge, max_charge) + + -- Set a demand (we allow batteries to charge on less than the demand though) + meta:set_int("HV_EU_demand", math.min(max_charge_rate, max_charge-current_charge)) + + -- Set how much we can supply + meta:set_int("HV_EU_supply", math.min(max_discharge_rate, current_charge)) + + meta:set_int("internal_EU_charge", current_charge) + --dprint("BA: input:"..eu_input.." supply="..meta:get_int("HV_EU_supply").." demand="..meta:get_int("HV_EU_demand").." current:"..current_charge) -- Select node textures - local i = math.ceil((charge/max_charge)*8) + local i=math.ceil((current_charge/max_charge)*8) if i > 8 then i = 8 end local j = meta:get_float("last_side_shown") if i~=j then @@ -111,221 +207,24 @@ minetest.register_abm( meta:set_float("last_side_shown",i) end - --charge registered power tools - local inv = meta:get_inventory() - if inv:is_empty("src")==false then - local srcstack = inv:get_stack("src", 1) - local src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - -- Do the charging - local item_max_charge = power_tools[i].max_charge - local load1 = src_meta["charge"] - local load_step = 16000 -- how much to charge per tick - if load10 then - if charge-load_step<0 then load_step=charge end - if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end - load1=load1+load_step - charge=charge-load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("src", 1, src_item) - end - meta:set_int("internal_EU_buffer",charge) - break - end - end - end - - -- discharging registered power tools - if inv:is_empty("dst") == false then - srcstack = inv:get_stack("dst", 1) - src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - local item_max_charge=nil - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - local item_max_charge = power_tools[i].max_charge - local load1 = src_meta["charge"] - local load_step = 16000 -- how much to discharge per tick - if load1>0 and chargemax_charge then load_step=max_charge-charge end - if load1-load_step<0 then load_step=load1 end - load1=load1-load_step - charge=charge+load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("dst", 1, src_item) - end - meta:set_int("internal_EU_buffer",charge) - break - end - end - end - - - local load = math.floor((charge/1500000) * 100) + local load = math.floor(current_charge/max_charge * 100) meta:set_string("formspec", - hv_battery_box_formspec.. + battery_box_formspec.. "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. (load)..":technic_power_meter_fg.png]" ) - -- Next index the surrounding network the get the producers and receivers on the - local pos1={} - pos1.y=pos.y-1 - pos1.x=pos.x - pos1.z=pos.z - - meta1 = minetest.env:get_meta(pos1) - if meta1:get_float("hv_cablelike")~=1 then return end - - local HV_nodes = {} - local PR_nodes = {} - local RE_nodes = {} - local BA_nodes = {} - - HV_nodes[1]={} - HV_nodes[1].x=pos1.x - HV_nodes[1].y=pos1.y - HV_nodes[1].z=pos1.z - HV_nodes[1].visited=false - - local table_index=1 - repeat - check_HV_node (PR_nodes,RE_nodes,BA_nodes,HV_nodes,table_index) - table_index=table_index+1 - if HV_nodes[table_index]==nil then break end - until false - - -- Get power from all connected producers - local pr_pos - for _,pr_pos in ipairs(PR_nodes) do - local meta1 = minetest.env:get_meta(pr_pos) - local internal_EU_buffer = meta1:get_float("internal_EU_buffer") - local charge_to_take = 4000 - if charge0 then - charge=charge+charge_to_take - internal_EU_buffer=internal_EU_buffer-charge_to_take - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - end - end - end - - if charge>max_charge then charge=max_charge end - - -- Provide power to all connected receivers - local re_pos - for _,re_pos in ipairs(RE_nodes) do - local meta1 = minetest.env:get_meta(re_pos) - local internal_EU_buffer = meta1:get_float("internal_EU_buffer") - local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size") - local charge_to_give = math.min(4000, charge/table.getn(RE_nodes)) - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - if charge-charge_to_give<0 then charge_to_give=charge end - - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - charge=charge-charge_to_give; + if eu_input == 0 then + meta:set_string("infotext", "HV Battery box: "..current_charge.."/"..max_charge.." (idle)") + else + meta:set_string("infotext", "HV Battery box: "..current_charge.."/"..max_charge) end - charge=math.floor(charge) - meta:set_string("infotext", "MV Battery box: "..charge.."/"..max_charge); - meta:set_int("internal_EU_buffer",charge) end }) -- Register as a battery type -- Battery type machines function as power reservoirs and can both receive and give back power -register_HV_machine("technic:hv_battery_box","BA") +technic.register_HV_machine("technic:hv_battery_box","BA") for i=1,8,1 do - register_HV_machine("technic:hv_battery_box"..i,"BA") -end - -function add_new_HVcable_node (HV_nodes,pos1) - if HV_nodes == nil then return true end - local i=1 - repeat - if HV_nodes[i]==nil then break end - if pos1.x==HV_nodes[i].x and pos1.y==HV_nodes[i].y and pos1.z==HV_nodes[i].z then return false end - i=i+1 - until false - HV_nodes[i]={} - HV_nodes[i].x=pos1.x - HV_nodes[i].y=pos1.y - HV_nodes[i].z=pos1.z - return true -end - -function check_HV_node(PR_nodes,RE_nodes,BA_nodes,HV_nodes,i) - local pos1={} - pos1.x=HV_nodes[i].x - pos1.y=HV_nodes[i].y - pos1.z=HV_nodes[i].z - - pos1.x=pos1.x+1 - check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) - pos1.x=pos1.x-2 - check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) - pos1.x=pos1.x+1 - - pos1.y=pos1.y+1 - check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) - pos1.y=pos1.y-2 - check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) - pos1.y=pos1.y+1 - - pos1.z=pos1.z+1 - check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) - pos1.z=pos1.z-2 - check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) - pos1.z=pos1.z+1 -end - -function check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1) - local meta = minetest.env:get_meta(pos1) - local name = minetest.env:get_node(pos1).name - if meta:get_float("hv_cablelike")==1 then - add_new_HVcable_node(HV_nodes,pos1) - elseif HV_machines[name] then - --print(name.." is a "..HV_machines[name]) - if HV_machines[name] == "PR" then - add_new_HVcable_node(PR_nodes,pos1) - elseif HV_machines[name] == "RE" then - add_new_HVcable_node(RE_nodes,pos1) - elseif HV_machines[name] == "BA" then - add_new_HVcable_node(BA_nodes,pos1) - end - end + technic.register_HV_machine("technic:hv_battery_box"..i,"BA") end diff --git a/technic/battery_box_mv.lua b/technic/battery_box_mv.lua index 86c445c..dfedc05 100644 --- a/technic/battery_box_mv.lua +++ b/technic/battery_box_mv.lua @@ -1,11 +1,4 @@ --- register MV machines here -technic.MV_machines = {} ---local MV_machines = {} -local MV_machines = technic.MV_machines -function register_MV_machine(string1,string2) - technic.MV_machines[string1] = string2 -end - +-- MV Battery box minetest.register_craft( { output = 'technic:mv_battery_box 1', @@ -16,7 +9,7 @@ minetest.register_craft( } }) -mv_battery_box_formspec = +local battery_box_formspec = "invsize[8,9;]".. "image[1,1;1,2;technic_power_meter_bg.png]".. "list[current_name;src;3,1;1,1;]".. @@ -43,73 +36,172 @@ minetest.register_node( meta:set_string("infotext", "MV Battery box") meta:set_float("technic_mv_power_machine", 1) meta:set_string("formspec", battery_box_formspec) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 300000) + meta:set_int("MV_EU_demand", 0) -- How much can this node charge + meta:set_int("MV_EU_supply", 0) -- How much can this node discharge + meta:set_int("MV_EU_input", 0) -- How much power is this machine getting. + meta:set_float("internal_EU_charge", 0) inv:set_size("src", 1) inv:set_size("dst", 1) end, can_dig = function(pos,player) - if pos==nil then return end local meta = minetest.env:get_meta(pos); local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); return false + else + return true end - return true - end + end, }) for i=1,8,1 do minetest.register_node( - "technic:mv_battery_box"..i, { + "technic:mv_battery_box"..i, + { description = "MV Battery Box", tiles = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png"}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, sounds = default.node_sound_wood_defaults(), drop = "technic:mv_battery_box", - on_construct = function(pos) - if pos==nil then return end - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - meta:set_string("infotext", "MV Battery box") - meta:set_float("technic_mv_power_machine", 1) - meta:set_string("formspec", battery_box_formspec) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 300000) - inv:set_size("src", 1) - inv:set_size("dst", 1) - end, can_dig = function(pos,player) - if pos==nil then return end local meta = minetest.env:get_meta(pos); local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); return false + else + return true end - return true - end + end, }) end +local power_tools = technic.MV_power_tools + +local charge_MV_tools = function(meta, charge) + --charge registered power tools + local inv = meta:get_inventory() + if inv:is_empty("src")==false then + local srcstack = inv:get_stack("src", 1) + local src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + + local toolname = src_item["name"] + if power_tools[toolname] ~= nil then + -- Set meta data for the tool if it didn't do it itself :-( + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_mv_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_mv_power_tool"]==nil then + src_meta["technic_mv_power_tool"]=true + src_meta["charge"]=0 + end + end + -- Do the charging + local item_max_charge = power_tools[toolname] + local load = src_meta["charge"] + local load_step = 1000 -- how much to charge per tick + if load0 then + if charge-load_step<0 then load_step=charge end + if load+load_step>item_max_charge then load_step=item_max_charge-load end + load=load+load_step + charge=charge-load_step + technic.set_RE_wear(src_item,load,item_max_charge) + src_meta["charge"] = load + src_item["metadata"] = set_item_meta(src_meta) + inv:set_stack("src", 1, src_item) + end + end + end + return charge -- return the remaining charge in the battery + end + +local discharge_MV_tools = function(meta, charge, max_charge) + -- discharging registered power tools + local inv = meta:get_inventory() + if inv:is_empty("dst") == false then + srcstack = inv:get_stack("dst", 1) + src_item=srcstack:to_table() + local src_meta=get_item_meta(src_item["metadata"]) + local toolname = src_item["name"] + if power_tools[toolname] ~= nil then + -- Set meta data for the tool if it didn't do it itself :-( + src_meta=get_item_meta(src_item["metadata"]) + if src_meta==nil then + src_meta={} + src_meta["technic_mv_power_tool"]=true + src_meta["charge"]=0 + else + if src_meta["technic_mv_power_tool"]==nil then + src_meta["technic_mv_power_tool"]=true + src_meta["charge"]=0 + end + end + -- Do the discharging + local item_max_charge = power_tools[toolname] + local load = src_meta["charge"] + local load_step = 4000 -- how much to discharge per tick + if load>0 and chargemax_charge then load_step=max_charge-charge end + if load-load_step<0 then load_step=load end + load=load-load_step + charge=charge+load_step + technic.set_RE_wear(src_item,load,item_max_charge) + src_meta["charge"]=load + src_item["metadata"]=set_item_meta(src_meta) + inv:set_stack("dst", 1, src_item) + end + end + end + return charge -- return the remaining charge in the battery + end + minetest.register_abm( - {nodenames = {"technic:mv_battery_box","technic:mv_battery_box1","technic:mv_battery_box2","technic:mv_battery_box3","technic:mv_battery_box4", - "technic:mv_battery_box5","technic:mv_battery_box6","technic:mv_battery_box7","technic:mv_battery_box8" - }, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - local max_charge = 300000 -- Set maximum charge for the device here - local charge = meta:get_int("internal_EU_buffer") + { + nodenames = {"technic:mv_battery_box","technic:mv_battery_box1","technic:mv_battery_box2","technic:mv_battery_box3","technic:mv_battery_box4", + "technic:mv_battery_box5","technic:mv_battery_box6","technic:mv_battery_box7","technic:mv_battery_box8" + }, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local max_charge = 300000 -- Set maximum charge for the device here + local max_charge_rate = 2000 -- Set maximum rate of charging (4000) + local max_discharge_rate = 3000 -- Set maximum rate of discharging + local eu_input = meta:get_int("MV_EU_input") + local current_charge = meta:get_int("internal_EU_charge") -- Battery charge right now + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "MV") + + -- Charge/discharge the battery with the input EUs + if eu_input >=0 then + current_charge = math.min(current_charge+eu_input, max_charge) + else + current_charge = math.max(current_charge+eu_input, 0) + end + + -- Charging/discharging tools here + current_charge = charge_MV_tools(meta, current_charge) + current_charge = discharge_MV_tools(meta, current_charge, max_charge) + + -- Set a demand (we allow batteries to charge on less than the demand though) + meta:set_int("MV_EU_demand", math.min(max_charge_rate, max_charge-current_charge)) + + -- Set how much we can supply + meta:set_int("MV_EU_supply", math.min(max_discharge_rate, current_charge)) + + meta:set_int("internal_EU_charge", current_charge) + --dprint("BA: input:"..eu_input.." supply="..meta:get_int("MV_EU_supply").." demand="..meta:get_int("MV_EU_demand").." current:"..current_charge) -- Select node textures - local i = math.ceil((charge/max_charge)*8) + local i=math.ceil((current_charge/max_charge)*8) if i > 8 then i = 8 end local j = meta:get_float("last_side_shown") if i~=j then @@ -118,221 +210,24 @@ minetest.register_abm( meta:set_float("last_side_shown",i) end - --charge registered power tools - local inv = meta:get_inventory() - if inv:is_empty("src")==false then - local srcstack = inv:get_stack("src", 1) - local src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - - -- Power tools should really be made into a hash table to avoid linear search. But the list is short so okay... - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - -- What is this code doing? Setting tool properties if not set already???? - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - -- Do the charging - local item_max_charge = power_tools[i].max_charge - local load1 = src_meta["charge"] - local load_step = 4000 -- how much to charge per tick - if load10 then - if charge-load_step<0 then load_step=charge end - if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end - load1=load1+load_step - charge=charge-load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"] = load1 - src_item["metadata"] = set_item_meta(src_meta) - inv:set_stack("src", 1, src_item) - end - meta:set_int("internal_EU_buffer",charge) - break - end - end - end - - -- discharging registered power tools - if inv:is_empty("dst") == false then - srcstack = inv:get_stack("dst", 1) - src_item=srcstack:to_table() - local src_meta=get_item_meta(src_item["metadata"]) - local item_max_charge=nil - for i=1,registered_power_tools_count,1 do - if power_tools[i].tool_name==src_item["name"] then - src_meta=get_item_meta(src_item["metadata"]) - if src_meta==nil then - src_meta={} - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - else - if src_meta["technic_power_tool"]==nil then - src_meta["technic_power_tool"]=true - src_meta["charge"]=0 - end - end - local item_max_charge = power_tools[i].max_charge - local load1 = src_meta["charge"] - local load_step = 4000 -- how much to discharge per tick - if load1>0 and chargemax_charge then load_step=max_charge-charge end - if load1-load_step<0 then load_step=load1 end - load1=load1-load_step - charge=charge+load_step - set_RE_wear(src_item,load1,item_max_charge) - src_meta["charge"]=load1 - src_item["metadata"]=set_item_meta(src_meta) - inv:set_stack("dst", 1, src_item) - end - meta:set_int("internal_EU_buffer",charge) - break - end - end - end - - local load = math.floor((charge/300000) * 100) + local load = math.floor(current_charge/max_charge * 100) meta:set_string("formspec", - mv_battery_box_formspec.. + battery_box_formspec.. "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. (load)..":technic_power_meter_fg.png]" ) - -- Next index the surrounding network the get the producers and receivers on the power grid - local pos1 = {} - pos1.y = pos.y-1 - pos1.x = pos.x - pos1.z = pos.z - - meta1 = minetest.env:get_meta(pos1) - if meta1:get_float("mv_cablelike")~=1 then return end - - local MV_nodes = {} - local PR_nodes = {} - local RE_nodes = {} - local BA_nodes = {} - - MV_nodes[1] = {} - MV_nodes[1].x = pos1.x - MV_nodes[1].y = pos1.y - MV_nodes[1].z = pos1.z - - local table_index=1 - repeat - check_MV_node(PR_nodes,RE_nodes,BA_nodes,MV_nodes,table_index) - table_index=table_index+1 - if MV_nodes[table_index]==nil then break end - until false - - -- Get power from all connected producers - local pr_pos - for _,pr_pos in ipairs(PR_nodes) do - local meta1 = minetest.env:get_meta(pr_pos) - local internal_EU_buffer = meta1:get_float("internal_EU_buffer") - local charge_to_take = 1000 - if charge0 then - charge=charge+charge_to_take - internal_EU_buffer=internal_EU_buffer-charge_to_take - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - end - end - end - - if charge>max_charge then charge=max_charge end - - -- Provide power to all connected receivers - local re_pos - for _,re_pos in ipairs(RE_nodes) do - local meta1 = minetest.env:get_meta(re_pos) - local internal_EU_buffer = meta1:get_float("internal_EU_buffer") - local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size") - local charge_to_give = math.min(1000, charge/table.getn(RE_nodes)) - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - if charge-charge_to_give<0 then charge_to_give=charge end - - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - charge=charge-charge_to_give; + if eu_input == 0 then + meta:set_string("infotext", "MV Battery box: "..current_charge.."/"..max_charge.." (idle)") + else + meta:set_string("infotext", "MV Battery box: "..current_charge.."/"..max_charge) end - charge=math.floor(charge) - meta:set_string("infotext", "MV Battery box: "..charge.."/"..max_charge); - meta:set_int("internal_EU_buffer",charge) end - }) + }) -- Register as a battery type -- Battery type machines function as power reservoirs and can both receive and give back power -register_MV_machine("technic:mv_battery_box","BA") +technic.register_MV_machine("technic:mv_battery_box","BA") for i=1,8,1 do - register_MV_machine("technic:mv_battery_box"..i,"BA") -end - -function add_new_MVcable_node (MV_nodes,pos1) - if MV_nodes == nil then return true end - local i=1 - repeat - if MV_nodes[i]==nil then break end - if pos1.x==MV_nodes[i].x and pos1.y==MV_nodes[i].y and pos1.z==MV_nodes[i].z then return false end - i=i+1 - until false - MV_nodes[i]={} - MV_nodes[i].x=pos1.x - MV_nodes[i].y=pos1.y - MV_nodes[i].z=pos1.z - return true -end - -function check_MV_node(PR_nodes,RE_nodes,BA_nodes,MV_nodes,i) - local pos1={} - pos1.x=MV_nodes[i].x - pos1.y=MV_nodes[i].y - pos1.z=MV_nodes[i].z - - pos1.x=pos1.x+1 - check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) - pos1.x=pos1.x-2 - check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) - pos1.x=pos1.x+1 - - pos1.y=pos1.y+1 - check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) - pos1.y=pos1.y-2 - check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) - pos1.y=pos1.y+1 - - pos1.z=pos1.z+1 - check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) - pos1.z=pos1.z-2 - check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) - pos1.z=pos1.z+1 -end - -function check_MV_node_subp (PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1) - local meta = minetest.env:get_meta(pos1) - local name = minetest.env:get_node(pos1).name - if meta:get_float("mv_cablelike")==1 then - add_new_MVcable_node(MV_nodes,pos1) - elseif MV_machines[name] then - --print(name.." is a "..MV_machines[name]) - if MV_machines[name] == "PR" then - add_new_MVcable_node(PR_nodes,pos1) - elseif MV_machines[name] == "RE" then - add_new_MVcable_node(RE_nodes,pos1) - elseif MV_machines[name] == "BA" then - add_new_MVcable_node(BA_nodes,pos1) - end - end + technic.register_MV_machine("technic:mv_battery_box"..i,"BA") end diff --git a/technic/cans.lua b/technic/cans.lua index 78ff413..6a98ce9 100644 --- a/technic/cans.lua +++ b/technic/cans.lua @@ -1,5 +1,5 @@ -water_can_max_load = 16 -lava_can_max_load = 8 +local water_can_max_load = 16 +local lava_can_max_load = 8 minetest.register_craft({ output = 'technic:water_can 1', @@ -42,7 +42,7 @@ minetest.register_tool("technic:water_can", { minetest.env:add_node(pointed_thing.under, {name="air"}) load=load+1; item["metadata"]=tostring(load) - set_RE_wear(item,load,water_can_max_load) + technic.set_RE_wear(item,load,water_can_max_load) itemstack:replace(item) end return itemstack @@ -54,7 +54,7 @@ minetest.register_tool("technic:water_can", { minetest.env:add_node(pointed_thing.under, {name="default:water_source"}) load=load-1; item["metadata"]=tostring(load) - set_RE_wear(item,load,water_can_max_load) + technic.set_RE_wear(item,load,water_can_max_load) itemstack:replace(item) return itemstack end @@ -64,7 +64,7 @@ minetest.register_tool("technic:water_can", { minetest.env:add_node(pointed_thing.above, {name="default:water_source"}) load=load-1; item["metadata"]=tostring(load) - set_RE_wear(item,load,water_can_max_load) + technic.set_RE_wear(item,load,water_can_max_load) itemstack:replace(item) return itemstack end @@ -90,7 +90,7 @@ minetest.register_tool("technic:lava_can", { minetest.env:add_node(pointed_thing.under, {name="air"}) load=load+1; item["metadata"]=tostring(load) - set_RE_wear(item,load,lava_can_max_load) + technic.set_RE_wear(item,load,lava_can_max_load) itemstack:replace(item) end return itemstack @@ -102,7 +102,7 @@ minetest.register_tool("technic:lava_can", { minetest.env:add_node(pointed_thing.under, {name="default:lava_source"}) load=load-1; item["metadata"]=tostring(load) - set_RE_wear(item,load,lava_can_max_load) + technic.set_RE_wear(item,load,lava_can_max_load) itemstack:replace(item) return itemstack end @@ -112,7 +112,7 @@ minetest.register_tool("technic:lava_can", { minetest.env:add_node(pointed_thing.above, {name="default:lava_source"}) load=load-1; item["metadata"]=tostring(load) - set_RE_wear(item,load,lava_can_max_load) + technic.set_RE_wear(item,load,lava_can_max_load) itemstack:replace(item) return itemstack end diff --git a/technic/chainsaw.lua b/technic/chainsaw.lua index 5b3b05b..5c5de4c 100644 --- a/technic/chainsaw.lua +++ b/technic/chainsaw.lua @@ -3,7 +3,7 @@ local chainsaw_max_charge = 30000 -- 30000 - Maximum charge of the saw local chainsaw_charge_per_node = 12 -- 12 - Gives 2500 nodes on a single charge (about 50 complete normal trees) local chainsaw_leaves = true -- true - Cut down entire trees, leaves and all -register_power_tool ("technic:chainsaw",chainsaw_max_charge) +technic.register_LV_power_tool ("technic:chainsaw",chainsaw_max_charge) minetest.register_tool("technic:chainsaw", { description = "Chainsaw", @@ -20,7 +20,7 @@ minetest.register_tool("technic:chainsaw", { if charge < chainsaw_charge_per_node then return end -- only cut if charged charge=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge) - set_RE_wear(item,charge,chainsaw_max_charge) + technic.set_RE_wear(item,charge,chainsaw_max_charge) meta["charge"]=charge item["metadata"]=set_item_meta(meta) itemstack:replace(item) diff --git a/technic/cnc.lua b/technic/cnc.lua index 4976502..ad3dc67 100644 --- a/technic/cnc.lua +++ b/technic/cnc.lua @@ -1,8 +1,8 @@ --- Technic CNC v1.0 by kpo +-- Technic CNC v1.0 by kpoppel -- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck -- Idea: --- Somehw have a tabbed/paged panel if the number of shapes should expand +-- Somehow have a tabbed/paged panel if the number of shapes should expand -- beyond what is available in the panel today. -- I could imagine some form of API allowing modders to come with their own node -- box definitions and easily stuff it in the this machine for production. @@ -32,24 +32,6 @@ local twosize_products = { element_edge = 2, } ---cnc_recipes ={} ---registered_cnc_recipes_count=1 --- ---function register_cnc_recipe (string1,string2) --- cnc_recipes[registered_cnc_recipes_count]={} --- cnc_recipes[registered_cnc_recipes_count].src_name=string1 --- cnc_recipes[registered_cnc_recipes_count].dst_name=string2 --- registered_cnc_recipes_count=registered_cnc_recipes_count+1 --- if unified_inventory then --- unified_inventory.register_craft({ --- type = "cnc milling", --- output = string2, --- items = {string1}, --- width = 0, --- }) --- end ---end - local cnc_formspec = "invsize[9,11;]".. "label[1,0;Choose Milling Program:]".. @@ -88,215 +70,212 @@ local cnc_formspec = "list[current_player;main;0,7;8,4;]" - -local cnc_power_formspec= - "label[0,3;Power]".. - "image[0,1;1,2;technic_power_meter_bg.png]" - local size = 1; -- The form handler is declared here because we need it in both the inactive and active modes -- in order to be able to change programs wile it is running. local form_handler = function(pos, formname, fields, sender) - -- REGISTER MILLING PROGRAMS AND OUTPUTS: - ------------------------------------------ - -- Program for half/full size - if fields["full"] then - size = 1 - return - end - - if fields["half"] then - size = 2 - return - end - - -- Resolve the node name and the number of items to make - local meta = minetest.env:get_meta(pos) - local inv = meta:get_inventory() - local inputstack = inv:get_stack("src", 1) - local inputname = inputstack:get_name() - local multiplier = 0 - for k, _ in pairs(fields) do - -- Set a multipier for the half/full size capable blocks - if twosize_products[k] ~= nil then - multiplier = size*twosize_products[k] - else - multiplier = onesize_products[k] - end - - if onesize_products[k] ~= nil or twosize_products[k] ~= nil then - meta:set_float( "cnc_multiplier", multiplier) - meta:set_string("cnc_user", sender:get_player_name()) - end - - if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then - meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k) - print(inputname .. "_technic_cnc_" .. k) - break - end - - if twosize_products[k] ~= nil and size==1 then - meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double") - print(inputname .. "_technic_cnc_" .. k .. "_double") - break - end - end - return - end -- callback function + -- REGISTER MILLING PROGRAMS AND OUTPUTS: + ------------------------------------------ + -- Program for half/full size + if fields["full"] then + size = 1 + return + end + + if fields["half"] then + size = 2 + return + end + + -- Resolve the node name and the number of items to make + local meta = minetest.env:get_meta(pos) + local inv = meta:get_inventory() + local inputstack = inv:get_stack("src", 1) + local inputname = inputstack:get_name() + local multiplier = 0 + for k, _ in pairs(fields) do + -- Set a multipier for the half/full size capable blocks + if twosize_products[k] ~= nil then + multiplier = size*twosize_products[k] + else + multiplier = onesize_products[k] + end + + if onesize_products[k] ~= nil or twosize_products[k] ~= nil then + meta:set_float( "cnc_multiplier", multiplier) + meta:set_string("cnc_user", sender:get_player_name()) + end + + if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then + meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k) + --print(inputname .. "_technic_cnc_" .. k) + break + end + + if twosize_products[k] ~= nil and size==1 then + meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double") + --print(inputname .. "_technic_cnc_" .. k .. "_double") + break + end + end + return + end -- callback function -- The actual block inactive state -minetest.register_node("technic:cnc", { - description = "CNC Milling Machine", - tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png", - "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front.png"}, - drawtype = "nodebox", - paramtype = "light", - paramtype2 = "facedir", - node_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - - }, - }, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - groups = {cracky=2}, - legacy_facedir_simple = true, - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=5000; - cnc_time = 0; - src_time = 0; -- fixme - - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "CNC Machine Inactive") - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 5000) - meta:set_string("formspec", cnc_formspec..cnc_power_formspec) - meta:set_float("cnc_time", 0) - - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 4) - end, - - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("src") or not inv:is_empty("dst") then - minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty"); - return false - end - return true - end, - - on_receive_fields = form_handler, - }) +minetest.register_node( + "technic:cnc", + { + description = "CNC Milling Machine", + tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png", + "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front.png"}, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + + }, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + groups = {cracky=2}, + legacy_facedir_simple = true, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "CNC Machine") + meta:set_float("technic_power_machine", 1) + meta:set_string("formspec", cnc_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) + inv:set_size("dst", 4) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, + on_receive_fields = form_handler, + }) -- Active state block minetest.register_node("technic:cnc_active", { - description = "CNC Machine", - tiles = {"technic_cnc_top_active.png", "technic_cnc_bottom.png", "technic_cnc_side.png", - "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"}, - paramtype2 = "facedir", - groups = {cracky=2,not_in_creative_inventory=1}, - legacy_facedir_simple = true, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("src") or not inv:is_empty("dst") then - minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty"); - return false - end - return true - end, - on_receive_fields = form_handler, -}) + description = "CNC Machine", + tiles = {"technic_cnc_top_active.png", "technic_cnc_bottom.png", "technic_cnc_side.png", + "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"}, + paramtype2 = "facedir", + groups = {cracky=2,not_in_creative_inventory=1}, + legacy_facedir_simple = true, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty"); + return false + end + return true + end, + on_receive_fields = form_handler, + }) -- Action code performing the transformation minetest.register_abm( - { - nodenames = {"technic:cnc","technic:cnc_active"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - local charge= meta:get_float("internal_EU_buffer") - local max_charge= meta:get_float("internal_EU_buffer_size") - local cnc_cost=350 - - local load = math.floor((charge/max_charge)*100) - meta:set_string("formspec", cnc_formspec.. - "image[0,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]" - ) - - local inv = meta:get_inventory() - local srclist = inv:get_list("src") - if inv:is_empty("src") then - meta:set_float("cnc_on",0) - meta:set_string("cnc_product", "") -- Reset the program - end - - if (meta:get_float("cnc_on") == 1) then - if charge>=cnc_cost then - charge=charge-cnc_cost; - meta:set_float("internal_EU_buffer",charge) - meta:set_float("src_time", meta:get_float("src_time") + 1) - if meta:get_float("src_time") >= meta:get_float("cnc_time") then - local product = meta:get_string("cnc_product") - if inv:room_for_item("dst",product) then - -- CNC does the transformation - ------------------------------ - if minetest.registered_nodes[product] ~= nil then - inv:add_item("dst",product .. " " .. meta:get_float("cnc_multiplier")) - srcstack = inv:get_stack("src", 1) - srcstack:take_item() - inv:set_stack("src",1,srcstack) - if inv:is_empty("src") then - meta:set_float("cnc_on",0) - meta:set_string("cnc_product", "") -- Reset the program --- print("cnc product reset") - end - else - minetest.chat_send_player(meta:get_string("cnc_user"), "CNC machine does not know how to handle this material. Please remove it."); - end - else - minetest.chat_send_player(meta:get_string("cnc_user"), "CNC inventory full!") - end - meta:set_float("src_time", 0) - end - end - end + { nodenames = {"technic:cnc","technic:cnc_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local eu_input = meta:get_int("LV_EU_input") + local state = meta:get_int("state") + local next_state = state - if (meta:get_float("cnc_on")==0) then - if not inv:is_empty("src") then - local product = meta:get_string("cnc_product") - if minetest.registered_nodes[product] ~= nil then - meta:set_float("cnc_on",1) - hacky_swap_node(pos,"technic:cnc_active") - meta:set_string("infotext", "CNC Machine Active") - cnc_time=3 - meta:set_float("cnc_time",cnc_time) - meta:set_float("src_time", 0) - return - end - else - hacky_swap_node(pos,"technic:cnc") - meta:set_string("infotext", "CNC Machine Inactive") - end - end - end - }) + -- Machine information + local machine_name = "CNC" + local machine_node = "technic:cnc" + local machine_state_demand = { 50, 450 } + + -- Setup meta data if it does not exist. state is used as an indicator of this + if state == 0 then + meta:set_int("state", 1) + meta:set_int("LV_EU_demand", machine_state_demand[1]) + meta:set_int("LV_EU_input", 0) + return + end + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "LV") + + -- State machine + if eu_input == 0 then + -- Unpowered - go idle + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + next_state = 1 + elseif eu_input == machine_state_demand[state] then + -- Powered - do the state specific actions + + local inv = meta:get_inventory() + local empty = inv:is_empty("src") + + if state == 1 then + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Idle") + + local result = meta:get_string("cnc_product") + if not empty and minetest.registered_nodes[result] ~= nil and inv:room_for_item("dst",result) then + next_state = 2 + else + meta:set_string("cnc_product", "") -- Reset the program + end + --minetest.chat_send_player(meta:get_string("cnc_user"), "CNC machine does not know how to handle this material. Please remove it."); + + elseif state == 2 then + hacky_swap_node(pos, machine_node.."_active") + meta:set_string("infotext", machine_name.." Active") + + if empty then + next_state = 1 + else + meta:set_int("src_time", meta:get_int("src_time") + 1) + if meta:get_int("src_time") >= 3 then -- 3 ticks per output + local result = meta:get_string("cnc_product") + -- check if there's room for output in "dst" list + if inv:room_for_item("dst",result) then + -- CNC does the transformation + ------------------------------ + meta:set_int("src_time", 0) + -- take stuff from "src" list + srcstack = inv:get_stack("src", 1) + srcstack:take_item() + inv:set_stack("src", 1, srcstack) + -- Put result in "dst" list + inv:add_item("dst",result .. " " .. meta:get_int("cnc_multiplier")) + else + next_state = 1 + end + end + end + end + end + -- Change state? + if next_state ~= state then + meta:set_int("LV_EU_demand", machine_state_demand[next_state]) + meta:set_int("state", next_state) + end + end + }) -register_LV_machine ("technic:cnc","RE") -register_LV_machine ("technic:cnc_active","RE") +technic.register_LV_machine ("technic:cnc","RE") +technic.register_LV_machine ("technic:cnc_active","RE") ------------------------- -- CNC Machine Recipe diff --git a/technic/electric_furnace.lua b/technic/electric_furnace.lua index e9d3236..4f2f11c 100644 --- a/technic/electric_furnace.lua +++ b/technic/electric_furnace.lua @@ -1,173 +1,159 @@ -minetest.register_craft({ - output = 'technic:electric_furnace', - recipe = { - {'default:cobble', 'default:cobble', 'default:cobble'}, - {'default:cobble', '', 'default:cobble'}, - {'default:steel_ingot', 'moreores:copper_ingot', 'default:steel_ingot'}, - } -}) +-- LV Electric Furnace +-- This is a faster version of the stone furnace which runs on EUs +-- FIXME: kpoppel I'd like to introduce an induction heating element here also +minetest.register_craft( + {output = 'technic:electric_furnace', + recipe = { + {'default:cobble', 'default:cobble', 'default:cobble'}, + {'default:cobble', '', 'default:cobble'}, + {'default:steel_ingot', 'moreores:copper_ingot', 'default:steel_ingot'}, + } + }) -electric_furnace_formspec = - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "list[current_name;src;3,1;1,1;]".. - "list[current_name;dst;5,1;2,2;]".. - "list[current_player;main;0,5;8,4;]".. - "label[0,0;Electric Furnace]".. - "label[1,3;Power level]" - -minetest.register_node("technic:electric_furnace", { - description = "Electric furnace", - tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png", - "technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front.png"}, - paramtype2 = "facedir", - groups = {cracky=2}, - legacy_facedir_simple = true, - sounds = default.node_sound_stone_defaults(), - technic_power_machine=1, - internal_EU_buffer=0; - interal_EU_buffer_size=2000; - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_float("technic_power_machine", 1) - meta:set_string("formspec", electric_furnace_formspec) - meta:set_string("infotext", "Electric furnace") - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 4) - local EU_used = 0 - local furnace_is_cookin = 0 - local cooked = nil - meta:set_float("internal_EU_buffer",0) - meta:set_float("internal_EU_buffer_size",2000) +local electric_furnace_formspec = + "invsize[8,9;]".. + "list[current_name;src;3,1;1,1;]".. + "list[current_name;dst;5,1;2,2;]".. + "list[current_player;main;0,5;8,4;]".. + "label[0,0;Electric Furnace]".. + "label[1,3;Power level]" - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, -}) +minetest.register_node( + "technic:electric_furnace", + {description = "Electric furnace", + tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png", + "technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front.png"}, + paramtype2 = "facedir", + groups = {cracky=2}, + legacy_facedir_simple = true, + sounds = default.node_sound_stone_defaults(), + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "Electric Furnace") + meta:set_float("technic_power_machine", 1) + meta:set_string("formspec", electric_furnace_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) + inv:set_size("dst", 4) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, + }) -minetest.register_node("technic:electric_furnace_active", { - description = "Electric Furnace", - tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png", - "technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front_active.png"}, - paramtype2 = "facedir", - light_source = 8, - drop = "technic:electric_furnace", - groups = {cracky=2, not_in_creative_inventory=1}, - legacy_facedir_simple = true, - sounds = default.node_sound_stone_defaults(), - internal_EU_buffer=0; - interal_EU_buffer_size=2000; - technic_power_machine=1, - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_float("technic_power_machine", 1) - meta:set_string("formspec", electric_furnace_formspec) - meta:set_string("infotext", "Electric furnace"); - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 4) - local EU_used = 0 - local furnace_is_cookin = 0 - local cooked = nil - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - end - return true - end, -}) +minetest.register_node( + "technic:electric_furnace_active", + {description = "Electric Furnace", + tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png", + "technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front_active.png"}, + paramtype2 = "facedir", + light_source = 8, + drop = "technic:electric_furnace", + groups = {cracky=2, not_in_creative_inventory=1}, + legacy_facedir_simple = true, + sounds = default.node_sound_stone_defaults(), + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, + }) -minetest.register_abm({ - nodenames = {"technic:electric_furnace","technic:electric_furnace_active"}, - interval = 1, - chance = 1, - - action = function(pos, node, active_object_count, active_object_count_wider) +minetest.register_abm( + { nodenames = {"technic:electric_furnace","technic:electric_furnace_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local eu_input = meta:get_int("LV_EU_input") + local state = meta:get_int("state") + local next_state = state - local meta = minetest.env:get_meta(pos) - internal_EU_buffer=meta:get_float("internal_EU_buffer") - internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size") - local load = math.floor(internal_EU_buffer/internal_EU_buffer_size * 100) - meta:set_string("formspec", - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]".. - "list[current_name;src;3,1;1,1;]".. - "list[current_name;dst;5,1;2,2;]".. - "list[current_player;main;0,5;8,4;]".. - "label[0,0;Electric Furnace]".. - "label[1,3;Power level]") + -- Machine information + local machine_name = "Electric furnace" + local machine_node = "technic:electric_furnace" + local machine_state_demand = { 50, 1000 } + + -- Setup meta data if it does not exist. state is used as an indicator of this + if state == 0 then + meta:set_int("state", 1) + meta:set_int("LV_EU_demand", machine_state_demand[1]) + meta:set_int("LV_EU_input", 0) + return + end + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "LV") + + -- State machine + if eu_input == 0 then + -- Unpowered - go idle + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + next_state = 1 + elseif eu_input == machine_state_demand[state] then + -- Powered - do the state specific actions + + -- Execute always if powered logic + local inv = meta:get_inventory() + local empty = inv:is_empty("src") - local inv = meta:get_inventory() - - local furnace_is_cookin = meta:get_float("furnace_is_cookin") - - - local srclist = inv:get_list("src") - local cooked=nil + if state == 1 then + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Idle") - if srclist then - cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) - end - - - if (furnace_is_cookin == 1) then - if internal_EU_buffer>=150 then - internal_EU_buffer=internal_EU_buffer-150; - meta:set_float("internal_EU_buffer",internal_EU_buffer) - meta:set_float("src_time", meta:get_float("src_time") + 3) - 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 - srcstack = inv:get_stack("src", 1) - srcstack:take_item() - inv:set_stack("src", 1, srcstack) - else - print("Furnace inventory full!") - end - meta:set_string("src_time", 0) - end - end - end + local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")}) + if not empty and result and inv:room_for_item("dst",result) then + next_state = 2 + end + elseif state == 2 then + hacky_swap_node(pos, machine_node.."_active") + meta:set_string("infotext", machine_name.." Active") - if srclist then - cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) - if cooked.time>0 then - hacky_swap_node(pos,"technic:electric_furnace_active") - meta:set_string("infotext","Furnace active") - meta:set_string("furnace_is_cookin",1) - meta:set_string("src_time", 0) - return - end + if empty then + next_state = 1 + else + meta:set_int("src_time", meta:get_int("src_time") + 3) -- Cooking time 3x + local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")}) + if result and result.item and meta:get_int("src_time") >= result.time then + -- check if there's room for output in "dst" list + meta:set_int("src_time", 0) + if inv:room_for_item("dst",result.item) then + -- take stuff from "src" list + srcstack = inv:get_stack("src", 1) + srcstack:take_item() + inv:set_stack("src", 1, srcstack) + -- Put result in "dst" list + inv:add_item("dst", result.item) + else + -- all full: go idle + next_state = 1 + end + end + end + end + end + -- Change state? + if next_state ~= state then + meta:set_int("LV_EU_demand", machine_state_demand[next_state]) + meta:set_int("state", next_state) + end + end, + }) - end - - hacky_swap_node(pos,"technic:electric_furnace") - meta:set_string("infotext","Furnace inactive") - meta:set_string("furnace_is_cookin",0) - meta:set_string("src_time", 0) - -end, -}) - -register_LV_machine ("technic:electric_furnace","RE") -register_LV_machine ("technic:electric_furnace_active","RE") +technic.register_LV_machine ("technic:electric_furnace","RE") +technic.register_LV_machine ("technic:electric_furnace_active","RE") diff --git a/technic/electric_furnace_mv.lua b/technic/electric_furnace_mv.lua index fd90b14..7f205b5 100644 --- a/technic/electric_furnace_mv.lua +++ b/technic/electric_furnace_mv.lua @@ -1,279 +1,304 @@ -minetest.register_craft({ - output = 'technic:mv_electric_furnace', - recipe = { - {'technic:stainless_steel_ingot', 'technic:electric_furnace', 'technic:stainless_steel_ingot'}, - {'pipeworks:tube_000000', 'technic:mv_transformer', 'pipeworks:tube_000000'}, - {'technic:stainless_steel_ingot', 'technic:mv_cable', 'technic:stainless_steel_ingot'}, - } -}) +-- MV Electric Furnace +-- This is a faster version of the stone furnace which runs on EUs +-- In addition to this it can be upgraded with microcontrollers and batteries +-- This new version uses the batteries to lower the power consumption of the machine +-- Also in addition this furnace can be attached to the pipe system from the pipeworks mod. +-- FIXME: kpoppel I'd like to introduce an induction heating element here also +minetest.register_craft( + {output = 'technic:mv_electric_furnace', + recipe = { + {'technic:stainless_steel_ingot', 'technic:electric_furnace', 'technic:stainless_steel_ingot'}, + {'pipeworks:tube_000000', 'technic:mv_transformer', 'pipeworks:tube_000000'}, + {'technic:stainless_steel_ingot', 'technic:mv_cable', 'technic:stainless_steel_ingot'}, + } + }) -mv_electric_furnace_formspec = - "invsize[8,10;]".. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "list[current_name;src;3,1;1,1;]".. - "list[current_name;dst;5,1;2,2;]".. - "list[current_player;main;0,6;8,4;]".. - "label[0,0;MV Electric Furnace]".. - "label[1,2.8;Power level]".. - "list[current_name;upgrade1;1,4;1,1;]".. - "list[current_name;upgrade2;2,4;1,1;]".. - "label[1,5;Upgrade Slots]" +local mv_electric_furnace_formspec = + "invsize[8,10;]".. + "list[current_name;src;3,1;1,1;]".. + "list[current_name;dst;5,1;2,2;]".. + "list[current_player;main;0,6;8,4;]".. + "label[0,0;MV Electric Furnace]".. + "list[current_name;upgrade1;1,4;1,1;]".. + "list[current_name;upgrade2;2,4;1,1;]".. + "label[1,5;Upgrade Slots]" -minetest.register_node("technic:mv_electric_furnace", { - description = "MV Electric furnace", - tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png", - "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front.png"}, - paramtype2 = "facedir", - groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,}, - tube={insert_object=function(pos,node,stack,direction) - local meta=minetest.env:get_meta(pos) - local inv=meta:get_inventory() - return inv:add_item("src",stack) - end, - can_insert=function(pos,node,stack,direction) +minetest.register_node( + "technic:mv_electric_furnace", + {description = "MV Electric furnace", + tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png", + "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front.png"}, + paramtype2 = "facedir", + groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,}, + tube={insert_object=function(pos,node,stack,direction) + local meta=minetest.env:get_meta(pos) + local inv=meta:get_inventory() + return inv:add_item("src",stack) + end, + can_insert=function(pos,node,stack,direction) local meta=minetest.env:get_meta(pos) local inv=meta:get_inventory() return inv:room_for_item("src",stack) - end, - }, - legacy_facedir_simple = true, - sounds = default.node_sound_stone_defaults(), - technic_power_machine=1, - internal_EU_buffer=0; - interal_EU_buffer_size=2000; - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_float("technic_mv_power_machine", 1) - meta:set_string("formspec", mv_electric_furnace_formspec) - meta:set_string("infotext", "Electric furnace") - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 4) - inv:set_size("upgrade1", 1) - inv:set_size("upgrade2", 1) - local EU_used = 0 - local furnace_is_cookin = 0 - local cooked = nil - meta:set_float("internal_EU_buffer",0) - meta:set_float("internal_EU_buffer_size",2000) - meta:set_float("tube_time", 0) - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - elseif not inv:is_empty("upgrade1") then - return false - elseif not inv:is_empty("upgrade2") then - return false - end - return true - end, -}) + end, + }, + legacy_facedir_simple = true, + sounds = default.node_sound_stone_defaults(), + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "MV Electric furnace") + meta:set_float("technic_mv_power_machine", 1) + meta:set_int("tube_time", 0) + meta:set_string("formspec", mv_electric_furnace_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) + inv:set_size("dst", 4) + inv:set_size("upgrade1", 1) + inv:set_size("upgrade2", 1) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, + }) -minetest.register_node("technic:mv_electric_furnace_active", { - description = "MV Electric Furnace", - tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png", - "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front_active.png"}, - paramtype2 = "facedir", - light_source = 8, - drop = "technic:mv_electric_furnace", - groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1}, - tube={insert_object=function(pos,node,stack,direction) - local meta=minetest.env:get_meta(pos) - local inv=meta:get_inventory() - return inv:add_item("src",stack) - end, - can_insert=function(pos,node,stack,direction) +minetest.register_node( + "technic:mv_electric_furnace_active", + {description = "MV Electric Furnace", + tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png", + "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front_active.png"}, + paramtype2 = "facedir", + light_source = 8, + drop = "technic:mv_electric_furnace", + groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1}, + tube={insert_object=function(pos,node,stack,direction) + local meta=minetest.env:get_meta(pos) + local inv=meta:get_inventory() + return inv:add_item("src",stack) + end, + can_insert=function(pos,node,stack,direction) local meta=minetest.env:get_meta(pos) local inv=meta:get_inventory() return inv:room_for_item("src",stack) - end, - }, - legacy_facedir_simple = true, - sounds = default.node_sound_stone_defaults(), - internal_EU_buffer=0; - interal_EU_buffer_size=2000; - technic_power_machine=1, - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_float("technic_mv_power_machine", 1) - meta:set_string("formspec", mv_electric_furnace_formspec) - meta:set_string("infotext", "Electric furnace"); - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 4) - inv:set_size("upgrade1", 1) - inv:set_size("upgrade2", 1) - local EU_used = 0 - local furnace_is_cookin = 0 - local cooked = nil - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("dst") then - return false - elseif not inv:is_empty("src") then - return false - elseif not inv:is_empty("upgrade1") then - return false - elseif not inv:is_empty("upgrade2") then - return false - end - return true - end, -}) - -minetest.register_abm({ - nodenames = {"technic:mv_electric_furnace","technic:mv_electric_furnace_active"}, - interval = 1, - chance = 1, + end, + }, + legacy_facedir_simple = true, + sounds = default.node_sound_stone_defaults(), + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, + -- These three makes sure upgrades are not moved in or out while the furnace is active. + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if listname == "src" or listname == "dst" then + return 99 + else + return 0 -- Disallow the move + end + end, + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if listname == "src" or listname == "dst" then + return 99 + else + return 0 -- Disallow the move + end + end, + allow_metadata_inventory_move = function(pos, from_list, to_list, to_list, to_index, count, player) + return 0 + end, + }) - action = function(pos, node, active_object_count, active_object_count_wider) +local send_cooked_items = function(pos,x_velocity,z_velocity) + -- Send items on their way in the pipe system. + local meta=minetest.env:get_meta(pos) + local inv = meta:get_inventory() + local i=0 + for _,stack in ipairs(inv:get_list("dst")) do + i=i+1 + if stack then + local item0=stack:to_table() + if item0 then + item0["count"]="1" + local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},item0) + item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z} + item1:setvelocity({x=x_velocity, y=0, z=z_velocity}) + item1:setacceleration({x=0, y=0, z=0}) + stack:take_item(1); + inv:set_stack("dst", i, stack) + return + end + end + end + end - local pos1={} - pos1.x=pos.x - pos1.y=pos.y - pos1.z=pos.z - local x_velocity=0 - local z_velocity=0 - - -- output is on the left side of the furnace - if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end - if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end - if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end - if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end - - local output_tube_connected = false - local meta=minetest.env:get_meta(pos1) - if meta:get_int("tubelike")==1 then output_tube_connected=true end - meta = minetest.env:get_meta(pos) - local inv = meta:get_inventory() - local upg_item1 - local upg_item1_name="" - local upg_item2 - local upg_item2_name="" - local srcstack = inv:get_stack("upgrade1", 1) - if srcstack then upg_item1=srcstack:to_table() end - srcstack = inv:get_stack("upgrade2", 1) - if srcstack then upg_item2=srcstack:to_table() end - if upg_item1 then upg_item1_name=upg_item1.name end - if upg_item2 then upg_item2_name=upg_item2.name end - - local speed=0 - if upg_item1_name=="technic:control_logic_unit" then speed=speed+1 end - if upg_item2_name=="technic:control_logic_unit" then speed=speed+1 end - tube_time=meta:get_float("tube_time") - tube_time=tube_time+speed - if tube_time>3 then - tube_time=0 - if output_tube_connected then send_cooked_items(pos,x_velocity,z_velocity) end - end - meta:set_float("tube_time", tube_time) - - local extra_buffer_size = 0 - if upg_item1_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end - if upg_item2_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end - local internal_EU_buffer_size=2000+extra_buffer_size - meta:set_float("internal_EU_buffer_size",internal_EU_buffer_size) - - internal_EU_buffer=meta:get_float("internal_EU_buffer") - if internal_EU_buffer > internal_EU_buffer_size then internal_EU_buffer = internal_EU_buffer_size end - local load = math.floor(internal_EU_buffer/(internal_EU_buffer_size) * 100) - meta:set_string("formspec", - "invsize[8,10;]".. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]".. - "list[current_name;src;3,1;1,1;]".. - "list[current_name;dst;5,1;2,2;]".. - "list[current_player;main;0,6;8,4;]".. - "label[0,0;MV Electric Furnace]".. - "label[1,2.8;Power level]".. - "list[current_name;upgrade1;1,4;1,1;]".. - "list[current_name;upgrade2;2,4;1,1;]".. - "label[1,5;Upgrade Slots]") +local smelt_item = function(pos) + local meta=minetest.env:get_meta(pos) + local inv = meta:get_inventory() + meta:set_int("src_time", meta:get_int("src_time") + 3) -- Cooking time 3x faster + local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")}) + if result and result.item and meta:get_int("src_time") >= result.time then + meta:set_int("src_time", 0) + -- check if there's room for output in "dst" list + if inv:room_for_item("dst",result) then + -- take stuff from "src" list + srcstack = inv:get_stack("src", 1) + srcstack:take_item() + inv:set_stack("src", 1, srcstack) + -- Put result in "dst" list + inv:add_item("dst", result.item) + return 1 + else + return 0 -- done + end + end + return 0 -- done + end - local furnace_is_cookin = meta:get_float("furnace_is_cookin") - - - local srclist = inv:get_list("src") - local cooked=nil +minetest.register_abm( + {nodenames = {"technic:mv_electric_furnace","technic:mv_electric_furnace_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local eu_input = meta:get_int("MV_EU_input") + local state = meta:get_int("state") + local next_state = state - if srclist then - cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + -- Machine information + local machine_name = "MV Electric Furnace" + local machine_node = "technic:mv_electric_furnace" + local machine_state_demand = { 50, 2000, 1500, 1000 } + + -- Setup meta data if it does not exist. state is used as an indicator of this + if state == 0 then + meta:set_int("state", 1) + meta:set_int("MV_EU_demand", machine_state_demand[1]) + meta:set_int("MV_EU_input", 0) + return end + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "MV") + -- Execute always logic + -- CODE HERE -- - if (furnace_is_cookin == 1) then - if internal_EU_buffer>=150 then - internal_EU_buffer=internal_EU_buffer-150; - meta:set_float("internal_EU_buffer",internal_EU_buffer) - meta:set_float("src_time", meta:get_float("src_time") + 3) - 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 - srcstack = inv:get_stack("src", 1) - srcstack:take_item() - inv:set_stack("src", 1, srcstack) - else - print("Furnace inventory full!") - end - meta:set_string("src_time", 0) - end - end + -- State machine + if eu_input == 0 then + -- Unpowered - go idle + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + next_state = 1 + elseif eu_input == machine_state_demand[state] then + -- Powered - do the state specific actions + + -- Execute always if powered logic + local meta=minetest.env:get_meta(pos) + + -- Get the names of the upgrades + local meta=minetest.env:get_meta(pos) + local inv = meta:get_inventory() + local upg_item1 + local upg_item1_name="" + local upg_item2 + local upg_item2_name="" + local srcstack = inv:get_stack("upgrade1", 1) + if srcstack then upg_item1=srcstack:to_table() end + srcstack = inv:get_stack("upgrade2", 1) + if srcstack then upg_item2=srcstack:to_table() end + if upg_item1 then upg_item1_name=upg_item1.name end + if upg_item2 then upg_item2_name=upg_item2.name end + + -- Save some power by installing battery upgrades. Fully upgraded makes this + -- furnace use the same amount of power as the LV version + local EU_saving_upgrade = 0 + if upg_item1_name=="technic:battery" then EU_saving_upgrade = EU_saving_upgrade + 1 end + if upg_item2_name=="technic:battery" then EU_saving_upgrade = EU_saving_upgrade + 1 end + + -- Tube loading speed can be upgraded using control logic units + local tube_speed_upgrade = 0 + if upg_item1_name=="technic:control_logic_unit" then tube_speed_upgrade = tube_speed_upgrade + 1 end + if upg_item2_name=="technic:control_logic_unit" then tube_speed_upgrade = tube_speed_upgrade + 1 end + + -- Handle pipeworks (consumes tube_speed_upgrade) + local pos1={x=pos.x, y=pos.y, z=pos.z} + local x_velocity=0 + local z_velocity=0 + + -- Output is on the left side of the furnace + if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end + if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end + if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end + if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end + + local output_tube_connected = false + local meta1 = minetest.env:get_meta(pos1) + if meta1:get_int("tubelike") == 1 then + output_tube_connected=true + end + tube_time = meta:get_int("tube_time") + tube_time = tube_time + tube_speed_upgrade + if tube_time > 3 then + tube_time = 0 + if output_tube_connected then + send_cooked_items(pos,x_velocity,z_velocity) + end + end + meta:set_int("tube_time", tube_time) + + -- The machine shuts down if we have nothing to smelt and no tube is connected + -- or if we have nothing to send with a tube connected. + if (not output_tube_connected and inv:is_empty("src")) + or ( output_tube_connected and inv:is_empty("dst")) then + next_state = 1 end - - - - if srclist then - cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) - if cooked.time>0 then - hacky_swap_node(pos,"technic:mv_electric_furnace_active") - meta:set_string("infotext","Furnace active") - meta:set_string("furnace_is_cookin",1) - meta:set_string("src_time", 0) - return - end - - end - - hacky_swap_node(pos,"technic:mv_electric_furnace") - meta:set_string("infotext","Furnace inactive") - meta:set_string("furnace_is_cookin",0) - meta:set_string("src_time", 0) - -end, -}) - -function send_cooked_items (pos,x_velocity,z_velocity) - local meta=minetest.env:get_meta(pos) - local inv = meta:get_inventory() - local i=0 - for _,stack in ipairs(inv:get_list("dst")) do - i=i+1 - if stack then - local item0=stack:to_table() - if item0 then - item0["count"]="1" - local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},item0) - item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z} - item1:setvelocity({x=x_velocity, y=0, z=z_velocity}) - item1:setacceleration({x=0, y=0, z=0}) - stack:take_item(1); - inv:set_stack("dst", i, stack) - return - end - end + ---------------------- + + if state == 1 then + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Idle") + + local meta=minetest.env:get_meta(pos) + local inv = meta:get_inventory() + if not inv:is_empty("src") then + local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")}) + if result then + meta:set_string("infotext", machine_name.." Active") + meta:set_int("src_time", 0) + next_state = 2+EU_saving_upgrade -- Next state is decided by the battery upgrade (state 2= 0 batteries, state 3 = 1 battery, 4 = 2 batteries) + end + else + meta:set_string("infotext", "Electric Furnace Idle") + end + + elseif state == 2 or state == 3 or state == 4 then + hacky_swap_node(pos, machine_node.."_active") + meta:set_string("infotext", machine_name.." Active") + result = smelt_item(pos, data) + if result == 0 then + next_state = 1 + end end -end + end + -- Change state? + if next_state ~= state then + meta:set_int("MV_EU_demand", machine_state_demand[next_state]) + meta:set_int("state", next_state) + end + end, + }) -register_MV_machine ("technic:mv_electric_furnace","RE") -register_MV_machine ("technic:mv_electric_furnace_active","RE") +technic.register_MV_machine ("technic:mv_electric_furnace","RE") +technic.register_MV_machine ("technic:mv_electric_furnace_active","RE") diff --git a/technic/flashlight.lua b/technic/flashlight.lua index f6e4dc2..dd36c31 100644 --- a/technic/flashlight.lua +++ b/technic/flashlight.lua @@ -1,7 +1,7 @@ -- original code comes from walkin_light mod by Echo http://minetest.net/forum/viewtopic.php?id=2621 -flashlight_max_charge=30000 -register_power_tool ("technic:flashlight",flashlight_max_charge) +local flashlight_max_charge=30000 +technic.register_LV_power_tool ("technic:flashlight",flashlight_max_charge) minetest.register_tool("technic:flashlight", { description = "Flashlight", diff --git a/technic/forcefield.lua b/technic/forcefield.lua index dbcae01..8af98f4 100644 --- a/technic/forcefield.lua +++ b/technic/forcefield.lua @@ -66,7 +66,7 @@ local function remove_forcefield(p, range) end end -forcefield_receive_fields = function(pos, formname, fields, sender) +local forcefield_receive_fields = function(pos, formname, fields, sender) local meta = minetest.env:get_meta(pos) local range = meta:get_int("range") if fields.add then range = range + 1 end @@ -88,7 +88,7 @@ forcefield_receive_fields = function(pos, formname, fields, sender) end end -function get_forcefield_formspec(range, load) +local get_forcefield_formspec = function(range, load) if not load then load = 0 end return "invsize[8,9;]".. "label[0,0;Forcefield emitter]".. @@ -103,7 +103,7 @@ function get_forcefield_formspec(range, load) "list[current_player;main;0,5;8,4;]" end -local function forcefield_check(pos) +local forcefield_check = function(pos) local meta = minetest.env:get_meta(pos) local node = minetest.env:get_node(pos) local internal_EU_buffer=meta:get_float("internal_EU_buffer") @@ -145,7 +145,6 @@ minetest.register_node("technic:forcefield_emitter_off", { tiles = {"technic_forcefield_emitter_off.png"}, is_ground_content = true, groups = {cracky = 1}, - technic_power_machine=1, on_timer = forcefield_check, on_receive_fields = forcefield_receive_fields, on_construct = function(pos) @@ -206,9 +205,5 @@ minetest.register_node("technic:forcefield", { }, }) -register_MV_machine ("technic:forcefield_emitter_on","RE") -register_MV_machine ("technic:forcefield_emitter_off","RE") - - - - +technic.register_MV_machine("technic:forcefield_emitter_on","RE") +technic.register_MV_machine("technic:forcefield_emitter_off","RE") diff --git a/technic/generator.lua b/technic/generator.lua index ae899a6..48f3b03 100644 --- a/technic/generator.lua +++ b/technic/generator.lua @@ -1,3 +1,7 @@ +-- Th coal driven EU generator. +-- A simple device to get started on the electric machines. +-- Inefficient and expensive in coal (200EU 16 ticks) +-- Also only allows for LV machinery to run. minetest.register_alias("generator", "technic:generator") minetest.register_alias("generator", "technic:generator_active") @@ -15,7 +19,7 @@ minetest.register_craftitem("technic:generator", { stack_max = 99, }) -generator_formspec = +local generator_formspec = "invsize[8,9;]".. "image[0,0;5,5;technic_generator_menu.png]".. "image[1,1;1,2;technic_power_meter_bg.png]".. @@ -26,124 +30,118 @@ generator_formspec = "list[current_player;main;0,5;8,4;]" -minetest.register_node("technic:generator", { - description = "Coal Driven Generator", - tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png", - "technic_generator_side.png", "technic_generator_side.png", "technic_generator_front.png"}, - paramtype2 = "facedir", - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=5000; - burn_time=0; - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "Generator") - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 5000) - meta:set_string("formspec", generator_formspec) - meta:set_float("burn_time", 0) - - local inv = meta:get_inventory() - inv:set_size("src", 1) - +minetest.register_node( + "technic:generator", + { + description = "Coal Driven Generator", + tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png", + "technic_generator_side.png", "technic_generator_side.png", "technic_generator_front.png"}, + paramtype2 = "facedir", + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=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("infotext", "Coal Electric Generator") + meta:set_float("technic_power_machine", 1) + meta:set_int("LV_EU_supply", 0) + meta:set_int("LV_EU_from_fuel", 1) -- Signal to the switching station that this device burns some sort of fuel and needs special handling + meta:set_int("burn_time", 0) + meta:set_string("formspec", generator_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("src") then - return false - end - return true + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end end, + }) -}) - -minetest.register_node("technic:generator_active", { - description = "Coal Driven Generator", - tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png", - "technic_generator_side.png", "technic_generator_side.png", "technic_generator_front_active.png"}, - paramtype2 = "facedir", - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - drop="technic:generator", - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=0; - burn_time=0; - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("src") then - return false - end - return true +minetest.register_node( + "technic:generator_active", + { + description = "Coal Driven Generator", + tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png", + "technic_generator_side.png", "technic_generator_side.png", "technic_generator_front_active.png"}, + paramtype2 = "facedir", + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + drop="technic:generator", + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end end, + }) -}) -minetest.register_abm({ - nodenames = {"technic:generator","technic:generator_active"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - - local meta = minetest.env:get_meta(pos) - local burn_time= meta:get_float("burn_time") - local charge= meta:get_float("internal_EU_buffer") - local max_charge= meta:get_float("internal_EU_buffer_size") - local burn_charge=200 +minetest.register_abm( + { + nodenames = {"technic:generator","technic:generator_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local burn_time= meta:get_int("burn_time") - if burn_time>0 then - if charge+burn_charge>max_charge then - burn_charge=max_charge-charge - end - if burn_charge>0 then - burn_time=burn_time-1 - meta:set_float("burn_time",burn_time) - charge=charge+burn_charge - meta:set_float("internal_EU_buffer",charge) - end - - end - if burn_time==0 then - local inv = meta:get_inventory() - if inv:is_empty("src")==false then - local srcstack = inv:get_stack("src", 1) - src_item=srcstack:to_table() - if src_item["name"]== "default:coal_lump" then - srcstack:take_item() - inv:set_stack("src", 1, srcstack) - burn_time=16 - meta:set_float("burn_time",burn_time) - hacky_swap_node (pos,"technic:generator_active") - end - end - end + -- If more to burn and the energy produced was used: produce some more + if burn_time>0 then + if meta:get_int("LV_EU_supply") == 0 then + -- We did not use the power + meta:set_int("LV_EU_supply", 200) -- Give 200EUs + else + burn_time = burn_time - 1 + meta:set_int("burn_time",burn_time) + end + end - local load = math.floor((charge/max_charge)*100) - local percent = math.floor((burn_time/16)*100) - meta:set_string("formspec", - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]".. - "label[0,0;Generator]".. - "label[1,3;Power level]".. - "list[current_name;src;3,1;1,1;]".. - "image[4,1;1,1;default_furnace_fire_bg.png^[lowpart:".. - (percent)..":default_furnace_fire_fg.png]".. - "list[current_player;main;0,5;8,4;]" - ) + -- Burn another piece of coal + if burn_time==0 then + local inv = meta:get_inventory() + if inv:is_empty("src") == false then + local srcstack = inv:get_stack("src", 1) + src_item=srcstack:to_table() + if src_item["name"] == "default:coal_lump" then + srcstack:take_item() + inv:set_stack("src", 1, srcstack) + burn_time=16 + meta:set_int("burn_time",burn_time) + hacky_swap_node (pos,"technic:generator_active") + meta:set_int("LV_EU_supply", 200) -- Give 200EUs + end + end + end - if burn_time==0 then - hacky_swap_node (pos,"technic:generator") - end + local load = 8 -- math.floor((charge/max_charge)*100) + local percent = math.floor((burn_time/16)*100) + meta:set_string("formspec", + "invsize[8,9;]".. + "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. + (load)..":technic_power_meter_fg.png]".. + "label[0,0;Generator]".. + "label[1,3;Power level]".. + "list[current_name;src;3,1;1,1;]".. + "image[4,1;1,1;default_furnace_fire_bg.png^[lowpart:".. + (percent)..":default_furnace_fire_fg.png]".. + "list[current_player;main;0,5;8,4;]" + ) - end -}) + if burn_time==0 then + hacky_swap_node (pos,"technic:generator") + end + end + }) -register_LV_machine ("technic:generator","PR") -register_LV_machine ("technic:generator_active","PR") +technic.register_LV_machine ("technic:generator","PR") +technic.register_LV_machine ("technic:generator_active","PR") diff --git a/technic/geothermal.lua b/technic/geothermal.lua index dccabf4..5ba7a23 100644 --- a/technic/geothermal.lua +++ b/technic/geothermal.lua @@ -1,3 +1,7 @@ +-- A geothermal EU generator +-- Using hot lava and water this device can create energy from steam +-- The machine is only producing LV EUs and can thus not drive more advanced equipment +-- The output is a little more than the coal burning generator (max 300EUs) minetest.register_alias("geothermal", "technic:geothermal") minetest.register_craft({ @@ -14,7 +18,7 @@ minetest.register_craftitem("technic:geothermal", { stack_max = 99, }) -geothermal_formspec = +local geothermal_formspec = "invsize[8,4;]".. "image[1,1;1,2;technic_power_meter_bg.png]".. "label[0,0;Geothermal Generator]".. @@ -22,117 +26,131 @@ geothermal_formspec = "list[current_player;main;0,5;8,4;]" -minetest.register_node("technic:geothermal", { - description = "Geothermal Generator", - tiles = {"technic_geothermal_top.png", "technic_machine_bottom.png", "technic_geothermal_side.png", - "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"}, - paramtype2 = "facedir", - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=5000; - burn_time=0; - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "Geothermal Generator") - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 2000) - meta:set_string("formspec", geothermal_formspec) - end, +minetest.register_node( + "technic:geothermal", + { + description = "Geothermal Generator", + tiles = {"technic_geothermal_top.png", "technic_machine_bottom.png", "technic_geothermal_side.png", + "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"}, + paramtype2 = "facedir", + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=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("infotext", "Geothermal Generator") + meta:set_float("technic_power_machine", 1) + meta:set_int("LV_EU_supply", 0) + meta:set_string("formspec", geothermal_formspec) + end, + }) -}) +minetest.register_node( + "technic:geothermal_active", + { + description = "Geothermal Generator", + tiles = {"technic_geothermal_top_active.png", "technic_machine_bottom.png", "technic_geothermal_side.png", + "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"}, + paramtype2 = "facedir", + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + drop="technic:geothermal", + }) -minetest.register_node("technic:geothermal_active", { - description = "Geothermal Generator", - tiles = {"technic_geothermal_top_active.png", "technic_machine_bottom.png", "technic_geothermal_side.png", - "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"}, - paramtype2 = "facedir", - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - drop="technic:geothermal", - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=0; -}) +local check_node_around = function(pos) + local node=minetest.env:get_node(pos) + if node.name=="default:water_source" or node.name=="default:water_flowing" then return 1 end + if node.name=="default:lava_source" or node.name=="default:lava_flowing" then return 2 end + return 0 + end + +minetest.register_abm( + { + nodenames = {"technic:geothermal","technic:geothermal_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local water_nodes = 0 + local lava_nodes = 0 + local production_level = 0 + local eu_supply = 0 -minetest.register_abm({ - nodenames = {"technic:geothermal","technic:geothermal_active"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) + -- Correct positioning is water on one side and lava on the other. + -- The two cannot be adjacent because the lava the turns into obsidian or rock. + -- To get to 100% production stack the water and lava one extra block down as well: + -- WGL (W=Water, L=Lava, G=the generator, |=an LV cable) + -- W|L + pos.x=pos.x+1 + local check=check_node_around(pos) + if check==1 then water_nodes=water_nodes+1 end + if check==2 then lava_nodes=lava_nodes+1 end + pos.y=pos.y-1 + local check=check_node_around(pos) + if check==1 then water_nodes=water_nodes+1 end + if check==2 then lava_nodes=lava_nodes+1 end - local meta = minetest.env:get_meta(pos) - local charge= meta:get_float("internal_EU_buffer") - local max_charge= meta:get_float("internal_EU_buffer_size") - local water_nodes = 0 - local lava_nodes = 0 - local production_level=0 - local load_step=0 + pos.x=pos.x-2 + check=check_node_around(pos) + if check==1 then water_nodes=water_nodes+1 end + if check==2 then lava_nodes=lava_nodes+1 end + pos.y=pos.y+1 + check=check_node_around(pos) + if check==1 then water_nodes=water_nodes+1 end + if check==2 then lava_nodes=lava_nodes+1 end - pos.x=pos.x+1 - local check=check_node_around (pos) - if check==1 then water_nodes=water_nodes+1 end - if check==2 then lava_nodes=lava_nodes+1 end - pos.x=pos.x-2 - check=check_node_around (pos) - if check==1 then water_nodes=water_nodes+1 end - if check==2 then lava_nodes=lava_nodes+1 end - pos.x=pos.x+1 - pos.z=pos.z+1 - check=check_node_around (pos) - if check==1 then water_nodes=water_nodes+1 end - if check==2 then lava_nodes=lava_nodes+1 end - pos.z=pos.z-2 - check=check_node_around (pos) - if check==1 then water_nodes=water_nodes+1 end - if check==2 then lava_nodes=lava_nodes+1 end - pos.z=pos.z+1 + pos.x=pos.x+1 + pos.z=pos.z+1 + check=check_node_around(pos) + if check==1 then water_nodes=water_nodes+1 end + if check==2 then lava_nodes=lava_nodes+1 end + pos.y=pos.y-1 + check=check_node_around(pos) + if check==1 then water_nodes=water_nodes+1 end + if check==2 then lava_nodes=lava_nodes+1 end + + pos.z=pos.z-2 + check=check_node_around(pos) + if check==1 then water_nodes=water_nodes+1 end + if check==2 then lava_nodes=lava_nodes+1 end + pos.y=pos.y+1 + check=check_node_around(pos) + if check==1 then water_nodes=water_nodes+1 end + if check==2 then lava_nodes=lava_nodes+1 end + + -- Back to (0,0,0) + pos.z=pos.z+1 - if water_nodes==1 and lava_nodes==1 then production_level=50 load_step=30 end - if water_nodes==2 and lava_nodes==1 then production_level=75 load_step=45 end - if water_nodes==1 and lava_nodes==2 then production_level=75 load_step=45 end - if water_nodes==2 and lava_nodes==2 then production_level=100 load_step=60 end - if water_nodes==3 and lava_nodes==1 then production_level=25 load_step=15 end - if water_nodes==1 and lava_nodes==3 then production_level=25 load_step=15 end + if water_nodes==1 and lava_nodes==1 then production_level = 25; eu_supply = 50 end + if water_nodes==2 and lava_nodes==1 then production_level = 50; eu_supply = 100 end + if water_nodes==1 and lava_nodes==2 then production_level = 75; eu_supply = 200 end + if water_nodes==2 and lava_nodes==2 then production_level = 100; eu_supply = 300 end - if production_level>0 then - if charge+load_step>max_charge then - load_step=max_charge-charge - end - if load_step>0 then - charge=charge+load_step - meta:set_float("internal_EU_buffer",charge) - end - end + if production_level>0 then + meta:set_int("LV_EU_supply", eu_supply) + end - local load = math.floor((charge/max_charge)*100) - meta:set_string("formspec", - "invsize[8,4;]".. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]".. - "label[0,0;Geothermal Generator]".. - "label[1,3;Power level]".. - "label[4,0;Production at "..tostring(production_level).."%]" - ) + local load = 1 -- math.floor((charge/max_charge)*100) + meta:set_string("formspec", + "invsize[8,4;]".. + "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. + (load)..":technic_power_meter_fg.png]".. + "label[0,0;Geothermal Generator]".. + "label[1,3;Power level]".. + "label[4,0;Production at "..tostring(production_level).."%]" + ) - if production_level>0 and minetest.env:get_node(pos).name=="technic:geothermal" then - hacky_swap_node (pos,"technic:geothermal_active") - return - end - if production_level==0 then hacky_swap_node (pos,"technic:geothermal") end -end -}) - -function check_node_around (pos) -local node=minetest.env:get_node(pos) -if node.name=="default:water_source" or node.name=="default:water_flowing" then return 1 end -if node.name=="default:lava_source" or node.name=="default:lava_flowing" then return 2 end -return 0 -end + if production_level>0 and minetest.env:get_node(pos).name=="technic:geothermal" then + hacky_swap_node (pos,"technic:geothermal_active") + return + end + if production_level==0 then + hacky_swap_node (pos,"technic:geothermal") + meta:set_int("LV_EU_supply", 0) + end + end + }) -register_LV_machine ("technic:geothermal","PR") -register_LV_machine ("technic:geothermal_active","PR") +technic.register_LV_machine ("technic:geothermal","PR") +technic.register_LV_machine ("technic:geothermal_active","PR") diff --git a/technic/grinder.lua b/technic/grinder.lua index 07baa05..8b41184 100644 --- a/technic/grinder.lua +++ b/technic/grinder.lua @@ -1,352 +1,360 @@ -grinder_recipes ={} - -registered_grinder_recipes_count=1 - -function register_grinder_recipe (string1,string2) -grinder_recipes[registered_grinder_recipes_count]={} -grinder_recipes[registered_grinder_recipes_count].src_name=string1 -grinder_recipes[registered_grinder_recipes_count].dst_name=string2 -registered_grinder_recipes_count=registered_grinder_recipes_count+1 -if unified_inventory then - unified_inventory.register_craft({ - type = "grinding", - output = string2, - items = {string1}, - width = 0, - }) - end -end - -register_grinder_recipe("default:stone","default:sand") -register_grinder_recipe("default:cobble","default:gravel") -register_grinder_recipe("default:gravel","default:dirt") -register_grinder_recipe("default:desert_stone","default:desert_sand") -register_grinder_recipe("default:iron_lump","technic:iron_dust 2") -register_grinder_recipe("default:steel_ingot","technic:iron_dust 1") -register_grinder_recipe("default:coal_lump","technic:coal_dust 2") -register_grinder_recipe("default:copper_lump","technic:copper_dust 2") -register_grinder_recipe("default:copper_ingot","technic:copper_dust 1") -register_grinder_recipe("default:gold_lump","technic:gold_dust 2") -register_grinder_recipe("default:gold_ingot","technic:gold_dust 1") ---register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 1") -- Dust does not exist yet ---register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 1") -- needs check for the mod -register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2") -register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 1") -register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2") -register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 1") -register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2") -register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 1") -register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2") -register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 1") -register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 1") -register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1") -register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2") -register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1") -register_grinder_recipe("technic:coal_dust","dye:black 2") -register_grinder_recipe("default:cactus","dye:green 2") -register_grinder_recipe("default:dry_shrub","dye:brown 2") -register_grinder_recipe("flowers:flower_geranium","dye:blue 2") -register_grinder_recipe("flowers:flower_dandelion_white","dye:white 2") -register_grinder_recipe("flowers:flower_dandelion_yellow","dye:yellow 2") -register_grinder_recipe("flowers:flower_tulip","dye:orange 2") -register_grinder_recipe("flowers:flower_rose","dye:red 2") -register_grinder_recipe("flowers:flower_viola","dye:violet 2") +technic.grinder_recipes ={} + +technic.register_grinder_recipe = function(src, dst) + technic.grinder_recipes[src] = dst + if unified_inventory then + unified_inventory.register_craft( + { + type = "grinding", + output = dst, + items = {src}, + width = 0, + }) + end + end + +-- Receive an ItemStack of result by an ItemStack input +technic.get_grinder_recipe = function(itemstack) + local src_item = itemstack:to_table() + if src_item == nil then + return nil + end + local item_name = src_item["name"] + if technic.grinder_recipes[item_name] then + return ItemStack(technic.grinder_recipes[item_name]) + else + return nil + end + end + + +technic.register_grinder_recipe("default:stone","default:sand") +technic.register_grinder_recipe("default:cobble","default:gravel") +technic.register_grinder_recipe("default:gravel","default:dirt") +technic.register_grinder_recipe("default:desert_stone","default:desert_sand") +technic.register_grinder_recipe("default:iron_lump","technic:iron_dust 2") +technic.register_grinder_recipe("default:steel_ingot","technic:iron_dust 1") +technic.register_grinder_recipe("default:coal_lump","technic:coal_dust 2") +technic.register_grinder_recipe("default:copper_lump","technic:copper_dust 2") +technic.register_grinder_recipe("default:copper_ingot","technic:copper_dust 1") +technic.register_grinder_recipe("default:gold_lump","technic:gold_dust 2") +technic.register_grinder_recipe("default:gold_ingot","technic:gold_dust 1") +--technic.register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 1") -- Dust does not exist yet +--technic.register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 1") -- needs check for the mod +technic.register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2") +technic.register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 1") +technic.register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2") +technic.register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 1") +technic.register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2") +technic.register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 1") +technic.register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2") +technic.register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 1") +technic.register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 1") +technic.register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1") +technic.register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2") +technic.register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1") +technic.register_grinder_recipe("technic:coal_dust","dye:black 2") +technic.register_grinder_recipe("default:cactus","dye:green 2") +technic.register_grinder_recipe("default:dry_shrub","dye:brown 2") +technic.register_grinder_recipe("flowers:flower_geranium","dye:blue 2") +technic.register_grinder_recipe("flowers:flower_dandelion_white","dye:white 2") +technic.register_grinder_recipe("flowers:flower_dandelion_yellow","dye:yellow 2") +technic.register_grinder_recipe("flowers:flower_tulip","dye:orange 2") +technic.register_grinder_recipe("flowers:flower_rose","dye:red 2") +technic.register_grinder_recipe("flowers:flower_viola","dye:violet 2") minetest.register_craftitem( "technic:coal_dust", { - description = "Coal Dust", - inventory_image = "technic_coal_dust.png", - on_place_on_ground = minetest.craftitem_place_item, - }) + description = "Coal Dust", + inventory_image = "technic_coal_dust.png", + on_place_on_ground = minetest.craftitem_place_item, + }) minetest.register_craftitem( "technic:iron_dust", { - description = "Iron Dust", - inventory_image = "technic_iron_dust.png", - on_place_on_ground = minetest.craftitem_place_item, - }) + description = "Iron Dust", + inventory_image = "technic_iron_dust.png", + on_place_on_ground = minetest.craftitem_place_item, + }) minetest.register_craft({ - type = "cooking", - output = "default:steel_ingot", - recipe = "technic:iron_dust", -}) + type = "cooking", + output = "default:steel_ingot", + recipe = "technic:iron_dust", + }) minetest.register_craftitem( "technic:copper_dust", { - description = "Copper Dust", - inventory_image = "technic_copper_dust.png", - on_place_on_ground = minetest.craftitem_place_item, - }) + description = "Copper Dust", + inventory_image = "technic_copper_dust.png", + on_place_on_ground = minetest.craftitem_place_item, + }) minetest.register_craft({ - type = "cooking", - output = "moreores:copper_ingot", - recipe = "technic:copper_dust", -}) + type = "cooking", + output = "moreores:copper_ingot", + recipe = "technic:copper_dust", + }) minetest.register_craftitem( "technic:tin_dust", { - description = "Tin Dust", - inventory_image = "technic_tin_dust.png", - on_place_on_ground = minetest.craftitem_place_item, - }) + description = "Tin Dust", + inventory_image = "technic_tin_dust.png", + on_place_on_ground = minetest.craftitem_place_item, + }) minetest.register_craft({ - type = "cooking", - output = "moreores:tin_ingot", - recipe = "technic:tin_dust", -}) + type = "cooking", + output = "moreores:tin_ingot", + recipe = "technic:tin_dust", + }) minetest.register_craftitem( "technic:silver_dust", { - description = "Silver Dust", - inventory_image = "technic_silver_dust.png", - on_place_on_ground = minetest.craftitem_place_item, - }) + description = "Silver Dust", + inventory_image = "technic_silver_dust.png", + on_place_on_ground = minetest.craftitem_place_item, + }) minetest.register_craft({ - type = "cooking", - output = "moreores:silver_ingot", - recipe = "technic:silver_dust", -}) + type = "cooking", + output = "moreores:silver_ingot", + recipe = "technic:silver_dust", + }) minetest.register_craftitem( "technic:gold_dust", { - description = "Gold Dust", - inventory_image = "technic_gold_dust.png", - on_place_on_ground = minetest.craftitem_place_item, - }) + description = "Gold Dust", + inventory_image = "technic_gold_dust.png", + on_place_on_ground = minetest.craftitem_place_item, + }) minetest.register_craft({ - type = "cooking", - output = "moreores:gold_ingot", - recipe = "technic:gold_dust", -}) + type = "cooking", + output = "moreores:gold_ingot", + recipe = "technic:gold_dust", + }) minetest.register_craftitem( "technic:mithril_dust", { - description = "Mithril Dust", - inventory_image = "technic_mithril_dust.png", - on_place_on_ground = minetest.craftitem_place_item, - }) + description = "Mithril Dust", + inventory_image = "technic_mithril_dust.png", + on_place_on_ground = minetest.craftitem_place_item, + }) minetest.register_craft({ - type = "cooking", - output = "moreores:mithril_ingot", - recipe = "technic:mithril_dust", -}) + type = "cooking", + output = "moreores:mithril_ingot", + recipe = "technic:mithril_dust", + }) minetest.register_craftitem( "technic:chromium_dust", { - description = "Chromium Dust", - inventory_image = "technic_chromium_dust.png", - on_place_on_ground = minetest.craftitem_place_item, - }) + description = "Chromium Dust", + inventory_image = "technic_chromium_dust.png", + on_place_on_ground = minetest.craftitem_place_item, + }) minetest.register_craft({ - type = "cooking", - output = "technic:chromium_ingot", - recipe = "technic:chromium_dust", -}) + type = "cooking", + output = "technic:chromium_ingot", + recipe = "technic:chromium_dust", + }) minetest.register_craftitem( "technic:bronze_dust", { - description = "Bronze Dust", - inventory_image = "technic_bronze_dust.png", - on_place_on_ground = minetest.craftitem_place_item, - }) + description = "Bronze Dust", + inventory_image = "technic_bronze_dust.png", + on_place_on_ground = minetest.craftitem_place_item, + }) minetest.register_craft({ - type = "cooking", - output = "moreores:bronze_ingot", - recipe = "technic:bronze_dust", -}) + type = "cooking", + output = "moreores:bronze_ingot", + recipe = "technic:bronze_dust", + }) minetest.register_craftitem( "technic:brass_dust", { - description = "Brass Dust", - inventory_image = "technic_brass_dust.png", - on_place_on_ground = minetest.craftitem_place_item, - }) + description = "Brass Dust", + inventory_image = "technic_brass_dust.png", + on_place_on_ground = minetest.craftitem_place_item, + }) minetest.register_craft({ - type = "cooking", - output = "technic:brass_ingot", - recipe = "technic:brass_dust", -}) + type = "cooking", + output = "technic:brass_ingot", + recipe = "technic:brass_dust", + }) minetest.register_craftitem( "technic:stainless_steel_dust", { - description = "Stainless Steel Dust", - inventory_image = "technic_stainless_steel_dust.png", - }) + description = "Stainless Steel Dust", + inventory_image = "technic_stainless_steel_dust.png", + }) minetest.register_craft({ - type = "cooking", - output = "technic:stainless_steel_ingot", - recipe = "technic:stainless_steel_dust", -}) + type = "cooking", + output = "technic:stainless_steel_ingot", + recipe = "technic:stainless_steel_dust", + }) minetest.register_craftitem( "technic:zinc_dust", { - description = "Zinc Dust", - inventory_image = "technic_zinc_dust.png", - }) + description = "Zinc Dust", + inventory_image = "technic_zinc_dust.png", + }) minetest.register_craft({ - type = "cooking", - output = "technic:zinc_ingot", - recipe = "technic:zinc_dust", -}) + type = "cooking", + output = "technic:zinc_ingot", + recipe = "technic:zinc_dust", + }) minetest.register_alias("grinder", "technic:grinder") minetest.register_craft({ - output = 'technic:grinder', - recipe = { - {'default:desert_stone', 'default:desert_stone', 'default:desert_stone'}, - {'default:desert_stone', 'default:diamond', 'default:desert_stone'}, - {'default:stone', 'moreores:copper_ingot', 'default:stone'}, - } -}) + output = 'technic:grinder', + recipe = { + {'default:desert_stone', 'default:desert_stone', 'default:desert_stone'}, + {'default:desert_stone', 'default:diamond', 'default:desert_stone'}, + {'default:stone', 'moreores:copper_ingot', 'default:stone'}, + } + }) minetest.register_craftitem("technic:grinder", { - description = "Grinder", - stack_max = 99, -}) - -grinder_formspec = - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "label[0,0;Grinder]".. - "label[1,3;Power level]".. - "list[current_name;src;3,1;1,1;]".. - "list[current_name;dst;5,1;2,2;]".. - "list[current_player;main;0,5;8,4;]" - - -minetest.register_node("technic:grinder", { - description = "Grinder", - tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png", - "technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front.png"}, - paramtype2 = "facedir", - groups = {cracky=2}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=5000; - grind_time=0; - grinded = nil; - src_time = 0; - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "Grinder") - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 5000) - meta:set_string("formspec", grinder_formspec) - meta:set_float("grind_time", 0) - local inv = meta:get_inventory() - inv:set_size("src", 1) - inv:set_size("dst", 4) - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("src") then - return false - end - if not inv:is_empty("dst") then - return false - end - return true + description = "Grinder", + stack_max = 99, + }) + +local grinder_formspec = + "invsize[8,9;]".. + "label[0,0;Grinder]".. + "list[current_name;src;3,1;1,1;]".. + "list[current_name;dst;5,1;2,2;]".. + "list[current_player;main;0,5;8,4;]" + +minetest.register_node( + "technic:grinder", + { + description = "Grinder", + tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png", + "technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front.png"}, + paramtype2 = "facedir", + groups = {cracky=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("infotext", "Grinder") + meta:set_float("technic_power_machine", 1) + meta:set_string("formspec", grinder_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) + inv:set_size("dst", 4) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end end, -}) - -minetest.register_node("technic:grinder_active", { - description = "Grinder", - tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png", - "technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front_active.png"}, - paramtype2 = "facedir", - groups = {cracky=2,not_in_creative_inventory=1}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("src") then - return false - end - if not inv:is_empty("dst") then - return false - end - return true + }) + +minetest.register_node( + "technic:grinder_active", + { + description = "Grinder", + tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png", + "technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front_active.png"}, + paramtype2 = "facedir", + groups = {cracky=2,not_in_creative_inventory=1}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end end, -}) - -minetest.register_abm({ - nodenames = {"technic:grinder","technic:grinder_active"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - - local meta = minetest.env:get_meta(pos) - local charge= meta:get_float("internal_EU_buffer") - local max_charge= meta:get_float("internal_EU_buffer_size") - local grind_cost=200 - - local load = math.floor((charge/max_charge)*100) - meta:set_string("formspec", - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]".. - "label[0,0;Grinder]".. - "label[1,3;Power level]".. - "list[current_name;src;3,1;1,1;]".. - "list[current_name;dst;5,1;2,2;]".. - "list[current_player;main;0,5;8,4;]" - ) - - local inv = meta:get_inventory() - local srclist = inv:get_list("src") - if inv:is_empty("src") then meta:set_float("grinder_on",0) end - - if (meta:get_float("grinder_on") == 1) then - if charge>=grind_cost then - charge=charge-grind_cost; - meta:set_float("internal_EU_buffer",charge) - meta:set_float("src_time", meta:get_float("src_time") + 1) - if meta:get_float("src_time") >= meta:get_float("grind_time") then - -- check if there's room for output in "dst" list - grinded = get_grinded_item (inv:get_stack("src", 1)) - if inv:room_for_item("dst",grinded) then - -- Put result in "dst" list - inv:add_item("dst", grinded) - -- take stuff from "src" list - srcstack = inv:get_stack("src", 1) - srcstack:take_item() - inv:set_stack("src", 1, srcstack) - if inv:is_empty("src") then meta:set_float("grinder_on",0) end - else - print("Grinder inventory full!") - end - meta:set_float("src_time", 0) - end - end - end - if (meta:get_float("grinder_on")==0) then - local grinded=nil - if not inv:is_empty("src") then - grinded = get_grinded_item (inv:get_stack("src", 1)) - if grinded then - meta:set_float("grinder_on",1) - hacky_swap_node(pos,"technic:grinder_active") - meta:set_string("infotext", "Grinder Active") - grind_time=4 - meta:set_float("grind_time",grind_time) - meta:set_float("src_time", 0) - return - end - else - hacky_swap_node(pos,"technic:grinder") - meta:set_string("infotext", "Grinder Inactive") - end - end - end -}) - -function get_grinded_item (items) -new_item =nil -src_item=items:to_table() -item_name=src_item["name"] - -local counter=registered_grinder_recipes_count-1 -for i=1, counter,1 do - if grinder_recipes[i].src_name==item_name then return ItemStack(grinder_recipes[i].dst_name) end -end -return nil -end - -register_LV_machine ("technic:grinder","RE") -register_LV_machine ("technic:grinder_active","RE") + }) + +minetest.register_abm( + { nodenames = {"technic:grinder","technic:grinder_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + -- Run a machine through its states. Takes the same arguments as the ABM action + -- and adds the machine's states and any extra data which is needed by the machine. + -- A machine is characterized by running through a set number of states (usually 2: + -- Idle and active) in some order. A state decides when to move to the next one + -- and the machine only changes state if it is powered correctly. + -- The machine will automatically shut down if disconnected from power in some fashion. + local meta = minetest.env:get_meta(pos) + local eu_input = meta:get_int("LV_EU_input") + local state = meta:get_int("state") + local next_state = state + + -- Machine information + local machine_name = "Grinder" + local machine_node = "technic:grinder" + local machine_state_demand = { 50, 300 } + + -- Setup meta data if it does not exist. state is used as an indicator of this + if state == 0 then + meta:set_int("state", 1) + meta:set_int("LV_EU_demand", machine_state_demand[1]) + meta:set_int("LV_EU_input", 0) + return + end + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "LV") + + -- State machine + if eu_input == 0 then + -- unpowered - go idle + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + next_state = 1 + elseif eu_input == machine_state_demand[state] then + -- Powered - do the state specific actions + + local inv = meta:get_inventory() + local empty = inv:is_empty("src") + + if state == 1 then + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Idle") + + local result = technic.get_grinder_recipe(inv:get_stack("src", 1)) + if not empty and result and inv:room_for_item("dst",result) then + meta:set_int("src_time", 0) + next_state = 2 + end + + elseif state == 2 then + hacky_swap_node(pos, machine_node.."_active") + meta:set_string("infotext", machine_name.." Active") + + if empty then + next_state = 1 + else + meta:set_int("src_time", meta:get_int("src_time") + 1) + if meta:get_int("src_time") == 4 then -- 4 ticks per output + -- check if there's room for output in "dst" list + local result = technic.get_grinder_recipe(inv:get_stack("src", 1)) + + meta:set_int("src_time", 0) + if inv:room_for_item("dst",result) then + -- take stuff from "src" list + srcstack = inv:get_stack("src", 1) + srcstack:take_item() + inv:set_stack("src", 1, srcstack) + -- Put result in "dst" list + inv:add_item("dst", result) + else + -- all full: go idle + next_state = 1 + end + end + end + end + end + -- Change state? + if next_state ~= state then + meta:set_int("LV_EU_demand", machine_state_demand[next_state]) + meta:set_int("state", next_state) + end + end + }) + +technic.register_LV_machine ("technic:grinder","RE") +technic.register_LV_machine ("technic:grinder_active","RE") diff --git a/technic/grinder_gloopores.lua b/technic/grinder_gloopores.lua index 0c58c98..6f603b3 100644 --- a/technic/grinder_gloopores.lua +++ b/technic/grinder_gloopores.lua @@ -1,8 +1,8 @@ -register_grinder_recipe("gloopores:alatro_lump","technic:alatro_dust 2") -register_grinder_recipe("gloopores:kalite_lump","technic:kalite_dust 2") -register_grinder_recipe("gloopores:arol_lump","technic:arol_dust 2") -register_grinder_recipe("gloopores:talinite_lump","technic:talinite_dust 2") -register_grinder_recipe("gloopores:akalin_lump","technic:akalin_dust 2") +technic.register_grinder_recipe("gloopores:alatro_lump","technic:alatro_dust 2") +technic.register_grinder_recipe("gloopores:kalite_lump","technic:kalite_dust 2") +technic.register_grinder_recipe("gloopores:arol_lump","technic:arol_dust 2") +technic.register_grinder_recipe("gloopores:talinite_lump","technic:talinite_dust 2") +technic.register_grinder_recipe("gloopores:akalin_lump","technic:akalin_dust 2")   minetest.register_craftitem("technic:alatro_dust", {         description = "Alatro Dust", diff --git a/technic/init.lua b/technic/init.lua index 6dd7eac..abe0439 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -4,7 +4,13 @@ technic = {} -modpath=minetest.get_modpath("technic") +technic.dprint = function(string) + if technic.DBG == 1 then + print(string) + end + end + +local modpath=minetest.get_modpath("technic") --Read technic config file dofile(modpath.."/config.lua") @@ -14,19 +20,26 @@ dofile(modpath.."/helpers.lua") --items dofile(modpath.."/items.lua") +-- Register functions +dofile(modpath.."/register_machine_and_tool.lua") +dofile(modpath.."/alloy_furnaces_commons.lua") -- Idea: Let the LV, MV, HV version of the furnace support different alloys + +-- Switching station LV,MV,HV +dofile(modpath.."/switching_station.lua") +dofile(modpath.."/supply_converter.lua") + --LV machines dofile(modpath.."/wires.lua") dofile(modpath.."/battery_box.lua") -dofile(modpath.."/alloy_furnaces_commons.lua") dofile(modpath.."/alloy_furnace.lua") dofile(modpath.."/solar_panel.lua") dofile(modpath.."/solar_array_lv.lua") dofile(modpath.."/geothermal.lua") dofile(modpath.."/water_mill.lua") +dofile(modpath.."/generator.lua") dofile(modpath.."/electric_furnace.lua") dofile(modpath.."/tool_workshop.lua") dofile(modpath.."/music_player.lua") -dofile(modpath.."/generator.lua") dofile(modpath.."/grinder.lua") dofile(modpath.."/cnc.lua") dofile(modpath.."/cnc_api.lua") @@ -36,20 +49,18 @@ dofile(modpath.."/cnc_nodes.lua") dofile(modpath.."/wires_mv.lua") dofile(modpath.."/battery_box_mv.lua") dofile(modpath.."/solar_array_mv.lua") -dofile(modpath.."/down_converter_mv.lua") dofile(modpath.."/electric_furnace_mv.lua") dofile(modpath.."/alloy_furnace_mv.lua") -dofile(modpath.."/forcefield.lua") --- These two are a concept study: Supplying appliances with inductive coupled power: --- lighting and associated textures is taken directly from VanessaE's homedecor and made electric. +--dofile(modpath.."/forcefield.lua") +---- The power radiator supplies appliances with inductive coupled power: +---- lighting and associated textures is taken directly from VanessaE's homedecor and made electric. dofile(modpath.."/power_radiator.lua") dofile(modpath.."/lighting.lua") - ---HV machines +-- +----HV machines dofile(modpath.."/wires_hv.lua") dofile(modpath.."/battery_box_hv.lua") dofile(modpath.."/solar_array_hv.lua") -dofile(modpath.."/down_converter_hv.lua") --Tools if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end @@ -59,8 +70,8 @@ dofile(modpath.."/cans.lua") dofile(modpath.."/chainsaw.lua") dofile(modpath.."/tree_tap.lua") dofile(modpath.."/sonic_screwdriver.lua") - --- mesecons and tubes related +-- +---- mesecons and tubes related dofile(modpath.."/injector.lua") dofile(modpath.."/node_breaker.lua") dofile(modpath.."/deployer.lua") @@ -68,24 +79,23 @@ dofile(modpath.."/constructor.lua") dofile(modpath.."/frames.lua") function has_locked_chest_privilege(meta, player) - if player:get_player_name() ~= meta:get_string("owner") then - return false - end - return true + if player:get_player_name() ~= meta:get_string("owner") then + return false + end + return true end +-- Swap nodes out. Return the node name. function hacky_swap_node(pos,name) - local node = minetest.env:get_node(pos) - local meta = minetest.env:get_meta(pos) - local meta0 = meta:to_table() - if node.name == name then - return nil - end - node.name = name - local meta0 = meta:to_table() - minetest.env:set_node(pos,node) - meta = minetest.env:get_meta(pos) - meta:from_table(meta0) - return 1 + local node = minetest.env:get_node(pos) + if node.name ~= name then + local meta = minetest.env:get_meta(pos) + local meta0 = meta:to_table() + node.name = name + minetest.env:set_node(pos,node) + meta = minetest.env:get_meta(pos) + meta:from_table(meta0) + end + return node.name end diff --git a/technic/lighting.lua b/technic/lighting.lua index 5aab4c3..1d4b45f 100644 --- a/technic/lighting.lua +++ b/technic/lighting.lua @@ -48,7 +48,7 @@ end local dirs1 = { 20, 23, 22, 21 } local dirs2 = { 9, 18, 7, 12 } -function technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) +local technic_homedecor_rotate_and_place = function(itemstack, placer, pointed_thing) if not technic_homedecor_node_is_owned(pointed_thing.under, placer) and not technic_homedecor_node_is_owned(pointed_thing.above, placer) then local node = minetest.env:get_node(pointed_thing.under) @@ -128,14 +128,10 @@ minetest.register_node('technic:homedecor_glowlight_half_yellow', { return itemstack end, on_construct = function(pos) - print("Hello") - technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thick)") - print("Hello2") + technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thick)") end, on_punch = function(pos, node, puncher) - print("Punch") - technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_yellow_active") - print("Punch2") + technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_yellow_active") end }) @@ -173,10 +169,10 @@ minetest.register_node('technic:homedecor_glowlight_half_yellow_active', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thick)") + technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thick)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_yellow") + technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_yellow") end }) @@ -213,10 +209,10 @@ minetest.register_node('technic:homedecor_glowlight_quarter_yellow', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thin)") + technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thin)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_yellow_active") + technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_yellow_active") end }) @@ -254,10 +250,10 @@ minetest.register_node('technic:homedecor_glowlight_quarter_yellow_active', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thin)") + technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thin)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_yellow") + technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_yellow") end }) @@ -295,10 +291,10 @@ minetest.register_node('technic:homedecor_glowlight_half_white', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 100, "White Glowlight (thick)") + technic.inductive_on_construct(pos, 100, "White Glowlight (thick)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_white_active") + technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_white_active") end }) @@ -336,10 +332,10 @@ minetest.register_node('technic:homedecor_glowlight_half_white_active', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 100, "White Glowlight (thick)") + technic.inductive_on_construct(pos, 100, "White Glowlight (thick)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_white") + technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_white") end }) @@ -376,10 +372,10 @@ minetest.register_node('technic:homedecor_glowlight_quarter_white', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 100, "White Glowlight (thin)") + technic.inductive_on_construct(pos, 100, "White Glowlight (thin)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_white_active") + technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_white_active") end }) @@ -417,10 +413,10 @@ minetest.register_node('technic:homedecor_glowlight_quarter_white_active', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 100, "White Glowlight (thin)") + technic.inductive_on_construct(pos, 100, "White Glowlight (thin)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_white") + technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_white") end }) @@ -457,10 +453,10 @@ minetest.register_node('technic:homedecor_glowlight_small_cube_yellow', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)") + technic.inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_yellow_active") + technic.inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_yellow_active") end }) @@ -498,10 +494,10 @@ minetest.register_node('technic:homedecor_glowlight_small_cube_yellow_active', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)") + technic.inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_yellow") + technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_yellow") end }) @@ -538,10 +534,10 @@ minetest.register_node('technic:homedecor_glowlight_small_cube_white', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 50, "White Glowlight (small cube)") + technic.inductive_on_construct(pos, 50, "White Glowlight (small cube)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_white_active") + technic.inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_white_active") end }) @@ -579,16 +575,16 @@ minetest.register_node('technic:homedecor_glowlight_small_cube_white_active', { return itemstack end, on_construct = function(pos) - technic_inductive_on_construct(pos, 50, "White Glowlight (small cube)") + technic.inductive_on_construct(pos, 50, "White Glowlight (small cube)") end, on_punch = function(pos, node, puncher) - technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_white") + technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_white") end }) -register_inductive_machine("technic:homedecor_glowlight_half_yellow") -register_inductive_machine("technic:homedecor_glowlight_half_white") -register_inductive_machine("technic:homedecor_glowlight_quarter_yellow") -register_inductive_machine("technic:homedecor_glowlight_quarter_white") -register_inductive_machine("technic:homedecor_glowlight_small_cube_yellow") -register_inductive_machine("technic:homedecor_glowlight_small_cube_white") +technic.register_inductive_machine("technic:homedecor_glowlight_half_yellow") +technic.register_inductive_machine("technic:homedecor_glowlight_half_white") +technic.register_inductive_machine("technic:homedecor_glowlight_quarter_yellow") +technic.register_inductive_machine("technic:homedecor_glowlight_quarter_white") +technic.register_inductive_machine("technic:homedecor_glowlight_small_cube_yellow") +technic.register_inductive_machine("technic:homedecor_glowlight_small_cube_white") diff --git a/technic/mining_drill.lua b/technic/mining_drill.lua index 33a8e5a..4a50f2f 100644 --- a/technic/mining_drill.lua +++ b/technic/mining_drill.lua @@ -1,9 +1,9 @@ -mining_drill_max_charge=60000 -mining_drill_mk2_max_charge=240000 -mining_drill_mk3_max_charge=960000 -mining_drill_power_usage=200 -mining_drill_mk2_power_usage=600 -mining_drill_mk3_power_usage=1800 +local mining_drill_max_charge=60000 +local mining_drill_mk2_max_charge=240000 +local mining_drill_mk3_max_charge=960000 +local mining_drill_power_usage=200 +local mining_drill_mk2_power_usage=600 +local mining_drill_mk3_power_usage=1800 minetest.register_craft({ output = 'technic:mining_drill', @@ -210,7 +210,7 @@ function drill_dig_it4 (pos,player) drill_dig_it0 (pos,player) end -register_power_tool ("technic:mining_drill",mining_drill_max_charge) +technic.register_MV_power_tool ("technic:mining_drill",mining_drill_max_charge) minetest.register_tool("technic:mining_drill", { description = "Mining Drill Mk1", inventory_image = "technic_mining_drill.png", @@ -227,7 +227,7 @@ minetest.register_tool("technic:mining_drill", { charge =charge-mining_drill_power_usage; meta["charge"]=charge item["metadata"]=set_item_meta(meta) - set_RE_wear(item,charge,mining_drill_max_charge) + technic.set_RE_wear(item,charge,mining_drill_max_charge) itemstack:replace(item) end return itemstack @@ -243,10 +243,10 @@ minetest.register_tool("technic:mining_drill_mk2", { return itemstack end, }) -register_power_tool ("technic:mining_drill_mk2",mining_drill_mk2_max_charge) +technic.register_HV_power_tool ("technic:mining_drill_mk2",mining_drill_mk2_max_charge) for i=1,4,1 do -register_power_tool ("technic:mining_drill_mk2_"..i,mining_drill_mk2_max_charge) +technic.register_HV_power_tool ("technic:mining_drill_mk2_"..i,mining_drill_mk2_max_charge) minetest.register_tool("technic:mining_drill_mk2_"..i, { description = "Mining Drill Mk2 in Mode "..i, inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png", @@ -267,10 +267,10 @@ minetest.register_tool("technic:mining_drill_mk3", { return itemstack end, }) -register_power_tool ("technic:mining_drill_mk3",mining_drill_mk3_max_charge) +technic.register_HV_power_tool ("technic:mining_drill_mk3",mining_drill_mk3_max_charge) for i=1,5,1 do -register_power_tool ("technic:mining_drill_mk3_"..i,mining_drill_mk3_max_charge) +technic.register_HV_power_tool ("technic:mining_drill_mk3_"..i,mining_drill_mk3_max_charge) minetest.register_tool("technic:mining_drill_mk3_"..i, { description = "Mining Drill Mk3 in Mode "..i, inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png", @@ -299,7 +299,7 @@ function mining_drill_mk2_handler (itemstack,user,pointed_thing) if charge<0 then charge=0 end meta["charge"]=charge item["metadata"]=set_item_meta(meta) - set_RE_wear(item,charge,mining_drill_mk2_max_charge) + technic.set_RE_wear(item,charge,mining_drill_mk2_max_charge) itemstack:replace(item) end return itemstack @@ -321,7 +321,7 @@ function mining_drill_mk3_handler (itemstack,user,pointed_thing) if charge<0 then charge=0 end meta["charge"]=charge item["metadata"]=set_item_meta(meta) - set_RE_wear(item,charge,mining_drill_mk3_max_charge) + technic.set_RE_wear(item,charge,mining_drill_mk3_max_charge) itemstack:replace(item) end return itemstack diff --git a/technic/mining_laser_mk1.lua b/technic/mining_laser_mk1.lua index 5bafb6c..4dc76f8 100644 --- a/technic/mining_laser_mk1.lua +++ b/technic/mining_laser_mk1.lua @@ -1,5 +1,5 @@ -laser_mk1_max_charge=40000 -register_power_tool ("technic:laser_mk1",laser_mk1_max_charge) +local laser_mk1_max_charge=40000 +technic.register_LV_power_tool ("technic:laser_mk1",laser_mk1_max_charge) local laser_shoot = function(itemstack, player, pointed_thing) local laser_straight_mode=0 @@ -62,8 +62,8 @@ minetest.register_tool("technic:laser_mk1", { charge=meta["charge"] if charge-400>0 then laser_shoot(item, user, pointed_thing) - charge =charge-400; - set_RE_wear(item,charge,laser_mk1_max_charge) + charge = charge-400; + technic.set_RE_wear(item,charge,laser_mk1_max_charge) meta["charge"]=charge item["metadata"]=set_item_meta(meta) itemstack:replace(item) diff --git a/technic/music_player.lua b/technic/music_player.lua index 81b9a65..e0520ff 100644 --- a/technic/music_player.lua +++ b/technic/music_player.lua @@ -1,3 +1,5 @@ +-- LV Music player. +-- The playe can play music. But it is high ampage! minetest.register_alias("music_player", "technic:music_player") minetest.register_craft({ output = 'technic:music_player', @@ -11,112 +13,144 @@ minetest.register_craft({ minetest.register_craftitem("technic:music_player", { description = "Music Player", stack_max = 99, -}) +}) -music_player_formspec = - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "label[0,0;Music Player]".. - "label[1,3;Power level]".. - "button[5,2;1,1;track1;1]".. - "button[6,2;1,1;track2;2]" - +local music_player_formspec = + "invsize[8,9;]".. + "label[0,0;Music Player]".. + "button[4,1;1,1;track1;1]".. + "button[5,1;1,1;track2;2]".. + "button[6,1;1,1;track3;3]".. + "button[4,2;1,1;track4;4]".. + "button[5,2;1,1;track5;5]".. + "button[6,2;1,1;track6;6]".. + "button[4,3;1,1;track7;7]".. + "button[5,3;1,1;track8;8]".. + "button[6,3;1,1;track9;9]".. + "button[4,4;1,2;play;Play]".. + "button[6,4;1,2;stop;Stop]".. + "label[4,0;Current track --]" -minetest.register_node("technic:music_player", { - description = "Music Player", - tiles = {"technic_music_player_top.png", "technic_machine_bottom.png", "technic_music_player_side.png", - "technic_music_player_side.png", "technic_music_player_side.png", "technic_music_player_side.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - sounds = default.node_sound_wood_defaults(), - technic_power_machine=1, - internal_EU_buffer=0, - internal_EU_buffer_size=5000, - music_player_on=0, - music_playing =0, - music_handle = 0, - music_player_current_track =1, - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "Music Player") - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 1) - meta:set_float("internal_EU_buffer_size", 5000) - meta:set_string("formspec", music_player_formspec) - meta:set_float("music_player_on", 0) - meta:set_float("music_player_current_track", 1) - end, +minetest.register_node( + "technic:music_player", + { + description = "Music Player", + tiles = {"technic_music_player_top.png", "technic_machine_bottom.png", "technic_music_player_side.png", + "technic_music_player_side.png", "technic_music_player_side.png", "technic_music_player_side.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "Music Player") + meta:set_float("technic_power_machine", 1) + meta:set_int("active", 0) -- Is the device on? + meta:set_int("music_player_current_track", 1) + meta:set_string("formspec", music_player_formspec) + end, + on_receive_fields = function(pos, formanme, fields, sender) + local meta = minetest.env:get_meta(pos) + music_handle = meta:get_int("music_handle") + music_player_current_track = meta:get_int("music_player_current_track") + if fields.track1 then music_player_current_track = 1 end + if fields.track2 then music_player_current_track = 2 end + if fields.track3 then music_player_current_track = 3 end + if fields.track4 then music_player_current_track = 4 end + if fields.track5 then music_player_current_track = 5 end + if fields.track6 then music_player_current_track = 6 end + if fields.track7 then music_player_current_track = 7 end + if fields.track8 then music_player_current_track = 8 end + if fields.track9 then music_player_current_track = 9 end + meta:set_int("music_player_current_track",music_player_current_track) + if fields.play and meta:get_int("active") == 0 then + if music_handle then minetest.sound_stop(music_handle) end + music_handle = minetest.sound_play("technic_track"..music_player_current_track, {pos = pos, gain = 1.0,loop = true, max_hear_distance = 72,}) + meta:set_int("active",1) + end + if fields.stop then + meta:set_int("active",0) + if music_handle then minetest.sound_stop(music_handle) end + end + meta:set_int("music_handle",music_handle) + end, + }) - on_receive_fields = function(pos, formanme, fields, sender) - - local meta = minetest.env:get_meta(pos) - player_on=meta:get_float("music_player_on") - music_handle=meta:get_float("music_handle") - music_player_current_track=meta:get_float("music_player_current_track") - if fields.track1 then music_player_current_track=1 end - if fields.track2 then music_player_current_track=2 end - if fields.track3 then music_player_current_track=3 end - if fields.track4 then music_player_current_track=4 end - if fields.track5 then music_player_current_track=5 end - if fields.track6 then music_player_current_track=6 end - if fields.track7 then music_player_current_track=7 end - if fields.track8 then music_player_current_track=8 end - if fields.track9 then music_player_current_track=9 end - meta:set_float("music_player_current_track",music_player_current_track) - if fields.play and player_on==1 then - if music_handle then minetest.sound_stop(music_handle) end - music_handle=minetest.sound_play("technic_track"..music_player_current_track, {pos = pos, gain = 1.0,loop = true, max_hear_distance = 72,}) - meta:set_float("music_playing",1) - end - if fields.stop then - meta:set_float("music_playing",0) - if music_handle then minetest.sound_stop(music_handle) end - end - meta:set_float("music_handle",music_handle) - end, -}) +minetest.register_abm( + { nodenames = {"technic:music_player"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local eu_input = meta:get_int("LV_EU_input") + local state = meta:get_int("state") + local next_state = state + + -- Machine information + local machine_name = "Music Player" + local machine_node = "technic:music_player" + local machine_state_demand = { 10, 150 } + + local music_handle = meta:get_int("music_handle") + + -- Setup meta data if it does not exist. state is used as an indicator of this + if state == 0 then + meta:set_int("state", 1) + meta:set_int("LV_EU_demand", machine_state_demand[1]) + meta:set_int("LV_EU_input", 0) + return + end + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "LV") + + -- State machine + if eu_input == 0 then + -- unpowered - go idle + -- hacky_swap_node(pos, machine_node) -- if someday two nodes for this + meta:set_string("infotext", machine_name.." Unpowered") + next_state = 1 + elseif eu_input == machine_state_demand[state] then + -- Powered - do the state specific actions + if state == 1 then + -- hacky_swap_node(pos, machine_node) -- if someday two nodes for this + meta:set_string("infotext", machine_name.." Idle") + + if meta:get_int("active") == 1 then + next_state = 2 + end + + elseif state == 2 then + -- hacky_swap_node(pos, machine_node.."_active") -- if someday two nodes for this + meta:set_string("infotext", machine_name.." Active") -minetest.register_abm({ - nodenames = {"technic:music_player"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - local charge= meta:get_float("internal_EU_buffer") - local max_charge= meta:get_float("internal_EU_buffer_size") - player_on=meta:get_float("music_player_on") - music_player_current_track=meta:get_float("music_player_current_track") - local play_cost=80 - - if charge>play_cost then - if meta:get_float("music_playing")==1 then charge=charge-play_cost end - meta:set_float("internal_EU_buffer",charge) - meta:set_float("music_player_on",1) - else - meta:set_float("music_playing",0) - meta:set_float("music_player_on",0) - if music_handle then minetest.sound_stop(music_handle) end - end - local load = math.floor((charge/max_charge)*100) - meta:set_string("formspec", - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]".. - "label[0,0;Music Player]".. - "label[1,3;Power level]".. - "button[4,1;1,1;track1;1]".. - "button[5,1;1,1;track2;2]".. - "button[6,1;1,1;track3;3]".. - "button[4,2;1,1;track4;4]".. - "button[5,2;1,1;track5;5]".. - "button[6,2;1,1;track6;6]".. - "button[4,3;1,1;track7;7]".. - "button[5,3;1,1;track8;8]".. - "button[6,3;1,1;track9;9]".. - "button[4,4;1,2;play;Play]".. - "button[6,4;1,2;stop;Stop]".. - "label[4,0;Current track "..tostring(music_player_current_track).."]" - ) - end -}) + music_player_current_track=meta:get_int("music_player_current_track") + meta:set_string("formspec", + "invsize[8,9;]".. + "label[0,0;Music Player]".. + "button[4,1;1,1;track1;1]".. + "button[5,1;1,1;track2;2]".. + "button[6,1;1,1;track3;3]".. + "button[4,2;1,1;track4;4]".. + "button[5,2;1,1;track5;5]".. + "button[6,2;1,1;track6;6]".. + "button[4,3;1,1;track7;7]".. + "button[5,3;1,1;track8;8]".. + "button[6,3;1,1;track9;9]".. + "button[4,4;1,2;play;Play]".. + "button[6,4;1,2;stop;Stop]".. + "label[4,0;Current track "..tostring(music_player_current_track).."]" + ) + if meta:get_int("active") == 0 then + if music_handle then minetest.sound_stop(music_handle) end + next_state = 1 + end + end + end + -- Change state? + if next_state ~= state then + meta:set_int("LV_EU_demand", machine_state_demand[next_state]) + meta:set_int("state", next_state) + end + end + }) -register_LV_machine ("technic:music_player","RE") +technic.register_LV_machine ("technic:music_player","RE") diff --git a/technic/power_radiator.lua b/technic/power_radiator.lua index 3383d18..383bf87 100644 --- a/technic/power_radiator.lua +++ b/technic/power_radiator.lua @@ -8,38 +8,34 @@ -- Using inductive power transfer is very inefficient so this is -- set to the factor 0.6. +------------------------------------------------------------------ -- API for inductive powered nodes: -- Use the functions below to set the corresponding callbacks -- Also two nodes are needed: The inactive and the active one. The active must be called _active . - +------------------------------------------------------------------ -- Register a new appliance using this function -technic_inductive_nodes = {} -registered_inductive_count=0 - -register_inductive_machine = function(name) - registered_inductive_count=registered_inductive_count+1 - technic_inductive_nodes[registered_inductive_count]=name - registered_inductive_count=registered_inductive_count+1 - technic_inductive_nodes[registered_inductive_count]=name.."_active" - end - +technic.inductive_nodes = {} +technic.register_inductive_machine = function(name) + table.insert(technic.inductive_nodes, name) + table.insert(technic.inductive_nodes, name.."_active") + end -- Appliances: -- has_supply: pos of supply node if the appliance has a power radiator near with sufficient power for the demand else "" -- EU_demand: The power demand of the device. -- EU_charge: Actual use. set to EU_demand if active==1 -- active: set to 1 if the device is on -technic_inductive_on_construct = function(pos, eu_demand, infotext) +technic.inductive_on_construct = function(pos, eu_demand, infotext) local meta = minetest.env:get_meta(pos) meta:set_string("infotext", infotext) meta:set_int("technic_inductive_power_machine", 1) - meta:set_int("EU_demand",eu_demand) -- The power demand of this appliance + meta:set_int("MV_EU_demand",eu_demand) -- The power demand of this appliance meta:set_int("EU_charge",0) -- The actual power draw of this appliance meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators. meta:set_int("active", 0) -- If the appliance can be turned on and off by using it use this. end -technic_inductive_on_punch_off = function(pos, eu_charge, swapnode) +technic.inductive_on_punch_off = function(pos, eu_charge, swapnode) local meta = minetest.env:get_meta(pos) if meta:get_string("has_supply") ~= "" then hacky_swap_node(pos, swapnode) @@ -53,7 +49,7 @@ technic_inductive_on_punch_off = function(pos, eu_charge, swapnode) end end -technic_inductive_on_punch_on = function(pos, eu_charge, swapnode) +technic.inductive_on_punch_on = function(pos, eu_charge, swapnode) local meta = minetest.env:get_meta(pos) hacky_swap_node(pos, swapnode) meta:set_int("active", 0) @@ -65,121 +61,12 @@ technic_inductive_on_punch_on = function(pos, eu_charge, swapnode) --print("<---------->") end ---minetest.register_node( --- "technic:test_induc", { --- description = "Test radiator node", --- drawtype = "nodebox", --- tiles = { --- 'homedecor_glowlight_yellow_tb.png', --- 'homedecor_glowlight_yellow_tb.png', --- 'homedecor_glowlight_thick_yellow_sides.png', --- 'homedecor_glowlight_thick_yellow_sides.png', --- 'homedecor_glowlight_thick_yellow_sides.png', --- 'homedecor_glowlight_thick_yellow_sides.png' --- }, --- ----- tiles = {"technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png", ----- "technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png"}, --- selection_box = { --- type = "fixed", --- fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } --- }, --- node_box = { --- type = "fixed", --- fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } --- }, --- sunlight_propagates = false, --- paramtype = "light", --- paramtype2 = "facedir", --- walkable = true, --- groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, --- on_place = function(itemstack, placer, pointed_thing) --- homedecor_rotate_and_place(itemstack, placer, pointed_thing) --- return itemstack --- end, --- on_construct = function(pos) --- local meta = minetest.env:get_meta(pos) --- meta:set_string("infotext", "Power Radiator Appliance") --- meta:set_int("technic_inductive_power_machine", 1) --- meta:set_int("EU_demand",200) -- The power demand of this appliance --- meta:set_int("EU_charge",0) -- The actual power draw of this appliance --- meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators. --- meta:set_int("active", 0) -- If the appliance can be turned on and off by using it use this. --- end, --- on_punch = function(pos,node,puncher) --- local meta = minetest.env:get_meta(pos) --- if meta:get_string("has_supply") ~= "" then --- hacky_swap_node(pos, "technic:test_induc_active") --- meta:set_int("active", 1) --- meta:set_int("EU_charge",200) --- print("-----------") --- print("Turn on:") --- print("EUcha:"..meta:get_int("EU_charge")) --- print("<----------->") --- end --- end, --- }) --- ---minetest.register_node( --- "technic:test_induc_active", { --- description = "Test radiator node", --- drawtype = "nodebox", --- tiles = { --- 'homedecor_glowlight_yellow_tb.png', --- 'homedecor_glowlight_yellow_tb.png', --- 'homedecor_glowlight_thick_yellow_sides.png', --- 'homedecor_glowlight_thick_yellow_sides.png', --- 'homedecor_glowlight_thick_yellow_sides.png', --- 'homedecor_glowlight_thick_yellow_sides.png' --- }, --- ----- tiles = {"technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", ----- "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png"}, --- selection_box = { --- type = "fixed", --- fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } --- }, --- node_box = { --- type = "fixed", --- fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 } --- }, --- sunlight_propagates = false, --- paramtype = "light", --- paramtype2 = "facedir", --- walkable = true, --- light_source=14, --- groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, --- drop="technic:test_induc", --- on_place = function(itemstack, placer, pointed_thing) --- homedecor_rotate_and_place(itemstack, placer, pointed_thing) --- return itemstack --- end, --- on_construct = function(pos) --- local meta = minetest.env:get_meta(pos) --- meta:set_string("infotext", "Power Radiator Appliance Active") --- meta:set_int("technic_inductive_power_machine", 1) --- meta:set_int("EU_demand",200) -- The power demand of this appliance --- meta:set_int("EU_charge",0) -- The actual power draw of this appliance --- meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators. --- end, --- on_punch = function(pos,node,puncher) --- local meta = minetest.env:get_meta(pos) --- hacky_swap_node(pos, "technic:test_induc") --- meta:set_int("active", 0) --- meta:set_int("EU_charge",0) --- print("-----------") --- print("Turn off:") --- print("EUcha:"..meta:get_int("EU_charge")) --- print("<---------->") --- end, --- }) - local shutdown_inductive_appliances = function(pos) -- The supply radius local rad = 4 -- If the radiator is removed. turn off all appliances in region -- If another radiator is near it will turn on the appliances again - local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic_inductive_nodes) + local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic.inductive_nodes) for _,pos1 in ipairs(positions) do local meta1 = minetest.env:get_meta(pos1) -- If the appliance is belonging to this node @@ -218,8 +105,7 @@ minetest.register_node( on_construct = function(pos) local meta = minetest.env:get_meta(pos) meta:set_int("technic_mv_power_machine", 1) -- MV machine - meta:set_int("internal_EU_buffer",0) -- internal buffer value - meta:set_int("internal_EU_buffer_size",1000) -- Size of buffer + meta:set_int("MV_EU_demand",1) -- Demand on the primary side when idle meta:set_int("connected_EU_demand",0) -- Potential demand of connected appliances meta:set_string("infotext", "Power Radiator") -- meta:set_int("active", 0) @@ -246,34 +132,45 @@ minetest.register_abm( chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) local meta = minetest.env:get_meta(pos) - local my_supply = meta:get_int("internal_EU_buffer") - -- The maximum EU sourcing a single radiator can provide. - local max_charge = 1000 -- == the max EU demand of the radiator - local connected_EU_demand = meta:get_int("connected_EU_demand") - --print("--------------------") - --print("My Supply:"..my_supply) - --print("Connected Demand:"..connected_EU_demand) - if my_supply > 0 then + local eu_input = meta:get_int("MV_EU_input") + local eu_demand = meta:get_int("MV_EU_demand") + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "MV") + + if eu_input == 0 then + -- No power + meta:set_string("infotext", "Power Radiator is unpowered"); +-- meta:set_int("active",1) -- used for setting textures someday maybe + shutdown_inductive_appliances(pos) + connected_EU_demand = 0 + elseif eu_input == eu_demand then + -- Powered and ready + + -- The maximum EU sourcing a single radiator can provide. + local max_charge = 3000 -- == the max EU demand of the radiator + local connected_EU_demand = meta:get_int("connected_EU_demand") + -- Efficiency factor local eff_factor = 0.6 -- The supply radius - local rad = 4 + local rad = 6 local meta1 = nil local pos1 = {} local used_charge = 0 -- Index all nodes within supply range - local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic_inductive_nodes) + local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic.inductive_nodes) for _,pos1 in ipairs(positions) do local meta1 = minetest.env:get_meta(pos1) -- If not supplied see if this node can handle it. if meta1:get_string("has_supply") == "" then -- if demand surpasses the capacity of this node, don't bother adding it. - local eu_demand = meta1:get_int("EU_demand")/eff_factor - if connected_EU_demand+eu_demand <= max_charge and connected_EU_demand+eu_demand <= my_supply then + local app_eu_demand = meta1:get_int("EU_demand")/eff_factor + if connected_EU_demand + app_eu_demand <= max_charge then -- We can power the appliance. Register, and spend power if it is on. - connected_EU_demand = connected_EU_demand+eu_demand + connected_EU_demand = connected_EU_demand + app_eu_demand meta1:set_string("has_supply", pos.x..pos.y..pos.z) used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor) @@ -281,28 +178,28 @@ minetest.register_abm( elseif meta1:get_string("has_supply") == pos.x..pos.y..pos.z then -- The appliance has power from this node. Spend power if it is on. used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor) + print("My Lamp ("..pos.x..","..pos.y..","..pos.z..") Used:"..used_charge) + end + meta:set_string("infotext", "Power Radiator is powered ("..math.floor(used_charge/max_charge*100).."% of maximum power)"); + if used_charge == 0 then + meta:set_int("MV_EU_demand", 1) -- Still idle + else + meta:set_int("MV_EU_demand", used_charge) end - end - --If demand surpasses actual supply turn off everything - we are out of power - if used_charge>my_supply then - meta:set_string("infotext", "Power Radiator is overloaded ("..math.floor(used_charge/my_supply*100).."% of available power)"); --- meta:set_int("active",1) -- used for setting textures someday maybe - shutdown_inductive_appliances(pos) - connected_EU_demand = 0 - else - meta:set_string("infotext", "Power Radiator is powered ("..math.floor(used_charge/my_supply*100).."% of available power)"); - meta:set_int("internal_EU_buffer",my_supply-used_charge) -- meta:set_int("active",1) -- used for setting textures someday maybe end + -- Save state + meta:set_int("connected_EU_demand",connected_EU_demand) else - meta:set_string("infotext", "Power Radiator is unpowered"); --- meta:set_int("active",0) -- used for setting textures someday maybe + -- This is the case where input ~= demand. Overloaded or underpowered! +-- --If demand surpasses actual supply turn off everything - we are out of power +-- if used_charge>eu_input then +-- meta:set_string("infotext", "Power Radiator is overloaded ("..math.floor(used_charge/eu_input*100).."% of available power)"); +---- meta:set_int("active",1) -- used for setting textures someday maybe +-- shutdown_inductive_appliances(pos) +-- connected_EU_demand = 0 end - - -- Save state - meta:set_int("connected_EU_demand",connected_EU_demand) - return end, }) -register_MV_machine ("technic:power_radiator","RE") +technic.register_MV_machine ("technic:power_radiator","RE") diff --git a/technic/register_machine_and_tool.lua b/technic/register_machine_and_tool.lua new file mode 100644 index 0000000..2178224 --- /dev/null +++ b/technic/register_machine_and_tool.lua @@ -0,0 +1,70 @@ +-- This file includes the functions and data structures for registering machines and tools for LV, MV, HV types. +-- We use the technioc namespace for these functions and data to avoid eventual conflict. + +-- register LV machines here +technic.LV_machines = {} +technic.LV_power_tools = {} +technic.register_LV_machine = function(nodename,type) + technic.LV_machines[nodename] = type + end + +technic.unregister_LV_machine = function(nodename,type) + technic.LV_machines[nodename] = nil + end + +technic.register_LV_power_tool = function(craftitem,max_charge) + technic.LV_power_tools[craftitem] = max_charge + end + +-- register MV machines here +technic.MV_machines = {} +technic.MV_power_tools = {} +technic.register_MV_machine = function(nodename,type) + technic.MV_machines[nodename] = type + end + +technic.unregister_MV_machine = function(nodename) + technic.MV_machines[nodename] = nil + end + +technic.register_MV_power_tool = function(craftitem,max_charge) + technic.MV_power_tools[craftitem] = max_charge + end + +-- register HV machines here +technic.HV_machines = {} +technic.HV_power_tools = {} +technic.register_HV_machine = function(nodename,type) + technic.HV_machines[nodename] = type + end + +technic.unregister_HV_machine = function(nodename) + technic.HV_machines[nodename] = nil + end + +technic.register_HV_power_tool = function(craftitem,max_charge) + technic.HV_power_tools[craftitem] = max_charge + end + + +-- Utility functions. Not sure exactly what they do.. water.lua uses the two first. +function technic.get_RE_item_load (load1,max_load) + if load1==0 then load1=65535 end + local temp = 65536-load1 + temp= temp/65535*max_load + return math.floor(temp + 0.5) +end + +function technic.set_RE_item_load (load1,max_load) + if load1 == 0 then return 65535 end + local temp=load1/max_load*65535 + temp=65536-temp + return math.floor(temp) +end + +-- Wear down a tool depending on the remaining charge. +function technic.set_RE_wear (item_stack,load,max_load) + local temp=65536-math.floor(load/max_load*65535) + item_stack["wear"]=tostring(temp) + return item_stack +end diff --git a/technic/solar_array_hv.lua b/technic/solar_array_hv.lua index e159248..a2fb516 100644 --- a/technic/solar_array_hv.lua +++ b/technic/solar_array_hv.lua @@ -10,9 +10,6 @@ minetest.register_node("technic:solar_array_hv", { sounds = default.node_sound_wood_defaults(), description="HV Solar Array", active = false, - technic_hv_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=3000; drawtype = "nodebox", paramtype = "light", is_ground_content = true, @@ -27,29 +24,25 @@ minetest.register_node("technic:solar_array_hv", { on_construct = function(pos) local meta = minetest.env:get_meta(pos) meta:set_float("technic_hv_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 3000) - + meta:set_int("HV_EU_supply", 0) meta:set_string("infotext", "HV Solar Array") - meta:set_float("active", false) end, }) -minetest.register_craft({ - output = 'technic:solar_array_hv 1', - recipe = { - {'technic:solar_array_mv', 'technic:solar_array_mv','technic:solar_array_mv'}, - {'technic:solar_array_mv', 'technic:hv_transformer','technic:solar_array_mv'}, - {'default:steel_ingot', 'technic:hv_cable', 'default:steel_ingot'}, - - } -}) +minetest.register_craft( + {output = 'technic:solar_array_hv 1', + recipe = { + {'technic:solar_array_mv', 'technic:solar_array_mv','technic:solar_array_mv'}, + {'technic:solar_array_mv', 'technic:hv_transformer','technic:solar_array_mv'}, + {'default:steel_ingot', 'technic:hv_cable', 'default:steel_ingot'}, + } + }) minetest.register_abm( - {nodenames = {"technic:solar_array_hv"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) + {nodenames = {"technic:solar_array_hv"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) -- The action here is to make the solar array produce power -- Power is dependent on the light level and the height above ground -- 130m and above is optimal as it would be above cloud level. @@ -62,7 +55,7 @@ minetest.register_abm( pos1.y=pos.y+1 pos1.x=pos.x pos1.z=pos.z - + local light = minetest.env:get_node_light(pos1, nil) local time_of_day = minetest.env:get_timeofday() local meta = minetest.env:get_meta(pos) @@ -70,24 +63,16 @@ minetest.register_abm( -- turn on array only during day time and if sufficient light -- I know this is counter intuitive when cheating by using other light sources. if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then - local internal_EU_buffer = meta:get_float("internal_EU_buffer") - local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size") - local charge_to_give = math.floor(light*(light*9.6+pos1.y/130*48)) - if charge_to_give<0 then charge_to_give=0 end - if charge_to_give>2880 then charge_to_give=2880 end - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)") - meta:set_float("active",1) - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta:set_float("internal_EU_buffer",internal_EU_buffer) - + local charge_to_give = math.floor(light*(light*9.6+pos1.y/130*48)) + if charge_to_give<0 then charge_to_give=0 end + if charge_to_give>160 then charge_to_give=160 end + meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)") + meta:set_int("HV_EU_supply", charge_to_give) else - meta:set_string("infotext", "Solar Array is inactive"); - meta:set_float("active",0) + meta:set_string("infotext", "Solar Array is inactive"); + meta:set_int("HV_EU_supply", 0) end - end, -}) + end, + }) -register_HV_machine ("technic:solar_array_hv","PR") +technic.register_HV_machine ("technic:solar_array_hv","PR") diff --git a/technic/solar_array_lv.lua b/technic/solar_array_lv.lua index f657814..ecc55d9 100644 --- a/technic/solar_array_lv.lua +++ b/technic/solar_array_lv.lua @@ -10,10 +10,6 @@ minetest.register_node("technic:solar_array_lv", { groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, sounds = default.node_sound_wood_defaults(), description="LV Solar Array", - active = false, - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=1000; drawtype = "nodebox", paramtype = "light", is_ground_content = true, @@ -27,68 +23,56 @@ minetest.register_node("technic:solar_array_lv", { }, on_construct = function(pos) local meta = minetest.env:get_meta(pos) - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 1000) - + meta:set_int("technic_power_machine", 1) + meta:set_int("LV_EU_supply", 0) meta:set_string("infotext", "LV Solar Array") - meta:set_float("active", false) end, }) -minetest.register_craft({ - output = 'technic:solar_array_lv 1', - recipe = { - {'technic:solar_panel', 'technic:solar_panel', 'technic:solar_panel'}, - {'technic:solar_panel', 'technic:lv_transformer', 'technic:solar_panel'}, - {'default:steel_ingot', 'technic:lv_cable', 'default:steel_ingot'}, - - } -}) +minetest.register_craft( + {output = 'technic:solar_array_lv 1', + recipe = { + {'technic:solar_panel', 'technic:solar_panel', 'technic:solar_panel'}, + {'technic:solar_panel', 'technic:lv_transformer', 'technic:solar_panel'}, + {'default:steel_ingot', 'technic:lv_cable', 'default:steel_ingot'}, + } + }) minetest.register_abm( - {nodenames = {"technic:solar_array_lv"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) + {nodenames = {"technic:solar_array_lv"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) -- The action here is to make the solar array produce power -- Power is dependent on the light level and the height above ground -- 130m and above is optimal as it would be above cloud level. - -- Height gives 1/4 of the effect, light 3/4. Max. effect is 160EU for the array. - -- There are many ways to cheat by using other light sources like lamps. - -- As there is no way to determine if light is sunlight that is just a shame. - -- To take care of some of it solar arrays do not work outside daylight hours or if - -- built below -10m + -- Height gives 1/4 of the effect, light 3/4. Max. effect is 160EU for the array. + -- There are many ways to cheat by using other light sources like lamps. + -- As there is no way to determine if light is sunlight that is just a shame. + -- To take care of some of it solar arrays do not work outside daylight hours or if + -- built below -10m local pos1={} pos1.y=pos.y+1 pos1.x=pos.x pos1.z=pos.z - + local light = minetest.env:get_node_light(pos1, nil) local time_of_day = minetest.env:get_timeofday() local meta = minetest.env:get_meta(pos) if light == nil then light = 0 end -- turn on array only during day time and if sufficient light - -- I know this is counter intuitive when cheating by using other light sources. + -- I know this is counter intuitive when cheating by using other light sources. if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then - local internal_EU_buffer = meta:get_float("internal_EU_buffer") - local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size") - local charge_to_give = math.floor(light*(light*0.5333+pos1.y/130*2.6667)) - if charge_to_give<0 then charge_to_give=0 end - if charge_to_give>160 then charge_to_give=160 end - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)") - meta:set_float("active",1) - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta:set_float("internal_EU_buffer",internal_EU_buffer) - + local charge_to_give = math.floor(light*(light*0.5333+pos1.y/130*2.6667)) + if charge_to_give<0 then charge_to_give=0 end + if charge_to_give>160 then charge_to_give=160 end + meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)") + meta:set_int("LV_EU_supply", charge_to_give) else - meta:set_string("infotext", "Solar Array is inactive"); - meta:set_float("active",0) + meta:set_string("infotext", "Solar Array is inactive"); + meta:set_int("LV_EU_supply", 0) end - end, -}) + end, + }) -register_LV_machine ("technic:solar_array_lv","PR") +technic.register_LV_machine ("technic:solar_array_lv","PR") diff --git a/technic/solar_array_mv.lua b/technic/solar_array_mv.lua index abcc027..3eba790 100644 --- a/technic/solar_array_mv.lua +++ b/technic/solar_array_mv.lua @@ -11,9 +11,6 @@ minetest.register_node("technic:solar_array_mv", { sounds = default.node_sound_wood_defaults(), description="MV Solar Array", active = false, - technic_mv_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=1000; drawtype = "nodebox", paramtype = "light", is_ground_content = true, @@ -28,68 +25,57 @@ minetest.register_node("technic:solar_array_mv", { on_construct = function(pos) local meta = minetest.env:get_meta(pos) meta:set_float("technic_mv_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 1000) - + meta:set_int("MV_EU_supply", 0) meta:set_string("infotext", "MV Solar Array") - meta:set_float("active", false) end, }) -minetest.register_craft({ - output = 'technic:solar_array_mv 1', - recipe = { - {'technic:solar_array_lv', 'technic:solar_array_lv','technic:solar_array_lv'}, - {'technic:solar_array_lv', 'technic:mv_transformer','technic:solar_array_lv'}, - {'default:steel_ingot', 'technic:mv_cable', 'default:steel_ingot'}, - - } +minetest.register_craft( + { + output = 'technic:solar_array_mv 1', + recipe = { + {'technic:solar_array_lv', 'technic:solar_array_lv','technic:solar_array_lv'}, + {'technic:solar_array_lv', 'technic:mv_transformer','technic:solar_array_lv'}, + {'default:steel_ingot', 'technic:mv_cable', 'default:steel_ingot'}, + } }) minetest.register_abm( - {nodenames = {"technic:solar_array_mv"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) + {nodenames = {"technic:solar_array_mv"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) -- The action here is to make the solar array produce power -- Power is dependent on the light level and the height above ground -- 130m and above is optimal as it would be above cloud level. - -- Height gives 1/4 of the effect, light 3/4. Max. effect is 720EU for the array. - -- There are many ways to cheat by using other light sources like lamps. - -- As there is no way to determine if light is sunlight that is just a shame. - -- To take care of some of it solar panels do not work outside daylight hours or if - -- built below -10m + -- Height gives 1/4 of the effect, light 3/4. Max. effect is 720EU for the array. + -- There are many ways to cheat by using other light sources like lamps. + -- As there is no way to determine if light is sunlight that is just a shame. + -- To take care of some of it solar panels do not work outside daylight hours or if + -- built below -10m local pos1={} pos1.y=pos.y+1 pos1.x=pos.x pos1.z=pos.z - + local light = minetest.env:get_node_light(pos1, nil) local time_of_day = minetest.env:get_timeofday() local meta = minetest.env:get_meta(pos) if light == nil then light = 0 end -- turn on array only during day time and if sufficient light - -- I know this is counter intuitive when cheating by using other light sources. + -- I know this is counter intuitive when cheating by using other light sources. if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then - local internal_EU_buffer = meta:get_float("internal_EU_buffer") - local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size") - local charge_to_give = math.floor(light*(light*2.4+pos1.y/130*12)) - if charge_to_give<0 then charge_to_give=0 end - if charge_to_give>720 then charge_to_give=720 end - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)") - meta:set_float("active",1) - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta:set_float("internal_EU_buffer",internal_EU_buffer) - -- Idea: How about letting solar panels provide power without battery boxes? - -- This could provide an even distribution to all receivers. + local charge_to_give = math.floor(light*(light*2.4+pos1.y/130*12)) + if charge_to_give<0 then charge_to_give=0 end + if charge_to_give>160 then charge_to_give=160 end + meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)") + -- meta:set_float("active",1) + meta:set_int("MV_EU_supply", charge_to_give) else - meta:set_string("infotext", "Solar Array is inactive"); - meta:set_float("active",0) + meta:set_string("infotext", "Solar Array is inactive"); + meta:set_int("MV_EU_supply", 0) end - end, -}) + end, + }) -register_MV_machine ("technic:solar_array_mv","PR") +technic.register_MV_machine ("technic:solar_array_mv","PR") diff --git a/technic/solar_panel.lua b/technic/solar_panel.lua index 5b53f5f..96ee744 100644 --- a/technic/solar_panel.lua +++ b/technic/solar_panel.lua @@ -8,9 +8,6 @@ minetest.register_node("technic:solar_panel", { sounds = default.node_sound_wood_defaults(), description="Solar Panel", active = false, - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=160; drawtype = "nodebox", paramtype = "light", is_ground_content = true, @@ -24,12 +21,9 @@ minetest.register_node("technic:solar_panel", { }, on_construct = function(pos) local meta = minetest.env:get_meta(pos) - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 160) - - meta:set_string("infotext", "Solar Panel") - meta:set_float("active", false) + meta:set_int("technic_power_machine", 1) + meta:set_int("LV_EU_supply", 0) + meta:set_string("infotext", "LV Solar Panel") end, }) @@ -68,24 +62,16 @@ minetest.register_abm( -- turn on panel only during day time and if sufficient light -- I know this is counter intuitive when cheating by using other light sources underground. if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then - local internal_EU_buffer=meta:get_float("internal_EU_buffer") - local internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size") local charge_to_give=math.floor(light*(light*0.0867+pos1.y/130*0.4333)) if charge_to_give<0 then charge_to_give=0 end if charge_to_give>26 then charge_to_give=26 end - if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end meta:set_string("infotext", "Solar Panel is active ("..charge_to_give.."EU)") - meta:set_float("active",1) - internal_EU_buffer=internal_EU_buffer+charge_to_give - meta:set_float("internal_EU_buffer",internal_EU_buffer) - + meta:set_int("LV_EU_supply", charge_to_give) else meta:set_string("infotext", "Solar Panel is inactive"); - meta:set_float("active",0) + meta:set_int("LV_EU_supply", 0) end end, }) -register_LV_machine ("technic:solar_panel","PR") +technic.register_LV_machine ("technic:solar_panel","PR") diff --git a/technic/sonic_screwdriver.lua b/technic/sonic_screwdriver.lua index 97ec446..1453862 100644 --- a/technic/sonic_screwdriver.lua +++ b/technic/sonic_screwdriver.lua @@ -1,5 +1,5 @@ -sonic_screwdriver_max_charge=15000 -register_power_tool ("technic:sonic_screwdriver",sonic_screwdriver_max_charge) +local sonic_screwdriver_max_charge=15000 +technic.register_HV_power_tool ("technic:sonic_screwdriver",sonic_screwdriver_max_charge) minetest.register_tool("technic:sonic_screwdriver", { description = "Sonic Screwdriver", diff --git a/technic/supply_converter.lua b/technic/supply_converter.lua new file mode 100644 index 0000000..5e04d42 --- /dev/null +++ b/technic/supply_converter.lua @@ -0,0 +1,223 @@ +-- The supply converter is a generic device which can convert from +-- LV to MV and back, and HV to MV and back. +-- The machine will not convert from HV directly to LV. +-- The machine is configured by the wiring below and above it. +-- It is prepared for an upgrade slot if this is to be implemented later. +-- +-- The conversion factor is a constant and the conversion is a lossy operation. +-- +-- It works like this: +-- The top side is setup as the "RE" side, the bottom as the "PR" side. +-- Once the RE side is powered it will deliver power to the other side. +-- Unused power is wasted just like any other producer! +-- +minetest.register_node( + "technic:supply_converter", { + description = "Supply Converter", + tiles = {"technic_mv_down_converter_top.png", "technic_mv_down_converter_bottom.png", "technic_mv_down_converter_side.png", + "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + drawtype = "nodebox", + paramtype = "light", + is_ground_content = true, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_float("technic_hv_power_machine", 1) + meta:set_float("technic_mv_power_machine", 1) + meta:set_float("technic_power_machine", 1) + meta:set_string("infotext", "Supply Converter") + meta:set_float("active", false) + end, + }) + +minetest.register_craft({ + output = 'technic:supply_converter 1', + recipe = { + {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot','technic:stainless_steel_ingot'}, + {'technic:mv_transformer', 'technic:mv_cable', 'technic:lv_transformer'}, + {'technic:mv_cable', 'technic:rubber', 'technic:lv_cable'}, + } +}) + +minetest.register_abm( + { nodenames = {"technic:supply_converter"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + -- Conversion factors (a picture of V*A - loss) Asymmetric. + local lv_mv_factor = 5 -- division (higher is less efficient) + local mv_lv_factor = 4 -- multiplication (higher is more efficient) + local mv_hv_factor = 5 -- division + local hv_mv_factor = 4 -- multiplication + local max_lv_demand = 2000 -- The increment size pwer supply tier. Determines how many are needed + local max_mv_demand = 2000 -- -""- + local max_hv_demand = 2000 -- -""- + + -- Machine information + local machine_name = "Supply Converter" + local meta = minetest.env:get_meta(pos) + local upgrade = "" -- Replace with expansion slot later?? + + -- High voltage on top, low at bottom regardless of converter direction + local pos_up = {x=pos.x, y=pos.y+1, z=pos.z} + local pos_down = {x=pos.x, y=pos.y-1, z=pos.z} + local meta_up = minetest.env:get_meta(pos_up) + local meta_down = minetest.env:get_meta(pos_down) + local convert_MV_LV = 0 + local convert_LV_MV = 0 + local convert_MV_HV = 0 + local convert_HV_MV = 0 + -- check cabling + if meta_up:get_float("mv_cablelike") == 1 and meta_down:get_float("cablelike") == 1 then + convert_MV_LV = 1 + upgrade = "MV-LV step down" + end + if meta_up:get_float("cablelike") == 1 and meta_down:get_float("mv_cablelike") == 1 then + convert_LV_MV = 1 + upgrade = "LV-MV step up" + end + if meta_up:get_float("mv_cablelike") == 1 and meta_down:get_float("hv_cablelike") == 1 then + convert_MV_HV = 1 + upgrade = "MV-HV step up" + end + if meta_up:get_float("hv_cablelike") == 1 and meta_down:get_float("mv_cablelike") == 1 then + convert_HV_MV = 1 + upgrade = "HV-MV step down" + end + --print("Cabling:"..convert_MV_LV.."|"..convert_LV_MV.."|"..convert_HV_MV.."|"..convert_MV_HV) + + if convert_MV_LV == 0 and convert_LV_MV == 0 and convert_HV_MV == 0 and convert_MV_HV == 0 then + meta:set_string("infotext", machine_name.." has bad cabling") + return + end + + -- The node is programmed with an upgrade slot + -- containing a MV-LV step down, LV-MV step up, HV-MV step down or MV-HV step up unit + + if upgrade == "" then + meta:set_string("infotext", machine_name.." has an empty converter slot"); + technic.unregister_LV_machine("technic:supply_converter") + technic.unregister_MV_machine("technic:supply_converter") + technic.unregister_HV_machine("technic:supply_converter") + meta:set_int("LV_EU_demand", 0) + meta:set_int("LV_EU_supply", 0) + meta:set_int("LV_EU_input", 0) + meta:set_int("MV_EU_demand", 0) + meta:set_int("MV_EU_supply", 0) + meta:set_int("MV_EU_input", 0) + meta:set_int("HV_EU_demand", 0) + meta:set_int("HV_EU_supply", 0) + meta:set_int("HV_EU_input", 0) + return + end + + -- State machine + if upgrade == "MV-LV step down" and convert_MV_LV then + -- Register machine type + technic.register_LV_machine("technic:supply_converter","PR") + technic.register_MV_machine("technic:supply_converter","RE") + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "MV") + + local eu_input = meta:get_int("MV_EU_input") + if eu_input == 0 then + -- Unpowered - go idle + --hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + meta:set_int("LV_EU_supply", 0) + meta:set_int("MV_EU_supply", 0) + + meta:set_int("LV_EU_demand", 0) + meta:set_int("MV_EU_demand", max_mv_demand) + else + -- MV side has got power to spare + meta:set_string("infotext", machine_name.." is active (MV:"..max_mv_demand.."->LV:"..eu_input*mv_lv_factor..")"); + meta:set_int("LV_EU_supply", eu_input*mv_lv_factor) + end + --------------------------------------------------- + elseif upgrade == "LV-MV step up" and convert_LV_MV then + -- Register machine type + technic.register_LV_machine("technic:supply_converter","RE") + technic.register_MV_machine("technic:supply_converter","PR") + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "LV") + + local eu_input = meta:get_int("LV_EU_input") + if eu_input == 0 then + -- Unpowered - go idle + --hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + meta:set_int("LV_EU_supply", 0) + meta:set_int("MV_EU_supply", 0) + + meta:set_int("LV_EU_demand", max_lv_demand) + meta:set_int("MV_EU_demand", 0) + else + -- LV side has got power to spare + meta:set_string("infotext", machine_name.." is active (LV:"..max_lv_demand.."->MV:"..eu_input/lv_mv_factor..")"); + meta:set_int("MV_EU_supply", eu_input/lv_mv_factor) + end + --------------------------------------------------- + + elseif upgrade == "HV-MV step down" and convert_HV_MV then + -- Register machine type + technic.register_MV_machine("technic:supply_converter","PR") + technic.register_HV_machine("technic:supply_converter","RE") + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "HV") + + local eu_input = meta:get_int("HV_EU_input") + if eu_input == 0 then + -- Unpowered - go idle + --hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + meta:set_int("MV_EU_supply", 0) + meta:set_int("HV_EU_supply", 0) + + meta:set_int("MV_EU_demand", 0) + meta:set_int("HV_EU_demand", max_hv_demand) + else + -- HV side has got power to spare + meta:set_string("infotext", machine_name.." is active (HV:"..max_hv_demand.."->MV:"..eu_input*hv_mv_factor..")"); + meta:set_int("MV_EU_supply", eu_input*hv_mv_factor) + end + --------------------------------------------------- + elseif upgrade == "MV-HV step up" and convert_MV_HV then + -- Register machine type + technic.register_MV_machine("technic:supply_converter","RE") + technic.register_HV_machine("technic:supply_converter","PR") + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "MV") + + local eu_input = meta:get_int("MV_EU_input") + if eu_input == 0 then + -- Unpowered - go idle + --hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + meta:set_int("MV_EU_supply", 0) + meta:set_int("HV_EU_supply", 0) + + meta:set_int("MV_EU_demand", max_mv_demand) + meta:set_int("HV_EU_demand", 0) + else + -- MV side has got power to spare + meta:set_string("infotext", machine_name.." is active (MV:"..max_mv_demand.."->HV:"..eu_input/mv_hv_factor..")"); + meta:set_int("HV_EU_supply", eu_input/mv_hv_factor) + end + --------------------------------------------------- + end + end, +}) diff --git a/technic/switching_station.lua b/technic/switching_station.lua new file mode 100644 index 0000000..7919d5e --- /dev/null +++ b/technic/switching_station.lua @@ -0,0 +1,352 @@ +-- SWITCHING STATION +-- The switching station is the center of all power distribution on an electric network. +-- The station will collect all produced power from producers (PR) and batteries (BA) +-- and distribute it to receivers (RE) and depleted batteries (BA). +-- +-- It works like this: +-- All PR,BA,RE nodes are indexed and tagged with the switching station. +-- The tagging is to allow more stations to be built without allowing a cheat +-- with duplicating power. +-- All the RE nodes are queried for their current EU demand. Those which are off +-- would require no or a small standby EU demand, while those which are on would +-- require more. +-- If the total demand is less than the available power they are all updated with the +-- demand number. +-- If any surplus exists from the PR nodes the batteries will be charged evenly with this. +-- If the total demand requires draw on the batteries they will be discharged evenly. +-- +-- If the total demand is more than the available power all RE nodes will be shut down. +-- We have a brown-out situation. +-- +-- Hence all the power distribution logic resides in this single node. +-- +-- Nodes connected to the network will have one or more of these parameters as meta data: +-- _EU_supply : Exists for PR and BA node types. This is the EU value supplied by the node. Output +-- _EU_demand : Exists for RE and BA node types. This is the EU value the node requires to run. Output +-- _EU_input : Exists for RE and BA node types. This is the actual EU value the network can give the node. Input +-- +-- The reason the LV|MV|HV type is prepended toe meta data is because some machine could require several supplies to work. +-- This way the supplies are separated per network. +technic.DBG = 1 +local dprint = technic.dprint + +minetest.register_craft( + { + output = 'technic:switching_station 1', + recipe = { + {'technic:lv_transformer', 'technic:mv_transformer', 'technic:hv_transformer'}, + {'technic:lv_transformer', 'technic:mv_transformer', 'technic:hv_transformer'}, + {'technic:lv_cable', 'technic:mv_cable', 'technic:hv_cable'}, + } + }) + +minetest.register_node( + "technic:switching_station", + {description = "Switching Station", + tiles = {"technic_mv_down_converter_top.png", "technic_mv_down_converter_bottom.png", "technic_mv_down_converter_side.png", + "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + drawtype = "nodebox", + paramtype = "light", + is_ground_content = true, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "Switching Station") +-- minetest.chat_send_player(puncher:get_player_name(), "Switching station constructed. Punch the station to shut down the network."); +-- meta:set_int("active", 1) + end, +-- on_punch = function(pos, node, puncher) +-- local meta = minetest.env:get_meta(pos) +-- local active = meta:get_int("active") +-- if active == 1 then +-- meta:set_int("active", 0) +-- minetest.chat_send_player(puncher:get_player_name(), "Electrical network shut down. Punch again to turn it on."); +-- else +-- meta:set_int("active", 1) +-- minetest.chat_send_player(puncher:get_player_name(), "Electrical network turned on. Punch again to shut it down."); +-- end +-- end + }) + +-------------------------------------------------- +-- Functions to help the machines on the electrical network +-------------------------------------------------- +-- This one provides a timeout for a node in case it was disconnected from the network +-- A node must be touched by the station continuously in order to function +technic.switching_station_timeout_count = function(pos, machine_tier) + local meta = minetest.env:get_meta(pos) + timeout = meta:get_int(machine_tier.."_EU_timeout") + --print("Counting timeout "..timeout) + if timeout == 0 then + --print("OFF") + meta:set_int(machine_tier.."_EU_input", 0) + else + --print("ON") + meta:set_int(machine_tier.."_EU_timeout", timeout-1) + end + end + +-------------------------------------------------- +-- Functions to traverse the electrical network +-------------------------------------------------- + +-- Add a wire node to the LV/MV/HV network +local add_new_cable_node = function(nodes,pos) + local i = 1 + repeat + if nodes[i]==nil then break end + if pos.x==nodes[i].x and pos.y==nodes[i].y and pos.z==nodes[i].z then return false end + i=i+1 + until false + nodes[i] = {x=pos.x, y=pos.y, z=pos.z, visited=1} -- copy position + return true + end + +-- Generic function to add found connected nodes to the right classification array +local check_node_subp = function(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos,machines,cablename) + local meta = minetest.env:get_meta(pos) + local name = minetest.env:get_node(pos).name + if meta:get_float(cablename)==1 then + add_new_cable_node(all_nodes,pos) + elseif machines[name] then + --dprint(name.." is a "..machines[name]) + if machines[name] == "PR" then + add_new_cable_node(PR_nodes,pos) + elseif machines[name] == "RE" then + add_new_cable_node(RE_nodes,pos) + elseif machines[name] == "BA" then + add_new_cable_node(BA_nodes,pos) + end + if cablename == "cablelike" then + meta:set_int("LV_EU_timeout", 2) -- Touch node + elseif cablename == "mv_cablelike" then + meta:set_int("MV_EU_timeout", 2) -- Touch node + elseif cablename == "hv_cablelike" then + meta:set_int("HV_EU_timeout", 2) -- Touch node + end + end + end + +-- Traverse a network given a list of machines and a cable type name +local traverse_network = function(PR_nodes,RE_nodes,BA_nodes,all_nodes, i, machines, cablename) + local pos = {x=all_nodes[i].x, y=all_nodes[i].y, z=all_nodes[i].z} -- copy position + pos.x=pos.x+1 + check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename) + pos.x=pos.x-2 + check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename) + pos.x=pos.x+1 + + pos.y=pos.y+1 + check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename) + pos.y=pos.y-2 + check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename) + pos.y=pos.y+1 + + pos.z=pos.z+1 + check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename) + pos.z=pos.z-2 + check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename) + pos.z=pos.z+1 + end + +---------------------------------------------- +-- The action code for the switching station +---------------------------------------------- +minetest.register_abm( + {nodenames = {"technic:switching_station"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local meta1 = nil + local pos1 = {} + local PR_EU = 0 -- EUs from PR nodes + local BA_PR_EU = 0 -- EUs from BA nodes (discharching) + local BA_RE_EU = 0 -- EUs to BA nodes (charging) + local RE_EU = 0 -- EUs to RE nodes + + local network = "" + local all_nodes = {} + local PR_nodes = {} + local BA_nodes = {} + local RE_nodes = {} + +-- -- Possible to turn off the entire network +-- if meta:get_int("active") == 0 then +-- for _,pos1 in pairs(RE_nodes) do +-- meta1 = minetest.env:get_meta(pos1) +-- meta1:set_int("EU_input", 0) +-- end +-- for _,pos1 in pairs(BA_nodes) do +-- meta1 = minetest.env:get_meta(pos1) +-- meta1:set_int("EU_input", 0) +-- end +-- return +-- end + + -- Which kind of network are we on: + pos1 = {x=pos.x, y=pos.y-1, z=pos.z} + all_nodes[1] = pos1 + + meta1 = minetest.env:get_meta(pos1) + if meta1:get_float("cablelike") ==1 then + -- LV type + --dprint("LV type") + network = "LV" + local table_index = 1 + repeat + traverse_network(PR_nodes,RE_nodes,BA_nodes,all_nodes,table_index, technic.LV_machines, "cablelike") + table_index = table_index + 1 + if all_nodes[table_index] == nil then break end + until false + elseif meta1:get_float("mv_cablelike") ==1 then + -- MV type + --dprint("MV type") + network = "MV" + local table_index = 1 + repeat + traverse_network(PR_nodes,RE_nodes,BA_nodes,all_nodes,table_index, technic.MV_machines, "mv_cablelike") + table_index = table_index + 1 + if all_nodes[table_index] == nil then break end + until false + elseif meta1:get_float("hv_cablelike") ==1 then + -- HV type + --dprint("HV type") + network = "HV" + local table_index = 1 + repeat + traverse_network(PR_nodes,RE_nodes,BA_nodes,all_nodes,table_index, technic.HV_machines, "hv_cablelike") + table_index = table_index + 1 + if all_nodes[table_index] == nil then break end + until false + else + -- No type :-) + --dprint("Not connected to a network") + meta:set_string("infotext", "Switching Station - no network") + return + end + --dprint("nodes="..table.getn(all_nodes).." PR="..table.getn(PR_nodes).." BA="..table.getn(BA_nodes).." RE="..table.getn(RE_nodes)) + + -- Strings for the meta data + local eu_demand_str = network.."_EU_demand" + local eu_input_str = network.."_EU_input" + local eu_supply_str = network.."_EU_supply" + local eu_from_fuel_str = network.."_EU_from_fuel" + + -- Get all the power from the PR nodes + local PR_eu_supply = 0 -- Total power + for _,pos1 in pairs(PR_nodes) do + meta1 = minetest.env:get_meta(pos1) + PR_eu_supply = PR_eu_supply + meta1:get_int(eu_supply_str) + end + --dprint("Total PR supply:"..PR_eu_supply) + + -- Get all the demand from the RE nodes + local RE_eu_demand = 0 + for _,pos1 in pairs(RE_nodes) do + meta1 = minetest.env:get_meta(pos1) + RE_eu_demand = RE_eu_demand + meta1:get_int(eu_demand_str) + end + --dprint("Total RE demand:"..RE_eu_demand) + + -- Get all the power from the BA nodes + local BA_eu_supply = 0 + for _,pos1 in pairs(BA_nodes) do + meta1 = minetest.env:get_meta(pos1) + BA_eu_supply = BA_eu_supply + meta1:get_int(eu_supply_str) + end + --dprint("Total BA supply:"..BA_eu_supply) + + -- Get all the demand from the BA nodes + local BA_eu_demand = 0 + for _,pos1 in pairs(BA_nodes) do + meta1 = minetest.env:get_meta(pos1) + BA_eu_demand = BA_eu_demand + meta1:get_int(eu_demand_str) + end + --dprint("Total BA demand:"..BA_eu_demand) + + meta:set_string("infotext", "Switching Station. PR("..(PR_eu_supply+BA_eu_supply)..") RE("..(RE_eu_demand+BA_eu_demand)..")") + + -- If the PR supply is enough for the RE demand supply them all + if PR_eu_supply >= RE_eu_demand then + --dprint("PR_eu_supply"..PR_eu_supply.." >= RE_eu_demand"..RE_eu_demand) + for _,pos1 in pairs(RE_nodes) do + meta1 = minetest.env:get_meta(pos1) + local eu_demand = meta1:get_int(eu_demand_str) + meta1:set_int(eu_input_str, eu_demand) + end + -- We have a surplus, so distribute the rest equally to the BA nodes + -- Let's calculate the factor of the demand + PR_eu_supply = PR_eu_supply - RE_eu_demand + local charge_factor = 0 -- Assume all batteries fully charged + if BA_eu_demand > 0 then + charge_factor = PR_eu_supply / BA_eu_demand + end + for n,pos1 in pairs(BA_nodes) do + meta1 = minetest.env:get_meta(pos1) + local eu_demand = meta1:get_int(eu_demand_str) + meta1:set_int(eu_input_str, math.floor(eu_demand*charge_factor)) + --dprint("Charging battery:"..math.floor(eu_demand*charge_factor)) + end + -- If still a surplus we can start giving back to the fuel burning generators + -- Only full EU packages are given back. The rest is wasted. + if BA_eu_demand == 0 then + for _,pos1 in pairs(PR_nodes) do + meta1 = minetest.env:get_meta(pos1) + if meta1:get_int(eu_from_fuel_str) == 1 then + local eu_supply = meta1:get_int(eu_supply_str) + if PR_eu_supply < eu_supply then + break + else + -- Set the supply to 0 if we did not require it. + meta1:set_int(eu_supply_str, 0) + PR_eu_supply = PR_eu_supply - eu_supply + end + end + end + end + return + end + + -- If the PR supply is not enough for the RE demand we will discharge the batteries too + if PR_eu_supply+BA_eu_supply >= RE_eu_demand then + --dprint("PR_eu_supply "..PR_eu_supply.."+BA_eu_supply "..BA_eu_supply.." >= RE_eu_demand"..RE_eu_demand) + for _,pos1 in pairs(RE_nodes) do + meta1 = minetest.env:get_meta(pos1) + local eu_demand = meta1:get_int(eu_demand_str) + meta1:set_int(eu_input_str, eu_demand) + end + -- We have a deficit, so distribute to the BA nodes + -- Let's calculate the factor of the supply + local charge_factor = 0 -- Assume all batteries depleted + if BA_eu_supply > 0 then + charge_factor = (PR_eu_supply - RE_eu_demand) / BA_eu_supply + end + for n,pos1 in pairs(BA_nodes) do + meta1 = minetest.env:get_meta(pos1) + local eu_supply = meta1:get_int(eu_supply_str) + meta1:set_int(eu_input_str, math.floor(eu_supply*charge_factor)) + --dprint("Discharging battery:"..math.floor(eu_supply*charge_factor)) + end + return + end + + -- If the PR+BA supply is not enough for the RE demand: Shut everything down! + -- Note: another behaviour could also be imagined: provide the average power for all and let the node decide what happens. + -- This is much simpler though: Not enough power for all==no power for all + --print("NO POWER") + for _,pos1 in pairs(RE_nodes) do + meta1 = minetest.env:get_meta(pos1) + meta1:set_int(eu_input_str, 0) + end + end, +}) diff --git a/technic/tool_workshop.lua b/technic/tool_workshop.lua index 1174633..9351c0e 100644 --- a/technic/tool_workshop.lua +++ b/technic/tool_workshop.lua @@ -1,3 +1,5 @@ +-- LV Tool workshop +-- This machine repairs tools. minetest.register_alias("tool_workshop", "technic:tool_workshop") minetest.register_craft({ output = 'technic:tool_workshop', @@ -13,88 +15,108 @@ minetest.register_craftitem("technic:tool_workshop", { stack_max = 99, }) -workshop_formspec = - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "list[current_name;src;3,1;1,1;]".. - "label[0,0;Tool Workshop]".. - "label[1,3;Power level]".. - "list[current_player;main;0,5;8,4;]" +local workshop_formspec = + "invsize[8,9;]".. + "list[current_name;src;3,1;1,1;]".. + "label[0,0;Tool Workshop]".. + "list[current_player;main;0,5;8,4;]" -minetest.register_node("technic:tool_workshop", { - description = "Tool Workshop", - tiles = {"technic_workshop_top.png", "technic_machine_bottom.png", "technic_workshop_side.png", - "technic_workshop_side.png", "technic_workshop_side.png", "technic_workshop_side.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - sounds = default.node_sound_wood_defaults(), - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=2000; +minetest.register_node( + "technic:tool_workshop", + { + description = "Tool Workshop", + tiles = {"technic_workshop_top.png", "technic_machine_bottom.png", "technic_workshop_side.png", + "technic_workshop_side.png", "technic_workshop_side.png", "technic_workshop_side.png"}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + sounds = default.node_sound_wood_defaults(), + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "Tool Workshop") + meta:set_float("technic_power_machine", 1) + meta:set_string("formspec", workshop_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + end + return true + end, + }) - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "Tool Workshop") - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 1) - meta:set_float("internal_EU_buffer_size", 2000) - meta:set_string("formspec", workshop_formspec) - local inv = meta:get_inventory() - inv:set_size("src", 1) - end, - can_dig = function(pos,player) - local meta = minetest.env:get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("src") then - return false - end - return true - end, -}) +minetest.register_abm( + { nodenames = {"technic:tool_workshop"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local eu_input = meta:get_int("LV_EU_input") + local state = meta:get_int("state") + local next_state = state -minetest.register_abm({ - nodenames = {"technic:tool_workshop"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local meta = minetest.env:get_meta(pos) - local charge= meta:get_float("internal_EU_buffer") - local max_charge= meta:get_float("internal_EU_buffer_size") - local load_step=2000 - local load_cost=200 - local inv = meta:get_inventory() - if inv:is_empty("src")==false then - srcstack = inv:get_stack("src", 1) - src_item=srcstack:to_table() - if (src_item["name"]=="technic:water_can" or src_item["name"]=="technic:lava_can") then - load_step=0 - load_cost=0 - end - local load1=tonumber((src_item["wear"])) - if charge>load_cost then - if load1>1 then - if load1-load_step<0 then load_step=load1 load1=1 - else load1=load1-load_step end - charge=charge-load_cost - src_item["wear"]=tostring(load1) - inv:set_stack("src", 1, src_item) - end - end - end - - meta:set_float("internal_EU_buffer",charge) - - - local load = math.floor((charge/max_charge)*100) - meta:set_string("formspec", - "invsize[8,9;]".. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]".. - "list[current_name;src;3,1;1,1;]".. - "label[0,0;Tool Workshop]".. - "label[1,3;Power level]".. - "list[current_player;main;0,5;8,4;]") - end -}) + -- Machine information + local machine_name = "Tool Workshop" + local machine_node = "technic:tool_workshop" + local machine_state_demand = { 50, 150 } + + -- Setup meta data if it does not exist. state is used as an indicator of this + if state == 0 then + meta:set_int("state", 1) + meta:set_int("LV_EU_demand", machine_state_demand[1]) + meta:set_int("LV_EU_input", 0) + return + end + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "LV") + + -- State machine + if eu_input == 0 then + -- Unpowered - go idle + --hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + next_state = 1 + elseif eu_input == machine_state_demand[state] then + -- Powered - do the state specific actions + local inv = meta:get_inventory() + + if state == 1 then + --hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Idle") + if not inv:is_empty("src") then + next_state = 2 + end + elseif state == 2 then + --hacky_swap_node(pos, machine_node.."_active") + meta:set_string("infotext", machine_name.." Active") + + if inv:is_empty("src") then + next_state = 1 + else + srcstack = inv:get_stack("src", 1) + src_item=srcstack:to_table() + -- Cannot charge cans + if (src_item["name"]=="technic:water_can" or src_item["name"]=="technic:lava_can") then + return + end + local wear=tonumber(src_item["wear"]) + wear = math.max(1, wear-2000) -- Improve the tool this much every tick + src_item["wear"]=tostring(wear) + inv:set_stack("src", 1, src_item) + end + end + end + -- Change state? + if next_state ~= state then + meta:set_int("LV_EU_demand", machine_state_demand[next_state]) + meta:set_int("state", next_state) + end + end + }) -register_LV_machine ("technic:tool_workshop","RE") +technic.register_LV_machine ("technic:tool_workshop","RE") diff --git a/technic/water_mill.lua b/technic/water_mill.lua index 52966ed..e6314f0 100644 --- a/technic/water_mill.lua +++ b/technic/water_mill.lua @@ -1,3 +1,6 @@ +-- A water mill produces LV EUs by exploiting flowing water across it +-- It is a LV EU supplyer and fairly low yield (max 120EUs) +-- It is a little under half as good as the thermal generator. minetest.register_alias("water_mill", "technic:water_mill") minetest.register_craft({ @@ -14,7 +17,7 @@ minetest.register_craftitem("technic:water_mill", { stack_max = 99, }) -water_mill_formspec = +local water_mill_formspec = "invsize[8,4;]".. "image[1,1;1,2;technic_power_meter_bg.png]".. "label[0,0;Water Mill]".. @@ -22,110 +25,98 @@ water_mill_formspec = "list[current_player;main;0,5;8,4;]" -minetest.register_node("technic:water_mill", { - description = "Water Mill", - tiles = {"technic_water_mill_top.png", "technic_machine_bottom.png", "technic_water_mill_side.png", - "technic_water_mill_side.png", "technic_water_mill_side.png", "technic_water_mill_side.png"}, - paramtype2 = "facedir", - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=5000; - burn_time=0; - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "Water Mill") - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", 3000) - meta:set_string("formspec", water_mill_formspec) - end, - -}) +minetest.register_node( + "technic:water_mill", + { + description = "Water Mill", + tiles = {"technic_water_mill_top.png", "technic_machine_bottom.png", "technic_water_mill_side.png", + "technic_water_mill_side.png", "technic_water_mill_side.png", "technic_water_mill_side.png"}, + paramtype2 = "facedir", + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=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("infotext", "Water Mill") + meta:set_float("technic_power_machine", 1) + meta:set_int("LV_EU_supply", 0) + meta:set_string("formspec", water_mill_formspec) + end, + }) -minetest.register_node("technic:water_mill_active", { - description = "Water Mill", - tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png", "technic_water_mill_side.png", - "technic_water_mill_side.png", "technic_water_mill_side.png", "technic_water_mill_side.png"}, - paramtype2 = "facedir", - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - drop="technic:water_mill", - technic_power_machine=1, - internal_EU_buffer=0; - internal_EU_buffer_size=0; +minetest.register_node( + "technic:water_mill_active", + { + description = "Water Mill", + tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png", "technic_water_mill_side.png", + "technic_water_mill_side.png", "technic_water_mill_side.png", "technic_water_mill_side.png"}, + paramtype2 = "facedir", + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + drop="technic:water_mill", }) -minetest.register_abm({ - nodenames = {"technic:water_mill","technic:water_mill_active"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) +local check_node_around_mill = function(pos) + local node=minetest.env:get_node(pos) + if node.name=="default:water_flowing" then return 1 end + return 0 + end - local meta = minetest.env:get_meta(pos) - local charge= meta:get_float("internal_EU_buffer") - local max_charge= meta:get_float("internal_EU_buffer_size") - local water_nodes = 0 - local lava_nodes = 0 - local production_level=0 - local load_step=0 +minetest.register_abm( + { + nodenames = {"technic:water_mill","technic:water_mill_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + local water_nodes = 0 + local lava_nodes = 0 + local production_level = 0 + local eu_supply = 0 - pos.x=pos.x+1 - local check=check_node_around_mill (pos) - if check==1 then water_nodes=water_nodes+1 end - pos.x=pos.x-2 - check=check_node_around_mill (pos) - if check==1 then water_nodes=water_nodes+1 end - pos.x=pos.x+1 - pos.z=pos.z+1 - check=check_node_around_mill (pos) - if check==1 then water_nodes=water_nodes+1 end - pos.z=pos.z-2 - check=check_node_around_mill (pos) - if check==1 then water_nodes=water_nodes+1 end - pos.z=pos.z+1 + pos.x=pos.x+1 + local check=check_node_around_mill (pos) + if check==1 then water_nodes=water_nodes+1 end + pos.x=pos.x-2 + check=check_node_around_mill (pos) + if check==1 then water_nodes=water_nodes+1 end + pos.x=pos.x+1 + pos.z=pos.z+1 + check=check_node_around_mill (pos) + if check==1 then water_nodes=water_nodes+1 end + pos.z=pos.z-2 + check=check_node_around_mill (pos) + if check==1 then water_nodes=water_nodes+1 end + pos.z=pos.z+1 - if water_nodes==1 then production_level=25 load_step=30 end - if water_nodes==2 then production_level=50 load_step=60 end - if water_nodes==3 then production_level=75 load_step=90 end - if water_nodes==4 then production_level=100 load_step=120 end + if water_nodes==1 then production_level = 25; eu_supply = 30 end + if water_nodes==2 then production_level = 50; eu_supply = 60 end + if water_nodes==3 then production_level = 75; eu_supply = 90 end + if water_nodes==4 then production_level = 100; eu_supply = 120 end - if production_level>0 then - if charge+load_step>max_charge then - load_step=max_charge-charge - end - if load_step>0 then - charge=charge+load_step - meta:set_float("internal_EU_buffer",charge) - end - end + if production_level>0 then + meta:set_int("LV_EU_supply", eu_supply) + end - local load = math.floor((charge/max_charge)*100) - meta:set_string("formspec", - "invsize[8,4;]".. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - (load)..":technic_power_meter_fg.png]".. - "label[0,0;Water Mill]".. - "label[1,3;Power level]".. - "label[4,0;Production at "..tostring(production_level).."%]" - ) + local load = 1 -- math.floor((charge/max_charge)*100) + meta:set_string("formspec", + "invsize[8,4;]".. + "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. + (load)..":technic_power_meter_fg.png]".. + "label[0,0;Water Mill]".. + "label[1,3;Power level]".. + "label[4,0;Production at "..tostring(production_level).."%]" + ) - if production_level>0 and minetest.env:get_node(pos).name=="technic:water_mill" then - hacky_swap_node (pos,"technic:water_mill_active") - return - end - if production_level==0 then hacky_swap_node (pos,"technic:water_mill") end -end -}) - -function check_node_around_mill (pos) -local node=minetest.env:get_node(pos) -if node.name=="default:water_flowing" then return 1 end -return 0 -end + if production_level>0 and minetest.env:get_node(pos).name=="technic:water_mill" then + hacky_swap_node (pos,"technic:water_mill_active") + meta:set_int("LV_EU_supply", 0) + return + end + if production_level==0 then hacky_swap_node (pos,"technic:water_mill") end + end + }) -register_LV_machine ("technic:water_mill","PR") -register_LV_machine ("technic:water_mill_active","PR") +technic.register_LV_machine ("technic:water_mill","PR") +technic.register_LV_machine ("technic:water_mill_active","PR") -- cgit v1.2.3 From 7201aeb6ba1b63afd95b23b44843acb6985f0ad4 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Tue, 2 Jul 2013 22:26:45 +0200 Subject: Removed down_converters as they are superseeded by the new supply converter. --- technic/down_converter_hv.lua | 225 ----------------------------------------- technic/down_converter_mv.lua | 226 ------------------------------------------ 2 files changed, 451 deletions(-) delete mode 100644 technic/down_converter_hv.lua delete mode 100644 technic/down_converter_mv.lua diff --git a/technic/down_converter_hv.lua b/technic/down_converter_hv.lua deleted file mode 100644 index 0e2e16d..0000000 --- a/technic/down_converter_hv.lua +++ /dev/null @@ -1,225 +0,0 @@ --- The HV down converter will step down HV EUs to MV EUs --- If we take the solar panel as calibration then the --- 1 HVEU = 5 MVEU as we stack 5 MV arrays to get a HV array. --- The downconverter does of course have a conversion loss. --- This loses 30% of the power. --- The converter does not store any energy by itself. -minetest.register_node("technic:down_converter_hv", { - description = "HV Down Converter", - tiles = {"technic_hv_down_converter_top.png", "technic_hv_down_converter_bottom.png", "technic_hv_down_converter_side.png", - "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - sounds = default.node_sound_wood_defaults(), - drawtype = "nodebox", - paramtype = "light", - is_ground_content = true, - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_float("technic_hv_power_machine", 1) - meta:set_float("technic_mv_power_machine", 1) - meta:set_float("internal_EU_buffer",0) - meta:set_float("internal_EU_buffer_size",0) - meta:set_string("infotext", "HV Down Converter") - meta:set_float("active", false) - end, - }) - -minetest.register_craft({ - output = 'technic:down_converter_hv 1', - recipe = { - {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot','technic:stainless_steel_ingot'}, - {'technic:hv_transformer', 'technic:hv_cable', 'technic:mv_transformer'}, - {'technic:hv_cable', 'technic:rubber', 'technic:mv_cable'}, - } -}) - -minetest.register_abm( - {nodenames = {"technic:down_converter_hv"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - -- HV->MV conversion factor - local hv_mv_factor = 5 - -- The maximun charge a single converter can handle. Let's set this to - -- what 5 HV solar arrays can produce - 30% loss (2880*5*0.7) - local max_charge = 10080*hv_mv_factor - - local meta = minetest.env:get_meta(pos) - local meta1 = nil - local pos1 = {} - local available_charge = 0 -- counted in MV units - local used_charge = 0 -- counted in MV units - - -- Index all HV nodes connected to the network - -- HV cable comes in through the bottom - pos1.y = pos.y-1 - pos1.x = pos.x - pos1.z = pos.z - meta1 = minetest.env:get_meta(pos1) - if meta1:get_float("hv_cablelike")~=1 then return end - - local HV_nodes = {} -- HV type - local HV_PR_nodes = {} -- HV type - local HV_BA_nodes = {} -- HV type - - HV_nodes[1] = {} - HV_nodes[1].x = pos1.x - HV_nodes[1].y = pos1.y - HV_nodes[1].z = pos1.z - - local table_index = 1 - repeat - check_HV_node(HV_PR_nodes,nil,HV_BA_nodes,HV_nodes,table_index) - table_index = table_index + 1 - if HV_nodes[table_index] == nil then break end - until false - - --print("HV_nodes: PR="..table.getn(HV_PR_nodes).." BA="..table.getn(HV_BA_nodes)) - - -- Index all MV nodes connected to the network - -- MV cable comes out of the top - pos1.y = pos.y+1 - pos1.x = pos.x - pos1.z = pos.z - meta1 = minetest.env:get_meta(pos1) - if meta1:get_float("mv_cablelike")~=1 then return end - - local MV_nodes = {} -- MV type - local MV_RE_nodes = {} -- MV type - local MV_BA_nodes = {} -- MV type - - MV_nodes[1] = {} - MV_nodes[1].x = pos1.x - MV_nodes[1].y = pos1.y - MV_nodes[1].z = pos1.z - - table_index = 1 - repeat - check_MV_node(nil,MV_RE_nodes,MV_BA_nodes,MV_nodes,table_index) - table_index = table_index + 1 - if MV_nodes[table_index] == nil then break end - until false - - --print("MV_nodes: RE="..table.getn(MV_RE_nodes).." BA="..table.getn(MV_BA_nodes)) - - -- First get available power from all the attached HV suppliers - -- Get the supplier internal EU buffer and read the EUs from it - -- No update yet! - local pos1 --- FIXME: Until further leave the producers out of it and just let the batteries be the hub --- for _,pos1 in ipairs(HV_PR_nodes) do --- meta1 = minetest.env:get_meta(pos1) --- local internal_EU_buffer = meta1:get_float("internal_EU_buffer") --- available_charge = available_charge + meta1:get_float("internal_EU_buffer") * hv_mv_factor --- -- Limit conversion capacity --- if available_charge > max_charge then --- available_charge = max_charge --- break --- end --- end --- --print("Available_charge PR:"..available_charge) - - for _,pos1 in ipairs(HV_BA_nodes) do - meta1 = minetest.env:get_meta(pos1) - local internal_EU_buffer = meta1:get_float("internal_EU_buffer") - available_charge = available_charge + meta1:get_float("internal_EU_buffer") * hv_mv_factor - -- Limit conversion capacity - if available_charge > max_charge then - available_charge = max_charge - break - end - end - --print("Available_charge PR+BA:"..available_charge) - - -- Calculate total number of receivers: - local MV_receivers = table.getn(MV_RE_nodes)+table.getn(MV_BA_nodes) - - -- Next supply power to all connected MV machines - -- Get the power receiver internal EU buffer and give EUs to it - -- Note: for now leave out RE type machines until producers distribute power themselves even without a battery --- for _,pos1 in ipairs(MV_RE_nodes) do --- local meta1 = minetest.env:get_meta(pos1) --- local internal_EU_buffer = meta1:get_float("internal_EU_buffer") --- local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size") --- local charge_to_give = math.min(4000, available_charge/MV_receivers) -- power rating limit on the MV wire --- -- How much can this unit take? --- if internal_EU_buffer+charge_to_give > internal_EU_buffer_size then --- charge_to_give=internal_EU_buffer_size-internal_EU_buffer --- end --- -- If we are emptying the supply take the remainder --- if available_charge internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - --print("charge_to_give2:"..charge_to_give) - -- If we are emptying the supply take the remainder - if available_charge 0 then - internal_EU_buffer = internal_EU_buffer-charge_to_take - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - end - end - - if used_charge>0 then - meta:set_string("infotext", "HV Down Converter is active (HV:"..available_charge.."/MV:"..used_charge..")"); - meta:set_float("active",1) -- used for setting textures someday maybe - else - meta:set_string("infotext", "HV Down Converter is inactive (HV:"..available_charge.."/MV:"..used_charge..")"); - meta:set_float("active",0) -- used for setting textures someday maybe - return - end - end, -}) - --- This machine does not store energy it receives energy from the HV side and outputs it on the MV side -register_HV_machine ("technic:down_converter_hv","RE") -register_MV_machine ("technic:down_converter_hv","PR") diff --git a/technic/down_converter_mv.lua b/technic/down_converter_mv.lua deleted file mode 100644 index 1d26630..0000000 --- a/technic/down_converter_mv.lua +++ /dev/null @@ -1,226 +0,0 @@ --- The MV down converter will step down MV EUs to LV EUs --- If we take the solar panel as calibration then the --- 1 MVEU = 5 LVEU as we stack 5 LV arrays to get an MV array. --- The downconverter does of course have a conversion loss. --- This loses 30% of the power. --- The converter does not store any energy by itself. -minetest.register_node( - "technic:down_converter_mv", { - description = "MV Down Converter", - tiles = {"technic_mv_down_converter_top.png", "technic_mv_down_converter_bottom.png", "technic_mv_down_converter_side.png", - "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, - sounds = default.node_sound_wood_defaults(), - drawtype = "nodebox", - paramtype = "light", - is_ground_content = true, - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_float("technic_mv_power_machine", 1) - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer",0) - meta:set_float("internal_EU_buffer_size",0) - meta:set_string("infotext", "MV Down Converter") - meta:set_float("active", false) - end, - }) - -minetest.register_craft({ - output = 'technic:down_converter_mv 1', - recipe = { - {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot','technic:stainless_steel_ingot'}, - {'technic:mv_transformer', 'technic:mv_cable', 'technic:lv_transformer'}, - {'technic:mv_cable', 'technic:rubber', 'technic:lv_cable'}, - } -}) - -minetest.register_abm( - {nodenames = {"technic:down_converter_mv"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - -- MV->LV conversion factor - local mv_lv_factor = 5 - -- The maximun charge a single converter can handle. Let's set this to - -- what 5 MV solar arrays can produce - 30% loss (720*5*0.7) - local max_charge = 2520*mv_lv_factor - - local meta = minetest.env:get_meta(pos) - local meta1 = nil - local pos1 = {} - local available_charge = 0 -- counted in LV units - local used_charge = 0 -- counted in LV units - - -- Index all MV nodes connected to the network - -- MV cable comes in through the bottom - pos1.y = pos.y-1 - pos1.x = pos.x - pos1.z = pos.z - meta1 = minetest.env:get_meta(pos1) - if meta1:get_float("mv_cablelike")~=1 then return end - - local MV_nodes = {} -- MV type - local MV_PR_nodes = {} -- MV type - local MV_BA_nodes = {} -- MV type - - MV_nodes[1] = {} - MV_nodes[1].x = pos1.x - MV_nodes[1].y = pos1.y - MV_nodes[1].z = pos1.z - - local table_index = 1 - repeat - check_MV_node(MV_PR_nodes,nil,MV_BA_nodes,MV_nodes,table_index) - table_index = table_index + 1 - if MV_nodes[table_index] == nil then break end - until false - - --print("MV_nodes: PR="..table.getn(MV_PR_nodes).." BA="..table.getn(MV_BA_nodes)) - - -- Index all LV nodes connected to the network - -- LV cable comes out of the top - pos1.y = pos.y+1 - pos1.x = pos.x - pos1.z = pos.z - meta1 = minetest.env:get_meta(pos1) - if meta1:get_float("cablelike")~=1 then return end - - local LV_nodes = {} -- LV type - local LV_RE_nodes = {} -- LV type - local LV_BA_nodes = {} -- LV type - - LV_nodes[1] = {} - LV_nodes[1].x = pos1.x - LV_nodes[1].y = pos1.y - LV_nodes[1].z = pos1.z - - table_index = 1 - repeat - check_LV_node(nil,LV_RE_nodes,LV_BA_nodes,LV_nodes,table_index) - table_index = table_index + 1 - if LV_nodes[table_index] == nil then break end - until false - - --print("LV_nodes: RE="..table.getn(LV_RE_nodes).." BA="..table.getn(LV_BA_nodes)) - - -- First get available power from all the attached MV suppliers - -- Get the supplier internal EU buffer and read the EUs from it - -- No update yet! - local pos1 --- FIXME: Until further leave the producers out of it and just let the batteries be the hub --- for _,pos1 in ipairs(MV_PR_nodes) do --- meta1 = minetest.env:get_meta(pos1) --- local internal_EU_buffer = meta1:get_float("internal_EU_buffer") --- available_charge = available_charge + meta1:get_float("internal_EU_buffer") * mv_lv_factor --- -- Limit conversion capacity --- if available_charge > max_charge then --- available_charge = max_charge --- break --- end --- end --- print("Available_charge PR:"..available_charge) - - for _,pos1 in ipairs(MV_BA_nodes) do - meta1 = minetest.env:get_meta(pos1) - local internal_EU_buffer = meta1:get_float("internal_EU_buffer") - available_charge = available_charge + meta1:get_float("internal_EU_buffer") * mv_lv_factor - -- Limit conversion capacity - if available_charge > max_charge then - available_charge = max_charge - break - end - end - --print("Available_charge PR+BA:"..available_charge) - - -- Calculate total number of receivers: - local LV_receivers = table.getn(LV_RE_nodes)+table.getn(LV_BA_nodes) - - -- Next supply power to all connected LV machines - -- Get the power receiver internal EU buffer and give EUs to it - -- Note: for now leave out RE type machines until producers distribute power themselves even without a battery --- for _,pos1 in ipairs(LV_RE_nodes) do --- local meta1 = minetest.env:get_meta(pos1) --- local internal_EU_buffer = meta1:get_float("internal_EU_buffer") --- local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size") --- local charge_to_give = math.min(1000, available_charge/LV_receivers) -- power rating limit on the LV wire --- -- How much can this unit take? --- if internal_EU_buffer+charge_to_give > internal_EU_buffer_size then --- charge_to_give=internal_EU_buffer_size-internal_EU_buffer --- end --- -- If we are emptying the supply take the remainder --- if available_charge internal_EU_buffer_size then - charge_to_give=internal_EU_buffer_size-internal_EU_buffer - end - --print("charge_to_give2:"..charge_to_give) - -- If we are emptying the supply take the remainder - if available_charge 0 then - internal_EU_buffer = internal_EU_buffer-charge_to_take - meta1:set_float("internal_EU_buffer",internal_EU_buffer) - end - end - - if used_charge>0 then - meta:set_string("infotext", "MV Down Converter is active (MV:"..available_charge.."/LV:"..used_charge..")"); - meta:set_float("active",1) -- used for setting textures someday maybe - else - meta:set_string("infotext", "MV Down Converter is inactive (MV:"..available_charge.."/LV:"..used_charge..")"); - meta:set_float("active",0) -- used for setting textures someday maybe - return - end - end, -}) - --- This machine does not store energy it receives energy from the MV side and outputs it on the LV side -register_MV_machine ("technic:down_converter_mv","RE") -register_LV_machine ("technic:down_converter_mv","PR") -- cgit v1.2.3 From c7207a9cba3293935811baf107be2edbead02943 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Tue, 2 Jul 2013 22:45:08 +0200 Subject: Silenced the power radiator. --- technic/power_radiator.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/technic/power_radiator.lua b/technic/power_radiator.lua index 383bf87..9a4c84a 100644 --- a/technic/power_radiator.lua +++ b/technic/power_radiator.lua @@ -178,7 +178,7 @@ minetest.register_abm( elseif meta1:get_string("has_supply") == pos.x..pos.y..pos.z then -- The appliance has power from this node. Spend power if it is on. used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor) - print("My Lamp ("..pos.x..","..pos.y..","..pos.z..") Used:"..used_charge) + --print("My Lamp ("..pos.x..","..pos.y..","..pos.z..") Used:"..used_charge) end meta:set_string("infotext", "Power Radiator is powered ("..math.floor(used_charge/max_charge*100).."% of maximum power)"); if used_charge == 0 then -- cgit v1.2.3 From ce5dfa311ebc1347e11721c21a83b808a5bbccbd Mon Sep 17 00:00:00 2001 From: m97 Date: Thu, 4 Jul 2013 19:05:00 +0200 Subject: Add extractor. Add extractor for make more rubber from latex. Moved make dyes from grinder to extractor. --- technic/extractor.lua | 212 ++++++++++++++++++++++++++++++++++++++++++++++ technic/grinder.lua | 9 -- technic/init.lua | 1 + unified_inventory/api.lua | 7 +- 4 files changed, 218 insertions(+), 11 deletions(-) create mode 100644 technic/extractor.lua diff --git a/technic/extractor.lua b/technic/extractor.lua new file mode 100644 index 0000000..92ccdd5 --- /dev/null +++ b/technic/extractor.lua @@ -0,0 +1,212 @@ +technic.extractor_recipes ={} + +technic.register_extractor_recipe = function(src, dst) + technic.extractor_recipes[src] = dst + if unified_inventory then + unified_inventory.register_craft( + { + type = "extracting", + output = dst, + items = {src}, + width = 0, + }) + end + end + +-- Receive an ItemStack of result by an ItemStack input +technic.get_extractor_recipe = function(itemstack) + local src_item = itemstack:to_table() + if src_item == nil then + return nil + end + local item_name = src_item["name"] + if technic.extractor_recipes[item_name] then + return ItemStack(technic.extractor_recipes[item_name]) + else + return nil + end + end + + + +technic.register_extractor_recipe("technic:coal_dust","dye:black 2") +technic.register_extractor_recipe("default:cactus","dye:green 2") +technic.register_extractor_recipe("default:dry_shrub","dye:brown 2") +technic.register_extractor_recipe("flowers:geranium","dye:blue 2") +technic.register_extractor_recipe("flowers:dandelion_white","dye:white 2") +technic.register_extractor_recipe("flowers:dandelion_yellow","dye:yellow 2") +technic.register_extractor_recipe("flowers:tulip","dye:orange 2") +technic.register_extractor_recipe("flowers:rose","dye:red 2") +technic.register_extractor_recipe("flowers:viola","dye:violet 2") +technic.register_extractor_recipe("technic:raw_latex","technic:rubber 3") +technic.register_extractor_recipe("moretrees:rubber_tree_trunk_empty","technic:rubber 1") +technic.register_extractor_recipe("moretrees:rubber_tree_trunk","technic:rubber 1") + +minetest.register_alias("extractor", "technic:extractor") +minetest.register_craft({ + output = 'technic:extractor', + recipe = { + {'technic:treetap', 'technic:motor', 'technic:treetap'}, + {'technic:treetap', 'technic:lv_cable', 'technic:treetap'}, + {'','',''}, + } + }) + +minetest.register_craftitem("technic:extractor", { + description = "Extractor", + stack_max = 99, + }) + +local extractor_formspec = + "invsize[8,9;]".. + "label[0,0;Extractor]".. + "list[current_name;src;3,1;1,1;]".. + "list[current_name;dst;5,1;2,2;]".. + "list[current_player;main;0,5;8,4;]" + +minetest.register_node( + "technic:extractor", + { + description = "Extractor", + tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png", + "technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front.png"}, + paramtype2 = "facedir", + groups = {cracky=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("infotext", "Extractor") + meta:set_float("technic_power_machine", 1) + meta:set_string("formspec", extractor_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) + inv:set_size("dst", 4) + end, + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, + }) + +minetest.register_node( + "technic:extractor_active", + { + description = "Extractor", + tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png", + "technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front_active.png"}, + paramtype2 = "facedir", + groups = {cracky=2,not_in_creative_inventory=1}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("src") or not inv:is_empty("dst") then + minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty"); + return false + else + return true + end + end, + }) + +minetest.register_abm( + { nodenames = {"technic:extractor","technic:extractor_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + -- Run a machine through its states. Takes the same arguments as the ABM action + -- and adds the machine's states and any extra data which is needed by the machine. + -- A machine is characterized by running through a set number of states (usually 2: + -- Idle and active) in some order. A state decides when to move to the next one + -- and the machine only changes state if it is powered correctly. + -- The machine will automatically shut down if disconnected from power in some fashion. + local meta = minetest.env:get_meta(pos) + local eu_input = meta:get_int("LV_EU_input") + local state = meta:get_int("state") + local next_state = state + + -- Machine information + local machine_name = "Extractor" + local machine_node = "technic:extractor" + local machine_state_demand = { 50, 300 } + + -- Setup meta data if it does not exist. state is used as an indicator of this + if state == 0 then + meta:set_int("state", 1) + meta:set_int("LV_EU_demand", machine_state_demand[1]) + meta:set_int("LV_EU_input", 0) + return + end + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "LV") + + -- State machine + if eu_input == 0 then + -- unpowered - go idle + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Unpowered") + next_state = 1 + elseif eu_input == machine_state_demand[state] then + -- Powered - do the state specific actions + + local inv = meta:get_inventory() + local empty = inv:is_empty("src") + + if state == 1 then + hacky_swap_node(pos, machine_node) + meta:set_string("infotext", machine_name.." Idle") + + local result = technic.get_extractor_recipe(inv:get_stack("src", 1)) + if not empty and result and inv:room_for_item("dst",result) then + meta:set_int("src_time", 0) + next_state = 2 + end + + elseif state == 2 then + hacky_swap_node(pos, machine_node.."_active") + meta:set_string("infotext", machine_name.." Active") + + if empty then + next_state = 1 + else + meta:set_int("src_time", meta:get_int("src_time") + 1) + if meta:get_int("src_time") == 4 then -- 4 ticks per output + -- check if there's room for output in "dst" list + local result = technic.get_extractor_recipe(inv:get_stack("src", 1)) + + meta:set_int("src_time", 0) + if inv:room_for_item("dst",result) then + -- take stuff from "src" list + srcstack = inv:get_stack("src", 1) + srcstack:take_item() + inv:set_stack("src", 1, srcstack) + -- Put result in "dst" list + inv:add_item("dst", result) + else + -- all full: go idle + next_state = 1 + end + end + end + end + end + -- Change state? + if next_state ~= state then + meta:set_int("LV_EU_demand", machine_state_demand[next_state]) + meta:set_int("state", next_state) + end + end + }) + +technic.register_LV_machine ("technic:extractor","RE") +technic.register_LV_machine ("technic:extractor_active","RE") + diff --git a/technic/grinder.lua b/technic/grinder.lua index 8b41184..ba78710 100644 --- a/technic/grinder.lua +++ b/technic/grinder.lua @@ -53,15 +53,6 @@ technic.register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel technic.register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1") technic.register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2") technic.register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1") -technic.register_grinder_recipe("technic:coal_dust","dye:black 2") -technic.register_grinder_recipe("default:cactus","dye:green 2") -technic.register_grinder_recipe("default:dry_shrub","dye:brown 2") -technic.register_grinder_recipe("flowers:flower_geranium","dye:blue 2") -technic.register_grinder_recipe("flowers:flower_dandelion_white","dye:white 2") -technic.register_grinder_recipe("flowers:flower_dandelion_yellow","dye:yellow 2") -technic.register_grinder_recipe("flowers:flower_tulip","dye:orange 2") -technic.register_grinder_recipe("flowers:flower_rose","dye:red 2") -technic.register_grinder_recipe("flowers:flower_viola","dye:violet 2") minetest.register_craftitem( "technic:coal_dust", { description = "Coal Dust", diff --git a/technic/init.lua b/technic/init.lua index abe0439..263b6b9 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -44,6 +44,7 @@ dofile(modpath.."/grinder.lua") dofile(modpath.."/cnc.lua") dofile(modpath.."/cnc_api.lua") dofile(modpath.."/cnc_nodes.lua") +dofile(modpath.."/extractor.lua") --MV machines dofile(modpath.."/wires_mv.lua") diff --git a/unified_inventory/api.lua b/unified_inventory/api.lua index 02c08e9..91681b1 100644 --- a/unified_inventory/api.lua +++ b/unified_inventory/api.lua @@ -230,7 +230,10 @@ unified_inventory.get_formspec = function(player,page) end if craft.type == "alloy" then method="Alloy cooking" - end + end + if craft.type == "extracting" then + method="Extracting" + end formspec = formspec.."label[6,3;"..method.."]" end @@ -558,7 +561,7 @@ unified_inventory.update_recipe = function(player, stack_name, alternate) inv:set_stack("output", 1, craft.output) local items=craft.items -- cook, fuel, grinding recipes - if craft.type == "cooking" or craft.type == "fuel" or craft.type == "grinding" then + if craft.type == "cooking" or craft.type == "fuel" or craft.type == "grinding" or craft.type == "extracting" then def=unified_inventory.find_item_def(craft["items"][1]) if def then inv:set_stack("build", 1, def) -- cgit v1.2.3 From 6e4ffb48831c8c275b450840830ed835a24d18a5 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Thu, 4 Jul 2013 19:19:45 +0200 Subject: Fix item wear. --- technic/flashlight.lua | 2 +- technic/sonic_screwdriver.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/technic/flashlight.lua b/technic/flashlight.lua index dd36c31..5f3ea96 100644 --- a/technic/flashlight.lua +++ b/technic/flashlight.lua @@ -161,7 +161,7 @@ local hotbar=inv:get_list("main") charge=meta["charge"] if charge-2>0 then charge =charge-2; - set_RE_wear(item,charge,flashlight_max_charge) + technic.set_RE_wear(item,charge,flashlight_max_charge) meta["charge"]=charge item["metadata"]=set_item_meta(meta) hotbar[i]:replace(item) diff --git a/technic/sonic_screwdriver.lua b/technic/sonic_screwdriver.lua index 1453862..00922f7 100644 --- a/technic/sonic_screwdriver.lua +++ b/technic/sonic_screwdriver.lua @@ -38,7 +38,7 @@ minetest.register_tool("technic:sonic_screwdriver", { charge=charge-100; meta1["charge"]=charge item["metadata"]=set_item_meta(meta1) - set_RE_wear(item,charge,sonic_screwdriver_max_charge) + technic.set_RE_wear(item,charge,sonic_screwdriver_max_charge) itemstack:replace(item) end return itemstack -- cgit v1.2.3 From 9770be430d04c18f1a2db2bfd5b1ef6e02de92e3 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Thu, 4 Jul 2013 20:29:38 +0200 Subject: Textures. I really need help on some nice ones. --- technic/power_radiator.lua | 4 ++-- technic/supply_converter.lua | 6 +++--- technic/switching_station.lua | 4 ++-- technic/textures/technic_hv_down_converter_bottom.png | Bin 653 -> 0 bytes technic/textures/technic_hv_down_converter_side.png | Bin 609 -> 0 bytes technic/textures/technic_hv_down_converter_top.png | Bin 653 -> 0 bytes technic/textures/technic_mv_down_converter_bottom.png | Bin 738 -> 0 bytes technic/textures/technic_mv_down_converter_side.png | Bin 670 -> 0 bytes technic/textures/technic_mv_down_converter_top.png | Bin 738 -> 0 bytes technic/textures/technic_supply_converter_bottom.png | Bin 0 -> 738 bytes technic/textures/technic_supply_converter_side.png | Bin 0 -> 670 bytes technic/textures/technic_supply_converter_top.png | Bin 0 -> 738 bytes 12 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 technic/textures/technic_hv_down_converter_bottom.png delete mode 100644 technic/textures/technic_hv_down_converter_side.png delete mode 100644 technic/textures/technic_hv_down_converter_top.png delete mode 100644 technic/textures/technic_mv_down_converter_bottom.png delete mode 100644 technic/textures/technic_mv_down_converter_side.png delete mode 100644 technic/textures/technic_mv_down_converter_top.png create mode 100644 technic/textures/technic_supply_converter_bottom.png create mode 100644 technic/textures/technic_supply_converter_side.png create mode 100644 technic/textures/technic_supply_converter_top.png diff --git a/technic/power_radiator.lua b/technic/power_radiator.lua index 9a4c84a..8b0666a 100644 --- a/technic/power_radiator.lua +++ b/technic/power_radiator.lua @@ -87,8 +87,8 @@ local shutdown_inductive_appliances = function(pos) minetest.register_node( "technic:power_radiator", { description = "Power Radiator", - tiles = {"technic_hv_down_converter_top.png", "technic_hv_down_converter_bottom.png", "technic_hv_down_converter_side.png", - "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png"}, + tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png", + "technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png"}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, sounds = default.node_sound_wood_defaults(), drawtype = "nodebox", diff --git a/technic/supply_converter.lua b/technic/supply_converter.lua index 5e04d42..d0714e7 100644 --- a/technic/supply_converter.lua +++ b/technic/supply_converter.lua @@ -14,8 +14,8 @@ minetest.register_node( "technic:supply_converter", { description = "Supply Converter", - tiles = {"technic_mv_down_converter_top.png", "technic_mv_down_converter_bottom.png", "technic_mv_down_converter_side.png", - "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png"}, + tiles = {"technic_supply_converter_top.png", "technic_supply_converter_bottom.png", "technic_supply_converter_side.png", + "technic_supply_converter_side.png", "technic_supply_converter_side.png", "technic_supply_converter_side.png"}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, sounds = default.node_sound_wood_defaults(), drawtype = "nodebox", @@ -58,7 +58,7 @@ minetest.register_abm( local mv_lv_factor = 4 -- multiplication (higher is more efficient) local mv_hv_factor = 5 -- division local hv_mv_factor = 4 -- multiplication - local max_lv_demand = 2000 -- The increment size pwer supply tier. Determines how many are needed + local max_lv_demand = 2000 -- The increment size power supply tier. Determines how many are needed local max_mv_demand = 2000 -- -""- local max_hv_demand = 2000 -- -""- diff --git a/technic/switching_station.lua b/technic/switching_station.lua index 7919d5e..36133fa 100644 --- a/technic/switching_station.lua +++ b/technic/switching_station.lua @@ -43,8 +43,8 @@ minetest.register_craft( minetest.register_node( "technic:switching_station", {description = "Switching Station", - tiles = {"technic_mv_down_converter_top.png", "technic_mv_down_converter_bottom.png", "technic_mv_down_converter_side.png", - "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png"}, + tiles = {"technic_water_mill_top_active.png", "technic_water_mill_top_active.png", "technic_water_mill_top_active.png", + "technic_water_mill_top_active.png", "technic_water_mill_top_active.png", "technic_water_mill_top_active.png"}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, sounds = default.node_sound_wood_defaults(), drawtype = "nodebox", diff --git a/technic/textures/technic_hv_down_converter_bottom.png b/technic/textures/technic_hv_down_converter_bottom.png deleted file mode 100644 index 996b2d4..0000000 Binary files a/technic/textures/technic_hv_down_converter_bottom.png and /dev/null differ diff --git a/technic/textures/technic_hv_down_converter_side.png b/technic/textures/technic_hv_down_converter_side.png deleted file mode 100644 index ab904f1..0000000 Binary files a/technic/textures/technic_hv_down_converter_side.png and /dev/null differ diff --git a/technic/textures/technic_hv_down_converter_top.png b/technic/textures/technic_hv_down_converter_top.png deleted file mode 100644 index 996b2d4..0000000 Binary files a/technic/textures/technic_hv_down_converter_top.png and /dev/null differ diff --git a/technic/textures/technic_mv_down_converter_bottom.png b/technic/textures/technic_mv_down_converter_bottom.png deleted file mode 100644 index a610660..0000000 Binary files a/technic/textures/technic_mv_down_converter_bottom.png and /dev/null differ diff --git a/technic/textures/technic_mv_down_converter_side.png b/technic/textures/technic_mv_down_converter_side.png deleted file mode 100644 index 6492d5c..0000000 Binary files a/technic/textures/technic_mv_down_converter_side.png and /dev/null differ diff --git a/technic/textures/technic_mv_down_converter_top.png b/technic/textures/technic_mv_down_converter_top.png deleted file mode 100644 index a610660..0000000 Binary files a/technic/textures/technic_mv_down_converter_top.png and /dev/null differ diff --git a/technic/textures/technic_supply_converter_bottom.png b/technic/textures/technic_supply_converter_bottom.png new file mode 100644 index 0000000..a610660 Binary files /dev/null and b/technic/textures/technic_supply_converter_bottom.png differ diff --git a/technic/textures/technic_supply_converter_side.png b/technic/textures/technic_supply_converter_side.png new file mode 100644 index 0000000..6492d5c Binary files /dev/null and b/technic/textures/technic_supply_converter_side.png differ diff --git a/technic/textures/technic_supply_converter_top.png b/technic/textures/technic_supply_converter_top.png new file mode 100644 index 0000000..a610660 Binary files /dev/null and b/technic/textures/technic_supply_converter_top.png differ -- cgit v1.2.3 From 9a0d3f216619b84dd818aff94efb6738de9b7622 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Thu, 4 Jul 2013 21:33:27 +0200 Subject: Forcefield now working with updated power scheme. --- README.md | 5 +- technic/forcefield.lua | 200 ++++++++++++++++++++++++++----------------------- technic/init.lua | 2 +- 3 files changed, 111 insertions(+), 96 deletions(-) diff --git a/README.md b/README.md index e93dd50..abec467 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ -technic 0.4.6 +technic 0.4.7 -Technic mod for Minetest 0.4.6 +Technic mod for Minetest 0.4.7 Credits for contributing to the project: Nekogloop ShadowNinja VanessaE Nore/Novatux +kpoppel And many others for ideas/inspiring Licences: diff --git a/technic/forcefield.lua b/technic/forcefield.lua index 8af98f4..98201e8 100644 --- a/technic/forcefield.lua +++ b/technic/forcefield.lua @@ -1,7 +1,9 @@ ---Forcefield mod by ShadowNinja +-- Forcefield mod by ShadowNinja +-- Modified by kpoppel +-- +-- Forcefields are powerful barriers but they consume huge amounts of power. +-- Forcefield Generator is a HV machine. -local forcefield_emitter_buffer_size = 10000 -local forcefield_emitter_power_consumption = 0.8 local forcefield_update_interval = 1 minetest.register_craft({ @@ -13,22 +15,13 @@ minetest.register_craft({ } }) -local function get_forcefield_count(range) - local count = 0 - for x=-range,range do - for y=-range,range do - for z=-range,range do - if ((x*x+y*y+z*z) <= (range * range + range)) then - if (y == 0) or ((range-1) * (range-1) + (range-1) <= x*x+y*y+z*z) then - count = count + 1 - end - end - end - end - end - return count -end - +-- Idea: Let forcefields have different colors by upgrade slot. +-- Idea: Let forcefields add up by detecting if one hits another. +-- ___ __ +-- / \/ \ +-- | | +-- \___/\___/ +-- local function add_forcefield(pos, range) for x=-range,range do for y=-range,range do @@ -66,69 +59,90 @@ local function remove_forcefield(p, range) end end -local forcefield_receive_fields = function(pos, formname, fields, sender) - local meta = minetest.env:get_meta(pos) - local range = meta:get_int("range") - if fields.add then range = range + 1 end - if fields.subtract then range = range - 1 end - if fields.toggle then - if meta:get_int("enabled") == 1 then - meta:set_int("enabled", 0) - else - meta:set_int("enabled", 1) - end - end - if range <= 20 and range >= 0 and meta:get_int("range") ~= range then - remove_forcefield(pos, meta:get_int("range")) - meta:set_int("range", range) - local buffer = meta:get_float("internal_EU_buffer") - local buffer_size = meta:get_float("internal_EU_buffer_size") - local load = math.floor(buffer / buffer_size * 100) - meta:set_string("formspec", get_forcefield_formspec(range, 0)) - end -end - -local get_forcefield_formspec = function(range, load) - if not load then load = 0 end - return "invsize[8,9;]".. +local get_forcefield_formspec = function(range) + -- return "invsize[8,9;]".. (if upgrades added later - colors for instance) + return "invsize[3,4;]".. "label[0,0;Forcefield emitter]".. - "label[1,3;Power level]".. - "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. - load..":technic_power_meter_fg.png]".. - "label[4,1;Range]".. - "label[4,2;"..range.."]".. - "button[3,2;1,1;add;+]".. - "button[5,2;1,1;subtract;-]".. - "button[3,3;3,1;toggle;Enable/Disable]".. - "list[current_player;main;0,5;8,4;]" + "label[1,1;Range]".. + "label[1,2;"..range.."]".. + "button[0,2;1,1;subtract;-]".. + "button[2,2;1,1;add;+]".. + "button[0,3;3,1;toggle;Enable/Disable]" -- .. +-- "list[current_player;main;0,5;8,4;]" end -local forcefield_check = function(pos) - local meta = minetest.env:get_meta(pos) - local node = minetest.env:get_node(pos) - local internal_EU_buffer=meta:get_float("internal_EU_buffer") - local internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size") - - local load = math.floor(internal_EU_buffer/internal_EU_buffer_size * 100) - meta:set_string("formspec", get_forcefield_formspec(meta:get_int("range"), load)) - - local power_requirement = get_forcefield_count(meta:get_int("range")) * forcefield_emitter_power_consumption - if meta:get_int("enabled") == 1 and internal_EU_buffer >= power_requirement then - if node.name == "technic:forcefield_emitter_off" then - hacky_swap_node(pos, "technic:forcefield_emitter_on") - end - internal_EU_buffer=internal_EU_buffer-power_requirement; - meta:set_float("internal_EU_buffer", internal_EU_buffer) - add_forcefield(pos, meta:get_int("range")) - else - if node.name == "technic:forcefield_emitter_on" then - remove_forcefield(pos, meta:get_int("range")) - hacky_swap_node(pos, "technic:forcefield_emitter_off") - end - end - return true +local forcefield_receive_fields = function(pos, formname, fields, sender) + local meta = minetest.env:get_meta(pos) + local range = meta:get_int("range") + if fields.add then range = range + 1 end + if fields.subtract then range = range - 1 end + if fields.toggle then + if meta:get_int("enabled") == 1 then + meta:set_int("enabled", 0) + else + meta:set_int("enabled", 1) + end + end + -- Smallest field is 5. Anything less is asking for trouble. + -- Largest is 20. It is a matter of pratical node handling. + if range < 5 then range = 5 end + if range > 20 then range = 20 end + + if range <= 20 and range >= 5 and meta:get_int("range") ~= range then + remove_forcefield(pos, meta:get_int("range")) + meta:set_int("range", range) + meta:set_string("formspec", get_forcefield_formspec(range)) + end + end -end +local forcefield_check = function(pos) + local meta = minetest.env:get_meta(pos) + local node = minetest.env:get_node(pos) + local eu_input = meta:get_int("HV_EU_input") + local eu_demand = meta:get_int("HV_EU_demand") + local enabled = meta:get_int("enabled") + + -- Power off automatically if no longer connected to a switching station + technic.switching_station_timeout_count(pos, "HV") + + local power_requirement + if enabled == 1 then + power_requirement = math.floor(4*math.pi*math.pow(meta:get_int("range"), 2)) * 1 + else + power_requirement = eu_demand + end + + if eu_input == 0 then + meta:set_string("infotext", "Forcefield Generator Unpowered") + meta:set_int("HV_EU_demand", 100) + if node.name == "technic:forcefield_emitter_on" then + remove_forcefield(pos, meta:get_int("range")) + hacky_swap_node(pos, "technic:forcefield_emitter_off") + meta:set_int("enabled", 0) + end + elseif eu_input == power_requirement then + if meta:get_int("enabled") == 1 then + if node.name == "technic:forcefield_emitter_off" then + hacky_swap_node(pos, "technic:forcefield_emitter_on") + meta:set_string("infotext", "Forcefield Generator Active") + add_forcefield(pos, meta:get_int("range")) + else + -- Range updated. Move the forcefield. + add_forcefield(pos, meta:get_int("range")) + end + else + if node.name == "technic:forcefield_emitter_on" then + remove_forcefield(pos, meta:get_int("range")) + hacky_swap_node(pos, "technic:forcefield_emitter_off") + meta:set_int("HV_EU_demand", 100) + meta:set_string("infotext", "Forcefield Generator Idle") + end + end + else + meta:set_int("HV_EU_demand", power_requirement) + end + return true + end local mesecons = {effector = { action_on = function(pos, node) @@ -150,12 +164,12 @@ minetest.register_node("technic:forcefield_emitter_off", { on_construct = function(pos) minetest.env:get_node_timer(pos):start(forcefield_update_interval) local meta = minetest.env:get_meta(pos) - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", forcefield_emitter_buffer_size) + meta:set_float("technic_hv_power_machine", 1) + meta:set_int("HV_EU_input", 0) + meta:set_int("HV_EU_demand", 0) meta:set_int("range", 10) - meta:set_int("enabled", 1) - meta:set_string("formspec", get_forcefield_formspec(meta:get_int("range", 0))) + meta:set_int("enabled", 0) + meta:set_string("formspec", get_forcefield_formspec(meta:get_int("range"))) meta:set_string("infotext", "Forcefield emitter"); end, mesecons = mesecons @@ -172,19 +186,18 @@ minetest.register_node("technic:forcefield_emitter_on", { on_construct = function(pos) minetest.env:get_node_timer(pos):start(forcefield_update_interval) local meta = minetest.env:get_meta(pos) - meta:set_float("technic_power_machine", 1) - meta:set_float("internal_EU_buffer", 0) - meta:set_float("internal_EU_buffer_size", forcefield_emitter_buffer_size) - meta:set_int("range", 10) - meta:set_int("enabled", 1) - meta:set_string("formspec", get_forcefield_formspec(meta:get_int("range"), 0)) - meta:set_string("infotext", "Forcefield emitter"); +-- meta:set_float("technic_hv_power_machine", 1) +-- meta:set_float("HV_EU_input", 0) +-- meta:set_float("HV_EU_demand", 0) +-- meta:set_int("range", 10) +-- meta:set_int("enabled", 1) + meta:set_string("formspec", get_forcefield_formspec(meta:get_int("range"))) +-- meta:set_string("infotext", "Forcefield emitter"); end, on_dig = function(pos, node, digger) remove_forcefield(pos, minetest.env:get_meta(pos):get_int("range")) return minetest.node_dig(pos, node, digger) end, - technic_power_machine=1, mesecons = mesecons }) @@ -192,6 +205,7 @@ minetest.register_node("technic:forcefield", { description = "Forcefield (you hacker you)", sunlight_propagates = true, drop = '', + light_source = 8, tiles = {{name="technic_forcefield_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}}}, is_ground_content = true, groups = {not_in_creative_inventory=1, unbreakable=1}, @@ -205,5 +219,5 @@ minetest.register_node("technic:forcefield", { }, }) -technic.register_MV_machine("technic:forcefield_emitter_on","RE") -technic.register_MV_machine("technic:forcefield_emitter_off","RE") +technic.register_HV_machine("technic:forcefield_emitter_on","RE") +technic.register_HV_machine("technic:forcefield_emitter_off","RE") diff --git a/technic/init.lua b/technic/init.lua index abe0439..3978aa9 100644 --- a/technic/init.lua +++ b/technic/init.lua @@ -51,7 +51,7 @@ dofile(modpath.."/battery_box_mv.lua") dofile(modpath.."/solar_array_mv.lua") dofile(modpath.."/electric_furnace_mv.lua") dofile(modpath.."/alloy_furnace_mv.lua") ---dofile(modpath.."/forcefield.lua") +dofile(modpath.."/forcefield.lua") ---- The power radiator supplies appliances with inductive coupled power: ---- lighting and associated textures is taken directly from VanessaE's homedecor and made electric. dofile(modpath.."/power_radiator.lua") -- cgit v1.2.3 From 73209cc37d61e3c90dbd0c441228faa0c8f312dc Mon Sep 17 00:00:00 2001 From: kpoppel Date: Thu, 4 Jul 2013 21:39:29 +0200 Subject: Fix cycling power drain on the forcefield. Now it disables itself if no power. --- technic/forcefield.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/technic/forcefield.lua b/technic/forcefield.lua index 98201e8..8ad5410 100644 --- a/technic/forcefield.lua +++ b/technic/forcefield.lua @@ -4,6 +4,8 @@ -- Forcefields are powerful barriers but they consume huge amounts of power. -- Forcefield Generator is a HV machine. +-- How expensive is the generator? Leaves room for upgrades lowering the power drain? +local forcefield_power_drain = 10 -- default 10 local forcefield_update_interval = 1 minetest.register_craft({ @@ -107,7 +109,7 @@ local forcefield_check = function(pos) local power_requirement if enabled == 1 then - power_requirement = math.floor(4*math.pi*math.pow(meta:get_int("range"), 2)) * 1 + power_requirement = math.floor(4*math.pi*math.pow(meta:get_int("range"), 2)) * forcefield_power_drain else power_requirement = eu_demand end @@ -115,10 +117,10 @@ local forcefield_check = function(pos) if eu_input == 0 then meta:set_string("infotext", "Forcefield Generator Unpowered") meta:set_int("HV_EU_demand", 100) + meta:set_int("enabled", 0) if node.name == "technic:forcefield_emitter_on" then remove_forcefield(pos, meta:get_int("range")) hacky_swap_node(pos, "technic:forcefield_emitter_off") - meta:set_int("enabled", 0) end elseif eu_input == power_requirement then if meta:get_int("enabled") == 1 then -- cgit v1.2.3 From e64994d473fce07b2a92bd86a85c6d118ae8ff7d Mon Sep 17 00:00:00 2001 From: kpoppel Date: Sat, 6 Jul 2013 00:17:56 +0200 Subject: Fix a bug when digging up a small cube light. Fix the power radiator so that it reacts correcty when power is lost. Add punch feature to toggle all attached appliances. --- technic/lighting.lua | 4 ++-- technic/power_radiator.lua | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/technic/lighting.lua b/technic/lighting.lua index 1d4b45f..546e42c 100644 --- a/technic/lighting.lua +++ b/technic/lighting.lua @@ -488,7 +488,7 @@ minetest.register_node('technic:homedecor_glowlight_small_cube_yellow_active', { sounds = default.node_sound_wood_defaults(), groups = { snappy = 3, not_in_creative_inventory=1}, - drop="technic:homedecor_glowlight_cube_yellow", + drop="technic:homedecor_glowlight_small_cube_yellow", on_place = function(itemstack, placer, pointed_thing) technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) return itemstack @@ -569,7 +569,7 @@ minetest.register_node('technic:homedecor_glowlight_small_cube_white_active', { sounds = default.node_sound_wood_defaults(), groups = { snappy = 3, not_in_creative_inventory=1}, - drop="technic:homedecor_glowlight_cube_white", + drop="technic:homedecor_glowlight_small_cube_white", on_place = function(itemstack, placer, pointed_thing) technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing) return itemstack diff --git a/technic/power_radiator.lua b/technic/power_radiator.lua index 8b0666a..4e248b1 100644 --- a/technic/power_radiator.lua +++ b/technic/power_radiator.lua @@ -7,6 +7,10 @@ -- sum(power rating of the attached appliances)/0.6 -- Using inductive power transfer is very inefficient so this is -- set to the factor 0.6. +-- +-- Punching the radiator will toggle the power state of all attached appliances. +-- +local power_radius = 6 ------------------------------------------------------------------ -- API for inductive powered nodes: @@ -29,7 +33,7 @@ technic.inductive_on_construct = function(pos, eu_demand, infotext) local meta = minetest.env:get_meta(pos) meta:set_string("infotext", infotext) meta:set_int("technic_inductive_power_machine", 1) - meta:set_int("MV_EU_demand",eu_demand) -- The power demand of this appliance + meta:set_int("EU_demand",eu_demand) -- The power demand of this appliance meta:set_int("EU_charge",0) -- The actual power draw of this appliance meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators. meta:set_int("active", 0) -- If the appliance can be turned on and off by using it use this. @@ -63,11 +67,11 @@ technic.inductive_on_punch_on = function(pos, eu_charge, swapnode) local shutdown_inductive_appliances = function(pos) -- The supply radius - local rad = 4 + local rad = power_radius -- If the radiator is removed. turn off all appliances in region -- If another radiator is near it will turn on the appliances again local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic.inductive_nodes) - for _,pos1 in ipairs(positions) do + for _,pos1 in pairs(positions) do local meta1 = minetest.env:get_meta(pos1) -- If the appliance is belonging to this node if meta1:get_string("has_supply") == pos.x..pos.y..pos.z then @@ -83,6 +87,18 @@ local shutdown_inductive_appliances = function(pos) end end +local toggle_on_off_inductive_appliances = function(pos, node, puncher) + if pos == nil then return end + -- The supply radius + local rad = power_radius + local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic.inductive_nodes) + for _,pos1 in pairs(positions) do + local meta1 = minetest.env:get_meta(pos1) + if meta1:get_string("has_supply") == pos.x..pos.y..pos.z then + minetest.env:punch_node(pos1) + end + end + end minetest.register_node( "technic:power_radiator", { @@ -114,6 +130,9 @@ minetest.register_node( shutdown_inductive_appliances(pos) return minetest.node_dig(pos, node, digger) end, + on_punch = function(pos, node, puncher) + toggle_on_off_inductive_appliances(pos, node, puncher) + end }) minetest.register_craft( @@ -143,7 +162,7 @@ minetest.register_abm( meta:set_string("infotext", "Power Radiator is unpowered"); -- meta:set_int("active",1) -- used for setting textures someday maybe shutdown_inductive_appliances(pos) - connected_EU_demand = 0 + meta:set_int("connected_EU_demand", 0) elseif eu_input == eu_demand then -- Powered and ready @@ -154,7 +173,7 @@ minetest.register_abm( -- Efficiency factor local eff_factor = 0.6 -- The supply radius - local rad = 6 + local rad = power_radius local meta1 = nil local pos1 = {} @@ -162,23 +181,24 @@ minetest.register_abm( -- Index all nodes within supply range local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic.inductive_nodes) - for _,pos1 in ipairs(positions) do + for _,pos1 in pairs(positions) do local meta1 = minetest.env:get_meta(pos1) -- If not supplied see if this node can handle it. if meta1:get_string("has_supply") == "" then -- if demand surpasses the capacity of this node, don't bother adding it. - local app_eu_demand = meta1:get_int("EU_demand")/eff_factor + local app_eu_demand = math.floor(meta1:get_int("EU_demand")/eff_factor) if connected_EU_demand + app_eu_demand <= max_charge then + --print("I can supply this:"..connected_EU_demand.."|"..app_eu_demand.."<="..max_charge.."|act:"..meta1:get_int("EU_charge")) -- We can power the appliance. Register, and spend power if it is on. connected_EU_demand = connected_EU_demand + app_eu_demand meta1:set_string("has_supply", pos.x..pos.y..pos.z) - used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor) + --Always 0: used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor) end elseif meta1:get_string("has_supply") == pos.x..pos.y..pos.z then -- The appliance has power from this node. Spend power if it is on. - used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor) - --print("My Lamp ("..pos.x..","..pos.y..","..pos.z..") Used:"..used_charge) + used_charge = used_charge+math.floor(meta1:get_int("EU_charge")/eff_factor) + --print("My Lamp ("..pos.x..","..pos.y..","..pos.z..") Used:"..used_charge.."Max:"..max_charge) end meta:set_string("infotext", "Power Radiator is powered ("..math.floor(used_charge/max_charge*100).."% of maximum power)"); if used_charge == 0 then -- cgit v1.2.3 From 4c6546ed56da9b8ac7db490af841d11ef9a10368 Mon Sep 17 00:00:00 2001 From: kpoppel Date: Sat, 6 Jul 2013 00:22:12 +0200 Subject: Forgot to reset demand on power failure. --- technic/power_radiator.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/technic/power_radiator.lua b/technic/power_radiator.lua index 4e248b1..86a770e 100644 --- a/technic/power_radiator.lua +++ b/technic/power_radiator.lua @@ -163,6 +163,7 @@ minetest.register_abm( -- meta:set_int("active",1) -- used for setting textures someday maybe shutdown_inductive_appliances(pos) meta:set_int("connected_EU_demand", 0) + meta:set_int("MV_EU_demand",1) elseif eu_input == eu_demand then -- Powered and ready -- cgit v1.2.3 From 85d937e1997bcaa833e40df78117d53708ecdccd Mon Sep 17 00:00:00 2001 From: kpoppel Date: Sat, 6 Jul 2013 00:31:48 +0200 Subject: Made the supply converter reset its supply and demand stats if the cabling is bad. --- technic/supply_converter.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/technic/supply_converter.lua b/technic/supply_converter.lua index d0714e7..bee99d2 100644 --- a/technic/supply_converter.lua +++ b/technic/supply_converter.lua @@ -97,6 +97,15 @@ minetest.register_abm( if convert_MV_LV == 0 and convert_LV_MV == 0 and convert_HV_MV == 0 and convert_MV_HV == 0 then meta:set_string("infotext", machine_name.." has bad cabling") + meta:set_int("LV_EU_demand", 0) + meta:set_int("LV_EU_supply", 0) + meta:set_int("LV_EU_input", 0) + meta:set_int("MV_EU_demand", 0) + meta:set_int("MV_EU_supply", 0) + meta:set_int("MV_EU_input", 0) + meta:set_int("HV_EU_demand", 0) + meta:set_int("HV_EU_supply", 0) + meta:set_int("HV_EU_input", 0) return end -- cgit v1.2.3 From e606b93ac633fd95bb2a65aac6acb94b30abcb14 Mon Sep 17 00:00:00 2001 From: Konstantin Oblaukhov Date: Sat, 6 Jul 2013 15:19:15 +0700 Subject: Support for multiple-input recipes in extractor. --- technic/extractor.lua | 69 ++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/technic/extractor.lua b/technic/extractor.lua index 92ccdd5..473a7b3 100644 --- a/technic/extractor.lua +++ b/technic/extractor.lua @@ -1,27 +1,23 @@ technic.extractor_recipes ={} -technic.register_extractor_recipe = function(src, dst) - technic.extractor_recipes[src] = dst +technic.register_extractor_recipe = function(src, src_count, dst, dst_count) + technic.extractor_recipes[src] = {src_count = src_count, dst_name = dst, dst_count = dst_count} if unified_inventory then unified_inventory.register_craft( { type = "extracting", - output = dst, - items = {src}, + output = dst.." "..dst_count, + items = {src.." "..src_count}, width = 0, }) end end -- Receive an ItemStack of result by an ItemStack input -technic.get_extractor_recipe = function(itemstack) - local src_item = itemstack:to_table() - if src_item == nil then - return nil - end - local item_name = src_item["name"] - if technic.extractor_recipes[item_name] then - return ItemStack(technic.extractor_recipes[item_name]) +technic.get_extractor_recipe = function(item) + if technic.extractor_recipes[item.name] + and item.count >= technic.extractor_recipes[item.name].src_count then + return technic.extractor_recipes[item.name] else return nil end @@ -29,18 +25,18 @@ technic.get_extractor_recipe = function(itemstack) -technic.register_extractor_recipe("technic:coal_dust","dye:black 2") -technic.register_extractor_recipe("default:cactus","dye:green 2") -technic.register_extractor_recipe("default:dry_shrub","dye:brown 2") -technic.register_extractor_recipe("flowers:geranium","dye:blue 2") -technic.register_extractor_recipe("flowers:dandelion_white","dye:white 2") -technic.register_extractor_recipe("flowers:dandelion_yellow","dye:yellow 2") -technic.register_extractor_recipe("flowers:tulip","dye:orange 2") -technic.register_extractor_recipe("flowers:rose","dye:red 2") -technic.register_extractor_recipe("flowers:viola","dye:violet 2") -technic.register_extractor_recipe("technic:raw_latex","technic:rubber 3") -technic.register_extractor_recipe("moretrees:rubber_tree_trunk_empty","technic:rubber 1") -technic.register_extractor_recipe("moretrees:rubber_tree_trunk","technic:rubber 1") +technic.register_extractor_recipe("technic:coal_dust", 1, "dye:black", 2) +technic.register_extractor_recipe("default:cactus", 1, "dye:green", 2) +technic.register_extractor_recipe("default:dry_shrub", 1, "dye:brown", 2) +technic.register_extractor_recipe("flowers:geranium", 1, "dye:blue", 2) +technic.register_extractor_recipe("flowers:dandelion_white", 1, "dye:white", 2) +technic.register_extractor_recipe("flowers:dandelion_yellow", 1, "dye:yellow", 2) +technic.register_extractor_recipe("flowers:tulip", 1, "dye:orange", 2) +technic.register_extractor_recipe("flowers:rose", 1, "dye:red", 2) +technic.register_extractor_recipe("flowers:viola", 1, "dye:violet", 2) +technic.register_extractor_recipe("technic:raw_latex", 1, "technic:rubber", 3) +technic.register_extractor_recipe("moretrees:rubber_tree_trunk_empty", 1, "technic:rubber", 1) +technic.register_extractor_recipe("moretrees:rubber_tree_trunk", 1, "technic:rubber", 1) minetest.register_alias("extractor", "technic:extractor") minetest.register_craft({ @@ -160,12 +156,25 @@ minetest.register_abm( local inv = meta:get_inventory() local empty = inv:is_empty("src") - + local srcstack = inv:get_stack("src", 1) + local src_item = nil + local recipe = nil + local result = nil + + if srcstack then + src_item = srcstack:to_table() + end + if src_item then + recipe = technic.get_extractor_recipe(src_item) + end + if recipe then + result = {name=recipe.dst_name, count=recipe.dst_count} + end + if state == 1 then hacky_swap_node(pos, machine_node) meta:set_string("infotext", machine_name.." Idle") - local result = technic.get_extractor_recipe(inv:get_stack("src", 1)) if not empty and result and inv:room_for_item("dst",result) then meta:set_int("src_time", 0) next_state = 2 @@ -181,14 +190,12 @@ minetest.register_abm( meta:set_int("src_time", meta:get_int("src_time") + 1) if meta:get_int("src_time") == 4 then -- 4 ticks per output -- check if there's room for output in "dst" list - local result = technic.get_extractor_recipe(inv:get_stack("src", 1)) meta:set_int("src_time", 0) - if inv:room_for_item("dst",result) then + if recipe and inv:room_for_item("dst",result) then -- take stuff from "src" list - srcstack = inv:get_stack("src", 1) - srcstack:take_item() - inv:set_stack("src", 1, srcstack) + srcstack:take_item(recipe.src_count) + inv:set_stack("src", 1, srcstack) -- Put result in "dst" list inv:add_item("dst", result) else -- cgit v1.2.3 From 8be389e774a99ec5d08ca86b3902bb98310fd58d Mon Sep 17 00:00:00 2001 From: Konstantin Oblaukhov Date: Sat, 6 Jul 2013 20:52:41 +0700 Subject: Enriched Uranium. --- technic/extractor.lua | 1 + technic/items.lua | 6 ++++++ technic/textures/technic_enriched_uranium.png | Bin 0 -> 301 bytes 3 files changed, 7 insertions(+) create mode 100644 technic/textures/technic_enriched_uranium.png diff --git a/technic/extractor.lua b/technic/extractor.lua index 473a7b3..d4fe1cc 100644 --- a/technic/extractor.lua +++ b/technic/extractor.lua @@ -37,6 +37,7 @@ technic.register_extractor_recipe("flowers:viola", 1, "dye:violet", 2) technic.register_extractor_recipe("technic:raw_latex", 1, "technic:rubber", 3) technic.register_extractor_recipe("moretrees:rubber_tree_trunk_empty", 1, "technic:rubber", 1) technic.register_extractor_recipe("moretrees:rubber_tree_trunk", 1, "technic:rubber", 1) +technic.register_extractor_recipe("technic:uranium", 5, "technic:enriched_uranium", 1) minetest.register_alias("extractor", "technic:extractor") minetest.register_craft({ diff --git a/technic/items.lua b/technic/items.lua index 66c5c85..0f23648 100644 --- a/technic/items.lua +++ b/technic/items.lua @@ -10,6 +10,12 @@ minetest.register_craftitem( "technic:doped_silicon_wafer", { on_place_on_ground = minetest.craftitem_place_item, }) +minetest.register_craftitem( "technic:enriched_uranium", { + description = "Enriched Uranium", + inventory_image = "technic_enriched_uranium.png", + on_place_on_ground = minetest.craftitem_place_item, +}) + -- tubes crafting recipes minetest.register_craft({ diff --git a/technic/textures/technic_enriched_uranium.png b/technic/textures/technic_enriched_uranium.png new file mode 100644 index 0000000..8759e65 Binary files /dev/null and b/technic/textures/technic_enriched_uranium.png differ -- cgit v1.2.3