-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaste_replace.lua
More file actions
101 lines (73 loc) · 2.51 KB
/
paste_replace.lua
File metadata and controls
101 lines (73 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
local utils = ...
local S = utils.S
local function paste_replace (pos, map, dir, player, param2)
local action = utils.new_action (player:get_player_name ())
if action then
for y = 0, map.leny - 1 do
for z = 0, map.lenz - 1 do
for x = 0, map.lenx - 1 do
local node_pos = vector.add (pos, utils.rotate_to_dir ({ x = x, y = y, z = z }, dir))
local node = utils.get_far_node (node_pos)
if node then
if not action:place_node_from_data (node_pos, map[y][z][x], (param2 - map.param2 + 4) % 4,
player) then
utils.commit_action (action)
utils.undo_action (player:get_player_name ())
return false
end
end
utils.long_process.expire (0.08)
end
end
end
utils.commit_action (action)
return true
end
return false
end
local function paste_replace_runner (pos, dir, player_name, param2)
local player = minetest.get_player_by_name (player_name)
if player then
local map = utils.get_player_copy_buffer (player)
if map then
paste_replace (pos, map, dir, player, param2)
minetest.log ("action", string.format ("lwcreative_tools paste replace by %s at %s",
player_name,
minetest.pos_to_string (pos, 0)))
else
utils.player_error_message (player_name, "No copy buffer!")
end
end
end
local function on_place (itemstack, placer, pointed_thing)
if not utils.is_creative (placer) or
not utils.check_privs (placer) then
return itemstack
end
local count = itemstack:get_count ()
local look_dir, _, under = utils.get_place_stats (placer, pointed_thing)
if look_dir.x ~= 0 or look_dir.z ~= 0 then
look_dir.y = 0
local param2 = minetest.dir_to_facedir (vector.normalize (look_dir))
if count and look_dir then
local on_rightclick = utils.get_on_rightclick (under, placer)
if on_rightclick then
return on_rightclick (under, utils.get_far_node (under), placer, itemstack, pointed_thing)
end
if not utils.add_long_process (placer:get_player_name (), paste_replace_runner, nil,
under, look_dir, placer:get_player_name (), param2) then
utils.player_error_message (placer:get_player_name (), "An operation is already in progress!")
end
end
end
return itemstack
end
minetest.register_craftitem ("lwcreative_tools:paste_replace", {
description = S("Paste Replace"),
short_description = S("Paste Replace"),
groups = { },
inventory_image = "lwcreative_tools_paste_replace.png",
wield_image = "lwcreative_tools_paste_replace.png",
stack_max = 1,
on_place = on_place,
})