From ef40266415897353d6f47edbd84e5b1d22bb6292 Mon Sep 17 00:00:00 2001 From: TernaryC <36998960+TernaryC@users.noreply.github.com> Date: Thu, 27 Jul 2023 02:37:24 -0500 Subject: [PATCH 01/11] Update README.md Added entry for lockrotation.sc --- programs/utilities/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/programs/utilities/README.md b/programs/utilities/README.md index df1dfc96..056f3d6b 100644 --- a/programs/utilities/README.md +++ b/programs/utilities/README.md @@ -57,6 +57,12 @@ for the display. _TODO: Update it!_ +### [lockrotation.sc](https://github.com/gnembon/scarpet/blob/master/programs/utilities/lockrotation.sc) +#### By TernaryC + +A command to preserve the player's current orientation for future block placements. +Recreation of the "lock rotation" feature from the Quark mod. + ### [nether_ceiling_backup.sc](https://github.com/gnembon/scarpet/blob/master/programs/utilities/nether_ceiling_backup.sc) #### By gnembon From fbca92fefd234052879f198273c1b3f4ea2e8060 Mon Sep 17 00:00:00 2001 From: TernaryC <36998960+TernaryC@users.noreply.github.com> Date: Thu, 27 Jul 2023 02:38:02 -0500 Subject: [PATCH 02/11] Added lockRotation.sc New program added to programs/utilities --- programs/utilities/lockRotation.sc | 207 +++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 programs/utilities/lockRotation.sc diff --git a/programs/utilities/lockRotation.sc b/programs/utilities/lockRotation.sc new file mode 100644 index 00000000..09ed1b95 --- /dev/null +++ b/programs/utilities/lockRotation.sc @@ -0,0 +1,207 @@ +/////////////////////////////////////////////////////////////////////////////// +// Rotation Lock +// v1.0.0 +// scarpet script written by "TernaryC" +// This description last updated 07/27/2023 +// +// This script aims to recreate the "lock rotation" feature of the Forge mod +// "Quark", as implemented in all versions of the mod since 1.14.4 +// +// This script uses no source code from the "Quark" mod, nor does is it a port +// of that mod or it's modules. +// +// By running the command "/lockrotation", the player records their current +// facing direction, as well as other data related to block placement. +// From then on, upon placing a block, the script will attempt to reorient the +// block to face the recorded placement data. +// +// The recorded data can be removed by typing the command "/lockrotation clear", +// or by locking into an identical rotation to the one already recorded (such +// as running the command twice in a row). +// +// The command "/lockrotation show" can be used to display the current +// recorded rotation data. +// +/////////////////////////////////////////////////////////////////////////////// + +__on_start() -> +( + global_lockProfile = null; +); +__command() -> _requestLock(); + +// Front Facing +show() -> +( + details = _getDetails(); + print(format('ig ' + details)); + return(); +); +_requestLock() -> +( + _getCurrentState(); + if (global_lockProfile == null || global_lockProfile:0 == null, + _tooltip(format(' Rotation lock ', 'b disabled')); + , + _tooltip(format(' Rotation lock ', 'b enabled')); + ); + return(); +); +_getDetails() -> +( + if (global_lockProfile == null, + return('[No lock set]') + ); + details = '[Locked: ' + global_lockProfile:2; + if (global_lockProfile:0 != global_lockProfile:2, + details += ' (' + global_lockProfile:0 + ')'; + ); + half = _halfSide(global_lockProfile:1); + if (half == null, half = 'no'); + details += ', ' + half + ' half]'; + return(details); +); +clear() -> +( + global_lockProfile = null; + _tooltip(format(' Rotation lock ', 'b disabled')); + return(); +); + +// Utility +_tooltip(text, outer(p)) -> +( + display_title(p, 'actionbar', text); +); +_getDir(yaw) -> +( + yaw += 45; + dir = 'south'; + if (yaw > 90, dir = 'west'); + if (yaw > 180, dir = 'north'); + if (yaw < 0, dir = 'east'); + if (yaw < -90, dir = 'north'); + return(dir); +); +_dirAxis(direction) -> +( + if (_contains(['north', 'south'], direction), + return('z'); + , _contains(['west', 'east'], direction), + return('x'); + , + return('y'); + ); +); +_flipDir(direction) -> +( + dirs = ['north', 'west', 'up', 'south', 'east', 'down']; + i = dirs ~ direction + 3; + if (i > 5, i += -6); + return(dirs:i); +); +_halfSide(half) -> +( + if (half == 0, return('bottom')); + if (half == 1, return('top')); + return(null); +); +_contains(list, value) -> return(list ~ value != null); +_isVertible(block) -> +( + if (_contains(block, 'shulker_box'), return(true)); + if (_contains(['end_rod', 'lightning_rod'], block), return(true)); + return(false); +); +_isBustable(block) -> +( + //Blocks that shouldn't be rotated lest they float or break + if (_contains(block, 'torch'), return(true)); + if (_contains(block, '_bud'), return(true)); + if (_contains(block, 'button'), return(true)); + if (_contains(block, '_bed'), return(true)); + if (_contains(block, 'coral_fan'), return(true)); + if (_contains(block, 'wall_head'), return(true)); + if (_contains(['amethyst_cluster', 'bell', 'ladder', 'lever', 'pointed_dripstone', 'tripwire_hook'], block), return(true)); + return(false); +); + +// App Methods +_getCurrentState(outer(p)) -> +( + newProfile = [null, null, null]; + + direction = query(p, 'facing'); + flat_direction = _getDir(query(p, 'yaw')); + + raycast = query(p, 'trace', 5, 'blocks', 'exact'); + if (raycast != null, + + half = abs(floor((raycast:1 - floor(raycast:1)) * 2)); + if (_dirAxis(direction) == 'y', + half = -1; + , raycast:1 < 0, + half = 1 - half; + ); + + newProfile = [_flipDir(direction), half, _flipDir(flat_direction)]; + , + newProfile = [direction, -1, flat_direction]; + ); + + if (global_lockProfile != null && newProfile == global_lockProfile, + global_lockProfile = null; + , + global_lockProfile = newProfile; + ); +); +_getIdealState(block) -> +( + state = block_state(block); + if(_isBustable(block), return(state)); + + direction = global_lockProfile:0; + half = global_lockProfile:1; + flat_dir = global_lockProfile:2; + if (global_lockProfile == null, return(state)); + + if (_contains(state, 'axis'), state:'axis' = _dirAxis(direction)); + if (_contains(state, 'type'), + //Slab Type + if (_contains(['top', 'bottom'], state:'type') && half != -1, + state:'type' = halfSide(half); + ); + ); + if (_contains(state, 'facing'), + state:'facing' = flat_dir; //Generic + //Hopper exception + if (block == 'hopper', + state:'facing' = _flipDir(flat_dir); + if (direction == 'up', state:'facing' = 'down'); + ); + //Vertibles exception + if (_isVertible(block), + state:'facing' = direction; + //Grindstone handling + if (block == 'grindstone', + state:'face' = 'wall'; + if (direction == 'up', state:'face' = 'floor'); + if (direction == 'down', state:'face' = 'ceiling'); + ); + ); + //Stairs addendum + if (_contains(state, 'half'), + if (_contains(['top', 'bottom'], state:'half') && half != -1, + state:'half' = halfSide(half); + ); + ); + ); + + return(state); +); + +__on_player_places_block(player, item_tuple, hand, block) -> +( + properties = _getIdealState(block); + set(pos(block), block, properties); +); \ No newline at end of file From 7f3120a0a4496a6b2554ca04842bd5259c37f172 Mon Sep 17 00:00:00 2001 From: Doodles <36998960+TernaryC@users.noreply.github.com> Date: Thu, 27 Jul 2023 16:00:26 -0500 Subject: [PATCH 03/11] lockRotation v1.0.1 update - Updated orientation calculation to better reflect actual Minecraft placement behavior. - Fixed major bug in reorientation function --- programs/utilities/lockRotation.sc | 43 +++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/programs/utilities/lockRotation.sc b/programs/utilities/lockRotation.sc index 09ed1b95..d77ffdba 100644 --- a/programs/utilities/lockRotation.sc +++ b/programs/utilities/lockRotation.sc @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Rotation Lock -// v1.0.0 +// v1.0.1 // scarpet script written by "TernaryC" // This description last updated 07/27/2023 // @@ -73,6 +73,10 @@ _tooltip(text, outer(p)) -> ( display_title(p, 'actionbar', text); ); +_sign(num) -> +( + return(num / abs(num)); +); _getDir(yaw) -> ( yaw += 45; @@ -100,6 +104,28 @@ _flipDir(direction) -> if (i > 5, i += -6); return(dirs:i); ); +_castSide(b, raycast) -> +( + blockpos = pos(b); + blockpos:0 += 0.5; + blockpos:1 += 0.5; + blockpos:2 += 0.5; + + difpos = [raycast:0 - blockpos:0, raycast:1 - blockpos:1, raycast:2 - blockpos:2]; + + truepos = []; + for (difpos, truepos:_i = ceil(abs(difpos:_i) - 0.49999) * _sign(difpos:_i)); + + direction = null; + if (truepos:0 == -1, direction = 'west'); + if (truepos:0 == 1, direction = 'east'); + if (truepos:1 == -1, direction = 'down'); + if (truepos:1 == 1, direction = 'up'); + if (truepos:2 == -1, direction = 'north'); + if (truepos:2 == 1, direction = 'south'); + + return(direction); +); _halfSide(half) -> ( if (half == 0, return('bottom')); @@ -132,11 +158,13 @@ _getCurrentState(outer(p)) -> newProfile = [null, null, null]; direction = query(p, 'facing'); - flat_direction = _getDir(query(p, 'yaw')); + flat_dir = _getDir(query(p, 'yaw')); raycast = query(p, 'trace', 5, 'blocks', 'exact'); + rayhit = query(p, 'trace', 5, 'blocks'); if (raycast != null, - + hit_dir = _castSide(rayhit, raycast); + half = abs(floor((raycast:1 - floor(raycast:1)) * 2)); if (_dirAxis(direction) == 'y', half = -1; @@ -144,9 +172,12 @@ _getCurrentState(outer(p)) -> half = 1 - half; ); - newProfile = [_flipDir(direction), half, _flipDir(flat_direction)]; + flat = hit_dir; + if (_contains(['up', 'down'], flat), flat = flat_dir); + + newProfile = [hit_dir, half, _flipDir(flat)]; , - newProfile = [direction, -1, flat_direction]; + newProfile = [direction, -1, flat_dir]; ); if (global_lockProfile != null && newProfile == global_lockProfile, @@ -192,7 +223,7 @@ _getIdealState(block) -> //Stairs addendum if (_contains(state, 'half'), if (_contains(['top', 'bottom'], state:'half') && half != -1, - state:'half' = halfSide(half); + state:'half' = _halfSide(half); ); ); ); From ae9aaddc52c9234e4171b0dfc05b5b64d86f8cf4 Mon Sep 17 00:00:00 2001 From: Doodles <36998960+TernaryC@users.noreply.github.com> Date: Thu, 27 Jul 2023 17:47:48 -0500 Subject: [PATCH 04/11] Update lockRotation.sc Fixed a typo in _getIdealState() --- programs/utilities/lockRotation.sc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/utilities/lockRotation.sc b/programs/utilities/lockRotation.sc index d77ffdba..9f35807e 100644 --- a/programs/utilities/lockRotation.sc +++ b/programs/utilities/lockRotation.sc @@ -200,7 +200,7 @@ _getIdealState(block) -> if (_contains(state, 'type'), //Slab Type if (_contains(['top', 'bottom'], state:'type') && half != -1, - state:'type' = halfSide(half); + state:'type' = _halfSide(half); ); ); if (_contains(state, 'facing'), @@ -235,4 +235,4 @@ __on_player_places_block(player, item_tuple, hand, block) -> ( properties = _getIdealState(block); set(pos(block), block, properties); -); \ No newline at end of file +); From b8fe13fe38f73c3d51c853808389592240994ac7 Mon Sep 17 00:00:00 2001 From: Doodles <36998960+TernaryC@users.noreply.github.com> Date: Fri, 28 Jul 2023 01:46:47 -0500 Subject: [PATCH 05/11] Update README.md Usage instructions added to lockrotation.sc entry --- programs/utilities/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/utilities/README.md b/programs/utilities/README.md index 056f3d6b..a8790bdd 100644 --- a/programs/utilities/README.md +++ b/programs/utilities/README.md @@ -61,6 +61,7 @@ _TODO: Update it!_ #### By TernaryC A command to preserve the player's current orientation for future block placements. +Use "/lockrotation" to save your orientation, including the way you're facing and which half of a block you're looking at. Recreation of the "lock rotation" feature from the Quark mod. ### [nether_ceiling_backup.sc](https://github.com/gnembon/scarpet/blob/master/programs/utilities/nether_ceiling_backup.sc) From cb637ed3c67353395b27bdb8ed9b347529e809c8 Mon Sep 17 00:00:00 2001 From: Doodles <36998960+TernaryC@users.noreply.github.com> Date: Fri, 28 Jul 2023 01:51:03 -0500 Subject: [PATCH 06/11] lockRotation v1.0.2 update - Holographic indicator added when running the command, to better indicate block halves - When locking rotation and immediately placing a block, some blocks would be placed opposite to how one would expect. This has been largely corrected. --- programs/utilities/lockRotation.sc | 103 +++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 6 deletions(-) diff --git a/programs/utilities/lockRotation.sc b/programs/utilities/lockRotation.sc index 9f35807e..b414acdb 100644 --- a/programs/utilities/lockRotation.sc +++ b/programs/utilities/lockRotation.sc @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Rotation Lock -// v1.0.1 +// v1.0.2 // scarpet script written by "TernaryC" // This description last updated 07/27/2023 // @@ -104,7 +104,7 @@ _flipDir(direction) -> if (i > 5, i += -6); return(dirs:i); ); -_castSide(b, raycast) -> +_castDif(b, raycast) -> ( blockpos = pos(b); blockpos:0 += 0.5; @@ -116,6 +116,12 @@ _castSide(b, raycast) -> truepos = []; for (difpos, truepos:_i = ceil(abs(difpos:_i) - 0.49999) * _sign(difpos:_i)); + return(truepos); +); +_castSide(b, raycast) -> +( + truepos = _castDif(b, raycast); + direction = null; if (truepos:0 == -1, direction = 'west'); if (truepos:0 == 1, direction = 'east'); @@ -151,8 +157,90 @@ _isBustable(block) -> if (_contains(['amethyst_cluster', 'bell', 'ladder', 'lever', 'pointed_dripstone', 'tripwire_hook'], block), return(true)); return(false); ); +_2to3(coord, third) -> +( + vector = []; + j = 0; + loop(3, + if (_ == third:1, + vector:_ = third:0; + , + vector:_ = coord:j; + j += 1; + ); + ); + return(vector); +); +_linetobox(point1, point2, xoff, yoff) -> +( + return([point2:0 + xoff, point2:1 + yoff]); +); // App Methods +_displayProfile(raycast, blockhit, profile) -> +( + if (raycast == null, return()); + + b_at = pos(blockhit); + b_cent = []; + for (b_at, b_cent:_i = _ + 0.5); + b_op = []; + for (b_at, b_op:_i = _ + 1); + + hitdir = _castDif(blockhit, raycast); + sidepos = []; + for (b_cent, sidepos:_i = _ + (hitdir:_i * 0.505)); + + filt = -1; + for (hitdir, if (_ != 0, filt = _i; break())); + third = [sidepos:filt, filt]; + cent = []; + for (sidepos, if(_i != third:1, cent += _)); + + corner = [[null,null], [null,null], [null,null], [null,null]]; + corner:0:0 = cent:0 - 0.45; + corner:0:1 = cent:1 - 0.45; + corner:1:0 = cent:0 - 0.45; + corner:1:1 = cent:1 + 0.45; + corner:2:0 = cent:0 + 0.45; + corner:2:1 = cent:1 + 0.45; + corner:3:0 = cent:0 + 0.45; + corner:3:1 = cent:1 - 0.45; + + if (profile:1 != -1, + y = 0; + if (third:1 == 2, y = 1); + if (profile:1 == 0, + for(corner, if(_:y > sidepos:1, corner:_i:y += -0.45)); + , + for(corner, if(_:y < sidepos:1, corner:_i:y += 0.45)); + ); + ); + + d = 20; //duration + w = 0.15; //line thickness + draw_shape('box', d, + 'from', _2to3(corner:0, third), + 'to', _2to3(_linetobox(corner:0, corner:1, w, 0), third), + 'fill', 4294967295 + ); + draw_shape('box', d, + 'from', _2to3(corner:1, third), + 'to', _2to3(_linetobox(corner:1, corner:2, 0, -w), third), + 'fill', 4294967295 + ); + draw_shape('box', d, + 'from', _2to3(corner:2, third), + 'to', _2to3(_linetobox(corner:2, corner:3, -w, 0), third), + 'fill', 4294967295 + ); + draw_shape('box', d, + 'from', _2to3(corner:3, third), + 'to', _2to3(_linetobox(corner:3, corner:0, 0, w), third), + 'fill', 4294967295 + ); + undef(w); +); _getCurrentState(outer(p)) -> ( newProfile = [null, null, null]; @@ -172,17 +260,19 @@ _getCurrentState(outer(p)) -> half = 1 - half; ); - flat = hit_dir; + flat = _flipDir(hit_dir); if (_contains(['up', 'down'], flat), flat = flat_dir); newProfile = [hit_dir, half, _flipDir(flat)]; , newProfile = [direction, -1, flat_dir]; ); + print(newProfile); if (global_lockProfile != null && newProfile == global_lockProfile, global_lockProfile = null; , + _displayProfile(raycast, rayhit, newProfile); global_lockProfile = newProfile; ); ); @@ -222,8 +312,9 @@ _getIdealState(block) -> ); //Stairs addendum if (_contains(state, 'half'), - if (_contains(['top', 'bottom'], state:'half') && half != -1, - state:'half' = _halfSide(half); + if (_contains(['top', 'bottom'], state:'half'), + if (state:'open' == null, state:'facing' = _flipDir(flat_dir)); + if (half != -1, state:'half' = _halfSide(half)); ); ); ); @@ -235,4 +326,4 @@ __on_player_places_block(player, item_tuple, hand, block) -> ( properties = _getIdealState(block); set(pos(block), block, properties); -); +); \ No newline at end of file From f3b31ede67b341ad9c11dafe445daff2e4ac285f Mon Sep 17 00:00:00 2001 From: Doodles <36998960+TernaryC@users.noreply.github.com> Date: Fri, 28 Jul 2023 01:59:55 -0500 Subject: [PATCH 07/11] Update lockRotation.sc Cleaned up errant print statement. Whoops --- programs/utilities/lockRotation.sc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/utilities/lockRotation.sc b/programs/utilities/lockRotation.sc index b414acdb..ae23cda3 100644 --- a/programs/utilities/lockRotation.sc +++ b/programs/utilities/lockRotation.sc @@ -267,7 +267,7 @@ _getCurrentState(outer(p)) -> , newProfile = [direction, -1, flat_dir]; ); - print(newProfile); + //print(newProfile); if (global_lockProfile != null && newProfile == global_lockProfile, global_lockProfile = null; @@ -326,4 +326,4 @@ __on_player_places_block(player, item_tuple, hand, block) -> ( properties = _getIdealState(block); set(pos(block), block, properties); -); \ No newline at end of file +); From 47b36d6d945a0a6881f3c2b8820758d50559715c Mon Sep 17 00:00:00 2001 From: Doodles <36998960+TernaryC@users.noreply.github.com> Date: Fri, 28 Jul 2023 02:17:40 -0500 Subject: [PATCH 08/11] Temporary fix to shaped stair bug Not an ideal solution, but one that works without meaningful side effects. --- programs/utilities/lockRotation.sc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/programs/utilities/lockRotation.sc b/programs/utilities/lockRotation.sc index ae23cda3..c2d4e83c 100644 --- a/programs/utilities/lockRotation.sc +++ b/programs/utilities/lockRotation.sc @@ -27,6 +27,7 @@ __on_start() -> ( global_lockProfile = null; + global_rotated = null; ); __command() -> _requestLock(); @@ -267,7 +268,6 @@ _getCurrentState(outer(p)) -> , newProfile = [direction, -1, flat_dir]; ); - //print(newProfile); if (global_lockProfile != null && newProfile == global_lockProfile, global_lockProfile = null; @@ -326,4 +326,22 @@ __on_player_places_block(player, item_tuple, hand, block) -> ( properties = _getIdealState(block); set(pos(block), block, properties); + global_rotated = block; ); +__on_tick() -> +( + if(global_rotated != null, + //sleep(1000); + //for(neighbours(global_rotated), + // print(pos(_)); + // update(pos(_)); + //); + //update(pos(global_rotated)); + upos = [pos(global_rotated):0 + 1, pos(global_rotated):1, pos(global_rotated):2]; + ublock = block(upos); + set(upos, 'air'); + place_item('stone', upos); + set(upos, ublock); + global_rotated = null; + ); +); \ No newline at end of file From 7f0c943f037040e29eb93c68550e4615412c5aa2 Mon Sep 17 00:00:00 2001 From: Doodles <36998960+TernaryC@users.noreply.github.com> Date: Fri, 28 Jul 2023 02:20:36 -0500 Subject: [PATCH 09/11] Cleanup to previous fix Made the stairs fix less overzealous --- programs/utilities/lockRotation.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/utilities/lockRotation.sc b/programs/utilities/lockRotation.sc index c2d4e83c..2fcc5515 100644 --- a/programs/utilities/lockRotation.sc +++ b/programs/utilities/lockRotation.sc @@ -326,7 +326,7 @@ __on_player_places_block(player, item_tuple, hand, block) -> ( properties = _getIdealState(block); set(pos(block), block, properties); - global_rotated = block; + if (_contains(block, 'stairs'), global_rotated = block); ); __on_tick() -> ( From a4a1fed5e3a62193ea12f106e7c1eac2aa805d49 Mon Sep 17 00:00:00 2001 From: Doodles <36998960+TernaryC@users.noreply.github.com> Date: Fri, 28 Jul 2023 02:23:33 -0500 Subject: [PATCH 10/11] Update to lockRotation.sc Added missing grindstone exception detection. --- programs/utilities/lockRotation.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/utilities/lockRotation.sc b/programs/utilities/lockRotation.sc index 2fcc5515..26b9bac3 100644 --- a/programs/utilities/lockRotation.sc +++ b/programs/utilities/lockRotation.sc @@ -143,7 +143,7 @@ _contains(list, value) -> return(list ~ value != null); _isVertible(block) -> ( if (_contains(block, 'shulker_box'), return(true)); - if (_contains(['end_rod', 'lightning_rod'], block), return(true)); + if (_contains(['end_rod', 'lightning_rod', 'grindstone'], block), return(true)); return(false); ); _isBustable(block) -> From a228871308dc6ad1ee6101bd8060ed92588da434 Mon Sep 17 00:00:00 2001 From: Doodles <36998960+TernaryC@users.noreply.github.com> Date: Thu, 3 Aug 2023 20:09:12 -0500 Subject: [PATCH 11/11] Update to lockRotation.sc - Cleaned up and quickened stair correction code - Fixed minor bug in hologram rendering --- programs/utilities/lockRotation.sc | 42 +++++++++++++----------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/programs/utilities/lockRotation.sc b/programs/utilities/lockRotation.sc index 26b9bac3..609b009e 100644 --- a/programs/utilities/lockRotation.sc +++ b/programs/utilities/lockRotation.sc @@ -11,7 +11,8 @@ // of that mod or it's modules. // // By running the command "/lockrotation", the player records their current -// facing direction, as well as other data related to block placement. +// facing direction, as well as other data related to block placement, such +// as block half. // From then on, upon placing a block, the script will attempt to reorient the // block to face the recorded placement data. // @@ -27,7 +28,6 @@ __on_start() -> ( global_lockProfile = null; - global_rotated = null; ); __command() -> _requestLock(); @@ -76,6 +76,7 @@ _tooltip(text, outer(p)) -> ); _sign(num) -> ( + if (num == 0, return(0)); return(num / abs(num)); ); _getDir(yaw) -> @@ -208,7 +209,8 @@ _displayProfile(raycast, blockhit, profile) -> corner:3:0 = cent:0 + 0.45; corner:3:1 = cent:1 - 0.45; - if (profile:1 != -1, + //Switch to half-block hologram if relevant + if (profile:1 != -1 && !_contains(['up', 'down'], profile:0), y = 0; if (third:1 == 2, y = 1); if (profile:1 == 0, @@ -272,8 +274,8 @@ _getCurrentState(outer(p)) -> if (global_lockProfile != null && newProfile == global_lockProfile, global_lockProfile = null; , - _displayProfile(raycast, rayhit, newProfile); global_lockProfile = newProfile; + _displayProfile(raycast, rayhit, newProfile); ); ); _getIdealState(block) -> @@ -324,24 +326,16 @@ _getIdealState(block) -> __on_player_places_block(player, item_tuple, hand, block) -> ( - properties = _getIdealState(block); - set(pos(block), block, properties); - if (_contains(block, 'stairs'), global_rotated = block); -); -__on_tick() -> -( - if(global_rotated != null, - //sleep(1000); - //for(neighbours(global_rotated), - // print(pos(_)); - // update(pos(_)); - //); - //update(pos(global_rotated)); - upos = [pos(global_rotated):0 + 1, pos(global_rotated):1, pos(global_rotated):2]; - ublock = block(upos); - set(upos, 'air'); - place_item('stone', upos); - set(upos, ublock); - global_rotated = null; - ); + if (global_lockProfile != null, + properties = _getIdealState(block); + set(pos(block), block, properties); + if (_contains(block, 'stairs'), + // This code is a little janky, but is neccessary to correctly update shaped stairs. + upos = [pos(block):0 + 1, pos(block):1, pos(block):2]; + ublock = block(upos); + set(upos, 'air'); + place_item(ublock, upos); + set(upos, ublock); + ); + ); ); \ No newline at end of file