Carter Kolwey
2014-01-11 ebc114df71cc20868afbd3c6dea4039dc14c1a0e
technic/machines/register/grinder.lua
@@ -64,18 +64,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.."_grinder_active",{
@@ -88,36 +80,10 @@
      legacy_facedir_simple = true,
      sounds = default.node_sound_wood_defaults(),
      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({
@@ -154,7 +120,7 @@
         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(tier.."_EU_demand", 0)
            return
@@ -162,11 +128,11 @@
      
         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)