Skip to content

Commit 87b448b

Browse files
fix wrench duplication (#117)
Co-authored-by: BuckarooBanzay <[email protected]>
1 parent 619b7db commit 87b448b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

.luacheckrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ read_globals = {
2121
"doc",
2222
"intllib",
2323
"fakelib",
24+
"wrench"
2425
}
2526

2627
files = {

nodes/node_builders.lua

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ local S = digtron.S
77

88
local node_inventory_table = {type="node"} -- a reusable parameter for get_inventory calls, set the pos parameter before using.
99

10+
local has_wrench_mod = minetest.get_modpath("wrench")
11+
1012
local displace_due_to_help_button = 1.0
1113
if minetest.get_modpath("doc") then
1214
displace_due_to_help_button = 0.0
@@ -70,6 +72,15 @@ local builder_on_rightclick = function(pos, _, clicker, itemstack, pointed_thing
7072
builder_formspec(pos, meta))
7173
end
7274

75+
local function sanitize_item(item)
76+
-- check if the item can be "wrenched"
77+
if has_wrench_mod and wrench.registered_nodes[item:get_name()] then
78+
-- item can be "wrenched" (contains the inventory serialized in the "data" field)
79+
-- remove the serialized data on the placed node
80+
item:get_meta():set_string("data", "")
81+
end
82+
end
83+
7384
minetest.register_on_player_receive_fields(function(sender, formname, fields)
7485

7586
if formname:sub(1, 15) ~= "digtron:builder" then
@@ -277,7 +288,10 @@ minetest.register_node("digtron:builder", {
277288

278289
node_inventory_table.pos = pos
279290
local inv = minetest.get_inventory(node_inventory_table)
280-
inv:set_stack(listname, index, stack:take_item(1))
291+
local item = stack:take_item(1)
292+
sanitize_item(item)
293+
294+
inv:set_stack(listname, index, item)
281295

282296
-- If we're adding a wallmounted item and the build facing is greater than 5, reset it to 0
283297
local meta = minetest.get_meta(pos)
@@ -524,7 +538,10 @@ minetest.register_node("digtron:master_builder", {
524538

525539
node_inventory_table.pos = pos
526540
local inv = minetest.get_inventory(node_inventory_table)
527-
inv:set_stack(listname, index, stack:take_item(1))
541+
local item = stack:take_item(1)
542+
sanitize_item(item)
543+
544+
inv:set_stack(listname, index, item)
528545

529546
-- If we're adding a wallmounted item and the build facing is greater than 5, reset it to 0
530547
local meta = minetest.get_meta(pos)

0 commit comments

Comments
 (0)