From ebc114df71cc20868afbd3c6dea4039dc14c1a0e Mon Sep 17 00:00:00 2001 From: Carter Kolwey <fhrfuyduduf@gmail.com> Date: Sat, 11 Jan 2014 18:30:10 +0100 Subject: [PATCH] Fixed music player --- technic/machines/register/alloy_furnace.lua | 120 ++++++++++++++++++++---------------------------------------- 1 files changed, 40 insertions(+), 80 deletions(-) diff --git a/technic/machines/register/alloy_furnace.lua b/technic/machines/register/alloy_furnace.lua index a3da4fe..1195b50 100644 --- a/technic/machines/register/alloy_furnace.lua +++ b/technic/machines/register/alloy_furnace.lua @@ -6,11 +6,11 @@ -- Register recipe in a table technic.register_alloy_recipe = function(metal1, count1, metal2, count2, result, count3) - in1 = { + local in1 = { name = metal1, count = count1, } - in2 = { + local in2 = { name = metal2, count = count2, } @@ -64,6 +64,20 @@ 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) +local tube = { + insert_object = function(pos, node, stack, direction) + local meta = minetest.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.get_meta(pos) + local inv = meta:get_inventory() + return inv:room_for_item("src", stack) + end, + connect_sides = {left=1, right=1, back=1, top=1, bottom=1}, +} + function technic.register_alloy_furnace(data) local tier = data.tier @@ -71,6 +85,7 @@ local tube_side_texture = data.tube and "technic_"..ltier.."_alloy_furnace_side_tube.png" or "technic_"..ltier.."_alloy_furnace_side.png" + local groups = {cracky=2} local active_groups = {cracky=2, not_in_creative_inventory=1} if data.tube then @@ -93,22 +108,6 @@ "label[1,5;Upgrade Slots]" end - data.formspec = formspec - - local tube = { - insert_object = function(pos, node, stack, direction) - local meta = minetest.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.get_meta(pos) - local inv = meta:get_inventory() - return inv:room_for_item("src", stack) - end, - connect_sides = {left=1, right=1, back=1, top=1, bottom=1}, - } - minetest.register_node("technic:"..ltier.."_alloy_furnace", { description = S("%s Alloy Furnace"):format(tier), tiles = {"technic_"..ltier.."_alloy_furnace_top.png", @@ -119,18 +118,15 @@ "technic_"..ltier.."_alloy_furnace_front.png"}, paramtype2 = "facedir", groups = groups, - tube = tube, - technic = data, + tube = data.tube and tube or nil, legacy_facedir_simple = true, sounds = default.node_sound_stone_defaults(), on_construct = function(pos) local meta = minetest.get_meta(pos) local name = minetest.get_node(pos).name - local data = minetest.registered_nodes[name].technic - - meta:set_string("infotext", S("%s Alloy Furnace"):format(data.tier)) - meta:set_string("formspec", data.formspec) + meta:set_string("infotext", S("%s Alloy Furnace"):format(tier)) + meta:set_string("formspec", formspec) meta:set_int("tube_time", 0) local inv = meta:get_inventory() inv:set_size("src", 2) @@ -138,18 +134,10 @@ inv:set_size("upgrade1", 1) inv:set_size("upgrade2", 1) end, - can_dig = function(pos, player) - local meta = minetest.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(), - S("Machine cannot be removed because it is not empty")) - return false - else - return true - end - end, + can_dig = technic.machine_can_dig, + allow_metadata_inventory_put = technic.machine_inventory_put, + allow_metadata_inventory_take = technic.machine_inventory_take, + allow_metadata_inventory_move = technic.machine_inventory_move, }) minetest.register_node("technic:"..ltier.."_alloy_furnace_active",{ @@ -164,40 +152,13 @@ light_source = 8, drop = "technic:"..ltier.."_alloy_furnace", groups = active_groups, - tube = tube, - technic = data, + tube = data.tube and tube or nil, legacy_facedir_simple = true, sounds = default.node_sound_stone_defaults(), - can_dig = function(pos, player) - local meta = minetest.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(), - S("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 stack:get_count() - 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 stack:get_count() - 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, + can_dig = technic.machine_can_dig, + allow_metadata_inventory_put = technic.machine_inventory_put, + allow_metadata_inventory_take = technic.machine_inventory_take, + allow_metadata_inventory_move = technic.machine_inventory_move, }) minetest.register_abm({ @@ -205,24 +166,23 @@ interval = 1, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - local data = minetest.registered_nodes[node.name].technic local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - local eu_input = meta:get_int(data.tier.."_EU_input") + local eu_input = meta:get_int(tier.."_EU_input") -- Machine information - local machine_name = S("%s Alloy Furnace"):format(data.tier) - local machine_node = "technic:"..string.lower(data.tier).."_alloy_furnace" + local machine_name = S("%s Alloy Furnace"):format(tier) + local machine_node = "technic:"..ltier.."_alloy_furnace" local machine_demand = data.demand -- Setup meta data if it does not exist. if not eu_input then - meta:set_int(data.tier.."_EU_demand", machine_demand[1]) - meta:set_int(data.tier.."_EU_input", 0) + meta:set_int(tier.."_EU_demand", machine_demand[1]) + meta:set_int(tier.."_EU_input", 0) end -- Power off automatically if no longer connected to a switching station - technic.switching_station_timeout_count(pos, data.tier) + technic.switching_station_timeout_count(pos, tier) local EU_upgrade, tube_upgrade = 0, 0 if data.upgrade then @@ -245,19 +205,19 @@ end if not result or not inv:room_for_item("dst", result) then - hacky_swap_node(pos, machine_node) + technic.swap_node(pos, machine_node) meta:set_string("infotext", S("%s Idle"):format(machine_name)) - meta:set_int(data.tier.."_EU_demand", 0) + meta:set_int(tier.."_EU_demand", 0) return end if eu_input < machine_demand[EU_upgrade+1] then -- Unpowered - go idle - hacky_swap_node(pos, machine_node) + technic.swap_node(pos, machine_node) meta:set_string("infotext", S("%s Unpowered"):format(machine_name)) elseif eu_input >= machine_demand[EU_upgrade+1] then -- Powered - hacky_swap_node(pos, machine_node.."_active") + technic.swap_node(pos, machine_node.."_active") meta:set_string("infotext", S("%s Active"):format(machine_name)) meta:set_int("src_time", meta:get_int("src_time") + 1) if meta:get_int("src_time") == data.cook_time then @@ -276,7 +236,7 @@ end end - meta:set_int(data.tier.."_EU_demand", machine_demand[EU_upgrade+1]) + meta:set_int(tier.."_EU_demand", machine_demand[EU_upgrade+1]) end, }) -- Gitblit v1.8.0