1
0
Fork 0

Fixes in `mcl_inventory`

- Fix (yet another) rebase conflict
- Remove unused code and annotations
- Fix annotations in `mcl_gamemode` to https://github.com/minetest-toolkit/minetest-lsp-api
This commit is contained in:
AFCMS 2023-06-29 09:03:48 +02:00
parent 4db0631133
commit ae632fe773
Signed by untrusted user: AFCMS
GPG Key ID: 8720389A25B652E3
2 changed files with 13 additions and 27 deletions

View File

@ -1,9 +1,3 @@
local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape
---get_inventory can return nil if object isn't a player, but we are sure sometimes this is one :)
---@diagnostic disable need-check-nil
mcl_inventory = {}
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/creative.lua")
@ -13,10 +7,10 @@ dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/survival.lua")
--local mod_craftguide = minetest.get_modpath("mcl_craftguide")
---Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left.
---@param itemstack ItemStack
---@param dropper ObjectRef
---@param pos Vector
---@param inv InvRef
---@param itemstack mt.ItemStack
---@param dropper mt.ObjectRef
---@param pos mt.Vector
---@param inv mt.InvRef
local function return_item(itemstack, dropper, pos, inv)
if dropper:is_player() then
-- Return to main inventory
@ -45,7 +39,7 @@ local function return_item(itemstack, dropper, pos, inv)
end
---Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left.
---@param player ObjectRef
---@param player mt.PlayerObjectRef
---@param name string
local function return_fields(player, name)
local inv = player:get_inventory()
@ -59,7 +53,7 @@ local function return_fields(player, name)
end
end
---@param player ObjectRef
---@param player mt.PlayerObjectRef
---@param armor_change_only? boolean
local function set_inventory(player, armor_change_only)
if minetest.is_creative_enabled(player:get_player_name()) then
@ -133,17 +127,11 @@ minetest.register_on_joinplayer(function(player)
return_fields(player, "enchanting_lapis")
end)
---@param player ObjectRef
---@param armor_change_only? boolean
function mcl_inventory.update_inventory(player, armor_change_only)
---@param player mt.PlayerObjectRef
function mcl_inventory.update_inventory(player)
local player_gamemode = mcl_gamemode.get_gamemode(player)
if player_gamemode == "creative" then
if armor_change_only then
-- Stay on survival inventory page if only the armor has been changed
mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv")
else
mcl_inventory.set_creative_formspec(player, 0, 1)
end
mcl_inventory.set_creative_formspec(player)
elseif player_gamemode == "survival" then
player:set_inventory_formspec(mcl_inventory.build_survival_formspec(player))
end

View File

@ -1,5 +1,3 @@
---@diagnostic disable lowercase-global
local S = minetest.get_translator("mcl_gamemode")
mcl_gamemode = {}
@ -19,15 +17,15 @@ local function in_table(n, h)
return false
end
---@type fun(player: ObjectRef, old_gamemode: '"survival"'|'"creative"', new_gamemode: '"survival"'|'"creative"')[]
---@type fun(player: mt.PlayerObjectRef, old_gamemode: '"survival"'|'"creative"', new_gamemode: '"survival"'|'"creative"')[]
mcl_gamemode.registered_on_gamemode_change = {}
---@param func fun(player: ObjectRef, old_gamemode: '"survival"'|'"creative"', new_gamemode: '"survival"'|'"creative"')
---@param func fun(player: mt.PlayerObjectRef, old_gamemode: '"survival"'|'"creative"', new_gamemode: '"survival"'|'"creative"')
function mcl_gamemode.register_on_gamemode_change(func)
table.insert(mcl_gamemode.registered_on_gamemode_change, func)
end
---@param player ObjectRef
---@param player mt.PlayerObjectRef
---@param gamemode '"survival"'|'"creative"'
function mcl_gamemode.set_gamemode(player, gamemode)
local meta = player:get_meta()
@ -40,7 +38,7 @@ end
local mt_is_creative_enabled = minetest.is_creative_enabled
---@param player ObjectRef
---@param player mt.PlayerObjectRef
---@return '"survival"'|'"creative"'
function mcl_gamemode.get_gamemode(player)
if mt_is_creative_enabled(player:get_player_name()) then