public static void PlayerAction_BuildNotifyBuiltPrefix(int postObjId, PlanetAuxData ___planetAux) { var entityBuilt = pc.player.factory.entityPool[postObjId]; ModelProto modelProto = LDB.models.Select(entityBuilt.modelIndex); var prefabDesc = modelProto.prefabDesc; if (!prefabDesc.isInserter) { // Check for pending inserter requests if (PatchCopyInserters.pendingInserters.Count > 0) { var factory = pc.player.factory; for (int i = pendingInserters.Count - 1; i >= 0; i--) // Reverse loop for removing found elements { var pi = pendingInserters[i]; // Is the NotifyBuilt assembler in the expected position for this pending inserter? var distance = Vector3.Distance(entityBuilt.pos, pi.AssemblerPos); if (distance < 0.2) { var assemblerId = entityBuilt.id; //Debug.Log($"!!! found assembler id={assemblerId} at Pos={entityBuilt.pos} expected {pi.AssemblerPos} distance={distance}"); // Create inserter Prebuild data var pbdata = new PrebuildData(); pbdata.protoId = (short)pi.ci.protoId; pbdata.modelIndex = (short)LDB.items.Select(pi.ci.protoId).ModelIndex; pbdata.modelId = factory.entityPool[pi.otherId].modelId; pbdata.insertOffset = pi.ci.insertOffset; pbdata.pickOffset = pi.ci.pickOffset; pbdata.filterId = pi.ci.filterId; // YukkuriC: recover absolute transforms Helper.AbsTransform(entityBuilt.pos, pi.ci.posDelta, pi.ci.rot, out pbdata.pos, out pbdata.rot); Helper.AbsTransform(entityBuilt.pos, pi.ci.pos2delta, pi.ci.rot2, out pbdata.pos2, out pbdata.rot2); pbdata.pos = ___planetAux.Snap(pbdata.pos, true, false); pbdata.pos2 = ___planetAux.Snap(pbdata.pos2, true, false); // Check the player has the item in inventory, no cheating here var itemcount = pc.player.package.GetItemCount(pi.ci.protoId); // If player has none; skip this request, as we dont create prebuild ghosts, must avoid confusion if (itemcount > 0) { var qty = 1; pc.player.package.TakeTailItems(ref pi.ci.protoId, ref qty); int pbCursor = factory.AddPrebuildData(pbdata); // Add the inserter request to Prebuild pool // Otherslot -1 will try to find one, otherwise could cache this from original assembler if it causes problems if (pi.ci.incoming) { factory.WriteObjectConn(-pbCursor, 0, true, assemblerId, -1); // assembler connection factory.WriteObjectConn(-pbCursor, 1, false, pi.otherId, -1); // other connection } else { factory.WriteObjectConn(-pbCursor, 0, false, assemblerId, -1); // assembler connection factory.WriteObjectConn(-pbCursor, 1, true, pi.otherId, -1); // other connection } } pendingInserters.RemoveAt(i); } } } } }