public static void PlayerAction_BuildAfterPrebuildPostfix(PlayerAction_Build __instance, ref PlanetFactory ___factory, PlanetAuxData ___planetAux) { // Do we have cached inserters? var ci = PatchCopyInserters.cachedInserters; if (ci.Count > 0) { foreach (var buildPreview in __instance.buildPreviews) { var targetPos = __instance.previewPose.position + __instance.previewPose.rotation * buildPreview.lpos; var entityPool = ___factory.entityPool; foreach (var inserter in ci) { // Find the desired belt/building position // As delta doesn't work over distance, re-trace the Grid Snapped steps from the original // to find the target belt/building for this inserters other connection var currentPos = targetPos; for (int u = 0; u < inserter.snapCount; u++) { currentPos = ___planetAux.Snap(currentPos + inserter.snapMoves[u], true, false); } var testPos = currentPos; // Find the other entity at the target location int otherId = 0; for (int x = 1; x < ___factory.entityCursor; x++) { if (entityPool[x].id == x) { var distance = Vector3.Distance(entityPool[x].pos, testPos); if (distance < 0.2) { otherId = entityPool[x].id; break; } } } if (otherId != 0) { // Order an inserter var pi = new PatchCopyInserters.PendingInserter(); pi.otherId = otherId; pi.ci = inserter; pi.AssemblerPos = targetPos; PatchCopyInserters.pendingInserters.Add(pi); } } } } }
public static void PlayerAction_BuildAfterPrebuildPostfix(PlayerAction_Build __instance, ref PlanetFactory ___factory, PlanetAuxData ___planetAux) { // Do we have cached inserters? var ci = PatchCopyInserters.cachedInserters; if (CopyInserters.copyEnabled && ci.Count > 0) { foreach (BuildPreview buildPreview in __instance.buildPreviews) { Vector3 targetPos; Quaternion targetRot; if (__instance.buildPreviews.Count > 1) { targetPos = buildPreview.lpos; targetRot = buildPreview.lrot; } else { targetPos = __instance.previewPose.position + __instance.previewPose.rotation * buildPreview.lpos; targetRot = __instance.previewPose.rotation; } // ignore buildings not being built at ground level if (__instance.multiLevelCovering) { continue; } var entityPool = ___factory.entityPool; foreach (var inserter in ci) { // Find the desired belt/building position // As delta doesn't work over distance, re-trace the Grid Snapped steps from the original // to find the target belt/building for this inserters other connection var testPos = targetPos; // Note: rotates each move relative to the rotation of the new building for (int u = 0; u < inserter.snapCount; u++) { testPos = ___planetAux.Snap(testPos + targetRot * inserter.snapMoves[u], true, false); } // Find the other entity at the target location int otherId = 0; for (int x = 1; x < ___factory.entityCursor; x++) { if (entityPool[x].id == x) { var distance = Vector3.Distance(entityPool[x].pos, testPos); if (distance < 0.2) { otherId = entityPool[x].id; break; } } } if (otherId != 0) { // Order an inserter var pi = new PatchCopyInserters.PendingInserter(); pi.otherId = otherId; pi.ci = inserter; pi.AssemblerPos = targetPos; PatchCopyInserters.pendingInserters.Add(pi); } } } } }