mirror of
https://github.com/minetest-mods/technic.git
synced 2025-01-09 01:30:21 +01:00
Get rid of deprecated metadata (#628)
The deprecated metadata gets converted to a proper ItemStackMetaRef. All keys stay the same except for: - Cans that use `can_level` now, since they didn't store a serialized table in the metadata before. - `charge` which is now `technic:charge`, since any item (also from other mods) may have a technic charge which can cause compatibility problems. Backwards compatibility is kept but going back to older `technic` versions might result in misbehaving circuits.
This commit is contained in:
parent
410e341da5
commit
a08ba2bb93
@ -65,15 +65,26 @@ function technic.swap_node(pos, name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Returns the meta of an item
|
||||||
|
-- Gets overridden when legacy.lua is loaded
|
||||||
|
function technic.get_stack_meta(itemstack)
|
||||||
|
return itemstack:get_meta()
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Same as technic.get_stack_meta for cans
|
||||||
|
function technic.get_stack_meta_cans(itemstack)
|
||||||
|
return itemstack:get_meta()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Fully charge RE chargeable item.
|
--- Fully charge RE chargeable item.
|
||||||
-- Must be defined early to reference in item definitions.
|
-- Must be defined early to reference in item definitions.
|
||||||
function technic.refill_RE_charge(stack)
|
function technic.refill_RE_charge(stack)
|
||||||
local max_charge = technic.power_tools[stack:get_name()]
|
local max_charge = technic.power_tools[stack:get_name()]
|
||||||
if not max_charge then return stack end
|
if not max_charge then return stack end
|
||||||
|
local meta = technic.get_stack_meta(stack)
|
||||||
|
meta:set_int("technic:charge", max_charge)
|
||||||
technic.set_RE_wear(stack, max_charge, max_charge)
|
technic.set_RE_wear(stack, max_charge, max_charge)
|
||||||
local meta = minetest.deserialize(stack:get_metadata()) or {}
|
|
||||||
meta.charge = max_charge
|
|
||||||
stack:set_metadata(minetest.serialize(meta))
|
|
||||||
return stack
|
return stack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,3 +39,40 @@ for i = 0, 64 do
|
|||||||
minetest.register_alias("technic:lv_cable"..i, "technic:lv_cable")
|
minetest.register_alias("technic:lv_cable"..i, "technic:lv_cable")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Item meta
|
||||||
|
|
||||||
|
-- Meta keys that have changed
|
||||||
|
technic.legacy_meta_keys = {
|
||||||
|
["charge"] = "technic:charge",
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Converts legacy itemstack metadata string to itemstack meta and returns the ItemStackMetaRef
|
||||||
|
function technic.get_stack_meta(itemstack)
|
||||||
|
local meta = itemstack:get_meta()
|
||||||
|
local legacy_string = meta:get("") -- Get deprecated metadata
|
||||||
|
if legacy_string then
|
||||||
|
local legacy_table = minetest.deserialize(legacy_string)
|
||||||
|
if legacy_table then
|
||||||
|
local table = meta:to_table()
|
||||||
|
for k, v in pairs(legacy_table) do
|
||||||
|
table.fields[technic.legacy_meta_keys[k] or k] = v
|
||||||
|
end
|
||||||
|
meta:from_table(table)
|
||||||
|
end
|
||||||
|
meta:set_string("", "") -- Remove deprecated metadata
|
||||||
|
end
|
||||||
|
return meta
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Same as technic.get_stack_meta for cans.
|
||||||
|
-- (Cans didn't store a serialized table in the legacy metadata string, but just a number.)
|
||||||
|
function technic.get_stack_meta_cans(itemstack)
|
||||||
|
local meta = itemstack:get_meta()
|
||||||
|
local legacy_string = meta:get("") -- Get deprecated metadata
|
||||||
|
if legacy_string then
|
||||||
|
meta:set_string("can_level", legacy_string)
|
||||||
|
meta:set_string("", "") -- Remove deprecated metadata
|
||||||
|
return meta
|
||||||
|
end
|
||||||
|
return meta
|
||||||
|
end
|
||||||
|
@ -415,12 +415,8 @@ local function default_get_charge(itemstack)
|
|||||||
if not technic.power_tools[tool_name] then
|
if not technic.power_tools[tool_name] then
|
||||||
return 0, 0
|
return 0, 0
|
||||||
end
|
end
|
||||||
-- Set meta data for the tool if it didn't do it itself
|
local item_meta = technic.get_stack_meta(itemstack)
|
||||||
local item_meta = minetest.deserialize(itemstack:get_metadata()) or {}
|
return item_meta:get_int("technic:charge"), technic.power_tools[tool_name]
|
||||||
if not item_meta.charge then
|
|
||||||
item_meta.charge = 0
|
|
||||||
end
|
|
||||||
return item_meta.charge, technic.power_tools[tool_name]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function default_set_charge(itemstack, charge)
|
local function default_set_charge(itemstack, charge)
|
||||||
@ -428,9 +424,8 @@ local function default_set_charge(itemstack, charge)
|
|||||||
if technic.power_tools[tool_name] then
|
if technic.power_tools[tool_name] then
|
||||||
technic.set_RE_wear(itemstack, charge, technic.power_tools[tool_name])
|
technic.set_RE_wear(itemstack, charge, technic.power_tools[tool_name])
|
||||||
end
|
end
|
||||||
local item_meta = minetest.deserialize(itemstack:get_metadata()) or {}
|
local item_meta = technic.get_stack_meta(itemstack)
|
||||||
item_meta.charge = charge
|
item_meta:set_int("technic:charge", charge)
|
||||||
itemstack:set_metadata(minetest.serialize(item_meta))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function technic.charge_tools(meta, batt_charge, charge_step)
|
function technic.charge_tools(meta, batt_charge, charge_step)
|
||||||
|
@ -12,14 +12,6 @@ local function set_can_wear(itemstack, level, max_level)
|
|||||||
itemstack:set_wear(temp)
|
itemstack:set_wear(temp)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_can_level(itemstack)
|
|
||||||
if itemstack:get_metadata() == "" then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return tonumber(itemstack:get_metadata())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function technic.register_can(d)
|
function technic.register_can(d)
|
||||||
local data = {}
|
local data = {}
|
||||||
for k, v in pairs(d) do data[k] = v end
|
for k, v in pairs(d) do data[k] = v end
|
||||||
@ -33,7 +25,8 @@ function technic.register_can(d)
|
|||||||
if pointed_thing.type ~= "node" then return end
|
if pointed_thing.type ~= "node" then return end
|
||||||
local node = minetest.get_node(pointed_thing.under)
|
local node = minetest.get_node(pointed_thing.under)
|
||||||
if node.name ~= data.liquid_source_name then return end
|
if node.name ~= data.liquid_source_name then return end
|
||||||
local charge = get_can_level(itemstack)
|
local meta = technic.get_stack_meta_cans(itemstack)
|
||||||
|
local charge = meta:get_int("can_level")
|
||||||
if charge == data.can_capacity then return end
|
if charge == data.can_capacity then return end
|
||||||
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
|
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
|
||||||
minetest.log("action", user:get_player_name()..
|
minetest.log("action", user:get_player_name()..
|
||||||
@ -44,7 +37,7 @@ function technic.register_can(d)
|
|||||||
end
|
end
|
||||||
minetest.remove_node(pointed_thing.under)
|
minetest.remove_node(pointed_thing.under)
|
||||||
charge = charge + 1
|
charge = charge + 1
|
||||||
itemstack:set_metadata(tostring(charge))
|
meta:set_int("can_level", charge)
|
||||||
set_can_wear(itemstack, charge, data.can_capacity)
|
set_can_wear(itemstack, charge, data.can_capacity)
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
@ -63,7 +56,8 @@ function technic.register_can(d)
|
|||||||
-- Try to place node above the pointed source, or abort.
|
-- Try to place node above the pointed source, or abort.
|
||||||
if not def.buildable_to or node_name == data.liquid_source_name then return end
|
if not def.buildable_to or node_name == data.liquid_source_name then return end
|
||||||
end
|
end
|
||||||
local charge = get_can_level(itemstack)
|
local meta = technic.get_stack_meta_cans(itemstack)
|
||||||
|
local charge = meta:get_int("can_level")
|
||||||
if charge == 0 then return end
|
if charge == 0 then return end
|
||||||
if minetest.is_protected(pos, user:get_player_name()) then
|
if minetest.is_protected(pos, user:get_player_name()) then
|
||||||
minetest.log("action", user:get_player_name()..
|
minetest.log("action", user:get_player_name()..
|
||||||
@ -74,12 +68,13 @@ function technic.register_can(d)
|
|||||||
end
|
end
|
||||||
minetest.set_node(pos, {name=data.liquid_source_name})
|
minetest.set_node(pos, {name=data.liquid_source_name})
|
||||||
charge = charge - 1
|
charge = charge - 1
|
||||||
itemstack:set_metadata(tostring(charge))
|
meta:set_int("can_level", charge)
|
||||||
set_can_wear(itemstack, charge, data.can_capacity)
|
set_can_wear(itemstack, charge, data.can_capacity)
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
on_refill = function(stack)
|
on_refill = function(stack)
|
||||||
stack:set_metadata(tostring(data.can_capacity))
|
local meta = technic.get_stack_meta_cans(stack)
|
||||||
|
meta:set_int("can_level", data.can_capacity)
|
||||||
set_can_wear(stack, data.can_capacity, data.can_capacity)
|
set_can_wear(stack, data.can_capacity, data.can_capacity)
|
||||||
return stack
|
return stack
|
||||||
end,
|
end,
|
||||||
|
@ -313,10 +313,8 @@ minetest.register_tool("technic:chainsaw", {
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
local meta = technic.get_stack_meta(itemstack)
|
||||||
if not meta or not meta.charge then
|
local charge = meta:get_int("technic:charge")
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local name = user:get_player_name()
|
local name = user:get_player_name()
|
||||||
if minetest.is_protected(pointed_thing.under, name) then
|
if minetest.is_protected(pointed_thing.under, name) then
|
||||||
@ -326,14 +324,14 @@ minetest.register_tool("technic:chainsaw", {
|
|||||||
|
|
||||||
-- Send current charge to digging function so that the
|
-- Send current charge to digging function so that the
|
||||||
-- chainsaw will stop after digging a number of nodes
|
-- chainsaw will stop after digging a number of nodes
|
||||||
chainsaw_dig(user, pointed_thing.under, meta.charge)
|
chainsaw_dig(user, pointed_thing.under, charge)
|
||||||
meta.charge = cutter.charge
|
charge = cutter.charge
|
||||||
|
|
||||||
cutter = {} -- Free RAM
|
cutter = {} -- Free RAM
|
||||||
|
|
||||||
if not technic.creative_mode then
|
if not technic.creative_mode then
|
||||||
technic.set_RE_wear(itemstack, meta.charge, chainsaw_max_charge)
|
meta:set_int("technic:charge", charge)
|
||||||
itemstack:set_metadata(minetest.serialize(meta))
|
technic.set_RE_wear(itemstack, charge, chainsaw_max_charge)
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
|
@ -38,12 +38,13 @@ local function check_for_flashlight(player)
|
|||||||
local hotbar = inv:get_list("main")
|
local hotbar = inv:get_list("main")
|
||||||
for i = 1, 8 do
|
for i = 1, 8 do
|
||||||
if hotbar[i]:get_name() == "technic:flashlight" then
|
if hotbar[i]:get_name() == "technic:flashlight" then
|
||||||
local meta = minetest.deserialize(hotbar[i]:get_metadata())
|
local meta = technic.get_stack_meta(hotbar[i])
|
||||||
if meta and meta.charge and meta.charge >= 2 then
|
local charge = meta:get_int("technic:charge")
|
||||||
|
if charge >= 2 then
|
||||||
if not technic.creative_mode then
|
if not technic.creative_mode then
|
||||||
meta.charge = meta.charge - 2;
|
charge = charge - 2;
|
||||||
technic.set_RE_wear(hotbar[i], meta.charge, flashlight_max_charge)
|
meta:set_int("technic:charge", charge)
|
||||||
hotbar[i]:set_metadata(minetest.serialize(meta))
|
technic.set_RE_wear(hotbar[i], charge, flashlight_max_charge)
|
||||||
inv:set_stack("main", i, hotbar[i])
|
inv:set_stack("main", i, hotbar[i])
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
@ -248,54 +248,53 @@ end
|
|||||||
|
|
||||||
local function mining_drill_mkX_setmode(user, itemstack, drill_type, max_modes)
|
local function mining_drill_mkX_setmode(user, itemstack, drill_type, max_modes)
|
||||||
local player_name = user:get_player_name()
|
local player_name = user:get_player_name()
|
||||||
local meta = minetest.deserialize(itemstack:get_metadata()) or {}
|
local meta = technic.get_stack_meta(itemstack)
|
||||||
|
|
||||||
if not meta["mode"] then
|
if not meta:contains("mode") then
|
||||||
minetest.chat_send_player(player_name,
|
minetest.chat_send_player(player_name,
|
||||||
S("Use while sneaking to change Mining Drill Mk%d modes."):format(drill_type))
|
S("Use while sneaking to change Mining Drill Mk%d modes."):format(drill_type))
|
||||||
end
|
end
|
||||||
local mode = (meta["mode"] or 0) + 1
|
local mode = meta:get_int("mode") + 1
|
||||||
if mode > max_modes then mode = 1 end
|
if mode > max_modes then mode = 1 end
|
||||||
|
|
||||||
minetest.chat_send_player(player_name,
|
minetest.chat_send_player(player_name,
|
||||||
S("Mining Drill Mk%d Mode %d"):format(2, mode)..
|
S("Mining Drill Mk%d Mode %d"):format(2, mode)..
|
||||||
": "..mining_drill_mode_text[mode][1])
|
": "..mining_drill_mode_text[mode][1])
|
||||||
itemstack:set_name(("technic:mining_drill_mk%d_%s"):format(drill_type, mode))
|
itemstack:set_name(("technic:mining_drill_mk%d_%s"):format(drill_type, mode))
|
||||||
meta["mode"] = mode
|
meta:set_int("mode", mode)
|
||||||
itemstack:set_metadata(minetest.serialize(meta))
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
local function mining_drill_mkX_handler(itemstack, user, pointed_thing, drill_type, max_modes)
|
local function mining_drill_mkX_handler(itemstack, user, pointed_thing, drill_type, max_modes)
|
||||||
local keys = user:get_player_control()
|
local keys = user:get_player_control()
|
||||||
local meta = minetest.deserialize(itemstack:get_metadata()) or {}
|
local meta = technic.get_stack_meta(itemstack)
|
||||||
|
|
||||||
-- Mode switching (if possible)
|
-- Mode switching (if possible)
|
||||||
if max_modes > 1 then
|
if max_modes > 1 then
|
||||||
if not meta.mode or keys.sneak then
|
if not meta:contains("mode") or keys.sneak then
|
||||||
return mining_drill_mkX_setmode(user, itemstack, drill_type, max_modes)
|
return mining_drill_mkX_setmode(user, itemstack, drill_type, max_modes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pointed_thing.type ~= "node" or not pos_is_pointable(pointed_thing.under) then
|
if pointed_thing.type ~= "node" or not pos_is_pointable(pointed_thing.under) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not meta.charge then
|
|
||||||
return
|
local charge = meta:get_int("technic:charge")
|
||||||
end
|
local mode = meta:contains("mode") and meta:get_int("mode") or 1
|
||||||
|
|
||||||
-- Check whether the tool has enough charge
|
-- Check whether the tool has enough charge
|
||||||
local charge_to_take = cost_to_use(drill_type, meta.mode or 1)
|
local charge_to_take = cost_to_use(drill_type, mode)
|
||||||
if meta.charge < charge_to_take then
|
if charge < charge_to_take then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Do the actual shoorting action
|
-- Do the actual shoorting action
|
||||||
local pos = minetest.get_pointed_thing_position(pointed_thing, false)
|
local pos = minetest.get_pointed_thing_position(pointed_thing, false)
|
||||||
drill_dig_it(pos, user, meta.mode or 1)
|
drill_dig_it(pos, user, mode)
|
||||||
if not technic.creative_mode then
|
if not technic.creative_mode then
|
||||||
meta.charge = meta.charge - charge_to_take
|
charge = charge - charge_to_take
|
||||||
itemstack:set_metadata(minetest.serialize(meta))
|
meta:set_int("technic:charge", charge)
|
||||||
technic.set_RE_wear(itemstack, meta.charge, max_charge[drill_type])
|
technic.set_RE_wear(itemstack, charge, max_charge[drill_type])
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
@ -101,25 +101,26 @@ for _, m in pairs(mining_lasers_list) do
|
|||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
on_refill = technic.refill_RE_charge,
|
on_refill = technic.refill_RE_charge,
|
||||||
on_use = function(itemstack, user)
|
on_use = function(itemstack, user)
|
||||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
local meta = technic.get_stack_meta(itemstack)
|
||||||
if not meta or not meta.charge or meta.charge == 0 then
|
local charge = meta:get_int("technic:charge")
|
||||||
|
if charge == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local range = m[2]
|
local range = m[2]
|
||||||
if meta.charge < m[4] then
|
if charge < m[4] then
|
||||||
if not allow_entire_discharging then
|
if not allow_entire_discharging then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- If charge is too low, give the laser a shorter range
|
-- If charge is too low, give the laser a shorter range
|
||||||
range = range * meta.charge / m[4]
|
range = range * charge / m[4]
|
||||||
end
|
end
|
||||||
laser_shoot(user, range, "technic_laser_beam_mk" .. m[1] .. ".png",
|
laser_shoot(user, range, "technic_laser_beam_mk" .. m[1] .. ".png",
|
||||||
"technic_laser_mk" .. m[1])
|
"technic_laser_mk" .. m[1])
|
||||||
if not technic.creative_mode then
|
if not technic.creative_mode then
|
||||||
meta.charge = math.max(meta.charge - m[4], 0)
|
charge = math.max(charge - m[4], 0)
|
||||||
technic.set_RE_wear(itemstack, meta.charge, m[3])
|
meta:set_int("technic:charge", charge)
|
||||||
itemstack:set_metadata(minetest.serialize(meta))
|
technic.set_RE_wear(itemstack, charge, m[3])
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
|
@ -2,14 +2,16 @@ local S = technic.getter
|
|||||||
|
|
||||||
technic.register_power_tool("technic:prospector", 300000)
|
technic.register_power_tool("technic:prospector", 300000)
|
||||||
|
|
||||||
local function get_metadata(toolstack)
|
-- Helper function to consolidate ItemStackMetaRef access and initialize
|
||||||
local m = minetest.deserialize(toolstack:get_metadata())
|
local function meta_to_table(meta)
|
||||||
if not m then m = {} end
|
local t = {}
|
||||||
if not m.charge then m.charge = 0 end
|
local mt = meta:to_table()
|
||||||
if not m.target then m.target = "" end
|
|
||||||
if not m.look_depth then m.look_depth = 7 end
|
t.charge = tonumber(mt.fields["technic:charge"]) or 0
|
||||||
if not m.look_radius then m.look_radius = 1 end
|
t.target = mt.fields.target or ""
|
||||||
return m
|
t.look_depth = tonumber(mt.fields.look_depth) or 7
|
||||||
|
t.look_radius = tonumber(mt.fields.look_radius) or 1
|
||||||
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_tool("technic:prospector", {
|
minetest.register_tool("technic:prospector", {
|
||||||
@ -20,7 +22,8 @@ minetest.register_tool("technic:prospector", {
|
|||||||
on_use = function(toolstack, user, pointed_thing)
|
on_use = function(toolstack, user, pointed_thing)
|
||||||
if not user or not user:is_player() or user.is_fake_player then return end
|
if not user or not user:is_player() or user.is_fake_player then return end
|
||||||
if pointed_thing.type ~= "node" then return end
|
if pointed_thing.type ~= "node" then return end
|
||||||
local toolmeta = get_metadata(toolstack)
|
local meta = technic.get_stack_meta(toolstack)
|
||||||
|
local toolmeta = meta_to_table(meta)
|
||||||
local look_diameter = toolmeta.look_radius * 2 + 1
|
local look_diameter = toolmeta.look_radius * 2 + 1
|
||||||
local charge_to_take = toolmeta.look_depth * (toolmeta.look_depth + 1) * look_diameter * look_diameter
|
local charge_to_take = toolmeta.look_depth * (toolmeta.look_depth + 1) * look_diameter * look_diameter
|
||||||
if toolmeta.charge < charge_to_take then return end
|
if toolmeta.charge < charge_to_take then return end
|
||||||
@ -30,7 +33,7 @@ minetest.register_tool("technic:prospector", {
|
|||||||
end
|
end
|
||||||
if not technic.creative_mode then
|
if not technic.creative_mode then
|
||||||
toolmeta.charge = toolmeta.charge - charge_to_take
|
toolmeta.charge = toolmeta.charge - charge_to_take
|
||||||
toolstack:set_metadata(minetest.serialize(toolmeta))
|
meta:set_int("technic:charge", toolmeta.charge)
|
||||||
technic.set_RE_wear(toolstack, toolmeta.charge, technic.power_tools[toolstack:get_name()])
|
technic.set_RE_wear(toolstack, toolmeta.charge, technic.power_tools[toolstack:get_name()])
|
||||||
end
|
end
|
||||||
-- What in the heaven's name is this evil sorcery ?
|
-- What in the heaven's name is this evil sorcery ?
|
||||||
@ -77,7 +80,8 @@ minetest.register_tool("technic:prospector", {
|
|||||||
end,
|
end,
|
||||||
on_place = function(toolstack, user, pointed_thing)
|
on_place = function(toolstack, user, pointed_thing)
|
||||||
if not user or not user:is_player() or user.is_fake_player then return end
|
if not user or not user:is_player() or user.is_fake_player then return end
|
||||||
local toolmeta = get_metadata(toolstack)
|
local meta = technic.get_stack_meta(toolstack)
|
||||||
|
local toolmeta = meta_to_table(meta)
|
||||||
local pointed
|
local pointed
|
||||||
if pointed_thing.type == "node" then
|
if pointed_thing.type == "node" then
|
||||||
local pname = minetest.get_node(pointed_thing.under).name
|
local pname = minetest.get_node(pointed_thing.under).name
|
||||||
@ -125,19 +129,16 @@ minetest.register_on_player_receive_fields(function(user, formname, fields)
|
|||||||
if not user or not user:is_player() or user.is_fake_player then return end
|
if not user or not user:is_player() or user.is_fake_player then return end
|
||||||
local toolstack = user:get_wielded_item()
|
local toolstack = user:get_wielded_item()
|
||||||
if toolstack:get_name() ~= "technic:prospector" then return true end
|
if toolstack:get_name() ~= "technic:prospector" then return true end
|
||||||
local toolmeta = get_metadata(toolstack)
|
local meta = technic.get_stack_meta(toolstack)
|
||||||
for field, value in pairs(fields) do
|
for field, value in pairs(fields) do
|
||||||
if field:sub(1, 7) == "target_" then
|
if field:sub(1, 7) == "target_" then
|
||||||
toolmeta.target = field:sub(8)
|
meta:set_string("target", field:sub(8))
|
||||||
end
|
elseif field:sub(1, 12) == "look_radius_" then
|
||||||
if field:sub(1, 12) == "look_radius_" then
|
meta:set_string("look_radius", field:sub(13))
|
||||||
toolmeta.look_radius = field:sub(13)
|
elseif field:sub(1, 11) == "look_depth_" then
|
||||||
end
|
meta:set_string("look_depth", field:sub(12))
|
||||||
if field:sub(1, 11) == "look_depth_" then
|
|
||||||
toolmeta.look_depth = field:sub(12)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
toolstack:set_metadata(minetest.serialize(toolmeta))
|
|
||||||
user:set_wielded_item(toolstack)
|
user:set_wielded_item(toolstack)
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
@ -41,8 +41,9 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode)
|
|||||||
-- contrary to the default screwdriver, do not check for can_dig, to allow rotating machines with CLU's in them
|
-- contrary to the default screwdriver, do not check for can_dig, to allow rotating machines with CLU's in them
|
||||||
-- this is consistent with the previous sonic screwdriver
|
-- this is consistent with the previous sonic screwdriver
|
||||||
|
|
||||||
local meta1 = minetest.deserialize(itemstack:get_metadata())
|
local meta = technic.get_stack_meta(itemstack)
|
||||||
if not meta1 or not meta1.charge or meta1.charge < 100 then
|
local charge = meta:get_int("technic:charge")
|
||||||
|
if charge < 100 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -64,9 +65,9 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode)
|
|||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
|
|
||||||
if not technic.creative_mode then
|
if not technic.creative_mode then
|
||||||
meta1.charge = meta1.charge - 100
|
charge = charge - 100
|
||||||
itemstack:set_metadata(minetest.serialize(meta1))
|
meta:set_int("technic:charge", charge)
|
||||||
technic.set_RE_wear(itemstack, meta1.charge, sonic_screwdriver_max_charge)
|
technic.set_RE_wear(itemstack, charge, sonic_screwdriver_max_charge)
|
||||||
end
|
end
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
|
@ -14,24 +14,23 @@ minetest.register_tool("technic:vacuum", {
|
|||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
on_refill = technic.refill_RE_charge,
|
on_refill = technic.refill_RE_charge,
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
local meta = technic.get_stack_meta(itemstack)
|
||||||
if not meta or not meta.charge then
|
local charge = meta:get_int("technic:charge")
|
||||||
|
if charge < vacuum_charge_per_object then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if meta.charge > vacuum_charge_per_object then
|
minetest.sound_play("vacuumcleaner", {
|
||||||
minetest.sound_play("vacuumcleaner", {
|
to_player = user:get_player_name(),
|
||||||
to_player = user:get_player_name(),
|
gain = 0.4,
|
||||||
gain = 0.4,
|
})
|
||||||
})
|
|
||||||
end
|
|
||||||
local pos = user:get_pos()
|
local pos = user:get_pos()
|
||||||
local inv = user:get_inventory()
|
local inv = user:get_inventory()
|
||||||
for _, object in ipairs(minetest.get_objects_inside_radius(pos, vacuum_range)) do
|
for _, object in ipairs(minetest.get_objects_inside_radius(pos, vacuum_range)) do
|
||||||
local luaentity = object:get_luaentity()
|
local luaentity = object:get_luaentity()
|
||||||
if not object:is_player() and luaentity and luaentity.name == "__builtin:item" and luaentity.itemstring ~= "" then
|
if not object:is_player() and luaentity and luaentity.name == "__builtin:item" and luaentity.itemstring ~= "" then
|
||||||
if inv and inv:room_for_item("main", ItemStack(luaentity.itemstring)) then
|
if inv and inv:room_for_item("main", ItemStack(luaentity.itemstring)) then
|
||||||
meta.charge = meta.charge - vacuum_charge_per_object
|
charge = charge - vacuum_charge_per_object
|
||||||
if meta.charge < vacuum_charge_per_object then
|
if charge < vacuum_charge_per_object then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
inv:add_item("main", ItemStack(luaentity.itemstring))
|
inv:add_item("main", ItemStack(luaentity.itemstring))
|
||||||
@ -45,8 +44,8 @@ minetest.register_tool("technic:vacuum", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
technic.set_RE_wear(itemstack, meta.charge, vacuum_max_charge)
|
meta:set_int("technic:charge", charge)
|
||||||
itemstack:set_metadata(minetest.serialize(meta))
|
technic.set_RE_wear(itemstack, charge, vacuum_max_charge)
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user