Update 1.0.2
parent
4c38c142ce
commit
3872f23074
61
api.txt
61
api.txt
|
@ -300,7 +300,7 @@ The arguments for the above "list" Formspec Element would be represented as such
|
|||
|
||||
### Subclasses:
|
||||
|
||||
* lua_inv.dynamic_list(inv_location, listname, x, y, w, h, start_index) - Like a list[], except it's a grid of buttons to form a lua_inv-compatible UI.
|
||||
* lua_inv.dynamic_list(inv_location, listname, x, y, w, h, start_index, slot_bg)- Like a list[], except it's a grid of buttons to form a lua_inv-compatible UI.
|
||||
* lua_inv.stack_mode_selector(x, y) - Meant to be paired with dynamic_list to offer more options for moving around ItemStacks.
|
||||
* lua_inv.drop_item_button(x, y) - Provides a way for formspecs with dynamic lists to drop items onto the ground.
|
||||
* lua_inv.active_indicator(x, y, w, y, base_img, cover_img, var)- Like an image[], except var% of cover_img will be drawn over base_img.
|
||||
|
@ -310,22 +310,52 @@ The arguments for the above "list" Formspec Element would be represented as such
|
|||
[DynamicFormspec]
|
||||
|
||||
This is essentially a formspec that is built to use FormspecElement as defined above.
|
||||
It can be set up to use a page structure pretty easily, just by using the related page functions.
|
||||
Every Dynamic Formspec requires at least one page to do anything. The first added page will have have an index of 1.
|
||||
|
||||
### Constructors:
|
||||
|
||||
lua_inv.dynamic_formspec({FormspecElements}) - The standard method for creating a DynamicFormspec.
|
||||
lua_inv.dynamic_formspec() - The standard method for creating a DynamicFormspec. Note that at least one page must always be created for it to be usable.
|
||||
|
||||
lua_inv.dynamic_formspec_from_string(formspec) - This is a way to automatically interpret and convert an existing formspec string into a DynamicFormspec.
|
||||
|
||||
### Fields [Read-Only]:
|
||||
|
||||
* elems - A table of all the pages of FormspecElements.
|
||||
* pageTitles - A table of each page's title.
|
||||
* meta - The primary MetaData object that belongs to the formspec, typically used by each FormspecElement for communication.
|
||||
* temp_meta - A secondary MetaData object, which is cleared after each time the formspec is changed or closed.
|
||||
* size_w - The width of this formspec, which applies to all pages.
|
||||
* size_h - The height of this formspec, which applies to all pages.
|
||||
* tabs_hidden - If true, the tabheader[] element will no longer be shown if the formspec has multiple pages.
|
||||
|
||||
### Functions
|
||||
|
||||
* :size() - Returns the number of FormspecElements.
|
||||
* :get(index) - Returns the FormspecElement at the given index.
|
||||
* :set(index, FormspecElement) - Replace the FormspecElement at the given index with a new one, or deletes it if the second argument is nil.
|
||||
* :add(FormspecElement) - Add the given FormspecElement to the end of the list.
|
||||
* :del(index) - Remove the FormspecElement at the given index. Elements after that one have their index reduced by 1 to close the gap.
|
||||
* :get_fs_size() - Returns (width, height) that will be applied to all pages in this formspec.
|
||||
* :set_fs_size(w, h) - Set the width and height of all pages in this formspec to the given numbers.
|
||||
* :set_tabs_hidden(bool) - Set to true to disable the tabheader[] shown when there is more than 1 page. Useful for making your own navigation.
|
||||
* :size(n) - Returns the number of FormspecElements in the given page. N defaults to 1.
|
||||
* :get(index, n) - Returns Page n's FormspecElement at the given index. N defaults to 1.
|
||||
* :set(index, FormspecElement, n) - Replace Page n's FormspecElement at the given index with a new one, or deletes it if the second argument is nil. N defaults to 1.
|
||||
* :add(FormspecElement, n) - Add the given FormspecElement to Page n the end of the list. N defaults to 1.
|
||||
* :del(index, n) - Remove the FormspecElement of Page n at the given index. N defaults to 1.
|
||||
* :page_add(title) - Add a new page with the given title. Returns the page's index to allow formspec elements to be added to it.
|
||||
* :page_count() - Returns the total number of pages.
|
||||
* :page_get(n) - Returns the page at the specified index, if it exists.
|
||||
* :page_title(n) - Returns the name given to the page at the specified index.
|
||||
* :page_del(n) - Deletes the page at the given index. Any pages that were after it will be pushed back in the list to fill the space.
|
||||
* :page_current() - Returns the currently displayed page.
|
||||
* :page_switch(n) - Switches the formspec to instead show the given page. If n is a number but out of bounds, it will wrap around.
|
||||
* :form(Player, formname, fields) - Build a presentable formspec string out of all existing FormspecElements according to their to_string method.
|
||||
|
||||
### Global Callbacks (Use with caution):
|
||||
|
||||
* lua_inv.register_on_formspec_open(function(player, formname, DynamicFormspec))
|
||||
-- The given function will be called whenever any formspec is shown to a player or updated.
|
||||
|
||||
* lua_inv.register_on_formspec_close(function(player, formname, DynamicFormspec, fields))
|
||||
-- The given function will be called whenever any formspec is properly closed.
|
||||
|
||||
|
||||
|
||||
[Manager]
|
||||
|
@ -401,8 +431,21 @@ lua_inv.get_detached_inventory(name) - Returns a detached inventory indexed by t
|
|||
|
||||
[Misc. Functions]
|
||||
|
||||
* lua_inv.change_involves_list(change, listname) - If the change table has an involved stack in the given listname, return the stack.
|
||||
* lua_inv.set_list_take_only(inv, change, listname) - Use in an allow_change callback to prevent players from placing items in the given listname.
|
||||
* lua_inv.change_involves_list(inv, change, listname) - If the change table has an involved stack in the given inv and listname, return the stack.
|
||||
* lua_inv.set_list_take_only(inv, change, listname) - Use in an allow_change callback to prevent players from placing items in the given listname.
|
||||
* lua_inv.tiles_to_cube_textures({tiles}) - Converts a table of tiles from an object's properties into a table of textures for an entity.
|
||||
* lua_inv.update_hotbar(player) - Update the player's hotbar visuals in the event of a change. Automatically called for most use cases.
|
||||
|
||||
|
||||
|
||||
[Default Support Functions]
|
||||
|
||||
* lua_inv.default.chest_override(name) - Overrides the named chest so its behaviors properly use lua_inv.
|
||||
|
||||
* lua_inv.default.furnace_override(name) - Overrides the named furnace so its behaviors properly use lua_inv.
|
||||
|
||||
* lua_inv.default.shelf_override(name, groupname, listname, slot_bg) - Overrides the named shelf to work with lua_inv.
|
||||
-- groupname: Only items with this groupname will be allowed on the shelf.
|
||||
-- listname: The name of the shelf's inventory's main list.
|
||||
-- slot_bg: The name of the image that will be shown in the shelf's slots to indicate the type of item it can accept.
|
||||
|
||||
|
|
|
@ -13,3 +13,20 @@
|
|||
-The hotbar HUD should now scale properly across different screen resolutions.
|
||||
-The game will no longer crash when you use an unknown item.
|
||||
-Right-clicking while holding a worn tool will no longer magically repair it.
|
||||
|
||||
|
||||
|
||||
1.0.2:
|
||||
-Dropped items now have velocity based on where the player is looking
|
||||
-Added support for default bookshelves and vessels shelves
|
||||
-Function lua_inv.change_involves_list now takes "inv" as its argument; it'll only check that inv to see if the change involves the given listname.
|
||||
-A few functions to override nodes from MTG to give them lua_inv support have become global. They can be reused for any similar nodes in other mods.
|
||||
-Dynamic Lists have a new element, "slot_bg", which will be drawn over any empty slot if its defined.
|
||||
-Added global callbacks for when a Dynamic Formspec is opened or closed.
|
||||
-Added native page support to Dynamic Formspecs.
|
||||
-Added "Fields" descriptions to the Dynamic Formspec API, as they were missing before.
|
||||
|
||||
-Fixed some cases where the player's wielded item would be invisible.
|
||||
-Wielded item entities will no longer be statically saved. This could cause them to secretly accumulate over time.
|
||||
-Fixed various crashes caused by anything that would cause the game to try evaluating an itemstring's count.
|
||||
-Restored various on_step behaviors for item entities that were previously absent from lua_inv.
|
||||
|
|
|
@ -17,51 +17,158 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
--]]
|
||||
|
||||
function lua_inv.dynamic_formspec(input_elems)
|
||||
local function page_tabs(df)
|
||||
--tabheader[<X>,<Y>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]
|
||||
|
||||
local elems = {{0, 0}, "page_tabs", {}, df:page_current()}
|
||||
|
||||
return lua_inv.formspec_element("tabheader", elems, function(self, player, formname, fields)
|
||||
self.args[3] = df.pageTitles
|
||||
|
||||
if fields then
|
||||
local df = lua_inv.open_formspecs[player:get_player_name()]
|
||||
local tab = fields.page_tabs
|
||||
|
||||
if tab then
|
||||
df:page_switch(tonumber(tab))
|
||||
self.args[4] = df:page_current()
|
||||
end
|
||||
end
|
||||
|
||||
return lua_inv.default_formspec_element_to_string(self)
|
||||
end)
|
||||
end
|
||||
|
||||
function lua_inv.dynamic_formspec()
|
||||
local index = {
|
||||
elems = setmetatable(input_elems or {}, {
|
||||
elems = setmetatable({}, {
|
||||
__newindex = function(self, key, val)
|
||||
error("Error: Attempt to directly set a value in a dynamic formspec's list of elements. Please call one of the provided functions instead.")
|
||||
end,
|
||||
|
||||
__metatable = false,
|
||||
}),
|
||||
|
||||
pageTitles = setmetatable({}, {
|
||||
__newindex = function(self, key, val)
|
||||
error("Error: Attempt to directly set a value in a dynamic formspec's list of page titles. Please call one of the provided functions instead.")
|
||||
end,
|
||||
|
||||
size = function(self)
|
||||
__metatable = false,
|
||||
}),
|
||||
|
||||
get_fs_size = function(self)
|
||||
return (rawget(self, "size_w") or 8), (rawget(self, "size_h") or 8)
|
||||
end,
|
||||
|
||||
set_tabs_hidden = function(self, bool)
|
||||
rawset(self, "tabs_hidden", bool)
|
||||
end,
|
||||
|
||||
set_fs_size = function(self, w, h)
|
||||
rawset(self, "size_w", tonumber(w))
|
||||
rawset(self, "size_h", tonumber(h))
|
||||
end,
|
||||
|
||||
size = function(self, n)
|
||||
n = n or 1
|
||||
return #self.elems[n]
|
||||
end,
|
||||
|
||||
get = function(self, i, n)
|
||||
n = n or 1
|
||||
return self.elems[n][i]
|
||||
end,
|
||||
|
||||
set = function(self, i, element, n)
|
||||
n = n or 1
|
||||
if not element then
|
||||
return self:del(i, n)
|
||||
else
|
||||
rawset(self.elems[n], i, element)
|
||||
end
|
||||
end,
|
||||
|
||||
add = function(self, element, n)
|
||||
n = n or 1
|
||||
self:set(self:size(n) + 1, element, n)
|
||||
end,
|
||||
|
||||
del = function(self, i, n)
|
||||
n = n or 1
|
||||
for a = i, self:size(n) - 1 do
|
||||
rawset(self.elems[n], a, self:get(a + 1, n))
|
||||
end
|
||||
|
||||
rawset(self.elems[n], self:size(n), nil)
|
||||
end,
|
||||
|
||||
page_add = function(self, title)
|
||||
local n = #self.elems + 1
|
||||
|
||||
rawset(self.elems, n, setmetatable({}, {
|
||||
__newindex = function(self, key, val)
|
||||
error("Error: Attempt to directly set a value in a dynamic formspec's list of elements. Please call one of the provided functions instead.")
|
||||
end,
|
||||
|
||||
__metatable = false,
|
||||
}))
|
||||
|
||||
rawset(self.pageTitles, n, title)
|
||||
|
||||
self:add(page_tabs(self), n)
|
||||
|
||||
return n
|
||||
end,
|
||||
|
||||
page_count = function(self)
|
||||
return #self.elems
|
||||
end,
|
||||
|
||||
get = function(self, i)
|
||||
return self.elems[i]
|
||||
|
||||
page_get = function(self, n)
|
||||
return self.elems[n]
|
||||
end,
|
||||
|
||||
set = function(self, i, element)
|
||||
if not element then
|
||||
return self:del(i)
|
||||
else
|
||||
rawset(self.elems, i, element)
|
||||
|
||||
page_title = function(self, n)
|
||||
return self.pageTitles[n]
|
||||
end,
|
||||
|
||||
page_del = function(self, n)
|
||||
for i = n, self:page_count() - 1 do
|
||||
rawset(self.elems, i, self:page_get(i+1))
|
||||
rawset(self.pageTitles, i, self:page_title(i+1))
|
||||
end
|
||||
|
||||
local i = self:page_count()
|
||||
rawset(self.elems, i, nil)
|
||||
rawset(self.pageTitles, i, nil)
|
||||
end,
|
||||
|
||||
add = function(self, element)
|
||||
self:set(self:size() + 1, element)
|
||||
|
||||
page_current = function(self)
|
||||
return self.currentPage or 1
|
||||
end,
|
||||
|
||||
del = function(self, i)
|
||||
for n = i, self:size() - 1 do
|
||||
rawset(self.elems, n, self:get(n + 1))
|
||||
end
|
||||
|
||||
rawset(self.elems, self:size(), nil)
|
||||
|
||||
page_switch = function(self, n)
|
||||
n = n and ((n - 1) % self:page_count() + 1) or 1
|
||||
rawset(self, "currentPage", n)
|
||||
|
||||
return n
|
||||
end,
|
||||
|
||||
form = function(self, player, formname, fields)
|
||||
self.meta:set_string("formname", formname)
|
||||
|
||||
local formspec = ""
|
||||
local w, h = self:get_fs_size()
|
||||
local formspec = "size["..w..","..h.."]"
|
||||
|
||||
if self:page_count() > 1 and not self.tabs_hidden then
|
||||
formspec = formspec..self:get(1, self:page_current()):to_string(player, formname, fields)
|
||||
end
|
||||
|
||||
local p = self:page_current()
|
||||
|
||||
for i = 1, self:size() do
|
||||
local element = self:get(i):to_string(player, formname, fields)
|
||||
for i = 2, self:size(p) do
|
||||
local element = self:get(i, p):to_string(player, formname, fields)
|
||||
|
||||
formspec = formspec..element
|
||||
end
|
||||
|
@ -101,9 +208,14 @@ function lua_inv.dynamic_formspec_from_string(str)
|
|||
end
|
||||
|
||||
local df = lua_inv.dynamic_formspec()
|
||||
df:page_add("Main")
|
||||
|
||||
for i = 1, #lines do
|
||||
df:add(lines[i])
|
||||
if lines[i].name == "size" then
|
||||
df:set_fs_size(lines[i].args[1], lines[i].args[2])
|
||||
else
|
||||
df:add(lines[i])
|
||||
end
|
||||
end
|
||||
|
||||
return df
|
||||
|
|
|
@ -20,8 +20,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
lua_inv.open_formspecs = {}
|
||||
local cooldown = {}
|
||||
|
||||
lua_inv.registered_on_formspec_open = {}
|
||||
lua_inv.registered_on_formspec_close = {}
|
||||
|
||||
function lua_inv.register_on_formspec_open(func)
|
||||
table.insert(lua_inv.registered_on_formspec_open, func)
|
||||
end
|
||||
|
||||
function lua_inv.register_on_formspec_close(func)
|
||||
table.insert(lua_inv.registered_on_formspec_close, func)
|
||||
end
|
||||
|
||||
function lua_inv.show_formspec(player, formname, dynamic_formspec)
|
||||
local pname = player:get_player_name()
|
||||
|
||||
for i = 1, #lua_inv.registered_on_formspec_open do
|
||||
lua_inv.registered_on_formspec_open[i](player, formname, dynamic_formspec)
|
||||
end
|
||||
|
||||
lua_inv.open_formspecs[pname] = dynamic_formspec
|
||||
|
||||
minetest.show_formspec(pname, formname, dynamic_formspec:form(player, formname))
|
||||
|
@ -44,6 +60,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
end
|
||||
|
||||
if fields.quit and formname ~= "" then
|
||||
for i = 1, #lua_inv.registered_on_formspec_close do
|
||||
lua_inv.registered_on_formspec_close[i](player, formname, lua_inv.open_formspecs[pname], fields)
|
||||
end
|
||||
|
||||
lua_inv.open_formspecs[pname] = nil
|
||||
return
|
||||
end
|
||||
|
|
|
@ -40,15 +40,17 @@ local function get_player_display(player)
|
|||
end
|
||||
|
||||
function lua_inv.survival_inventory.form()
|
||||
return lua_inv.dynamic_formspec({
|
||||
lua_inv.formspec_element("size", {{8, 8.5}}),
|
||||
lua_inv.formspec_element("player_view", {}, function(self, player, formname, fields) return get_player_display(player) end),
|
||||
lua_inv.drop_item_button(7, 7.9),
|
||||
lua_inv.dynamic_list("current_player", "main", 0, 3.75, 8, 4),
|
||||
lua_inv.dynamic_list("current_player", "craft", 3, 0, 3, 3),
|
||||
lua_inv.dynamic_list("current_player", "craftpreview", 7, 1, 1, 1),
|
||||
lua_inv.stack_mode_selector(0, 7.9),
|
||||
})
|
||||
local df = lua_inv.dynamic_formspec()
|
||||
df:page_add("Crafting")
|
||||
|
||||
df:add(lua_inv.formspec_element("player_view", {}, function(self, player, formname, fields) return get_player_display(player) end))
|
||||
df:add(lua_inv.drop_item_button(7, 7.4))
|
||||
df:add(lua_inv.dynamic_list("current_player", "main", 0, 3.25, 8, 4))
|
||||
df:add(lua_inv.dynamic_list("current_player", "craft", 3, 0, 3, 3))
|
||||
df:add(lua_inv.dynamic_list("current_player", "craftpreview", 7, 1, 1, 1))
|
||||
df:add(lua_inv.stack_mode_selector(0, 7.4))
|
||||
|
||||
return df
|
||||
end
|
||||
|
||||
function lua_inv.survival_inventory.ref(player)
|
||||
|
|
|
@ -1,3 +1,22 @@
|
|||
--[[
|
||||
Complete and Total Lua-Only Inventory Rewrite
|
||||
Copyright (C) 2021 Noodlemire
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
--]]
|
||||
|
||||
function lua_inv.active_indicator(in_x, in_y, in_w, in_h, in_base_img, in_cover_img, in_var)
|
||||
return lua_inv.formspec_element(
|
||||
"fuel_indicator",
|
||||
|
|
|
@ -59,6 +59,7 @@ function lua_inv.drop_item_button(in_x, in_y)
|
|||
local ent = minetest.add_entity(pos, "__builtin:item")
|
||||
|
||||
if ent then
|
||||
ent:set_velocity(player:get_look_dir())
|
||||
ent:get_luaentity():set_item(dropped:to_string())
|
||||
end
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ function lua_inv.inventory_from_location(inv_location, player)
|
|||
return inv
|
||||
end
|
||||
|
||||
function lua_inv.dynamic_list(in_inv_location, in_listname, in_x, in_y, in_w, in_h, in_start_i)
|
||||
function lua_inv.dynamic_list(in_inv_location, in_listname, in_x, in_y, in_w, in_h, in_start_i, in_slot_bg)
|
||||
return lua_inv.formspec_element(
|
||||
"dynamic_list",
|
||||
|
||||
|
@ -87,6 +87,7 @@ function lua_inv.dynamic_list(in_inv_location, in_listname, in_x, in_y, in_w, in
|
|||
{in_x, in_y},
|
||||
{in_w, in_h},
|
||||
in_start_i,
|
||||
in_slot_bg
|
||||
},
|
||||
|
||||
function(self, player, formname, fields)
|
||||
|
@ -163,6 +164,7 @@ function lua_inv.dynamic_list(in_inv_location, in_listname, in_x, in_y, in_w, in
|
|||
local pos = self.args[3]
|
||||
local size = self.args[4]
|
||||
local start_i = (tonumber(self.args[5]) or 0)
|
||||
local slot_bg = self.args[6]
|
||||
|
||||
local inv = lua_inv.inventory_from_location(inv_location, player)
|
||||
|
||||
|
@ -207,6 +209,8 @@ function lua_inv.dynamic_list(in_inv_location, in_listname, in_x, in_y, in_w, in
|
|||
if stack:get_wear() > 0 then
|
||||
str = str.."image["..(pos[1] + x - 0.95)..','..(pos[2] + y - 1.0625)..";0.875,1;"..stack:get_wear_visual()..']'
|
||||
end
|
||||
elseif slot_bg then
|
||||
str = str.."image["..(pos[1] + x - 1)..','..(pos[2] + y - 1)..";0.875,1;"..slot_bg.."]"
|
||||
end
|
||||
|
||||
if meta:get_string("selection") == slotname then
|
||||
|
|
8
init.lua
8
init.lua
|
@ -46,8 +46,6 @@ if minetest.get_modpath("default") then
|
|||
dofile(mp.."optional_depends/default.lua")
|
||||
end
|
||||
|
||||
minetest.register_on_mods_loaded(function()
|
||||
if minetest.get_modpath("sfinv") then
|
||||
sfinv.enabled = false
|
||||
end
|
||||
end)
|
||||
if minetest.get_modpath("sfinv") then
|
||||
sfinv.enabled = false
|
||||
end
|
||||
|
|
|
@ -36,6 +36,7 @@ function lua_inv.tiles_to_cube_textures(tiles)
|
|||
end
|
||||
|
||||
local old_on_punch = minetest.registered_entities["__builtin:item"].on_punch
|
||||
local old_on_step = minetest.registered_entities["__builtin:item"].on_step
|
||||
|
||||
entitycontrol.override_entity("__builtin:item", {
|
||||
initial_properties = {
|
||||
|
@ -125,7 +126,7 @@ entitycontrol.override_entity("__builtin:item", {
|
|||
self.object:remove()
|
||||
end,
|
||||
|
||||
on_step = function(self, dtime)
|
||||
on_step = function(self, dtime, moveresult)
|
||||
if self._anim then
|
||||
self._anim.time = self._anim.time - dtime * 1000
|
||||
|
||||
|
@ -140,5 +141,9 @@ entitycontrol.override_entity("__builtin:item", {
|
|||
self.object:set_properties({textures = {self._anim.get_frame:format(self._anim.frame)}})
|
||||
end
|
||||
end
|
||||
|
||||
if old_on_step then
|
||||
return old_on_step(self, dtime, moveresult)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
|
@ -434,13 +434,13 @@ local static = {
|
|||
}
|
||||
|
||||
function lua_inv.itemstack(input_name, input_count, input_wear, input_meta, input_parent)
|
||||
input_name = (not input_count or input_count > 0) and input_name
|
||||
input_count = input_name and input_name ~= "" and input_count
|
||||
input_name = (not input_count or tonumber(input_count) > 0) and input_name
|
||||
input_count = input_name and input_name ~= "" and tonumber(input_count)
|
||||
|
||||
local itemstack = {
|
||||
name = input_name or "",
|
||||
count = input_count or (input_name and 1) or 0,
|
||||
wear = input_wear or 0,
|
||||
wear = tonumber(input_wear or 0),
|
||||
tool_capabilities = nil,
|
||||
}
|
||||
|
||||
|
|
8
misc.lua
8
misc.lua
|
@ -17,10 +17,10 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
--]]
|
||||
|
||||
function lua_inv.change_involves_list(change, listname)
|
||||
if change.stack and change.stack.parent.list == listname then return change.stack end
|
||||
if change.stack1 and change.stack1.parent.list == listname then return change.stack2 end
|
||||
if change.stack2 and change.stack2.parent.list == listname then return change.stack1 end
|
||||
function lua_inv.change_involves_list(inv, change, listname)
|
||||
if change.stack and change.stack.parent.inv == inv and change.stack.parent.list == listname then return change.stack end
|
||||
if change.stack1 and change.stack1.parent.inv == inv and change.stack1.parent.list == listname then return change.stack2 end
|
||||
if change.stack2 and change.stack2.parent.inv == inv and change.stack2.parent.list == listname then return change.stack1 end
|
||||
end
|
||||
|
||||
function lua_inv.set_list_take_only(inv, change, listname)
|
||||
|
|
2
mod.conf
2
mod.conf
|
@ -2,5 +2,5 @@ name = lua_inv
|
|||
title = Complete and Total Lua-Only Inventory Rewrite
|
||||
description = Creates a completely custom inventory system, which doesn't rely at all on any of the usual UserData objects. It's built from the ground up to support various features that are considered "impossible" in normal Minetest. Animated items, items that can dynamically change their sprite without making a million copies of the same registration, itemstacks that have both count and wear set at once, and more.
|
||||
depends = controls, entitycontrol, smart_vector_table
|
||||
optional_depends = default, sfinv
|
||||
optional_depends = default, sfinv, vessels
|
||||
min_minetest_version = 5.4
|
||||
|
|
|
@ -17,6 +17,8 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
--]]
|
||||
|
||||
lua_inv.default = {}
|
||||
|
||||
local function can_dig_container(pos, player)
|
||||
local inv = lua_inv.fetch_node_inventory(pos, true)
|
||||
|
||||
|
@ -28,16 +30,19 @@ end
|
|||
-----------------------------------------------------
|
||||
|
||||
local function chest_formspec(pos)
|
||||
return lua_inv.dynamic_formspec({
|
||||
lua_inv.formspec_element("size", {{8, 10}}),
|
||||
lua_inv.dynamic_list({k = "nodemeta", v = {pos.x, pos.y, pos.z}}, "main", 0, 0.3, 8, 4),
|
||||
lua_inv.dynamic_list("current_player", "main", 0, 4.85, 8, 1),
|
||||
lua_inv.dynamic_list("current_player", "main", 0, 6.08, 8, 3, 8),
|
||||
lua_inv.stack_mode_selector(0, 9.1)
|
||||
})
|
||||
local df = lua_inv.dynamic_formspec()
|
||||
df:page_add("Main")
|
||||
df:set_fs_size(8, 10)
|
||||
|
||||
df:add(lua_inv.dynamic_list({k = "nodemeta", v = {pos.x, pos.y, pos.z}}, "main", 0, 0.3, 8, 4))
|
||||
df:add(lua_inv.dynamic_list("current_player", "main", 0, 4.85, 8, 1))
|
||||
df:add(lua_inv.dynamic_list("current_player", "main", 0, 6.08, 8, 3, 8))
|
||||
df:add(lua_inv.stack_mode_selector(0, 9.1))
|
||||
|
||||
return df
|
||||
end
|
||||
|
||||
local function chest_override(name)
|
||||
function lua_inv.default.chest_override(name)
|
||||
local def = minetest.registered_items[name]
|
||||
|
||||
local override_def = {}
|
||||
|
@ -69,25 +74,28 @@ local function chest_override(name)
|
|||
minetest.override_item(name.."_open", override_def)
|
||||
end
|
||||
|
||||
chest_override("default:chest")
|
||||
chest_override("default:chest_locked")
|
||||
lua_inv.default.chest_override("default:chest")
|
||||
lua_inv.default.chest_override("default:chest_locked")
|
||||
|
||||
-----------------------------------------------------
|
||||
-- Furnaces --
|
||||
-----------------------------------------------------
|
||||
|
||||
local function furnace_formspec(pos)
|
||||
return lua_inv.dynamic_formspec({
|
||||
lua_inv.formspec_element("size", {{8, 10}}),
|
||||
lua_inv.dynamic_list({k = "nodemeta", v = {pos.x, pos.y, pos.z}}, "src", 2.75, 0.5, 1, 1),
|
||||
lua_inv.dynamic_list({k = "nodemeta", v = {pos.x, pos.y, pos.z}}, "fuel", 2.75, 2.5, 1, 1),
|
||||
lua_inv.dynamic_list({k = "nodemeta", v = {pos.x, pos.y, pos.z}}, "dst", 4.75, 0.96, 2, 2),
|
||||
lua_inv.active_indicator(2.75, 1.5, 1, 1, "default_furnace_fire_bg.png", "default_furnace_fire_fg.png", "fuel_percent"),
|
||||
lua_inv.active_indicator(3.75, 1.5, 1, 1, "gui_furnace_arrow_bg.png", "gui_furnace_arrow_fg.png^[transformR270", "item_percent"),
|
||||
lua_inv.dynamic_list("current_player", "main", 0, 4.85, 8, 1),
|
||||
lua_inv.dynamic_list("current_player", "main", 0, 6.08, 8, 3, 8),
|
||||
lua_inv.stack_mode_selector(0, 9.1)
|
||||
})
|
||||
local df = lua_inv.dynamic_formspec()
|
||||
df:page_add("main")
|
||||
df:set_fs_size(8, 10)
|
||||
|
||||
df:add(lua_inv.dynamic_list({k = "nodemeta", v = {pos.x, pos.y, pos.z}}, "src", 2.75, 0.5, 1, 1))
|
||||
df:add(lua_inv.dynamic_list({k = "nodemeta", v = {pos.x, pos.y, pos.z}}, "fuel", 2.75, 2.5, 1, 1))
|
||||
df:add(lua_inv.dynamic_list({k = "nodemeta", v = {pos.x, pos.y, pos.z}}, "dst", 4.75, 0.96, 2, 2))
|
||||
df:add(lua_inv.active_indicator(2.75, 1.5, 1, 1, "default_furnace_fire_bg.png", "default_furnace_fire_fg.png", "fuel_percent"))
|
||||
df:add(lua_inv.active_indicator(3.75, 1.5, 1, 1, "gui_furnace_arrow_bg.png", "gui_furnace_arrow_fg.png^[transformR270", "item_percent"))
|
||||
df:add(lua_inv.dynamic_list("current_player", "main", 0, 4.85, 8, 1))
|
||||
df:add(lua_inv.dynamic_list("current_player", "main", 0, 6.08, 8, 3, 8))
|
||||
df:add(lua_inv.stack_mode_selector(0, 9.1))
|
||||
|
||||
return df
|
||||
end
|
||||
|
||||
local function swap_node(pos, name)
|
||||
|
@ -99,7 +107,7 @@ local function swap_node(pos, name)
|
|||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function override_furnace(name)
|
||||
function lua_inv.default.furnace_override(name)
|
||||
local def = minetest.registered_items[name]
|
||||
|
||||
local override_def = {}
|
||||
|
@ -112,7 +120,7 @@ local function override_furnace(name)
|
|||
return false
|
||||
end
|
||||
|
||||
local fuel = lua_inv.change_involves_list(change, "fuel")
|
||||
local fuel = lua_inv.change_involves_list(inv, change, "fuel")
|
||||
if fuel then
|
||||
if change.key == "name" then
|
||||
fuel = ItemStack(change.val)
|
||||
|
@ -147,7 +155,6 @@ local function override_furnace(name)
|
|||
return inv
|
||||
end
|
||||
|
||||
---[[
|
||||
override_def.on_timer = function(pos, elapsed)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
|
@ -339,7 +346,7 @@ local function override_furnace(name)
|
|||
end
|
||||
|
||||
return result
|
||||
end--]]
|
||||
end
|
||||
|
||||
override_def.on_construct = function() end
|
||||
|
||||
|
@ -358,4 +365,64 @@ local function override_furnace(name)
|
|||
minetest.override_item(name.."_active", override_def)
|
||||
end
|
||||
|
||||
override_furnace("default:furnace")
|
||||
lua_inv.default.furnace_override("default:furnace")
|
||||
|
||||
-----------------------------------------------------
|
||||
-- Shelves --
|
||||
-----------------------------------------------------
|
||||
|
||||
local function shelf_formspec(pos, listname, slot_bg)
|
||||
local df = lua_inv.dynamic_formspec()
|
||||
df:page_add("Main")
|
||||
|
||||
df:add(lua_inv.dynamic_list({k = "nodemeta", v = {pos.x, pos.y, pos.z}}, listname, 0, 0.3, 8, 2, nil, slot_bg))
|
||||
df:add(lua_inv.dynamic_list("current_player", "main", 0, 2.85, 8, 1))
|
||||
df:add(lua_inv.dynamic_list("current_player", "main", 0, 4.08, 8, 3, 8))
|
||||
df:add(lua_inv.stack_mode_selector(0, 7.1))
|
||||
|
||||
return df
|
||||
end
|
||||
|
||||
function lua_inv.default.shelf_override(name, groupname, listname, slot_bg)
|
||||
local def = minetest.registered_items[name]
|
||||
|
||||
local override_def = {}
|
||||
|
||||
override_def._lua_inv_inventory = function(pos)
|
||||
local inv = lua_inv.inventory(pos,
|
||||
--Allow Change
|
||||
function(inv, change)
|
||||
local stack = lua_inv.change_involves_list(inv, change, listname)
|
||||
if not stack then return true end
|
||||
|
||||
local stackname = stack:get_name()
|
||||
|
||||
if change.key == "name" then
|
||||
stackname = change.val
|
||||
elseif stack:is_empty() then
|
||||
return true
|
||||
end
|
||||
|
||||
return minetest.get_item_group(stackname, groupname) ~= 0
|
||||
end
|
||||
)
|
||||
|
||||
inv:set_size(listname, 16)
|
||||
|
||||
return inv
|
||||
end
|
||||
|
||||
override_def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
lua_inv.show_formspec(clicker, name, shelf_formspec(pos, listname, slot_bg))
|
||||
end
|
||||
|
||||
override_def.can_dig = can_dig_container
|
||||
|
||||
minetest.override_item(name, override_def)
|
||||
end
|
||||
|
||||
lua_inv.default.shelf_override("default:bookshelf", "book", "books", "default_bookshelf_slot.png")
|
||||
|
||||
if minetest.get_modpath("vessels") then
|
||||
lua_inv.default.shelf_override("vessels:shelf", "vessel", "vessels", "vessels_shelf_slot.png")
|
||||
end
|
||||
|
|
|
@ -25,6 +25,7 @@ minetest.register_entity("lua_inv:wielded_item", {
|
|||
textures = {""},
|
||||
pointable = false,
|
||||
is_visible = false,
|
||||
static_save = false
|
||||
},
|
||||
|
||||
_item = "",
|
||||
|
@ -91,10 +92,12 @@ minetest.register_entity("lua_inv:wielded_item", {
|
|||
minetest.register_on_joinplayer(function(player)
|
||||
player:hud_set_flags({wielditem = false})
|
||||
|
||||
local ent = minetest.add_entity(player:get_pos(), "lua_inv:wielded_item"):get_luaentity()
|
||||
minetest.after(0.1, function()
|
||||
local ent = minetest.add_entity(player:get_pos(), "lua_inv:wielded_item"):get_luaentity()
|
||||
|
||||
ent._owner = player
|
||||
wielded_item_entities[player:get_player_name()] = ent
|
||||
ent._owner = player
|
||||
wielded_item_entities[player:get_player_name()] = ent
|
||||
|
||||
ent.object:set_attach(player, "Arm_Right", {x=0, y=4, z=2.5}, {x=-45, y=180, z=0}, true)
|
||||
ent.object:set_attach(player, "Arm_Right", {x=0, y=4, z=2.5}, {x=-45, y=180, z=0}, true)
|
||||
end)
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue