From 245e0a6e97b0e6419b3e50438999f625fdeb681c Mon Sep 17 00:00:00 2001 From: gpcf Date: Mon, 16 Oct 2017 19:11:07 +0200 Subject: Forbid stealing drawer upgrades (#11) --- lua/api.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/api.lua b/lua/api.lua index 736a8fb..ad32a3f 100755 --- a/lua/api.lua +++ b/lua/api.lua @@ -144,6 +144,10 @@ function drawers.drawer_on_dig(pos, node, player) end function drawers.drawer_allow_metadata_inventory_put(pos, listname, index, stack, player) + if core.is_protected(pos,player:get_player_name()) then + core.record_protection_violation(pos,player:get_player_name()) + return 0 + end if listname ~= "upgrades" then return 0 end @@ -198,6 +202,7 @@ function drawers.register_drawer(name, def) def.on_destruct = drawers.drawer_on_destruct def.on_dig = drawers.drawer_on_dig def.allow_metadata_inventory_put = drawers.drawer_allow_metadata_inventory_put + def.allow_metadata_inventory_take = drawers.drawer_allow_metadata_inventory_put def.on_metadata_inventory_put = drawers.add_drawer_upgrade def.on_metadata_inventory_take = drawers.remove_drawer_upgrade -- cgit v1.2.3 From 7d69f7d1a9e81fa76fae93172177e47bc8ac2637 Mon Sep 17 00:00:00 2001 From: gpcf Date: Fri, 27 Oct 2017 15:27:00 +0200 Subject: Prevent items from entering drawers without room for the item (#12) * Honor protection with drawer upgrades * Add function for pipeworks can_insert, so items don't attempt to enter a drawer with no room for them --- lua/api.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lua/api.lua b/lua/api.lua index ad32a3f..2bca40c 100755 --- a/lua/api.lua +++ b/lua/api.lua @@ -185,6 +185,17 @@ function drawers.drawer_insert_object(pos, node, stack, direction) return leftover end +function drawers.drawer_can_insert_object(pos, node, stack, direction) + local drawer_visuals = drawers.drawer_visuals[core.serialize(pos)] + if not drawer_visuals then return false end + + local leftover = stack + for _, visual in pairs(drawer_visuals) do + leftover = visual:try_insert_stack(leftover, true) + end + return not (leftover == stack) +end + function drawers.register_drawer(name, def) def.description = def.description or S("Wooden") def.drawtype = "nodebox" @@ -215,7 +226,10 @@ function drawers.register_drawer(name, def) def.groups.tubedevice_receiver = 1 def.tube = def.tube or {} def.tube.insert_object = def.tube.insert_object or - drawers.drawer_insert_object + drawers.drawer_insert_object + def.tube.can_insert = def.tube.can_insert or + drawers.drawer_can_insert_object + def.tube.connect_sides = {left = 1, right = 1, back = 1, top = 1, bottom = 1} def.after_place_node = pipeworks.after_place -- cgit v1.2.3