1010import com .ishland .flowsched .util .Assertions ;
1111import it .unimi .dsi .fastutil .Pair ;
1212import it .unimi .dsi .fastutil .ints .IntObjectPair ;
13+ import net .minecraft .util .function .ToFloatFunction ;
1314import net .minecraft .util .math .MathHelper ;
1415import net .minecraft .util .math .Spline ;
1516import net .minecraft .world .gen .densityfunction .DensityFunctionTypes ;
2627public class SplineAstNode implements AstNode {
2728
2829 public static final String SPLINE_METHOD_DESC = Type .getMethodDescriptor (Type .getType (float .class ), Type .getType (int .class ), Type .getType (int .class ), Type .getType (int .class ), Type .getType (EvalType .class ));
29- private final Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes .Spline .DensityFunctionWrapper > spline ;
30+ private final Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > spline ;
31+ private final ToFloatFunction <DensityFunctionTypes .Spline .SplinePos > applier ;
3032
31- public SplineAstNode (Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > spline ) {
33+ public SplineAstNode (Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > spline ) {
3234 this .spline = spline ;
35+ this .applier = Spline .method_1_3942 (spline );
3336 }
3437
3538 @ Override
3639 public double evalSingle (int x , int y , int z , EvalType type ) {
37- return spline .apply (new DensityFunctionTypes .Spline .SplinePos (new NoisePosVanillaInterface (x , y , z , type )));
40+ return applier .apply (new DensityFunctionTypes .Spline .SplinePos (new NoisePosVanillaInterface (x , y , z , type )));
3841 }
3942
4043 @ Override
@@ -62,14 +65,14 @@ public void doBytecodeGenSingle(BytecodeGen.Context context, InstructionAdapter
6265 m .areturn (Type .DOUBLE_TYPE );
6366 }
6467
65- private static ValuesMethodDef doBytecodeGenSpline (BytecodeGen .Context context , Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > spline ) {
68+ private static ValuesMethodDef doBytecodeGenSpline (BytecodeGen .Context context , Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > spline ) {
6669 {
6770 String cachedSplineMethod = context .getCachedSplineMethod (spline );
6871 if (cachedSplineMethod != null ) {
6972 return new ValuesMethodDef (false , cachedSplineMethod , 0.0F );
7073 }
7174 }
72- if (spline instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > spline1 ) {
75+ if (spline instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .DensityFunctionWrapper > spline1 ) {
7376 return new ValuesMethodDef (true , null , spline1 .value ());
7477 }
7578 String name = context .nextMethodName ("Spline" );
@@ -98,7 +101,7 @@ private static ValuesMethodDef doBytecodeGenSpline(BytecodeGen.Context context,
98101 return ordinal ;
99102 };
100103
101- if (spline instanceof Spline .Implementation <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > impl ) {
104+ if (spline instanceof Spline .Implementation <DensityFunctionTypes .Spline .DensityFunctionWrapper > impl ) {
102105 ValuesMethodDef [] valuesMethods = impl .values ().stream ()
103106 .map (spline1 -> doBytecodeGenSpline (context , spline1 ))
104107 .toArray (ValuesMethodDef []::new );
@@ -111,7 +114,7 @@ private static ValuesMethodDef doBytecodeGenSpline(BytecodeGen.Context context,
111114
112115 int lastConst = impl .locations ().length - 1 ;
113116
114- String locationFunction = context .newSingleMethod (McToAst .toAst (impl .locationFunction ().function (). value () ));
117+ String locationFunction = context .newSingleMethod (McToAst .toAst (impl .locationFunction ().function ()));
115118 context .callDelegateSingle (m , locationFunction );
116119 m .cast (Type .DOUBLE_TYPE , Type .FLOAT_TYPE );
117120 m .store (point , Type .FLOAT_TYPE );
@@ -375,7 +378,7 @@ private static ValuesMethodDef doBytecodeGenSpline(BytecodeGen.Context context,
375378 m .areturn (Type .FLOAT_TYPE );
376379 }
377380
378- } else if (spline instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > floatFunction ) {
381+ } else if (spline instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .DensityFunctionWrapper > floatFunction ) {
379382 m .fconst (floatFunction .value ());
380383 m .areturn (Type .FLOAT_TYPE );
381384 } else {
@@ -420,17 +423,17 @@ public void doBytecodeGenMulti(BytecodeGen.Context context, InstructionAdapter m
420423 m .areturn (Type .VOID_TYPE );
421424 }
422425
423- private static boolean deepEquals (Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a ,
424- Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > b ) {
425- if (a instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a1 &&
426- b instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > b1 ) {
426+ private static boolean deepEquals (Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > a ,
427+ Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > b ) {
428+ if (a instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .DensityFunctionWrapper > a1 &&
429+ b instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .DensityFunctionWrapper > b1 ) {
427430 return a1 .value () == b1 .value ();
428- } else if (a instanceof Spline .Implementation <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a1 &&
429- b instanceof Spline .Implementation <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > b1 ) {
431+ } else if (a instanceof Spline .Implementation <DensityFunctionTypes .Spline .DensityFunctionWrapper > a1 &&
432+ b instanceof Spline .Implementation <DensityFunctionTypes .Spline .DensityFunctionWrapper > b1 ) {
430433 boolean equals1 = Arrays .equals (a1 .derivatives (), b1 .derivatives ()) &&
431434 Arrays .equals (a1 .locations (), b1 .locations ()) &&
432435 a1 .values ().size () == b1 .values ().size () &&
433- McToAst .toAst (a1 .locationFunction ().function (). value ()) .equals (McToAst .toAst (b1 .locationFunction ().function (). value ()));
436+ McToAst .toAst (a1 .locationFunction ().function ()) .equals (McToAst .toAst (b1 .locationFunction ().function ()));
434437 if (!equals1 ) return false ;
435438 int size = a1 .values ().size ();
436439 for (int i = 0 ; i < size ; i ++) {
@@ -445,15 +448,15 @@ private static boolean deepEquals(Spline<DensityFunctionTypes.Spline.SplinePos,
445448 }
446449 }
447450
448- private static boolean deepRelaxedEquals (Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a ,
449- Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > b ) {
450- if (a instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a1 &&
451- b instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > b1 ) {
451+ private static boolean deepRelaxedEquals (Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > a ,
452+ Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > b ) {
453+ if (a instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .DensityFunctionWrapper > a1 &&
454+ b instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .DensityFunctionWrapper > b1 ) {
452455 return a1 .value () == b1 .value ();
453- } else if (a instanceof Spline .Implementation <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a1 &&
454- b instanceof Spline .Implementation <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > b1 ) {
456+ } else if (a instanceof Spline .Implementation <DensityFunctionTypes .Spline .DensityFunctionWrapper > a1 &&
457+ b instanceof Spline .Implementation <DensityFunctionTypes .Spline .DensityFunctionWrapper > b1 ) {
455458 boolean equals1 = a1 .values ().size () == b1 .values ().size () &&
456- McToAst .toAst (a1 .locationFunction ().function (). value ()) .relaxedEquals (McToAst .toAst (b1 .locationFunction ().function (). value ()));
459+ McToAst .toAst (a1 .locationFunction ().function ()) .relaxedEquals (McToAst .toAst (b1 .locationFunction ().function ()));
457460 if (!equals1 ) return false ;
458461 int size = a1 .values ().size ();
459462 for (int i = 0 ; i < size ; i ++) {
@@ -468,35 +471,35 @@ private static boolean deepRelaxedEquals(Spline<DensityFunctionTypes.Spline.Spli
468471 }
469472 }
470473
471- private static int deepHashcode (Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a ) {
472- if (a instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a1 ) {
474+ private static int deepHashcode (Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > a ) {
475+ if (a instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .DensityFunctionWrapper > a1 ) {
473476 return Float .hashCode (a1 .value ());
474- } else if (a instanceof Spline .Implementation <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a1 ) {
477+ } else if (a instanceof Spline .Implementation <DensityFunctionTypes .Spline .DensityFunctionWrapper > a1 ) {
475478 int result = 1 ;
476479
477480 result = 31 * result + Arrays .hashCode (a1 .derivatives ());
478481 result = 31 * result + Arrays .hashCode (a1 .locations ());
479- for (Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > spline : a1 .values ()) {
482+ for (Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > spline : a1 .values ()) {
480483 result = 31 * result + deepHashcode (spline );
481484 }
482- result = 31 * result + McToAst .toAst (a1 .locationFunction ().function (). value () ).hashCode ();
485+ result = 31 * result + McToAst .toAst (a1 .locationFunction ().function ()).hashCode ();
483486
484487 return result ;
485488 } else {
486489 return a .hashCode ();
487490 }
488491 }
489492
490- private static int deepRelaxedHashcode (Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a ) {
491- if (a instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a1 ) {
493+ private static int deepRelaxedHashcode (Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > a ) {
494+ if (a instanceof Spline .FixedFloatFunction <DensityFunctionTypes .Spline .DensityFunctionWrapper > a1 ) {
492495 return Float .hashCode (a1 .value ());
493- } else if (a instanceof Spline .Implementation <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > a1 ) {
496+ } else if (a instanceof Spline .Implementation <DensityFunctionTypes .Spline .DensityFunctionWrapper > a1 ) {
494497 int result = 1 ;
495498
496- for (Spline <DensityFunctionTypes .Spline .SplinePos , DensityFunctionTypes . Spline . DensityFunctionWrapper > spline : a1 .values ()) {
499+ for (Spline <DensityFunctionTypes .Spline .DensityFunctionWrapper > spline : a1 .values ()) {
497500 result = 31 * result + deepRelaxedHashcode (spline );
498501 }
499- result = 31 * result + McToAst .toAst (a1 .locationFunction ().function (). value () ).relaxedHashCode ();
502+ result = 31 * result + McToAst .toAst (a1 .locationFunction ().function ()).relaxedHashCode ();
500503
501504 return result ;
502505 } else {
0 commit comments