@@ -771,59 +771,29 @@ private static void DisPlace(Player player, CommandReader cmd) {
771771 }
772772
773773 Block block ;
774- if ( ! cmd . NextBlock ( player , false , out block ) ) return ;
775- int dis ;
776- if ( ! cmd . NextInt ( out dis ) ) return ;
774+ if ( ! cmd . NextBlock ( player , false , out block ) ) return ;
775+ int length ;
776+ if ( ! cmd . NextInt ( out length ) ) return ;
777777
778- dis = dis * 32 ;
779778 byte yaw = player . Position . R , pitch = player . Position . L ;
780- Vector3I Pos ;
781-
782- if ( 225 < pitch || pitch < 32 ) {
783- if ( 225 <= yaw || yaw <= 32 ) {
784- Pos = new Vector3I ( player . Position . X / 32 , ( player . Position . Y - dis ) / 32 ,
785- ( player . Position . Z - 32 ) / 32 ) ;
786-
787- } else if ( 33 <= yaw && yaw <= 96 ) {
788- Pos = new Vector3I ( ( player . Position . X + dis ) / 32 , player . Position . Y / 32 ,
789- ( player . Position . Z - 32 ) / 32 ) ;
790- } else if ( 97 <= yaw && yaw <= 160 ) {
791- Pos = new Vector3I ( player . Position . X / 32 , ( player . Position . Y + dis ) / 32 ,
792- ( player . Position . Z - 32 ) / 32 ) ;
793- } else if ( 161 <= yaw && yaw <= 224 ) {
794- Pos = new Vector3I ( ( player . Position . X - dis ) / 32 , player . Position . Y / 32 ,
795- ( player . Position . Z - 32 ) / 32 ) ;
796- } else {
797- player . Message ( "Error occurred, please try again." ) ;
798- return ;
799- }
800- } else {
801- if ( 192 <= pitch && pitch <= 224 ) {
802- Pos = new Vector3I ( player . Position . X / 32 , player . Position . Y / 32 ,
803- ( player . Position . Z - 32 + dis ) / 32 ) ;
804- } else if ( 33 <= pitch && pitch <= 65 ) {
805- Pos = new Vector3I ( player . Position . X / 32 , player . Position . Y / 32 ,
806- ( player . Position . Z - 32 - dis ) / 32 ) ;
807- } else {
808- player . Message ( "Error occurred, please try again." ) ;
809- return ;
810- }
811- }
779+ Vector3I pos = player . Position . ToBlockCoordsRaw ( ) ; pos . Y -- ;
780+ Vector3I dir = Vector3I . FlatDirection ( yaw , pitch ) ;
781+ pos += dir * length ;
812782
813- Pos . X = Math . Min ( player . WorldMap . Width - 1 , Math . Max ( 0 , Pos . X ) ) ;
814- Pos . Y = Math . Min ( player . WorldMap . Length - 1 , Math . Max ( 0 , Pos . Y ) ) ;
815- Pos . Z = Math . Min ( player . WorldMap . Height - 1 , Math . Max ( 0 , Pos . Z ) ) ;
783+ pos . X = Math . Min ( player . WorldMap . Width - 1 , Math . Max ( 0 , pos . X ) ) ;
784+ pos . Y = Math . Min ( player . WorldMap . Length - 1 , Math . Max ( 0 , pos . Y ) ) ;
785+ pos . Z = Math . Min ( player . WorldMap . Height - 1 , Math . Max ( 0 , pos . Z ) ) ;
816786
817- if ( player . CanPlace ( player . World . Map , Pos , block , BlockChangeContext . Drawn ) != CanPlaceResult . Allowed ) {
787+ if ( player . CanPlace ( player . World . Map , pos , block , BlockChangeContext . Drawn ) != CanPlaceResult . Allowed ) {
818788 player . Message ( "&WYou are not allowed to build here" ) ;
819789 return ;
820790 }
821791
822- Player . RaisePlayerPlacedBlockEvent ( player , player . WorldMap , Pos , player . WorldMap . GetBlock ( Pos ) ,
792+ Player . RaisePlayerPlacedBlockEvent ( player , player . WorldMap , pos , player . WorldMap . GetBlock ( pos ) ,
823793 block , BlockChangeContext . Drawn ) ;
824- BlockUpdate blockUpdate = new BlockUpdate ( null , Pos , block ) ;
794+ BlockUpdate blockUpdate = new BlockUpdate ( null , pos , block ) ;
825795 player . World . Map . QueueUpdate ( blockUpdate ) ;
826- player . Message ( "Block placed at {0} ({1} blocks away from you)" , Pos , dis / 32 ) ;
796+ player . Message ( "Block placed at {0} ({1} blocks away from you)" , pos , length ) ;
827797 }
828798
829799 #endregion
0 commit comments