ShadowNinja
2013-12-17 5cf765b2f19ef9bf443178e26787fe16233b3f4c
technic/machines/register/battery_box.lua
@@ -1,6 +1,33 @@
local S = technic.getter
technic.register_power_tool("technic:battery", 10000)
technic.register_power_tool("technic:red_energy_crystal", 100000)
technic.register_power_tool("technic:green_energy_crystal", 250000)
technic.register_power_tool("technic:blue_energy_crystal", 500000)
minetest.register_craft({
   output = 'technic:battery',
   recipe = {
      {'group:wood', 'default:copper_ingot', 'group:wood'},
      {'group:wood', 'moreores:tin_ingot',   'group:wood'},
      {'group:wood', 'default:copper_ingot', 'group:wood'},
   }
})
minetest.register_tool("technic:battery", {
   description = S("RE Battery"),
   inventory_image = "technic_battery.png",
   tool_capabilities = {
      charge = 0,
      max_drop_level = 0,
      groupcaps = {
         fleshy = {times={}, uses=10000, maxlevel=0}
      }
   }
})
function technic.register_battery_box(data)
   local tier = data.tier
   local ltier = string.lower(tier)
@@ -47,17 +74,10 @@
            inv:set_size("src", 1)
            inv:set_size("dst", 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") 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,
      })
   end
@@ -106,7 +126,7 @@
         charge_count = math.max(charge_count, 0)
         local last_count = meta:get_float("last_side_shown")
         if charge_count ~= last_count then
            hacky_swap_node(pos,"technic:"..ltier.."_battery_box"..charge_count)
            technic.swap_node(pos,"technic:"..ltier.."_battery_box"..charge_count)
            meta:set_float("last_side_shown", charge_count)
         end
@@ -141,14 +161,14 @@
      return batt_charge
   end
   local srcstack = inv:get_stack("src", 1)
   local src_meta = get_item_meta(srcstack:get_metadata())
   local src_meta = minetest.deserialize(srcstack:get_metadata())
   local toolname = srcstack:get_name()
   if not technic.power_tools[toolname] then
      return batt_charge
   end
   -- Set meta data for the tool if it didn't do it itself
   src_meta = get_item_meta(srcstack:get_metadata())
   src_meta = minetest.deserialize(srcstack:get_metadata())
   src_meta = src_meta or {}
   if not src_meta.charge then
      src_meta.charge = 0
@@ -165,7 +185,7 @@
   batt_charge = batt_charge - charge_step
   technic.set_RE_wear(srcstack, tool_charge, item_max_charge)
   src_meta.charge = tool_charge
   srcstack:set_metadata(set_item_meta(src_meta))
   srcstack:set_metadata(minetest.serialize(src_meta))
   inv:set_stack("src", 1, srcstack)
   return batt_charge
end
@@ -182,7 +202,7 @@
      return batt_charge
   end
   -- Set meta data for the tool if it didn't do it itself :-(
   local src_meta = get_item_meta(srcstack:get_metadata())
   local src_meta = minetest.deserialize(srcstack:get_metadata())
   src_meta = src_meta or {}
   if not src_meta.charge then
      src_meta.charge = 0
@@ -200,7 +220,7 @@
   batt_charge = batt_charge + charge_step
   technic.set_RE_wear(srcstack, tool_charge, item_max_charge)
   src_meta.charge = tool_charge
   srcstack:set_metadata(set_item_meta(src_meta))
   srcstack:set_metadata(minetest.serialize(src_meta))
   inv:set_stack("dst", 1, srcstack)
   return batt_charge
end