mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-12-22 20:32:22 +01:00
Add filters to prevent non-whitelisted craft items from being built
This commit is contained in:
parent
317877cda5
commit
123e470544
@ -158,9 +158,16 @@ minetest.register_node("digtron:builder", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
if minetest.get_item_group(stack:get_name(), "digtron") ~= 0 then
|
local stack_name = stack:get_name()
|
||||||
|
|
||||||
|
if minetest.get_item_group(stack_name, "digtron") ~= 0 then
|
||||||
return 0 -- don't allow builders to be set to build Digtron nodes, they'll just clog the output.
|
return 0 -- don't allow builders to be set to build Digtron nodes, they'll just clog the output.
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not minetest.registered_nodes[stack_name] and not digtron.whitelisted_on_place(stack_name) then
|
||||||
|
return 0 -- don't allow craft items unless their on_place is whitelisted.
|
||||||
|
end
|
||||||
|
|
||||||
local inv = minetest.get_inventory({type="node", pos=pos})
|
local inv = minetest.get_inventory({type="node", pos=pos})
|
||||||
inv:set_stack(listname, index, stack:take_item(1))
|
inv:set_stack(listname, index, stack:take_item(1))
|
||||||
return 0
|
return 0
|
||||||
|
@ -32,7 +32,7 @@ local function has_prefix(str, prefix)
|
|||||||
return str:sub(1, string.len(prefix)) == prefix
|
return str:sub(1, string.len(prefix)) == prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
local function whitelisted_on_place(item_name)
|
digtron.whitelisted_on_place = function (item_name)
|
||||||
for listed_item, value in pairs(digtron.builder_on_place_items) do
|
for listed_item, value in pairs(digtron.builder_on_place_items) do
|
||||||
if item_name == listed_item then return value end
|
if item_name == listed_item then return value end
|
||||||
end
|
end
|
||||||
@ -76,6 +76,7 @@ local function check_attached_node(p, n)
|
|||||||
end
|
end
|
||||||
|
|
||||||
digtron.item_place_node = function(itemstack, placer, place_to, param2)
|
digtron.item_place_node = function(itemstack, placer, place_to, param2)
|
||||||
|
local item_name = itemstack:get_name()
|
||||||
local def = itemstack:get_definition()
|
local def = itemstack:get_definition()
|
||||||
if not def then
|
if not def then
|
||||||
return itemstack, false
|
return itemstack, false
|
||||||
@ -87,7 +88,7 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2)
|
|||||||
pointed_thing.under = {x=place_to.x, y=place_to.y - 1, z=place_to.z}
|
pointed_thing.under = {x=place_to.x, y=place_to.y - 1, z=place_to.z}
|
||||||
|
|
||||||
-- Handle node-specific on_place calls as best we can.
|
-- Handle node-specific on_place calls as best we can.
|
||||||
if def.on_place and def.on_place ~= minetest.nodedef_default.on_place and whitelisted_on_place(itemstack:get_name()) then
|
if def.on_place and def.on_place ~= minetest.nodedef_default.on_place and digtron.whitelisted_on_place(item_name) then
|
||||||
if def.paramtype2 == "facedir" then
|
if def.paramtype2 == "facedir" then
|
||||||
pointed_thing.under = vector.add(place_to, minetest.facedir_to_dir(param2))
|
pointed_thing.under = vector.add(place_to, minetest.facedir_to_dir(param2))
|
||||||
elseif def.paramtype2 == "wallmounted" then
|
elseif def.paramtype2 == "wallmounted" then
|
||||||
@ -110,6 +111,14 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2)
|
|||||||
return returnstack, success
|
return returnstack, success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if minetest.registered_nodes[item_name] == nil then
|
||||||
|
-- Permitted craft items are handled by the node-specific on_place call, above.
|
||||||
|
-- if we are a craft item and we get here then we're not whitelisted and we should fail.
|
||||||
|
-- Note that builders should be filtering out craft items like this, but this will protect us
|
||||||
|
-- just in case.
|
||||||
|
return itemstack, false
|
||||||
|
end
|
||||||
|
|
||||||
local oldnode = minetest.get_node_or_nil(place_to)
|
local oldnode = minetest.get_node_or_nil(place_to)
|
||||||
|
|
||||||
--this should never happen, digtron is testing for adjacent unloaded nodes before getting here.
|
--this should never happen, digtron is testing for adjacent unloaded nodes before getting here.
|
||||||
|
Loading…
Reference in New Issue
Block a user