Skip to content
This repository was archived by the owner on Jul 5, 2025. It is now read-only.

Commit a8bd8af

Browse files
Merge pull request #41 from jonathan-robertson/dev
Crash Fix
2 parents b5dde86 + 938093d commit a8bd8af

7 files changed

Lines changed: 50 additions & 31 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.3] - 2023-04-16
9+
10+
- fix crash caused by complex multi-dim blocks
11+
- fix unintentional offset check at wrong time
12+
- update upper y check to 253 build limit
13+
814
## [1.1.2] - 2023-03-05
915

1016
- add conf check when applying warp effects buff

ModInfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Name value="Quantum Elevators" />
44
<Description value="Add infinite distance, vertical-warp elevator panels." />
55
<Author value="Jonathan Robertson (Kanaverum)" />
6-
<Version value="1.1.2" />
6+
<Version value="1.1.3" />
77
<Website value="https://github.com/jonathan-robertson/quantum-elevators" />
88
</ModInfo>
99
</xml>

QuantumElevators.dll

0 Bytes
Binary file not shown.

src/CoreLogic.cs

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
[assembly: AssemblyTitle("QuantumElevators")]
88
[assembly: AssemblyDescription("")]
99
[assembly: AssemblyConfiguration("")]
10-
[assembly: AssemblyCompany("HP")]
10+
[assembly: AssemblyCompany("Jonathan Robertson")]
1111
[assembly: AssemblyProduct("QuantumElevators")]
12-
[assembly: AssemblyCopyright("Copyright © HP 2022")]
12+
[assembly: AssemblyCopyright("Copyright © Jonathan Robertson 2023")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

src/QuantumElevators.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<ItemGroup>
6565
<Compile Include="ConsoleCmdQuantumElevators.cs" />
6666
<Compile Include="CoreLogic.cs" />
67-
<Compile Include="EntityAlive_Patches.cs" />
67+
<Compile Include="Patches.cs" />
6868
<Compile Include="ModApi.cs" />
6969
<Compile Include="Properties\AssemblyInfo.cs" />
7070
<Compile Include="ModLog.cs" />

0 commit comments

Comments
 (0)