Fix inexistence of this

This commit is contained in:
Kimapr 2024-01-16 23:51:28 +05:00
commit 11c95679ef
3 changed files with 133 additions and 0 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
Copyright (C)2024 Kimapr
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

111
init.lua Normal file
View File

@ -0,0 +1,111 @@
local function pack(...)
local n = select('#',...)
local t = {...}
return function()
return unpack(t, 1, n)
end, t
end
local function splurp_node(name, def)
local over = {}
local allow_put = def.allow_metadata_inventory_put
local on_put = def.on_metadata_inventory_put or function() end
local on_construct = def.on_construct or function() end
local on_timer = def.on_timer
if not on_timer then return end
if not allow_put then return end
local function construct(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:get_list("src")
and inv:get_list("dst")
and inv:get_list("fuel")
then
inv:set_size("cooksneak",1)
end
end
def.on_construct = function(...)
local ret = pack(on_construct(...))
construct(...)
return ret()
end
def.on_timer = function(...)
local ret = pack(on_timer(...))
construct(...)
return ret()
end
local function room_in_list(inv, listname, stack)
local list = inv:get_list(listname)
local count = stack:get_count() - inv:add_item(listname, stack):get_count()
inv:set_list(listname, list)
return count
end
local function cooklist(stack)
if minetest.get_craft_result({method = "cooking", width = 1, items = {stack}}).time ~= 0 then
return "src"
elseif minetest.get_craft_result({method = "fuel", width = 1, items = {stack}}).time ~= 0 then
return "fuel"
end
return "src"
end
over.allow_metadata_inventory_put = function(pos, listname, index, stack, ...)
if listname ~= "cooksneak" then
return allow_put(pos, listname, index, stack, ...)
end
local inv = minetest.get_meta(pos):get_inventory()
local output = cooklist(stack)
local ret, ret_t = pack(allow_put(pos, output, index, stack, ...))
print(output..ret_t[1])
ret_t[1] = math.min(ret_t[1], room_in_list(inv, output, stack))
print(ret_t[1])
return ret()
end
over.on_metadata_inventory_put = function(pos, listname, index, stack, ...)
if listname ~= "cooksneak" then
return on_put(pos, listname, index, stack, ...)
end
local inv = minetest.get_meta(pos):get_inventory()
local output = cooklist(stack)
inv:add_item(output, inv:remove_item("cooksneak", stack))
end
minetest.override_item(name, over)
end
for name, def in pairs(minetest.registered_nodes) do
splurp_node(name, def)
end
local register_node = minetest.register_node
function minetest.register_node(name, def, ...)
local ret = pack(register_node(name, def, ...))
splurp_node(def.name, def)
return ret()
end
minetest.after(0, function()
local meta = getmetatable(minetest.get_meta(vector.new(0,0,0)))
local set_string = meta.set_string
function meta.set_string(self, k, v, ...)
if k == "formspec" then
v = v:gsub(table.concat({
"listring[context;dst]",
"listring[current_player;main]",
"listring[context;src]",
"listring[current_player;main]",
"listring[context;fuel]",
"listring[current_player;main]",
}):gsub("%p","%%%0"), table.concat {
"listring[context;cooksneak]",
"listring[current_player;main]",
"listring[context;cooksneak]",
"listring[context;dst]",
"listring[current_player;main]",
"listring[context;src]",
"listring[current_player;main]",
"listring[context;fuel]",
"listring[current_player;main]",
})
end
return set_string(self, k, v, ...)
end
end)

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name = cooksneak