disallow putting stacks w/metadata into stations (currently, metadata is lost)

This commit is contained in:
flux 2022-09-23 09:57:17 -07:00
parent 16c72b1aa3
commit b342247367
No known key found for this signature in database
GPG Key ID: 9333B27816848A15
2 changed files with 82 additions and 68 deletions

View File

@ -2,6 +2,7 @@
local api = stairsplus.api local api = stairsplus.api
local has_metadata = stairsplus.util.has_metadata
local resolve_aliases = stairsplus.util.resolve_aliases local resolve_aliases = stairsplus.util.resolve_aliases
local default_stack_max = tonumber(minetest.settings:get("default_stack_max")) or 99 local default_stack_max = tonumber(minetest.settings:get("default_stack_max")) or 99
@ -171,6 +172,10 @@ function station.allow_inventory_put(meta, inv, listname, index, stack, player)
return 0 return 0
end end
if has_metadata(stack) then
return 0
end
local to_put_node = resolve_aliases(stack:get_name()) local to_put_node = resolve_aliases(stack:get_name())
local node = api.get_node_of_shaped_node(to_put_node) local node = api.get_node_of_shaped_node(to_put_node)
local shape = api.get_shape_of_shaped_node(to_put_node) local shape = api.get_shape_of_shaped_node(to_put_node)

View File

@ -1,16 +1,17 @@
stairsplus.util = { local util = {}
table_set_all = function(t, other_table)
function util.table_set_all(t, other_table)
for key, value in pairs(other_table) do for key, value in pairs(other_table) do
t[key] = value t[key] = value
end end
return t return t
end, end
table_is_empty = function(t) function util.table_is_empty(t)
return next(t) == nil return next(t) == nil
end, end
table_sort_keys = function(t, sort_function) function util.table_sort_keys(t, sort_function)
local sorted = {} local sorted = {}
for key in pairs(t) do for key in pairs(t) do
table.insert(sorted, key) table.insert(sorted, key)
@ -21,9 +22,9 @@ stairsplus.util = {
table.sort(sorted) table.sort(sorted)
end end
return sorted return sorted
end, end
table_equals = function(t1, t2) function util.table_equals(t1, t2)
if t1 == t2 then if t1 == t2 then
return true return true
end end
@ -52,9 +53,9 @@ stairsplus.util = {
end end
return true return true
end, end
get_location_string = function(inv) function util.get_location_string(inv)
local location = inv:get_location() local location = inv:get_location()
if location.type == "node" then if location.type == "node" then
return ("nodemeta:%i,%i,%i"):format(location.pos.x, location.pos.y, location.pos.z) return ("nodemeta:%i,%i,%i"):format(location.pos.x, location.pos.y, location.pos.z)
@ -65,9 +66,9 @@ stairsplus.util = {
else else
error(("unexpected location? %s"):format(dump(location))) error(("unexpected location? %s"):format(dump(location)))
end end
end, end
resolve_aliases = function(node, seen) function util.resolve_aliases(node, seen)
seen = seen or {} seen = seen or {}
if seen[node] then if seen[node] then
error(("alias loop on %s"):format(node)) error(("alias loop on %s"):format(node))
@ -75,8 +76,16 @@ stairsplus.util = {
local aliased_to = minetest.registered_aliases[node] local aliased_to = minetest.registered_aliases[node]
if aliased_to then if aliased_to then
seen[node] = true seen[node] = true
return stairsplus.util.resolve_aliases(aliased_to, seen) return util.resolve_aliases(aliased_to, seen)
end end
return node return node
end, end
}
function util.has_metadata(item)
item = type(item) == "userdata" and item or ItemStack(item)
local meta = item:get_meta()
return not util.table_is_empty(meta:to_table().fields)
end
stairsplus.util = util