Skip to content

Instantly share code, notes, and snippets.

@mkarneim
Last active January 8, 2017 14:41
Show Gist options
  • Save mkarneim/ca86c86dd33064254ed9d28585ed36b7 to your computer and use it in GitHub Desktop.
Save mkarneim/ca86c86dd33064254ed9d28585ed36b7 to your computer and use it in GitHub Desktop.
require "gist.8deed890e0d92ef19506e889819b2e97.sample"
-- Wand of equal Trade
function woet()
print("Starting Wand of equal Trade 1")
click = events.register("RIGHT_CLICK", "LEFT_CLICK")
for event in click.next do
print("event",event.type,event.id)
if event.item ~= nil
and event.item.name == 'minecraft:stick'
and event.item.displayName == 'Wand of equal Trade'
then
print("pos",toPosString(toPos(event.pos)))
setWorldPos(toPos(event.pos))
print("block",getBlock())
if getBlock()~="air" then
if event.type == "RIGHT_CLICK" then
woet_copy()
end
if event.type == "LEFT_CLICK" then
woet_paste()
end
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