11package rbasamoyai .escalated .walkways ;
22
3+ import it .unimi .dsi .fastutil .objects .ReferenceArrayList ;
34import net .minecraft .core .BlockPos ;
45import net .minecraft .core .Direction ;
56import net .minecraft .core .Vec3i ;
1920import rbasamoyai .escalated .advancements .WalkwayTravelTracker ;
2021
2122import java .util .List ;
23+ import java .util .Optional ;
2224
2325import static net .minecraft .core .Direction .AxisDirection .NEGATIVE ;
2426import static net .minecraft .core .Direction .AxisDirection .POSITIVE ;
@@ -77,8 +79,10 @@ public static void transportEntity(WalkwayBlockEntity walkwayBE, Entity entity,
7779 if (Math .abs (walkwayBE .getSpeed ()) < 1 || !walkwayBlock .movesEntities (blockState ))
7880 return ;
7981
82+ Vec3 entityPos = getEntityPos (entity , walkwayBE );
83+ double entityY = entityPos .y ;
8084 // Not on top
81- if (entity . getY () + 0.25f < pos .getY ())
85+ if (entityY + 0.25d < pos .getY ())
8286 return ;
8387
8488 // Lock entities in place
@@ -95,13 +99,13 @@ public static void transportEntity(WalkwayBlockEntity walkwayBE, Entity entity,
9599 Vec3i centeringDirection = Direction .get (POSITIVE , walkwayFacing .getClockWise ().getAxis ()).getNormal ();
96100 Vec3 movement = Vec3 .atLowerCornerOf (movementDirection .getNormal ()).scale (movementSpeed );
97101
98- double diffCenter = axis == Direction .Axis .Z ? (pos .getX () + .5f - entity . getX ()) : (pos .getZ () + .5f - entity . getZ () );
99- if (Math .abs (diffCenter ) > 48 / 64f )
102+ double diffCenter = axis == Direction .Axis .Z ? (pos .getX () + .5d - entityPos . x ) : (pos .getZ () + .5d - entityPos . z );
103+ if (Math .abs (diffCenter ) > 48 / 64d )
100104 return ;
101105
102- float top = 15.5f / 16f ;
103- boolean onSlope = slope == WalkwaySlope .MIDDLE || slope == WalkwaySlope .TOP && entity . getY () - pos .getY () < top
104- || slope == WalkwaySlope .BOTTOM && entity . getY () - pos .getY () > top ;
106+ double top = 15.5d / 16d ;
107+ boolean onSlope = slope == WalkwaySlope .MIDDLE || slope == WalkwaySlope .TOP && entityY - pos .getY () < top
108+ || slope == WalkwaySlope .BOTTOM && entityY - pos .getY () > top ;
105109
106110 boolean movingDown = onSlope && movementFacing != walkwayFacing ;
107111 boolean movingUp = onSlope && movementFacing == walkwayFacing ;
@@ -117,7 +121,7 @@ public static void transportEntity(WalkwayBlockEntity walkwayBE, Entity entity,
117121 if (movingDown )
118122 movement = movement .add (0 , -Math .abs (axis .choose (movement .x , movement .y , movement .z )), 0 );
119123
120- Vec3 centering = Vec3 .atLowerCornerOf (centeringDirection ).scale (diffCenter * Math .min (Math .abs (movementSpeed ), .1f ) * 4 );
124+ Vec3 centering = Vec3 .atLowerCornerOf (centeringDirection ).scale (diffCenter * Math .min (Math .abs (movementSpeed ), .1d ) * 4 );
121125
122126 if (!(entity instanceof LivingEntity living ) || living .zza == 0 && living .xxa == 0 )
123127 movement = movement .add (centering );
@@ -130,7 +134,7 @@ public static void transportEntity(WalkwayBlockEntity walkwayBE, Entity entity,
130134 }
131135
132136 // Entity Collisions
133- if (Math .abs (movementSpeed ) < .5f ) {
137+ if (Math .abs (movementSpeed ) < .5d ) {
134138 Vec3 checkDistance = movement .normalize ()
135139 .scale (0.5 );
136140 AABB bb = entity .getBoundingBox ();
@@ -150,17 +154,17 @@ public static void transportEntity(WalkwayBlockEntity walkwayBE, Entity entity,
150154
151155 if (movingUp ) {
152156 Vec3 prevPos = entity .position ();
153- entity .move (SELF , movement );
157+ entity .move (SELF , transformMovement ( movement , walkwayBE ) );
154158 if (entity .horizontalCollision ) {
155159 entity .setPos (prevPos ); // Restore position and try again, but with adjusted starting condition
156- entity .move (SELF , new Vec3 (0 , movement .y * 0.1 , 0 )); // adjusted
157- entity .move (SELF , movement );
160+ entity .move (SELF , transformMovement ( new Vec3 (0 , movement .y * 0.1 , 0 ), walkwayBE )); // adjusted
161+ entity .move (SELF , transformMovement ( movement , walkwayBE ) );
158162 }
159163 } else if (movingDown ) {
160- entity .move (SELF , movement .multiply (1 , 0 , 1 ));
161- entity .move (SELF , movement .multiply (0 , 1 , 0 ));
164+ entity .move (SELF , transformMovement ( movement .multiply (1 , 0 , 1 ), walkwayBE ));
165+ entity .move (SELF , transformMovement ( movement .multiply (0 , 1 , 0 ), walkwayBE ));
162166 } else {
163- entity .move (SELF , movement );
167+ entity .move (SELF , transformMovement ( movement , walkwayBE ) );
164168 }
165169
166170 // Placement on steps
@@ -192,4 +196,33 @@ public static boolean isRidingOrBeingRiddenBy(Entity me, Entity other) {
192196 return false ;
193197 }
194198
199+ // Compatibility code //
200+
201+ private static final List <WalkwayTransformer > TRANSFORMERS = new ReferenceArrayList <>();
202+
203+ public static void addWalkwayTransformer (WalkwayTransformer t ) { TRANSFORMERS .add (t ); }
204+
205+ public static Vec3 getEntityPos (Entity entity , BlockEntity be ) {
206+ for (WalkwayTransformer t : TRANSFORMERS ) {
207+ Optional <Vec3 > o = t .transformPos (entity , be );
208+ if (o .isPresent ())
209+ return o .get ();
210+ }
211+ return entity .position ();
212+ }
213+
214+ public static Vec3 transformMovement (Vec3 movement , BlockEntity be ) {
215+ for (WalkwayTransformer t : TRANSFORMERS ) {
216+ Optional <Vec3 > o = t .transformMovement (movement , be );
217+ if (o .isPresent ())
218+ return o .get ();
219+ }
220+ return movement ;
221+ }
222+
223+ public interface WalkwayTransformer {
224+ Optional <Vec3 > transformPos (Entity entity , BlockEntity be );
225+ Optional <Vec3 > transformMovement (Vec3 movement , BlockEntity be );
226+ }
227+
195228}
0 commit comments