mirror of
https://github.com/minetest-mods/technic.git
synced 2024-11-14 06:20:41 +01:00
Rename get_stack_meta_compat and add non-compat version
This commit is contained in:
parent
15ced081e3
commit
287b3676b4
|
@ -65,12 +65,24 @@ function technic.swap_node(pos, name)
|
|||
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.
|
||||
-- Must be defined early to reference in item definitions.
|
||||
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)
|
||||
local meta = technic.get_stack_meta(stack)
|
||||
meta:set_int("technic:charge", max_charge)
|
||||
technic.set_RE_wear(stack, max_charge, max_charge)
|
||||
return stack
|
||||
|
|
|
@ -47,7 +47,7 @@ technic.legacy_meta_keys = {
|
|||
}
|
||||
|
||||
-- Converts legacy itemstack metadata string to itemstack meta and returns the ItemStackMetaRef
|
||||
function technic.get_stack_meta_compat(itemstack)
|
||||
function technic.get_stack_meta(itemstack)
|
||||
local meta = itemstack:get_meta()
|
||||
local legacy_string = meta:get("") -- Get deprecated metadata
|
||||
if legacy_string then
|
||||
|
@ -69,9 +69,9 @@ function technic.get_stack_meta_compat(itemstack)
|
|||
return meta
|
||||
end
|
||||
|
||||
-- Same as technic.get_stack_meta_compat for cans.
|
||||
-- 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_compat_cans(itemstack)
|
||||
function technic.get_stack_meta_cans(itemstack)
|
||||
local meta = itemstack:get_meta()
|
||||
local legacy_string = meta:get("") -- Get deprecated metadata
|
||||
if legacy_string then
|
||||
|
|
|
@ -415,7 +415,7 @@ local function default_get_charge(itemstack)
|
|||
if not technic.power_tools[tool_name] then
|
||||
return 0, 0
|
||||
end
|
||||
local item_meta = technic.get_stack_meta_compat(itemstack)
|
||||
local item_meta = technic.get_stack_meta(itemstack)
|
||||
return item_meta:get_int("technic:charge"), technic.power_tools[tool_name]
|
||||
end
|
||||
|
||||
|
@ -424,7 +424,7 @@ local function default_set_charge(itemstack, charge)
|
|||
if technic.power_tools[tool_name] then
|
||||
technic.set_RE_wear(itemstack, charge, technic.power_tools[tool_name])
|
||||
end
|
||||
local item_meta = technic.get_stack_meta_compat(itemstack)
|
||||
local item_meta = technic.get_stack_meta(itemstack)
|
||||
item_meta:set_int("technic:charge", charge)
|
||||
end
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ function technic.register_can(d)
|
|||
if pointed_thing.type ~= "node" then return end
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
if node.name ~= data.liquid_source_name then return end
|
||||
local meta = technic.get_stack_meta_compat_cans(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 minetest.is_protected(pointed_thing.under, user:get_player_name()) then
|
||||
|
@ -56,7 +56,7 @@ function technic.register_can(d)
|
|||
-- 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
|
||||
end
|
||||
local meta = technic.get_stack_meta_compat_cans(itemstack)
|
||||
local meta = technic.get_stack_meta_cans(itemstack)
|
||||
local charge = meta:get_int("can_level")
|
||||
if charge == 0 then return end
|
||||
if minetest.is_protected(pos, user:get_player_name()) then
|
||||
|
@ -73,7 +73,7 @@ function technic.register_can(d)
|
|||
return itemstack
|
||||
end,
|
||||
on_refill = function(stack)
|
||||
local meta = technic.get_stack_meta_compat_cans(stack)
|
||||
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)
|
||||
return stack
|
||||
|
|
|
@ -313,7 +313,7 @@ minetest.register_tool("technic:chainsaw", {
|
|||
return itemstack
|
||||
end
|
||||
|
||||
local meta = technic.get_stack_meta_compat(itemstack)
|
||||
local meta = technic.get_stack_meta(itemstack)
|
||||
local charge = meta:get_int("technic:charge")
|
||||
|
||||
local name = user:get_player_name()
|
||||
|
|
|
@ -38,7 +38,7 @@ local function check_for_flashlight(player)
|
|||
local hotbar = inv:get_list("main")
|
||||
for i = 1, 8 do
|
||||
if hotbar[i]:get_name() == "technic:flashlight" then
|
||||
local meta = technic.get_stack_meta_compat(hotbar[i])
|
||||
local meta = technic.get_stack_meta(hotbar[i])
|
||||
local charge = meta:get_int("technic:charge")
|
||||
if charge >= 2 then
|
||||
if not technic.creative_mode then
|
||||
|
|
|
@ -248,7 +248,7 @@ end
|
|||
|
||||
local function mining_drill_mkX_setmode(user, itemstack, drill_type, max_modes)
|
||||
local player_name = user:get_player_name()
|
||||
local meta = technic.get_stack_meta_compat(itemstack)
|
||||
local meta = technic.get_stack_meta(itemstack)
|
||||
|
||||
if not meta:contains("mode") then
|
||||
minetest.chat_send_player(player_name,
|
||||
|
@ -267,7 +267,7 @@ end
|
|||
|
||||
local function mining_drill_mkX_handler(itemstack, user, pointed_thing, drill_type, max_modes)
|
||||
local keys = user:get_player_control()
|
||||
local meta = technic.get_stack_meta_compat(itemstack)
|
||||
local meta = technic.get_stack_meta(itemstack)
|
||||
|
||||
-- Mode switching (if possible)
|
||||
if max_modes > 1 then
|
||||
|
|
|
@ -101,7 +101,7 @@ for _, m in pairs(mining_lasers_list) do
|
|||
wear_represents = "technic_RE_charge",
|
||||
on_refill = technic.refill_RE_charge,
|
||||
on_use = function(itemstack, user)
|
||||
local meta = technic.get_stack_meta_compat(itemstack)
|
||||
local meta = technic.get_stack_meta(itemstack)
|
||||
local charge = meta:get_int("technic:charge")
|
||||
if charge == 0 then
|
||||
return
|
||||
|
|
|
@ -22,7 +22,7 @@ minetest.register_tool("technic:prospector", {
|
|||
on_use = function(toolstack, user, pointed_thing)
|
||||
if not user or not user:is_player() or user.is_fake_player then return end
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
local meta = technic.get_stack_meta_compat(toolstack)
|
||||
local meta = technic.get_stack_meta(toolstack)
|
||||
local toolmeta = meta_to_table(meta)
|
||||
local look_diameter = toolmeta.look_radius * 2 + 1
|
||||
local charge_to_take = toolmeta.look_depth * (toolmeta.look_depth + 1) * look_diameter * look_diameter
|
||||
|
@ -80,7 +80,7 @@ minetest.register_tool("technic:prospector", {
|
|||
end,
|
||||
on_place = function(toolstack, user, pointed_thing)
|
||||
if not user or not user:is_player() or user.is_fake_player then return end
|
||||
local meta = technic.get_stack_meta_compat(toolstack)
|
||||
local meta = technic.get_stack_meta(toolstack)
|
||||
local toolmeta = meta_to_table(meta)
|
||||
local pointed
|
||||
if pointed_thing.type == "node" then
|
||||
|
@ -129,7 +129,7 @@ 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
|
||||
local toolstack = user:get_wielded_item()
|
||||
if toolstack:get_name() ~= "technic:prospector" then return true end
|
||||
local meta = technic.get_stack_meta_compat(toolstack)
|
||||
local meta = technic.get_stack_meta(toolstack)
|
||||
for field, value in pairs(fields) do
|
||||
if field:sub(1, 7) == "target_" then
|
||||
meta:set_string("target", field:sub(8))
|
||||
|
|
|
@ -41,7 +41,7 @@ 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
|
||||
-- this is consistent with the previous sonic screwdriver
|
||||
|
||||
local meta = technic.get_stack_meta_compat(itemstack)
|
||||
local meta = technic.get_stack_meta(itemstack)
|
||||
local charge = meta:get_int("technic:charge")
|
||||
if charge < 100 then
|
||||
return
|
||||
|
|
|
@ -14,7 +14,7 @@ minetest.register_tool("technic:vacuum", {
|
|||
wear_represents = "technic_RE_charge",
|
||||
on_refill = technic.refill_RE_charge,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
local meta = technic.get_stack_meta_compat(itemstack)
|
||||
local meta = technic.get_stack_meta(itemstack)
|
||||
local charge = meta:get_int("technic:charge")
|
||||
if charge < vacuum_charge_per_object then
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user