1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2025-06-29 14:50:41 +02:00

Replace minetest namespace with core (#158)

Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com>
This commit is contained in:
The4codeblocks
2025-06-26 02:41:04 -05:00
committed by GitHub
parent d39ff8a097
commit 2ebc4ac92d
34 changed files with 619 additions and 617 deletions

View File

@ -1,6 +1,6 @@
local S = minetest.get_translator("pipeworks")
local S = core.get_translator("pipeworks")
-- cache some recipe data to avoid calling the slow function
-- minetest.get_craft_result() every second
-- core.get_craft_result() every second
local autocrafterCache = {}
local craft_time = 1
@ -20,7 +20,7 @@ end
local function get_item_info(stack)
local name = stack:get_name()
local def = minetest.registered_items[name]
local def = core.registered_items[name]
local description = def and def.description or S("Unknown item")
return description, name
end
@ -28,7 +28,7 @@ end
-- Get best matching recipe for what user has put in crafting grid.
-- This function does not consider crafting method (mix vs craft)
local function get_matching_craft(output_name, example_recipe)
local recipes = minetest.get_all_craft_recipes(output_name)
local recipes = core.get_all_craft_recipes(output_name)
if not recipes then
return example_recipe
end
@ -49,7 +49,7 @@ local function get_matching_craft(output_name, example_recipe)
elseif recipe_item_name:sub(1, 6) == "group:" then
group = recipe_item_name:sub(7)
for example_item_name, _ in pairs(index_example) do
if minetest.get_item_group(
if core.get_item_group(
example_item_name, group) ~= 0
then
score = score + 1
@ -68,12 +68,12 @@ local function get_matching_craft(output_name, example_recipe)
end
local function get_craft(pos, inventory, hash)
local hash = hash or minetest.hash_node_position(pos)
local hash = hash or core.hash_node_position(pos)
local craft = autocrafterCache[hash]
if craft then return craft end
local example_recipe = inventory:get_list("recipe")
local output, decremented_input = minetest.get_craft_result({
local output, decremented_input = core.get_craft_result({
method = "normal", width = 3, items = example_recipe
})
@ -132,7 +132,7 @@ local function calculate_consumption(inv_index, consumption_with_groups)
local found = 0
local count_ingredient_groups = #ingredient_groups
for i = 1, count_ingredient_groups do
if minetest.get_item_group(name,
if core.get_item_group(name,
ingredient_groups[i]) ~= 0
then
found = found + 1
@ -241,7 +241,7 @@ local function autocraft(inventory, craft)
for i = 1, 9 do
leftover = inventory:add_item("dst", craft.decremented_input[i])
if leftover and not leftover:is_empty() then
minetest.log("warning", "[pipeworks] autocrafter didn't " ..
core.log("warning", "[pipeworks] autocrafter didn't " ..
"calculate output space correctly.")
end
end
@ -252,7 +252,7 @@ end
-- is started only from start_autocrafter(pos) after sanity checks and
-- recipe is cached
local function run_autocrafter(pos, elapsed)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
local inventory = meta:get_inventory()
local craft = get_craft(pos, inventory)
local output_item = craft.output.item
@ -270,9 +270,9 @@ local function run_autocrafter(pos, elapsed)
end
local function start_crafter(pos)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
if meta:get_int("enabled") == 1 then
local timer = minetest.get_node_timer(pos)
local timer = core.get_node_timer(pos)
if not timer:is_started() then
timer:start(craft_time)
end
@ -286,12 +286,12 @@ end
-- note, that this function assumes allready being updated to virtual items
-- and doesn't handle recipes with stacksizes > 1
local function after_recipe_change(pos, inventory)
local hash = minetest.hash_node_position(pos)
local meta = minetest.get_meta(pos)
local hash = core.hash_node_position(pos)
local meta = core.get_meta(pos)
autocrafterCache[hash] = nil
-- if we emptied the grid, there's no point in keeping it running or cached
if inventory:is_empty("recipe") then
minetest.get_node_timer(pos):stop()
core.get_node_timer(pos):stop()
meta:set_string("infotext", S("unconfigured Autocrafter"))
inventory:set_stack("output", 1, "")
return
@ -307,12 +307,12 @@ end
-- clean out unknown items and groups, which would be handled like unknown
-- items in the crafting grid
-- if minetest supports query by group one day, this might replace them
-- if Luanti supports query by group one day, this might replace them
-- with a canonical version instead
local function normalize(item_list)
for i = 1, #item_list do
local name = item_list[i]
if not minetest.registered_items[name] then
if not core.registered_items[name] then
item_list[i] = ""
end
end
@ -324,7 +324,7 @@ local function on_output_change(pos, inventory, stack)
inventory:set_list("output", {})
inventory:set_list("recipe", {})
else
local input = minetest.get_craft_recipe(stack:get_name())
local input = core.get_craft_recipe(stack:get_name())
if not input.items or input.type ~= "normal" then return end
local items, width = normalize(input.items), input.width
local item_idx, width_idx = 1, 1
@ -349,7 +349,7 @@ local function update_meta(meta, enabled)
local state = enabled and "on" or "off"
meta:set_int("enabled", enabled and 1 or 0)
local list_backgrounds = ""
if minetest.get_modpath("i3") or minetest.get_modpath("mcl_formspec") then
if core.get_modpath("i3") or core.get_modpath("mcl_formspec") then
list_backgrounds = "style_type[box;colors=#666]"
for i = 0, 2 do
for j = 0, 2 do
@ -389,7 +389,7 @@ local function update_meta(meta, enabled)
"listring[current_player;main]" ..
"listring[context;dst]" ..
"listring[current_player;main]"
if minetest.get_modpath("digilines") then
if core.get_modpath("digilines") then
fs = fs .. "field[0.22,4.1;4.5,0.75;channel;" .. S("Channel") ..
";${channel}]" ..
"button[5,4.1;1.5,0.75;set_channel;" .. S("Set") .. "]" ..
@ -422,7 +422,7 @@ end
-- so we work out way backwards on this history and update each single case
-- to the newest version
local function upgrade_autocrafter(pos, meta)
local meta = meta or minetest.get_meta(pos)
local meta = meta or core.get_meta(pos)
local inv = meta:get_inventory()
if inv:get_size("output") == 0 then -- we are version 2 or 1
@ -439,7 +439,7 @@ local function upgrade_autocrafter(pos, meta)
if not recipe then return end
for idx, stack in ipairs(recipe) do
if not stack:is_empty() then
minetest.add_item(pos, stack)
core.add_item(pos, stack)
stack:set_count(1)
stack:set_wear(0)
inv:set_stack("recipe", idx, stack)
@ -448,12 +448,12 @@ local function upgrade_autocrafter(pos, meta)
end
-- update the recipe, cache, and start the crafter
autocrafterCache[minetest.hash_node_position(pos)] = nil
autocrafterCache[core.hash_node_position(pos)] = nil
after_recipe_change(pos, inv)
end
end
minetest.register_node("pipeworks:autocrafter", {
core.register_node("pipeworks:autocrafter", {
description = S("Autocrafter"),
drawtype = "normal",
tiles = {"pipeworks_autocrafter.png"},
@ -461,14 +461,14 @@ minetest.register_node("pipeworks:autocrafter", {
is_ground_content = false,
_mcl_hardness=0.8,
tube = {insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
local added = inv:add_item("src", stack)
after_inventory_change(pos)
return added
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
return inv:room_for_item("src", stack)
end,
@ -478,7 +478,7 @@ minetest.register_node("pipeworks:autocrafter", {
}
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("src", 3 * 8)
inv:set_size("recipe", 3 * 3)
@ -492,10 +492,10 @@ minetest.register_node("pipeworks:autocrafter", {
then
return
end
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
if fields.on then
update_meta(meta, false)
minetest.get_node_timer(pos):stop()
core.get_node_timer(pos):stop()
elseif fields.off then
if update_meta(meta, true) then
start_crafter(pos)
@ -507,7 +507,7 @@ minetest.register_node("pipeworks:autocrafter", {
end,
can_dig = function(pos, player)
upgrade_autocrafter(pos)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
return (inv:is_empty("src") and inv:is_empty("dst"))
end,
@ -516,12 +516,12 @@ minetest.register_node("pipeworks:autocrafter", {
pipeworks.scan_for_tube_objects(pos)
end,
on_destruct = function(pos)
autocrafterCache[minetest.hash_node_position(pos)] = nil
autocrafterCache[core.hash_node_position(pos)] = nil
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if not pipeworks.may_configure(pos, player) then return 0 end
upgrade_autocrafter(pos)
local inv = minetest.get_meta(pos):get_inventory()
local inv = core.get_meta(pos):get_inventory()
if listname == "recipe" then
stack:set_count(1)
inv:set_stack(listname, index, stack)
@ -536,13 +536,13 @@ minetest.register_node("pipeworks:autocrafter", {
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if not pipeworks.may_configure(pos, player) then
minetest.log("action", string.format("%s attempted to take from " ..
core.log("action", string.format("%s attempted to take from " ..
"autocrafter at %s",
player:get_player_name(), minetest.pos_to_string(pos)))
player:get_player_name(), core.pos_to_string(pos)))
return 0
end
upgrade_autocrafter(pos)
local inv = minetest.get_meta(pos):get_inventory()
local inv = core.get_meta(pos):get_inventory()
if listname == "recipe" then
inv:set_stack(listname, index, ItemStack(""))
after_recipe_change(pos, inv)
@ -559,7 +559,7 @@ minetest.register_node("pipeworks:autocrafter", {
if not pipeworks.may_configure(pos, player) then return 0 end
upgrade_autocrafter(pos)
local inv = minetest.get_meta(pos):get_inventory()
local inv = core.get_meta(pos):get_inventory()
local stack = inv:get_stack(from_list, from_index)
if to_list == "output" then
@ -592,7 +592,7 @@ minetest.register_node("pipeworks:autocrafter", {
receptor = {},
effector = {
action = function(pos,node,channel,msg)
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
if channel ~= meta:get_string("channel") then return end
if type(msg) == "table" then
if #msg < 3 then return end
@ -601,7 +601,7 @@ minetest.register_node("pipeworks:autocrafter", {
local row = msg[y + 1]
for x = 1, 3, 1 do
local slot = y * 3 + x
if type(row) == "table" and minetest.registered_items[row[x]] then
if type(row) == "table" and core.registered_items[row[x]] then
inv:set_stack("recipe", slot, ItemStack(
row[x]))
else
@ -611,7 +611,7 @@ minetest.register_node("pipeworks:autocrafter", {
end
after_recipe_change(pos,inv)
elseif msg == "get_recipe" then
local meta = minetest.get_meta(pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
local recipe = {}
for y = 0, 2, 1 do
@ -634,7 +634,7 @@ minetest.register_node("pipeworks:autocrafter", {
})
elseif msg == "off" then
update_meta(meta, false)
minetest.get_node_timer(pos):stop()
core.get_node_timer(pos):stop()
elseif msg == "on" then
if update_meta(meta, true) then
start_crafter(pos)