Last active
December 12, 2021 10:46
-
-
Save Adrodoc/9ab9b5f74c186a70bac5510750b97da8 to your computer and use it in GitHub Desktop.
Lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "https://gist.github.com/mkarneim/8deed890e0d92ef19506e889819b2e97" | |
-- Wand of equal Trade | |
function woet() | |
print("Starting Wand of equal Trade") | |
click = cursor.registerForEvents("RIGHT_CLICK", "LEFT_CLICK") | |
for event in click.next do | |
if event.item ~= nil | |
and event.item.name == 'minecraft:stick' | |
and event.item.displayName == 'Wand of equal Trade' | |
then | |
setWorldPos(toPos(event.pos)) | |
if event.type == "RIGHT_CLICK" then | |
woet_copy() | |
end | |
if event.type == "LEFT_CLICK" then | |
woet_paste() | |
end | |
end | |
sleep(1) | |
end | |
end | |
function woet_copy() | |
copyClip(selectBox(1, 1, 1), "woet_selected") | |
end | |
function woet_paste() | |
blockToReplace = getBlock() | |
toVisit = {toVec(getWorldPos())} | |
toReplace = {} | |
while #toVisit > 0 do | |
visit = table.remove(toVisit) | |
setWorldPos(toPos(visit)) | |
table.addVec(toReplace, visit) | |
neighbours = getNeighbours(function(block) return block==blockToReplace; end) | |
for _, neighbour in pairs(neighbours) do | |
if not table.containsVec(toReplace, neighbour) then | |
table.insert(toVisit, neighbour) | |
end | |
end | |
end | |
for _, replace in pairs(toReplace) do | |
setWorldPos(toPos(replace)) | |
pasteClip("woet_selected") | |
end | |
end | |
function table.addVec(table, vec) | |
vecString = toVecString(vec) | |
table[vecString] = vec | |
end | |
function table.containsVec(table, vec) | |
vecString = toVecString(vec) | |
return table[vecString] ~= nil | |
end | |
function toVec(x,y,z) | |
return {x=x,y=y,z=z} | |
end | |
function toVecString(vec) | |
return toPosString(toPos(vec)) | |
end | |
function toPos(vec) | |
return vec.x,vec.y,vec.z | |
end | |
function toPosString(x,y,z) | |
return x.."/"..y.."/"..z | |
end | |
function toString(var) | |
if type(var) == "table" then | |
return table.toString(var) | |
end | |
return var | |
end | |
function table.toString(table) | |
result = '{' | |
for k, v in pairs(table) do | |
result = result .. toString(k) .. '=' .. toString(v) .. ',' | |
end | |
endIndex = next(table) and -2 or -1 | |
return string.sub(result, 1, endIndex) .. '}' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment