diff --git a/technic/helpers.lua b/technic/helpers.lua index db38d0c..45fd2c9 100644 --- a/technic/helpers.lua +++ b/technic/helpers.lua @@ -71,7 +71,7 @@ function technic.refill_RE_charge(stack) local max_charge = technic.power_tools[stack:get_name()] if not max_charge then return stack end local meta = technic.get_stack_meta_compat(stack) - meta:set_int("charge", max_charge) + meta:set_int("technic:charge", max_charge) technic.set_RE_wear(stack, max_charge, max_charge) return stack end diff --git a/technic/legacy.lua b/technic/legacy.lua index 457f459..f760e84 100644 --- a/technic/legacy.lua +++ b/technic/legacy.lua @@ -39,6 +39,13 @@ for i = 0, 64 do minetest.register_alias("technic:lv_cable"..i, "technic:lv_cable") end +-- Item meta + +-- Meta keys that have changed +technic.legacy_meta_keys = { + ["charge"] = "technic:charge", +} + -- Converts legacy itemstack metadata to itemstack meta and returns the ItemStackMetaRef function technic.get_stack_meta_compat(itemstack) local meta = itemstack:get_meta() @@ -48,7 +55,12 @@ function technic.get_stack_meta_compat(itemstack) if metadata_table then local table = meta:to_table() for k, v in pairs(metadata_table) do - table.fields[k] = v + local legacy_key = technic.legacy_meta_keys[k] + if legacy_key then + table.fields[legacy_key] = v + else + table.fields[k] = v + end end meta:from_table(table) end diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua index c5275f0..ded8402 100644 --- a/technic/machines/register/battery_box.lua +++ b/technic/machines/register/battery_box.lua @@ -416,7 +416,7 @@ local function default_get_charge(itemstack) return 0, 0 end local item_meta = technic.get_stack_meta_compat(itemstack) - return item_meta:get_int("charge"), technic.power_tools[tool_name] + return item_meta:get_int("technic:charge"), technic.power_tools[tool_name] end local function default_set_charge(itemstack, charge) @@ -425,7 +425,7 @@ local function default_set_charge(itemstack, charge) technic.set_RE_wear(itemstack, charge, technic.power_tools[tool_name]) end local item_meta = technic.get_stack_meta_compat(itemstack) - item_meta:set_int("charge", charge) + item_meta:set_int("technic:charge", charge) end function technic.charge_tools(meta, batt_charge, charge_step) diff --git a/technic/tools/chainsaw.lua b/technic/tools/chainsaw.lua index 90eee3a..ef1c263 100644 --- a/technic/tools/chainsaw.lua +++ b/technic/tools/chainsaw.lua @@ -314,7 +314,7 @@ minetest.register_tool("technic:chainsaw", { end local meta = technic.get_stack_meta_compat(itemstack) - local charge = meta:get_int("charge") + local charge = meta:get_int("technic:charge") local name = user:get_player_name() if minetest.is_protected(pointed_thing.under, name) then @@ -330,7 +330,7 @@ minetest.register_tool("technic:chainsaw", { cutter = {} -- Free RAM if not technic.creative_mode then - meta:set_int("charge", charge) + meta:set_int("technic:charge", charge) technic.set_RE_wear(itemstack, charge, chainsaw_max_charge) end return itemstack diff --git a/technic/tools/flashlight.lua b/technic/tools/flashlight.lua index b1953bb..9a47665 100644 --- a/technic/tools/flashlight.lua +++ b/technic/tools/flashlight.lua @@ -39,11 +39,11 @@ local function check_for_flashlight(player) for i = 1, 8 do if hotbar[i]:get_name() == "technic:flashlight" then local meta = technic.get_stack_meta_compat(hotbar[i]) - local charge = meta:get_int("charge") + local charge = meta:get_int("technic:charge") if charge >= 2 then if not technic.creative_mode then charge = charge - 2; - meta:set_int("charge", charge) + meta:set_int("technic:charge", charge) technic.set_RE_wear(hotbar[i], charge, flashlight_max_charge) inv:set_stack("main", i, hotbar[i]) end diff --git a/technic/tools/mining_drill.lua b/technic/tools/mining_drill.lua index 141e6f8..3403af0 100644 --- a/technic/tools/mining_drill.lua +++ b/technic/tools/mining_drill.lua @@ -279,7 +279,7 @@ local function mining_drill_mkX_handler(itemstack, user, pointed_thing, drill_ty return end - local charge = meta:get_int("charge") + local charge = meta:get_int("technic:charge") local mode = meta:contains("mode") and meta:get_int("mode") or 1 -- Check whether the tool has enough charge @@ -292,7 +292,7 @@ local function mining_drill_mkX_handler(itemstack, user, pointed_thing, drill_ty local pos = minetest.get_pointed_thing_position(pointed_thing, false) drill_dig_it(pos, user, mode) if not technic.creative_mode then - meta:set_int("charge", charge) + meta:set_int("technic:charge", charge) technic.set_RE_wear(itemstack, charge, max_charge[drill_type]) end return itemstack diff --git a/technic/tools/mining_lasers.lua b/technic/tools/mining_lasers.lua index 760f378..aea8d50 100644 --- a/technic/tools/mining_lasers.lua +++ b/technic/tools/mining_lasers.lua @@ -102,7 +102,7 @@ for _, m in pairs(mining_lasers_list) do on_refill = technic.refill_RE_charge, on_use = function(itemstack, user) local meta = technic.get_stack_meta_compat(itemstack) - local charge = meta:get_int("charge") + local charge = meta:get_int("technic:charge") if charge == 0 then return end @@ -119,7 +119,7 @@ for _, m in pairs(mining_lasers_list) do "technic_laser_mk" .. m[1]) if not technic.creative_mode then charge = math.max(charge - m[4], 0) - meta:set_int("charge", charge) + meta:set_int("technic:charge", charge) technic.set_RE_wear(itemstack, charge, m[3]) end return itemstack diff --git a/technic/tools/prospector.lua b/technic/tools/prospector.lua index f3352b2..2f4019d 100644 --- a/technic/tools/prospector.lua +++ b/technic/tools/prospector.lua @@ -7,7 +7,7 @@ local function meta_to_table(meta) local t = {} local mt = meta:to_table() - t.charge = tonumber(mt.fields.charge) or 0 + t.charge = tonumber(mt.fields["technic:charge"]) or 0 t.target = mt.fields.target or "" t.look_depth = tonumber(mt.fields.look_depth) or 7 t.look_radius = tonumber(mt.fields.look_radius) or 1 @@ -33,7 +33,7 @@ minetest.register_tool("technic:prospector", { end if not technic.creative_mode then toolmeta.charge = toolmeta.charge - charge_to_take - meta:set_int("charge", toolmeta.charge) + meta:set_int("technic:charge", toolmeta.charge) technic.set_RE_wear(toolstack, toolmeta.charge, technic.power_tools[toolstack:get_name()]) end -- What in the heaven's name is this evil sorcery ? diff --git a/technic/tools/sonic_screwdriver.lua b/technic/tools/sonic_screwdriver.lua index 4a9b17b..1778a79 100644 --- a/technic/tools/sonic_screwdriver.lua +++ b/technic/tools/sonic_screwdriver.lua @@ -42,7 +42,7 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode) -- this is consistent with the previous sonic screwdriver local meta = technic.get_stack_meta_compat(itemstack) - local charge = meta:get_int("charge") + local charge = meta:get_int("technic:charge") if charge < 100 then return end @@ -66,7 +66,7 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode) if not technic.creative_mode then charge = charge - 100 - meta:set_int("charge", charge) + meta:set_int("technic:charge", charge) technic.set_RE_wear(itemstack, charge, sonic_screwdriver_max_charge) end diff --git a/technic/tools/vacuum.lua b/technic/tools/vacuum.lua index 45c810b..3d97150 100644 --- a/technic/tools/vacuum.lua +++ b/technic/tools/vacuum.lua @@ -15,7 +15,7 @@ minetest.register_tool("technic:vacuum", { on_refill = technic.refill_RE_charge, on_use = function(itemstack, user, pointed_thing) local meta = technic.get_stack_meta_compat(itemstack) - local charge = meta:get_int("charge") + local charge = meta:get_int("technic:charge") if charge < vacuum_charge_per_object then return end @@ -44,7 +44,7 @@ minetest.register_tool("technic:vacuum", { end end - meta:set_int("charge", charge) + meta:set_int("technic:charge", charge) technic.set_RE_wear(itemstack, charge, vacuum_max_charge) return itemstack end,