Skip to content

Commit

Permalink
minetest -> core
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed Dec 9, 2024
1 parent 4ddda3a commit 300a1bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions mods/other/crafting/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function crafting.get_unlocked(name)
return players_recipes[name]
end

minetest.register_on_leaveplayer(function(player)
core.register_on_leaveplayer(function(player)
players_recipes[player:get_player_name()] = nil
end)

Expand Down Expand Up @@ -97,7 +97,7 @@ local function fetch_items_from_inv(inv, listname)
local itemname = stack:get_name()
items[itemname] = (items[itemname] or 0) + stack:get_count()

local def = minetest.registered_items[itemname]
local def = core.registered_items[itemname]
if def and def.groups then
for groupname, _ in pairs(def.groups) do
local group = "group:" .. groupname
Expand Down Expand Up @@ -135,7 +135,7 @@ local function find_required_items(inv, listname, recipe)
-- Find stacks in group
for _, stack in ipairs(inv:get_list(listname)) do
-- Is it in group?
local def = minetest.registered_items[stack:get_name()]
local def = core.registered_items[stack:get_name()]
if def and def.groups and def.groups[groupname] then
if stack:get_count() > required then
stack:set_count(required)
Expand Down Expand Up @@ -181,7 +181,7 @@ function crafting.perform_craft(player, listname, outlistname, recipe)
local took = inv:remove_item(listname, item)
taken[#taken + 1] = took
if took:get_count() ~= item:get_count() then
minetest.log("error", "Unexpected lack of items in inventory")
core.log("error", "Unexpected lack of items in inventory")
give_all_to_player(inv, taken)
return false
end
Expand All @@ -192,8 +192,8 @@ function crafting.perform_craft(player, listname, outlistname, recipe)
inv:add_item(outlistname, recipe.output)
else
local pos = player:get_pos()
minetest.chat_send_player(player:get_player_name(), "No room in inventory!")
minetest.add_item(pos, recipe.output)
core.chat_send_player(player:get_player_name(), "No room in inventory!")
core.add_item(pos, recipe.output)
end
return true
end
Expand All @@ -209,5 +209,5 @@ function crafting.calc_inventory_list_hash(inv, listname)
for _, stack in pairs(inv:get_list(listname)) do
str = str .. stack:get_name() .. stack:get_count()
end
return minetest.sha1(to_hex(str))
return core.sha1(to_hex(str))
end
26 changes: 13 additions & 13 deletions mods/other/crafting/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local function get_item_description(name)
local group = name:sub(7, #name):gsub("%_", " ")
return "Any " .. group
else
local def = minetest.registered_items[name] or {}
local def = core.registered_items[name] or {}
return def.description or name
end
end
Expand Down Expand Up @@ -66,7 +66,7 @@ function crafting.make_result_selector(player, size, context)
table_insert(formspec, "container_end[]")

table_insert(formspec, "label[0,-0.1;")
table_insert(formspec, minetest.formspec_escape(
table_insert(formspec, core.formspec_escape(
"Page: " .. page .. "/" .. max_pages)
)
table_insert(formspec, "]")
Expand Down Expand Up @@ -94,18 +94,18 @@ function crafting.make_result_selector(player, size, context)
table_insert(formspec, "tooltip[result_")
table_insert(formspec, tostring(recipe.id))
table_insert(formspec, ";")
table_insert(formspec, minetest.formspec_escape(item_description .. "\n"))
table_insert(formspec, core.formspec_escape(item_description .. "\n"))
for _, item in ipairs(result.items) do
local color = item.have >= item.need and "#6f6" or "#f66"
local itemtab = {
"\n",
minetest.get_color_escape_sequence(color),
core.get_color_escape_sequence(color),
get_item_description(item.name), ": ",
item.have, "/", item.need
}
table_insert(formspec, minetest.formspec_escape(table.concat(itemtab, "")))
table_insert(formspec, core.formspec_escape(table.concat(itemtab, "")))
end
table_insert(formspec, minetest.get_color_escape_sequence("#ffffff"))
table_insert(formspec, core.get_color_escape_sequence("#ffffff"))
table_insert(formspec, "]")

table_insert(formspec, "image[")
Expand Down Expand Up @@ -168,23 +168,23 @@ function crafting.result_select_on_receive_results(player, context, fields)
local recipe = crafting.get_recipe(tonumber(num))
local name = player:get_player_name()
if not crafting.can_craft(name, recipe) then
minetest.log("error", "[crafting] Player clicked a button they shouldn't have been able to")
core.log("error", "[crafting] Player clicked a button they shouldn't have been able to")
return true
elseif crafting.perform_craft(player, "main", "main", recipe) then
return true -- crafted
else
minetest.chat_send_player(name, "Missing required items!")
core.chat_send_player(name, "Missing required items!")
return false
end
end
end
end
end

if minetest.global_exists("sfinv") then
if core.global_exists("sfinv") then
local player_inv_hashes = {}

local trash = minetest.create_detached_inventory("crafting_trash", {
local trash = core.create_detached_inventory("crafting_trash", {
-- Allow the stack to be placed and remove it in on_put()
-- This allows the creative inventory to restore the stack
allow_put = function(inv, listname, index, stack, player)
Expand Down Expand Up @@ -219,7 +219,7 @@ if minetest.global_exists("sfinv") then
cooldown:set(player, 0.5)
ctf_modebase.player.save_initial_stuff_positions(player)

minetest.sound_play("crafting_save_sound", {
core.sound_play("crafting_save_sound", {
to_player = player:get_player_name(),
}, true)
end
Expand All @@ -229,13 +229,13 @@ if minetest.global_exists("sfinv") then
})

local globalstep_timer = 0
minetest.register_globalstep(function(dtime)
core.register_globalstep(function(dtime)
globalstep_timer = globalstep_timer + dtime
if globalstep_timer < 1 then return end

globalstep_timer = 0

for _, player in pairs(minetest.get_connected_players() or {}) do
for _, player in pairs(core.get_connected_players() or {}) do
if sfinv.get_or_create_context(player).page == "sfinv:crafting" then
local hash = crafting.calc_inventory_list_hash(player:get_inventory(), "main")
local old_hash = player_inv_hashes[player:get_player_name()]
Expand Down
4 changes: 2 additions & 2 deletions mods/other/crafting/init.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dofile(minetest.get_modpath("crafting") .. "/api.lua")
dofile(minetest.get_modpath("crafting") .. "/gui.lua")
dofile(core.get_modpath("crafting") .. "/api.lua")
dofile(core.get_modpath("crafting") .. "/gui.lua")

0 comments on commit 300a1bb

Please sign in to comment.