Update README and support replace and replaceinverse

This commit is contained in:
Hybrid Dog 2017-12-09 16:40:03 +01:00
parent 7ba4e30ff6
commit 6d08b6ce7e
2 changed files with 82 additions and 9 deletions

@ -9,22 +9,71 @@ Related issues:
* https://forum.minetest.net/viewtopic.php?p=296543#p296543
Supported chatcommands:
* /pos1
* /pos2
* /pos1 and /1
* /pos2 and /2
* /p
* /set
* /set and /s
* /replace and /r
* /replaceinverse and /ri
* /load
* /y
* /n
Ignored chatcommands:
* /lua
* /luatransform
* /clearobjects
* /fixlight
* /volume
* /save
* /mtschemcreate
* /mtschemprob
* /inspect /i
* /mark /mk
* /unmark /umk
* /volume and /v
* /about
Not yet implemented:
* /fixedpos /fp
* /reset /rst
* /shift
* /expand
* /contract
* /outset
* /inset
* /mix
* /hollowsphere /hspr
* /sphere /spr
* /hollowdome /hdo
* /dome /do
* /hollowcylinder /hcyl
* /cylinder /cyl
* /hollowpyramid /hpyr
* /pyramid /pyr
* /spiral
* /copy
* /move
* /stack
* /stack2
* /scale
* /transpose
* /flip
* /rotate
* /orient
* /drain
* /hide
* /suppress
* /highlight
* /restore
* /allocate
* /mtschemplace
* /deleteblocks
TODO:
* Add parameters to undo and redo: undo the last n
* Allow undoing changes which happened before other changes (considered unsafe)
e.g. //undo ~1 to undo the change before the latest one
* Add times to the changes, show in //show_journal
* Implement more commands

@ -12,7 +12,7 @@ local max_memory_usage = tonumber(
minetest.settings:get"we_undo.max_memory_usage") or 2^25
----------------- Journal and chatcommands -------------------------------------
----------------- Journal and we_undo chatcommands -----------------------------
local command_invoker
@ -229,6 +229,7 @@ minetest.register_chatcommand("/show_journal", {
if remember_innocuous then
-- short commands (/1 in this case) are automatically supported
override_chatcommand("/pos1",
function()
add_to_history{
@ -452,8 +453,7 @@ end
----------------------- World changing commands --------------------------------
local we_set = worldedit.set
local function my_we_set(pos1, pos2, ...)
local function we_nodeset_wrapper(func, pos1, pos2, ...)
assert(command_invoker, "Player not known")
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
-- FIXME: Protection support isn't needed
@ -464,7 +464,7 @@ local function my_we_set(pos1, pos2, ...)
local data_before = manip:get_data()
we_data = nil
local rv = we_set(pos1, pos2, ...)
local rv = func(pos1, pos2, ...)
local ystride = pos2.x - pos1.x + 1
local zstride = (pos2.y - pos1.y + 1) * ystride
@ -504,8 +504,15 @@ local function my_we_set(pos1, pos2, ...)
index_bytes = index_bytes,
compressed_data = compressed_data
}, command_invoker)
-- Note: param1, param2 and metadata are not changed by worldedit.set
return rv
-- Note: param1, param2 and metadata are not changed by worldedit.set and
-- similar functions
end
local we_set = worldedit.set
local function my_we_set(pos1, pos2, ...)
return we_nodeset_wrapper(we_set, pos1, pos2, ...)
end
override_cc_with_confirm("/set",
function()
@ -516,6 +523,23 @@ override_cc_with_confirm("/set",
end
)
local we_replace = worldedit.replace
local function my_we_replace(pos1, pos2, ...)
return we_nodeset_wrapper(we_replace, pos1, pos2, ...)
end
-- both commands share the same function
local replace_cmds = {"/replace", "/replaceinverse"}
for i = 1,2 do
override_cc_with_confirm(replace_cmds[i],
function()
worldedit.replace = my_we_replace
end,
function()
worldedit.replace = we_replace
end
)
end
undo_funcs.nodeids = function(name, data)
local pos1 = data.pos1
local pos2 = data.pos2