mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 18:41:09 +01:00
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:
parent
4db0631133
commit
ae632fe773
2 changed files with 13 additions and 27 deletions
|
@ -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 = {}
|
mcl_inventory = {}
|
||||||
|
|
||||||
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/creative.lua")
|
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")
|
--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.
|
---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 itemstack mt.ItemStack
|
||||||
---@param dropper ObjectRef
|
---@param dropper mt.ObjectRef
|
||||||
---@param pos Vector
|
---@param pos mt.Vector
|
||||||
---@param inv InvRef
|
---@param inv mt.InvRef
|
||||||
local function return_item(itemstack, dropper, pos, inv)
|
local function return_item(itemstack, dropper, pos, inv)
|
||||||
if dropper:is_player() then
|
if dropper:is_player() then
|
||||||
-- Return to main inventory
|
-- Return to main inventory
|
||||||
|
@ -45,7 +39,7 @@ local function return_item(itemstack, dropper, pos, inv)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left.
|
---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
|
---@param name string
|
||||||
local function return_fields(player, name)
|
local function return_fields(player, name)
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
|
@ -59,7 +53,7 @@ local function return_fields(player, name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param player ObjectRef
|
---@param player mt.PlayerObjectRef
|
||||||
---@param armor_change_only? boolean
|
---@param armor_change_only? boolean
|
||||||
local function set_inventory(player, armor_change_only)
|
local function set_inventory(player, armor_change_only)
|
||||||
if minetest.is_creative_enabled(player:get_player_name()) then
|
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")
|
return_fields(player, "enchanting_lapis")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---@param player ObjectRef
|
---@param player mt.PlayerObjectRef
|
||||||
---@param armor_change_only? boolean
|
function mcl_inventory.update_inventory(player)
|
||||||
function mcl_inventory.update_inventory(player, armor_change_only)
|
|
||||||
local player_gamemode = mcl_gamemode.get_gamemode(player)
|
local player_gamemode = mcl_gamemode.get_gamemode(player)
|
||||||
if player_gamemode == "creative" then
|
if player_gamemode == "creative" then
|
||||||
if armor_change_only then
|
mcl_inventory.set_creative_formspec(player)
|
||||||
-- 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
|
|
||||||
elseif player_gamemode == "survival" then
|
elseif player_gamemode == "survival" then
|
||||||
player:set_inventory_formspec(mcl_inventory.build_survival_formspec(player))
|
player:set_inventory_formspec(mcl_inventory.build_survival_formspec(player))
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
---@diagnostic disable lowercase-global
|
|
||||||
|
|
||||||
local S = minetest.get_translator("mcl_gamemode")
|
local S = minetest.get_translator("mcl_gamemode")
|
||||||
|
|
||||||
mcl_gamemode = {}
|
mcl_gamemode = {}
|
||||||
|
@ -19,15 +17,15 @@ local function in_table(n, h)
|
||||||
return false
|
return false
|
||||||
end
|
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 = {}
|
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)
|
function mcl_gamemode.register_on_gamemode_change(func)
|
||||||
table.insert(mcl_gamemode.registered_on_gamemode_change, func)
|
table.insert(mcl_gamemode.registered_on_gamemode_change, func)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param player ObjectRef
|
---@param player mt.PlayerObjectRef
|
||||||
---@param gamemode '"survival"'|'"creative"'
|
---@param gamemode '"survival"'|'"creative"'
|
||||||
function mcl_gamemode.set_gamemode(player, gamemode)
|
function mcl_gamemode.set_gamemode(player, gamemode)
|
||||||
local meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
|
@ -40,7 +38,7 @@ end
|
||||||
|
|
||||||
local mt_is_creative_enabled = minetest.is_creative_enabled
|
local mt_is_creative_enabled = minetest.is_creative_enabled
|
||||||
|
|
||||||
---@param player ObjectRef
|
---@param player mt.PlayerObjectRef
|
||||||
---@return '"survival"'|'"creative"'
|
---@return '"survival"'|'"creative"'
|
||||||
function mcl_gamemode.get_gamemode(player)
|
function mcl_gamemode.get_gamemode(player)
|
||||||
if mt_is_creative_enabled(player:get_player_name()) then
|
if mt_is_creative_enabled(player:get_player_name()) then
|
||||||
|
|
Loading…
Reference in a new issue