@@ -312,31 +312,28 @@ private static bool TryGetClientInfo(int entityId, out ClientInfo clientInfo)
312312 private static bool TryGetFloorAbove ( PlatformUserIdentifierAbs internalId , Vector3i sourcePos , BlockValue sourceBlockValue , TileEntitySign source , out Vector3i targetPos )
313313 {
314314 _log . Trace ( "calling TryGetFloorAbove" ) ;
315- var clrId = GameManager . Instance . World . ChunkCache . ClusterIdx ;
316-
317315 var crawlerPos = sourcePos ;
318316 BlockValue targetBlockValue ;
317+ var clrId = GameManager . Instance . World . ChunkCache . ClusterIdx ;
319318 _log . Debug ( $ "planning to look above, starting from { crawlerPos } ") ;
320319 for ( crawlerPos . y += GetBlockHeight ( sourceBlockValue ) ; crawlerPos . y < 253 ; crawlerPos . y += GetBlockHeight ( targetBlockValue ) )
321320 {
322- targetBlockValue = GetBaseBlockPositionAndValue ( crawlerPos , out targetPos ) ;
323- if ( targetBlockValue . Block . blockID == ModApi . PortableQuantumBlockId )
321+ if ( GameManager . Instance . World . IsOpenSkyAbove ( clrId , crawlerPos . x , crawlerPos . y , crawlerPos . z ) )
324322 {
325- _log . Debug ( $ "found the next accessible (portable) elevator at { targetPos } can be accessed") ;
326- return true ;
323+ _log . Debug ( $ "open sky above { crawlerPos } ; abandoning above check") ;
324+ targetPos = default ;
325+ return false ;
327326 }
328327
329- if ( targetBlockValue . Block . blockID != ModApi . SecureQuantumBlockId )
328+ targetBlockValue = GetBaseBlockPositionAndValue ( crawlerPos , out targetPos ) ;
329+ if ( ModApi . PortableQuantumBlockId == targetBlockValue . Block . blockID )
330330 {
331- if ( GameManager . Instance . World . IsOpenSkyAbove ( clrId , targetPos . x , targetPos . y , targetPos . z ) )
332- {
333- _log . Debug ( $ "open sky above { targetPos } ; abandoning above check") ;
334- return false ;
335- }
336- continue ;
331+ _log . Debug ( $ "found the next accessible (portable) elevator at { targetPos } can be accessed") ;
332+ return true ;
337333 }
338334
339- if ( CanAccess ( internalId , source , GetTileEntitySignAt ( targetPos ) ) )
335+ if ( ModApi . SecureQuantumBlockId == targetBlockValue . Block . blockID
336+ && CanAccess ( internalId , source , GetTileEntitySignAt ( targetPos ) ) )
340337 {
341338 _log . Debug ( $ "found the next accessible (secured) elevator at { targetPos } can be accessed") ;
342339 return true ;
@@ -387,50 +384,84 @@ private static bool TryGetFloorBelow(PlatformUserIdentifierAbs internalId, Vecto
387384 /// <summary>
388385 /// Calculate and return the given BlockValue's height.
389386 /// </summary>
390- /// <param name="blockValue">The BlockValue to determine height for.</param>
387+ /// <param name="blockValue">The BlockValue to determine height for; if multidim, this value is expected to be the parent .</param>
391388 /// <returns>The height of the BlockValue provided.</returns>
392389 private static int GetBlockHeight ( BlockValue blockValue )
393390 {
391+ var height = 1 ;
394392 if ( blockValue . Block . isMultiBlock )
395393 {
396- _log . Debug ( $ "height of focused block is { blockValue . Block . multiBlockPos . dim . y } ") ;
397- return blockValue . Block . multiBlockPos . dim . y ;
394+ switch ( blockValue . rotation ) // note: if multidim, we can only pull rotation properly via the parent blockValue
395+ {
396+ case 0 :
397+ case 1 :
398+ case 2 :
399+ case 3 :
400+ case 4 :
401+ case 5 :
402+ case 6 :
403+ case 7 :
404+ height = blockValue . Block . multiBlockPos . dim . y ;
405+ break ;
406+ case 8 :
407+ case 10 :
408+ case 13 :
409+ case 15 :
410+ case 16 :
411+ case 18 :
412+ case 21 :
413+ case 23 :
414+ height = blockValue . Block . multiBlockPos . dim . z ;
415+ break ;
416+ case 9 :
417+ case 11 :
418+ case 12 :
419+ case 14 :
420+ case 17 :
421+ case 19 :
422+ case 20 :
423+ case 22 :
424+ height = blockValue . Block . multiBlockPos . dim . x ;
425+ break ;
426+ }
427+
428+ _log . Debug ( $ "calculatedHeight=[{ height } ] for multidim blockValue=[{ blockValue } ], multiBlockPos.dim=[{ blockValue . Block . multiBlockPos . dim } ]") ;
398429 }
399- _log . Debug ( $ "height of focused block is 1") ;
400- return 1 ;
430+ else
431+ {
432+ _log . Debug ( $ "calculatedHeight=[{ height } ] for non-multidim blockValue=[{ blockValue } ]") ;
433+ }
434+ return height ;
401435 }
402436
403437 /// <summary>
404438 /// Fetch and return the BlockValue found at the given position.
405439 /// </summary>
406440 /// <param name="pos">The given Block Position to retrieve a block value from.</param>
407441 /// <param name="blockPosition">Parent block position of the retrieved BlockValue found at the given position.</param>
408- /// <returns>The block value found at the given position.</returns>
442+ /// <returns>The block value found at the given position or its parent position .</returns>
409443 private static BlockValue GetBaseBlockPositionAndValue ( Vector3i pos , out Vector3i blockPosition )
410444 {
411445 _log . Trace ( $ "GetBaseBlockPositionAndValue at position { pos } ") ;
412- blockPosition = pos ;
413446
414447 var blockValue = GameManager . Instance . World . ChunkCache . GetBlock ( pos ) ;
415- var blockId = blockValue . Block . blockID ;
416- _log . Trace ( $ "blockId: { blockId } ") ;
417- var blockName = blockId == 0
448+
449+ var blockName = blockValue . Block . blockID == 0
418450 ? "air"
419451 : Block . nameIdMapping != null
420452 ? Block . nameIdMapping . GetNameForId ( blockValue . Block . blockID )
421453 : "no name mapping" ;
422- _log . Debug ( $ "Identified block: id=[{ blockId } ], name=[{ blockName } ].") ;
423454
424- var isChild = blockValue . ischild ;
425- _log . Debug ( $ "block: { blockValue } , isChild? { isChild } { ( isChild ? ", parent:" + blockValue . parent : "" ) } ") ;
426- if ( isChild )
455+ if ( blockValue . ischild )
456+ {
457+ blockPosition = pos + blockValue . parent ;
458+ blockValue = GameManager . Instance . World . GetBlock ( blockPosition ) ;
459+ _log . Debug ( $ "Identified block: id=[{ blockValue . Block . blockID } ], name=[{ blockName } ], blockValue=[{ blockValue } ], originalPos=[{ pos } ], parentPos=[{ blockPosition } ].") ;
460+ }
461+ else
427462 {
428- var parentY = blockValue . parenty ;
429- _log . Debug ( $ ">> parentY: { parentY } ") ;
430- blockPosition . y += parentY ;
431- _log . Debug ( $ "parent/tile position determined to be at { blockPosition } ") ;
432- // NOTE: block value will be the same; leaving note here in case we ever find a way to make compound blocks
433- // blockValueBody = GameManager.Instance.World.GetBlock(blockPosition);
463+ blockPosition = pos ;
464+ _log . Debug ( $ "Identified block: id=[{ blockValue . Block . blockID } ], name=[{ blockName } ], blockValue=[{ blockValue } ], position=[{ pos } ].") ;
434465 }
435466 return blockValue ;
436467 }
@@ -547,5 +578,19 @@ private static bool CanMoveTo(Vector3i blockPos, bool _bAllowToSpawnOnAirPos = f
547578 && ! block2 . IsCollideMovement && ! block2 . shape . IsSolidSpace
548579 && ! block3 . IsCollideMovement && ! block3 . shape . IsSolidSpace ;
549580 }
581+
582+ private static bool TryGetParentBlock ( Vector3i blockPos , BlockValue blockValue , out Vector3i parentPos , out BlockValue parentBlockValue )
583+ {
584+ if ( ! blockValue . Block . isMultiBlock || ! blockValue . ischild )
585+ {
586+ parentPos = default ;
587+ parentBlockValue = default ;
588+ return false ;
589+ }
590+
591+ parentPos = blockPos + blockValue . parent ;
592+ parentBlockValue = GameManager . Instance . World . ChunkCache . GetBlock ( parentPos ) ;
593+ return true ;
594+ }
550595 }
551596}
0 commit comments