@@ -104,6 +104,11 @@ internal static bool Push(Vector3i blockPos)
104104 var crowd = GetEntitiesAt ( blockPos ) ;
105105 _log . Debug ( $ "found { crowd . Count } entities at position") ;
106106
107+ if ( crowd . Count == 0 )
108+ {
109+ return false ;
110+ }
111+
107112 var offsets = FindOffsets ( blockPos ) ;
108113 _log . Debug ( $ "found { offsets . Count } possible offsets") ;
109114
@@ -149,7 +154,7 @@ internal static bool Push(Vector3i blockPos)
149154 crowd [ i ] . SetPosition ( newPos ) ;
150155 }
151156 }
152- return crowd . Count > 0 ;
157+ return true ;
153158 }
154159
155160 /// <summary>
@@ -192,7 +197,7 @@ private static bool CanAccess(EntityPlayer player, PlatformUserIdentifierAbs int
192197 {
193198 if ( blockValue . Block . blockID == ModApi . PortableQuantumBlockId )
194199 {
195- _log . Debug ( $ "{ player . GetBlockPosition ( ) } contains a PortableQuantumBlock; premission is always granted") ;
200+ _log . Debug ( $ "{ player . GetBlockPosition ( ) } contains a PortableQuantumBlock; permission is always granted") ;
196201 secureTileEntity = null ;
197202 return true ;
198203 }
@@ -306,18 +311,15 @@ private static bool TryGetClientInfo(int entityId, out ClientInfo clientInfo)
306311 /// <returns>Whether a quantum elevator block above the sourcePos can be warped to.</returns>
307312 private static bool TryGetFloorAbove ( PlatformUserIdentifierAbs internalId , Vector3i sourcePos , BlockValue sourceBlockValue , TileEntitySign source , out Vector3i targetPos )
308313 {
309- _log . Debug ( "calling TryGetFloorAbove" ) ;
310- targetPos = sourcePos ;
314+ _log . Trace ( "calling TryGetFloorAbove" ) ;
311315 var clrId = GameManager . Instance . World . ChunkCache . ClusterIdx ;
312- // confirm if 256 is the right place to stop
313316
314- _log . Debug ( $ "planning to look above, starting at { targetPos } " ) ;
317+ var crawlerPos = sourcePos ;
315318 BlockValue targetBlockValue ;
316- for ( targetPos . y += GetBlockHeight ( sourceBlockValue ) ; targetPos . y < 256 ; targetPos . y += GetBlockHeight ( targetBlockValue ) )
319+ _log . Debug ( $ "planning to look above, starting from { crawlerPos } ") ;
320+ for ( crawlerPos . y += GetBlockHeight ( sourceBlockValue ) ; crawlerPos . y < 253 ; crawlerPos . y += GetBlockHeight ( targetBlockValue ) )
317321 {
318- targetBlockValue = GetBaseBlockPositionAndValue ( targetPos , out targetPos ) ;
319- _log . Debug ( $ "now checking { targetPos } ") ;
320-
322+ targetBlockValue = GetBaseBlockPositionAndValue ( crawlerPos , out targetPos ) ;
321323 if ( targetBlockValue . Block . blockID == ModApi . PortableQuantumBlockId )
322324 {
323325 _log . Debug ( $ "found the next accessible (portable) elevator at { targetPos } can be accessed") ;
@@ -341,7 +343,8 @@ private static bool TryGetFloorAbove(PlatformUserIdentifierAbs internalId, Vecto
341343 }
342344 }
343345
344- _log . Debug ( $ "no elevator was found below") ;
346+ _log . Trace ( $ "no elevator was found below") ;
347+ targetPos = default ;
345348 return false ;
346349 }
347350
@@ -355,13 +358,13 @@ private static bool TryGetFloorAbove(PlatformUserIdentifierAbs internalId, Vecto
355358 /// <returns>Whether a quantum elevator block above the sourcePos can be warped to.</returns>
356359 private static bool TryGetFloorBelow ( PlatformUserIdentifierAbs internalId , Vector3i sourcePos , TileEntitySign source , out Vector3i targetPos )
357360 {
358- _log . Debug ( "calling TryGetFloorBelow" ) ;
359- targetPos = sourcePos ;
360- for ( targetPos . y -- ; targetPos . y > 1 ; targetPos . y -- )
361+ _log . Trace ( "calling TryGetFloorBelow" ) ;
362+ var crawlerPos = sourcePos ;
363+ BlockValue targetBlockValue ;
364+ _log . Debug ( $ "planning to look below, starting from { crawlerPos } ") ;
365+ for ( crawlerPos . y -- ; crawlerPos . y > 1 ; crawlerPos . y -= GetBlockHeight ( targetBlockValue ) )
361366 {
362- var targetBlockValue = GetBaseBlockPositionAndValue ( targetPos , out targetPos ) ;
363- _log . Debug ( $ "checking { targetPos } ({ Block . nameIdMapping . GetNameForId ( targetBlockValue . Block . blockID ) } )") ;
364-
367+ targetBlockValue = GetBaseBlockPositionAndValue ( crawlerPos , out targetPos ) ;
365368 if ( ModApi . PortableQuantumBlockId == targetBlockValue . Block . blockID )
366369 {
367370 _log . Debug ( $ "found the next accessible (portable) elevator at { targetPos } can be accessed") ;
@@ -376,7 +379,8 @@ private static bool TryGetFloorBelow(PlatformUserIdentifierAbs internalId, Vecto
376379 }
377380 }
378381
379- _log . Debug ( $ "no elevator was found below") ;
382+ _log . Trace ( $ "no elevator was found below") ;
383+ targetPos = default ;
380384 return false ;
381385 }
382386
@@ -404,21 +408,30 @@ private static int GetBlockHeight(BlockValue blockValue)
404408 /// <returns>The block value found at the given position.</returns>
405409 private static BlockValue GetBaseBlockPositionAndValue ( Vector3i pos , out Vector3i blockPosition )
406410 {
411+ _log . Trace ( $ "GetBaseBlockPositionAndValue at position { pos } ") ;
407412 blockPosition = pos ;
408- _log . Debug ( $ "GetBaseBlockPositionAndValue at position { pos } " ) ;
413+
409414 var blockValue = GameManager . Instance . World . ChunkCache . GetBlock ( pos ) ;
410- if ( blockValue . ischild )
415+ var blockId = blockValue . Block . blockID ;
416+ _log . Trace ( $ "blockId: { blockId } ") ;
417+ var blockName = blockId == 0
418+ ? "air"
419+ : Block . nameIdMapping != null
420+ ? Block . nameIdMapping . GetNameForId ( blockValue . Block . blockID )
421+ : "no name mapping" ;
422+ _log . Debug ( $ "Identified block: id=[{ blockId } ], name=[{ blockName } ].") ;
423+
424+ var isChild = blockValue . ischild ;
425+ _log . Debug ( $ "block: { blockValue } , isChild? { isChild } { ( isChild ? ", parent:" + blockValue . parent : "" ) } ") ;
426+ if ( isChild )
411427 {
412- _log . Debug ( $ "Block found is a multi-block; self: { blockValue } , isChild? { blockValue . ischild } , parent: { blockValue . parent } ") ;
413- _log . Debug ( $ ">> parentY: { blockValue . parenty } ") ;
414- blockPosition . y += blockValue . parenty ;
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 } ") ;
415432 // NOTE: block value will be the same; leaving note here in case we ever find a way to make compound blocks
416433 // blockValueBody = GameManager.Instance.World.GetBlock(blockPosition);
417434 }
418- else
419- {
420- _log . Debug ( $ "Block found is not a multi-block; self: { blockValue } , isChild? { blockValue . ischild } ") ;
421- }
422435 return blockValue ;
423436 }
424437
0 commit comments