Skip to content

Commit 02ce16e

Browse files
committed
Block copying some items
1 parent 2424c0c commit 02ce16e

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

worldedit/common.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,38 @@ function worldedit.keep_loaded(pos1, pos2)
5959
end
6060

6161

62+
local function block_copying_item(stack)
63+
local def = stack:get_definition()
64+
return def and (def.premium or def.restrict_to_owner)
65+
end
66+
67+
68+
function worldedit.sanitize_meta(meta_tbl)
69+
if meta_tbl.fields and meta_tbl.fields.item then
70+
-- Item frames etc
71+
local stack = ItemStack(meta_tbl.fields.item)
72+
if block_copying_item(stack) then
73+
meta_tbl.fields.item = nil
74+
end
75+
end
76+
77+
if not meta_tbl.inventory then return end
78+
79+
for _, inventory in pairs(meta_tbl.inventory) do
80+
for _, stack in ipairs(inventory) do
81+
-- The existence of to_string is checked elsewhere, I don't know
82+
-- that it's needed but it won't hurt to do
83+
if stack.to_string and block_copying_item(stack) then
84+
-- We can't set inventory[i] to nil otherwise that would
85+
-- interfere with future iteration (e.g. in
86+
-- serialization.lua), so just empty the ItemStack.
87+
stack:replace(nil)
88+
end
89+
end
90+
end
91+
end
92+
93+
6294
local mh = {}
6395
worldedit.manip_helpers = mh
6496

worldedit/manipulations.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ end
165165
-- @param off
166166
-- @param meta_backwards (not officially part of API)
167167
-- @return The number of nodes copied.
168-
function worldedit.copy2(pos1, pos2, off, meta_backwards)
168+
function worldedit.copy2(pos1, pos2, off, meta_backwards, skip_meta_sanitize)
169169
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
170170

171171
local src_manip, src_area = mh.init(pos1, pos2)
@@ -226,6 +226,9 @@ function worldedit.copy2(pos1, pos2, off, meta_backwards)
226226
local pos = vector.new(pos1.x+x, pos1.y+y, pos1.z+z)
227227
local meta = get_meta(pos):to_table()
228228
pos = vector.add(pos, off)
229+
if not skip_meta_sanitize then
230+
worldedit.sanitize_meta(meta)
231+
end
229232
get_meta(pos):from_table(meta)
230233
end
231234
end
@@ -237,6 +240,9 @@ function worldedit.copy2(pos1, pos2, off, meta_backwards)
237240
local pos = vector.new(pos1.x+x, pos1.y+y, pos1.z+z)
238241
local meta = get_meta(pos):to_table()
239242
pos = vector.add(pos, off)
243+
if not skip_meta_sanitize then
244+
worldedit.sanitize_meta(meta)
245+
end
240246
get_meta(pos):from_table(meta)
241247
end
242248
end
@@ -285,7 +291,7 @@ function worldedit.move(pos1, pos2, axis, amount)
285291
-- Copy stuff to new location
286292
local off = vector.new()
287293
off[axis] = amount
288-
worldedit.copy2(pos1, pos2, off, backwards)
294+
worldedit.copy2(pos1, pos2, off, backwards, true)
289295
-- Nuke old area
290296
if not overlap then
291297
nuke_area(vector.new(), dim)
@@ -375,6 +381,7 @@ function worldedit.stretch(pos1, pos2, stretch_x, stretch_y, stretch_z)
375381
while pos.z >= pos1.z do
376382
local node = get_node(pos) -- Get current node
377383
local meta = get_meta(pos):to_table() -- Get meta of current node
384+
worldedit.sanitize_meta(meta)
378385

379386
-- Calculate far corner of the big node
380387
local pos_x = pos1.x + (pos.x - pos1.x) * stretch_x

worldedit/serialization.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function worldedit.serialize(pos1, pos2)
8181
local meta
8282
if has_meta[hash_node_position(pos)] then
8383
meta = get_meta(pos):to_table()
84+
worldedit.sanitize_meta(meta)
8485

8586
-- Convert metadata item stacks to item strings
8687
for _, invlist in pairs(meta.inventory) do

0 commit comments

Comments
 (0)