Carter Kolwey
2014-01-11 ebc114df71cc20868afbd3c6dea4039dc14c1a0e
technic/machines/LV/cnc.lua
@@ -7,6 +7,7 @@
--   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 S = technic.getter
local shape = {}
local onesize_products = {
@@ -126,7 +127,7 @@
-- The actual block inactive state
minetest.register_node("technic:cnc", {
   description = "CNC Milling Machine",
   description = S("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.png"},
   drawtype    = "nodebox",
@@ -142,45 +143,32 @@
   legacy_facedir_simple = true,
   on_construct = function(pos)
      local meta = minetest.get_meta(pos)
      meta:set_string("infotext", "CNC Machine")
      meta:set_string("infotext", S("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.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,
   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,
   on_receive_fields = form_handler,
})
-- Active state block
minetest.register_node("technic:cnc_active", {
   description = "CNC Machine",
   description = S("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.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,
   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,
   on_receive_fields = form_handler,
})
@@ -193,7 +181,7 @@
      local meta         = minetest.get_meta(pos)
      local inv          = meta:get_inventory()
      local eu_input     = meta:get_int("LV_EU_input")
      local machine_name = "CNC"
      local machine_name = S("CNC Machine")
      local machine_node = "technic:cnc"
      local demand       = 450
@@ -212,18 +200,18 @@
      if inv:is_empty("src") or 
         (not minetest.registered_nodes[result]) or
         (not inv:room_for_item("dst", result)) then
         hacky_swap_node(pos, machine_node)
         meta:set_string("infotext", machine_name.." Idle")
         technic.swap_node(pos, machine_node)
         meta:set_string("infotext", S("%s Idle"):format(machine_name))
         meta:set_string("cnc_product", "")
         return
      end
      if eu_input < demand then
         hacky_swap_node(pos, machine_node)
         meta:set_string("infotext", machine_name.." Unpowered")
         technic.swap_node(pos, machine_node)
         meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
      elseif eu_input >= demand then
         hacky_swap_node(pos, machine_node.."_active")
         meta:set_string("infotext", machine_name.." 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") >= 3 then -- 3 ticks per output
            meta:set_int("src_time", 0)