# this function store build with some id
# pos1 - start location, pos2 - end location,
# inlucdeAir - save air or not?
function storeBuild(id: text,pos1: location, pos2: location, includeAir: boolean = true):
set {_pos1} to location of block at {_pos1}
set {_pos2} to location of block at {_pos2}
set {_x} to min((x coord of {_pos1}),(x coord of {_pos2}))
set {_y} to min((y coord of {_pos1}),(y coord of {_pos2}))
set {_z} to min((z coord of {_pos1}),(z coord of {_pos2}))
set {_vec} to vector({_x}-0.5,{_y}-0.5,{_z}-0.5)
delete {savedbuilds::%{_id}%::offsets::*}
delete {savedbuilds::%{_id}%::blocks::*}
if {_includeAir} is true:
loop blocks within {_pos1} and {_pos2}:
add 1 to {_i}
set {savedbuilds::%{_id}%::offsets::%{_i}%} to vector((x coord of loop-block)-{_x},(y coord of loop-block)-{_y},(z coord of loop-block)-{_z})
set {savedbuilds::%{_id}%::blocks::%{_i}%} to type of loop-block
else:
loop blocks within {_pos1} and {_pos2}:
if type of loop-block is not air:
add 1 to {_i}
set {savedbuilds::%{_id}%::offsets::%{_i}%} to vector((x coord of loop-block)-{_x},(y coord of loop-block)-{_y},(z coord of loop-block)-{_z})
set {savedbuilds::%{_id}%::blocks::%{_i}%} to type of loop-block
# this function paste saved build by id start at 'pos'
# includeAir - paste air?
function pasteBuild(id: text,pos: location, includeAir: boolean = true):
set {_pos} to location of block at {_pos}
if {_includeAir} is true:
loop {savedbuilds::%{_id}%::blocks::*}:
set block at ({_pos} ~ {savedbuilds::%{_id}%::offsets::%loop-index%}) to loop-value
else:
loop {savedbuilds::%{_id}%::blocks::*}:
if loop-value is not air:
set block at ({_pos} ~ {savedbuilds::%{_id}%::offsets::%loop-index%}) to loop-value
# for example:
# rotateBuild("id",vector(0,1,0),-90) will rotate build around Y position
# x x
# | |_ -> | _|
# |_____z |_____z
#
# rotateBuild("id",vector(0,0,1),-90) will rotate build around Z position
# y y
# | |_ -> | _|
# |_____x |_____x
function rotateBuild(id:text, axis: vector, degrees: number):
set {_mcos} to 1 - cos({_degrees})
set {_sin} to sin({_degrees})
set {_mcos} to vector({_mcos},{_mcos},{_mcos})
set {_sin} to vector({_sin},{_sin},{_sin})
loop {savedbuilds::%{_id}%::offsets::*}:
set {_vec} to loop-value
set {_vxp} to ({_axis} cross {_vec})
set {_vxvxp} to ({_axis} cross {_vxp})
set {savedbuilds::%{_id}%::offsets::%loop-index%} to ({_vec} ++ ({_sin} ** {_vxp}) ++ ({_mcos} ** {_vxvxp}))