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/grinder.lua |   81 ++++++++++------------------------------
 1 files changed, 21 insertions(+), 60 deletions(-)

diff --git a/technic/machines/register/grinder.lua b/technic/machines/register/grinder.lua
index 5ababfc..24072e1 100644
--- a/technic/machines/register/grinder.lua
+++ b/technic/machines/register/grinder.lua
@@ -41,7 +41,6 @@
 			"list[current_name;upgrade2;2,4;1,1;]"..
 			"label[1,5;Upgrade Slots]"
 	end
-	data.formspec = formspec
 
 	minetest.register_node("technic:"..ltier.."_grinder", {
 		description = S("%s Grinder"):format(tier),
@@ -50,35 +49,25 @@
 			 "technic_"..ltier.."_grinder_side.png", "technic_"..ltier.."_grinder_front.png"},
 		paramtype2 = "facedir",
 		groups = groups,
-		technic = data,
 		tube = data.tube and tube or nil,
 		legacy_facedir_simple = true,
 		sounds = default.node_sound_wood_defaults(),
 		on_construct = function(pos)
 			local node = minetest.get_node(pos)
 			local meta = minetest.get_meta(pos)
-			local data = minetest.registered_nodes[node.name].technic
-			meta:set_string("infotext", S("%s Grinder"):format(data.tier))
+			meta:set_string("infotext", S("%s Grinder"):format(tier))
 			meta:set_int("tube_time",  0)
-			meta:set_string("formspec", data.formspec)
+			meta:set_string("formspec", 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.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.."_grinder_active",{
@@ -90,38 +79,11 @@
 		groups = active_groups,
 		legacy_facedir_simple = true,
 		sounds = default.node_sound_wood_defaults(),
-		technic = data,
 		tube = data.tube and tube or nil,
-		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 grinder is active.
-		allow_metadata_inventory_put = function(pos, listname, index, stack, player)
-			if listname == "src" or listname == "dst" then
-				return stack:get_stack_max()
-			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_stack_max()
-			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({
@@ -129,24 +91,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")
 
-			local machine_name   = S("%s Grinder"):format(data.tier)
-			local machine_node   = "technic:"..string.lower(data.tier).."_grinder"
+			local machine_name   = S("%s Grinder"):format(tier)
+			local machine_node   = "technic:"..ltier.."_grinder"
 			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)
 				return
 			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
@@ -159,19 +120,19 @@
 			local result = technic.get_grinder_recipe(inv:get_stack("src", 1))
 
 			if not 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)
@@ -186,7 +147,7 @@
 					end
 				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