1- using PearlCalculatorLib . PearlCalculationLib . MathLib ;
2- using PearlCalculatorLib . Result ;
1+ using PearlCalculatorLib . Result ;
32using PearlCalculatorLib . PearlCalculationLib ;
43using PearlCalculatorLib . PearlCalculationLib . World ;
54using System ;
65using System . Collections . Generic ;
76using System . Collections ;
87using PearlCalculatorLib . PearlCalculationLib . Entity ;
9- using System . Security . Cryptography ;
10- using System . Transactions ;
118
129namespace PearlCalculatorLib . General
1310{
@@ -41,10 +38,12 @@ private static PearlEntity PearlSimulation(int redTNT , int blueTNT , int ticks
4138 /// <exception cref="ArgumentException"></exception>
4239 public static bool CalculateTNTAmount ( int maxTicks , double maxDistance )
4340 {
44- int redTNT , blueTNT ;
45- double divider = 0 ;
41+ int redTNT , blueTNT ;
42+ double trueRed , trueBlue ;
4643 Direction direction ;
47- Space3D distance , trueDistance , truePosition ;
44+ Space3D trueDistance , truePosition ;
45+
46+ double divider = 0 ;
4847
4948 truePosition = Data . Pearl . Position + Data . PearlOffset . ToSpace3D ( ) ;
5049 trueDistance = Data . Destination - truePosition ;
@@ -56,17 +55,18 @@ public static bool CalculateTNTAmount(int maxTicks , double maxDistance)
5655 Data . TNTResult . Clear ( ) ;
5756 direction = DirectionUtils . GetDirection ( truePosition . WorldAngle ( Data . Destination ) ) ;
5857 CalculateTNTVector ( direction , out Space3D redTNTVector , out Space3D blueTNTVector ) ;
59-
58+ //Calculate redTNT and blueTNT through simultaneous equations
59+ trueRed = ( trueDistance . Z * blueTNTVector . X - trueDistance . X * blueTNTVector . Z ) / ( redTNTVector . Z * blueTNTVector . X - blueTNTVector . Z * redTNTVector . X ) ;
60+ trueBlue = ( trueDistance . X - trueRed * redTNTVector . X ) / blueTNTVector . X ;
61+
6062 for ( int tick = 1 ; tick <= maxTicks ; tick ++ )
6163 {
62- //Factorization trueDistance to get a easier calculation
64+ //Factorization trueDistance to make a easier calculation
6365 divider += Math . Pow ( 0.99 , tick - 1 ) ;
64- distance = trueDistance / divider ;
6566
66- //Calculate redTNT and blueTNT through simultaneous equations
67- redTNT = Convert . ToInt32 ( Math . Round ( ( distance . Z * blueTNTVector . X - distance . X * blueTNTVector . Z ) / ( redTNTVector . Z * blueTNTVector . X - blueTNTVector . Z * redTNTVector . X ) ) ) ;
68- blueTNT = Convert . ToInt32 ( Math . Round ( ( distance . X - redTNT * redTNTVector . X ) / blueTNTVector . X ) ) ;
69-
67+ redTNT = Convert . ToInt32 ( trueRed / divider ) ;
68+ blueTNT = Convert . ToInt32 ( trueBlue / divider ) ;
69+
7070 //Run through the loops to get a better result around the redTNT and blueTNT
7171 //It is not perfect dude to the round up
7272 for ( int r = - 5 ; r <= 5 ; r ++ )
@@ -78,7 +78,7 @@ public static bool CalculateTNTAmount(int maxTicks , double maxDistance)
7878 PearlEntity pearlEntity = PearlSimulation ( redTNT + r , blueTNT + b , tick , direction ) ;
7979
8080 //Only the pearl with a difference smaller than 5 will pass the check
81- if ( ( pearlEntity . Position - Data . Destination ) . ToSurface2D ( ) . Absolute ( ) <= 5 )
81+ if ( ( pearlEntity . Position - Data . Destination ) . ToSurface2D ( ) . Absolute ( ) <= maxDistance )
8282 {
8383
8484 TNTCalculationResult result = new TNTCalculationResult
@@ -93,7 +93,7 @@ public static bool CalculateTNTAmount(int maxTicks , double maxDistance)
9393
9494 //Bypass MaxTNT check if it is set to 0
9595 //If MaxTNT is greater than 0 , only add those result which is lesser than MaxTNT
96- //If both redTNT and blueTNT are not greater or equal than zero , ignore them
96+ //If both redTNT and blueTNT are not greater or equal to zero , ignore them
9797 if ( ( Data . MaxTNT <= 0 || ( result . Blue <= Data . MaxTNT && result . Red <= Data . MaxTNT ) ) && result . Blue >= 0 && result . Red >= 0 )
9898 Data . TNTResult . Add ( result ) ;
9999
@@ -123,7 +123,7 @@ public static bool CalculateTNTAmount(int maxTicks , double maxDistance)
123123 /// <exception cref="ArgumentException"></exception>
124124 public static List < Entity > CalculatePearlTrace ( int redTNT , int blueTNT , int ticks , Direction direction )
125125 {
126- List < Entity > result = new List < Entity > ( ) ;
126+ List < Entity > result = new List < Entity > ( ticks + 1 ) ;
127127 PearlEntity pearl = new PearlEntity ( ( PearlEntity ) Data . Pearl . AddPosition ( Data . PearlOffset ) ) ;
128128
129129 CalculateTNTVector ( direction , out Space3D redTNTVector , out Space3D blueTNTVector ) ;
@@ -166,7 +166,6 @@ public static bool CalculateTNTConfiguration(int redTNT , int blueTNT , out BitA
166166
167167 for ( int i = 0 ; i < sortedRedConfig . Count ; i ++ )
168168 {
169-
170169 if ( redTNT >= sortedRedConfig [ i ] )
171170 {
172171 redTNT -= sortedRedConfig [ i ] ;
@@ -179,7 +178,6 @@ public static bool CalculateTNTConfiguration(int redTNT , int blueTNT , out BitA
179178
180179 for ( int i = 0 ; i < sortedBlueConfig . Count ; i ++ )
181180 {
182-
183181 if ( blueTNT >= sortedBlueConfig [ i ] )
184182 {
185183 blueTNT -= sortedBlueConfig [ i ] ;
@@ -199,10 +197,10 @@ public static bool CalculateTNTConfiguration(int redTNT , int blueTNT , out BitA
199197 }
200198
201199 /// <summary>
202- /// Calculate the accelerating vector of each Blue and Red TNT in given Direction
200+ /// Calculate the accelerating vector created by Blue and Red TNT in a given Direction
203201 /// </summary>
204202 /// <param name="direction">The Acceleration Direction of the Ender Pearl</param>
205- /// <param name="redTNTVector">Return am accelerating vector of Red TNT</param>
203+ /// <param name="redTNTVector">Return an accelerating vector of Red TNT</param>
206204 /// <param name="blueTNTVector">Return an accelerating vector of Blue TNT</param>
207205 /// <exception cref="ArgumentException"></exception>
208206 public static void CalculateTNTVector ( Direction direction , out Space3D redTNTVector , out Space3D blueTNTVector )
@@ -246,18 +244,14 @@ public static void CalculateTNTVector(Direction direction , out Space3D redTNTVe
246244
247245 private static Space3D TNTDirectionToCoordinate ( Direction coner )
248246 {
249- Space3D tntCoordinate = new Space3D ( 0 , 0 , 0 ) ;
250-
251- if ( coner == Direction . NorthEast )
252- tntCoordinate = Data . NorthEastTNT ;
253- else if ( coner == Direction . NorthWest )
254- tntCoordinate = Data . NorthWestTNT ;
255- else if ( coner == Direction . SouthEast )
256- tntCoordinate = Data . SouthEastTNT ;
257- else if ( coner == Direction . SouthWest )
258- tntCoordinate = Data . SouthWestTNT ;
259-
260- return tntCoordinate ;
247+ return coner switch
248+ {
249+ Direction . NorthEast => Data . NorthEastTNT ,
250+ Direction . NorthWest => Data . NorthWestTNT ,
251+ Direction . SouthEast => Data . SouthEastTNT ,
252+ Direction . SouthWest => Data . SouthWestTNT ,
253+ _ => Space3D . zero
254+ } ;
261255 }
262256 }
263257}
0 commit comments